PcapPlusPlus  19.12
RadiusLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_RADIUS_LAYER
2 #define PACKETPP_RADIUS_LAYER
3 
4 #include "Layer.h"
5 #include "TLVData.h"
6 
8 
13 namespace pcpp
14 {
15 
20 #pragma pack(push, 1)
22  {
24  uint8_t code;
26  uint8_t id;
28  uint16_t length;
30  uint8_t authenticator[16];
31  };
32 #pragma pack(pop)
33 
34 
40  class RadiusAttribute : public TLVRecord
41  {
42  public:
43 
48  RadiusAttribute(uint8_t* attrRawData) : TLVRecord(attrRawData) { }
49 
53  virtual ~RadiusAttribute() { }
54 
55  // implement abstract methods
56 
57  size_t getTotalSize() const
58  {
59  return (size_t)m_Data->recordLen;
60  }
61 
62  size_t getDataSize() const
63  {
64  return (size_t)m_Data->recordLen - 2*sizeof(uint8_t);
65  }
66  };
67 
68 
75  {
76  public:
77 
85  RadiusAttributeBuilder(uint8_t attrType, const uint8_t* attrValue, uint8_t attrValueLen) :
86  TLVRecordBuilder(attrType, attrValue, attrValueLen) { }
87 
94  RadiusAttributeBuilder(uint8_t attrType, uint8_t attrValue) :
95  TLVRecordBuilder(attrType, attrValue) { }
96 
103  RadiusAttributeBuilder(uint8_t attrType, uint16_t attrValue) :
104  TLVRecordBuilder(attrType, attrValue) { }
105 
112  RadiusAttributeBuilder(uint8_t attrType, uint32_t attrValue) :
113  TLVRecordBuilder(attrType, attrValue) { }
114 
121  RadiusAttributeBuilder(uint8_t attrType, const IPv4Address& attrValue) :
122  TLVRecordBuilder(attrType, attrValue) { }
123 
130  RadiusAttributeBuilder(uint8_t attrType, const std::string& attrValue) :
131  TLVRecordBuilder(attrType, attrValue) { }
132 
138  TLVRecordBuilder(other) { }
139 
144  RadiusAttribute build() const;
145  };
146 
147 
152  class RadiusLayer : public Layer
153  {
154  private:
155 
156  TLVRecordReader<RadiusAttribute> m_AttributeReader;
157 
158  uint8_t* getAttributesBasePtr() const { return m_Data + sizeof(radius_header); }
159 
160  RadiusAttribute addAttrAt(const RadiusAttributeBuilder& attrBuilder, int offset);
161 
162  public:
163 
171  RadiusLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) :
172  Layer(data, dataLen, prevLayer, packet)
173  { m_Protocol = Radius; }
174 
184  RadiusLayer(uint8_t code, uint8_t id, const uint8_t* authenticator, uint8_t authenticatorArrSize);
185 
195  RadiusLayer(uint8_t code, uint8_t id, const std::string authenticator);
196 
201 
206  radius_header* getRadiusHeader() const { return (radius_header*)m_Data; }
207 
211  std::string getAuthenticatorValue() const;
212 
217  void setAuthenticatorValue(const std::string& authValue);
218 
225  static std::string getRadiusMessageString(uint8_t radiusMessageCode);
226 
232 
241 
248  RadiusAttribute getAttribute(uint8_t attrType) const;
249 
253  size_t getAttributeCount() const;
254 
262 
270  RadiusAttribute addAttributeAfter(const RadiusAttributeBuilder& attrBuilder, uint8_t prevAttrType);
271 
277  bool removeAttribute(uint8_t attrType);
278 
283  bool removeAllAttributes();
284 
285 
286  // implement abstract methods
287 
291  size_t getHeaderLen() const;
292 
296  void parseNextLayer() {}
297 
301  void computeCalculateFields();
302 
303  std::string toString() const;
304 
306 
313  static bool isDataValid(const uint8_t* udpData, size_t udpDataLen);
314 
315  };
316 }
317 
318 #endif // PACKETPP_RADIUS_LAYER
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:224
pcpp::TLVRecord
Definition: TLVData.h:23
pcpp::RadiusLayer::getFirstAttribute
RadiusAttribute getFirstAttribute() const
pcpp::IPv4Address
Definition: IpAddress.h:119
pcpp::RadiusLayer::addAttributeAfter
RadiusAttribute addAttributeAfter(const RadiusAttributeBuilder &attrBuilder, uint8_t prevAttrType)
pcpp::Packet
Definition: Packet.h:26
pcpp::RadiusAttributeBuilder::RadiusAttributeBuilder
RadiusAttributeBuilder(uint8_t attrType, const uint8_t *attrValue, uint8_t attrValueLen)
Definition: RadiusLayer.h:85
pcpp::RadiusAttribute::getTotalSize
size_t getTotalSize() const
Definition: RadiusLayer.h:57
pcpp::RadiusAttributeBuilder
Definition: RadiusLayer.h:74
pcpp::radius_header::code
uint8_t code
Definition: RadiusLayer.h:24
pcpp::Radius
Definition: ProtocolType.h:206
Layer.h
pcpp::RadiusLayer::getRadiusMessageString
static std::string getRadiusMessageString(uint8_t radiusMessageCode)
pcpp::RadiusAttribute::getDataSize
size_t getDataSize() const
Definition: RadiusLayer.h:62
pcpp::RadiusAttributeBuilder::RadiusAttributeBuilder
RadiusAttributeBuilder(uint8_t attrType, const IPv4Address &attrValue)
Definition: RadiusLayer.h:121
pcpp::RadiusLayer::getRadiusHeader
radius_header * getRadiusHeader() const
Definition: RadiusLayer.h:206
pcpp::RadiusLayer::removeAttribute
bool removeAttribute(uint8_t attrType)
pcpp::RadiusAttribute
Definition: RadiusLayer.h:40
pcpp::radius_header::id
uint8_t id
Definition: RadiusLayer.h:26
pcpp::RadiusLayer::removeAllAttributes
bool removeAllAttributes()
pcpp::RadiusAttribute::~RadiusAttribute
virtual ~RadiusAttribute()
Definition: RadiusLayer.h:53
pcpp::RadiusLayer::isDataValid
static bool isDataValid(const uint8_t *udpData, size_t udpDataLen)
TLVData.h
pcpp::RadiusAttribute::RadiusAttribute
RadiusAttribute(uint8_t *attrRawData)
Definition: RadiusLayer.h:48
pcpp::radius_header::length
uint16_t length
Definition: RadiusLayer.h:28
pcpp::RadiusLayer::RadiusLayer
RadiusLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: RadiusLayer.h:171
pcpp::RadiusAttributeBuilder::RadiusAttributeBuilder
RadiusAttributeBuilder(uint8_t attrType, const std::string &attrValue)
Definition: RadiusLayer.h:130
pcpp::radius_header::authenticator
uint8_t authenticator[16]
Definition: RadiusLayer.h:30
pcpp::RadiusLayer::setAuthenticatorValue
void setAuthenticatorValue(const std::string &authValue)
pcpp::RadiusAttributeBuilder::RadiusAttributeBuilder
RadiusAttributeBuilder(uint8_t attrType, uint32_t attrValue)
Definition: RadiusLayer.h:112
pcpp::RadiusAttributeBuilder::RadiusAttributeBuilder
RadiusAttributeBuilder(const RadiusAttributeBuilder &other)
Definition: RadiusLayer.h:137
pcpp::RadiusAttributeBuilder::build
RadiusAttribute build() const
pcpp::RadiusLayer::toString
std::string toString() const
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::RadiusLayer::addAttribute
RadiusAttribute addAttribute(const RadiusAttributeBuilder &attrBuilder)
pcpp::TLVRecordBuilder
Definition: TLVData.h:351
pcpp::RadiusLayer
Definition: RadiusLayer.h:152
pcpp::OsiModelSesionLayer
Definition: ProtocolType.h:235
pcpp::RadiusAttributeBuilder::RadiusAttributeBuilder
RadiusAttributeBuilder(uint8_t attrType, uint16_t attrValue)
Definition: RadiusLayer.h:103
pcpp::RadiusLayer::computeCalculateFields
void computeCalculateFields()
pcpp::Layer
Definition: Layer.h:70
pcpp::RadiusLayer::getAttributeCount
size_t getAttributeCount() const
pcpp::TLVRecordReader
Definition: TLVData.h:197
pcpp::radius_header
Definition: RadiusLayer.h:21
pcpp::RadiusLayer::parseNextLayer
void parseNextLayer()
Definition: RadiusLayer.h:296
pcpp::RadiusLayer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: RadiusLayer.h:305
pcpp::RadiusLayer::getAuthenticatorValue
std::string getAuthenticatorValue() const
pcpp::RadiusLayer::~RadiusLayer
~RadiusLayer()
Definition: RadiusLayer.h:200
pcpp::TLVRecord::TLVRawData::recordLen
uint8_t recordLen
Definition: TLVData.h:33
pcpp::RadiusLayer::getAttribute
RadiusAttribute getAttribute(uint8_t attrType) const
pcpp::RadiusLayer::getHeaderLen
size_t getHeaderLen() const
pcpp::RadiusAttributeBuilder::RadiusAttributeBuilder
RadiusAttributeBuilder(uint8_t attrType, uint8_t attrValue)
Definition: RadiusLayer.h:94
pcpp::RadiusLayer::getNextAttribute
RadiusAttribute getNextAttribute(RadiusAttribute &attr) const