PcapPlusPlus  21.05
PPPoELayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_PPPOE_LAYER
2 #define PACKETPP_PPPOE_LAYER
3 
4 #include "Layer.h"
5 #include <vector>
6 #include <string.h>
7 
9 
14 namespace pcpp
15 {
16 
21 #pragma pack(push, 1)
22  struct pppoe_header {
23 #if (BYTE_ORDER == LITTLE_ENDIAN)
24 
25  uint8_t version:4,
27  type:4;
29  uint8_t code;
30 #else
31 
32  uint16_t version:4,
34  type:4,
36  code:8;
37 #endif
38 
39  uint16_t sessionId;
41  uint16_t payloadLength;
42  };
43 #pragma pack(pop)
44 
45 
51  class PPPoELayer : public Layer
52  {
53  public:
57  enum PPPoECode
58  {
60  PPPOE_CODE_SESSION = 0x00,
62  PPPOE_CODE_PADO = 0x07,
64  PPPOE_CODE_PADI = 0x09,
66  PPPOE_CODE_PADG = 0x0a,
68  PPPOE_CODE_PADC = 0x0b,
70  PPPOE_CODE_PADQ = 0x0c,
72  PPPOE_CODE_PADR = 0x19,
74  PPPOE_CODE_PADS = 0x65,
76  PPPOE_CODE_PADT = 0xa7,
78  PPPOE_CODE_PADM = 0xd3,
80  PPPOE_CODE_PADN = 0xd4
81  };
82 
83  ~PPPoELayer() {}
84 
89  pppoe_header* getPPPoEHeader() const { return (pppoe_header*)m_Data; }
90 
91  // abstract methods implementation
92 
96  virtual void computeCalculateFields();
97 
99 
100  protected:
101 
102  // protected c'tor as this class shouldn't be instantiated
103  PPPoELayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { }
104 
105  // protected c'tor as this class shouldn't be instantiated
106  PPPoELayer(uint8_t version, uint8_t type, PPPoELayer::PPPoECode code, uint16_t sessionId, size_t additionalBytesToAllocate = 0);
107 
108  };
109 
110 
116  {
117  public:
118 
126  PPPoESessionLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : PPPoELayer(data, dataLen, prevLayer, packet) { m_Protocol = PPPoESession; }
127 
135  PPPoESessionLayer(uint8_t version, uint8_t type, uint16_t sessionId, uint16_t pppNextProtocol) : PPPoELayer(version, type, PPPoELayer::PPPOE_CODE_SESSION, sessionId, sizeof(uint16_t)) { setPPPNextProtocol(pppNextProtocol); }
136 
137  virtual ~PPPoESessionLayer() {}
138 
143  uint16_t getPPPNextProtocol() const;
144 
149  void setPPPNextProtocol(uint16_t nextProtocol);
150 
157  static inline bool isDataValid(const uint8_t* data, size_t dataLen);
158 
159  // abstract methods implementation
160 
164  virtual void parseNextLayer();
165 
169  virtual size_t getHeaderLen() const { return sizeof(pppoe_header) + sizeof(uint16_t); }
170 
171  virtual std::string toString() const;
172  };
173 
174 
175 
181  {
182  public:
187  {
189  PPPOE_TAG_EOL = 0x0000,
191  PPPOE_TAG_SVC_NAME = 0x0101,
193  PPPOE_TAG_AC_NAME = 0x0102,
195  PPPOE_TAG_HOST_UNIQ = 0x0103,
197  PPPOE_TAG_AC_COOKIE = 0x0104,
199  PPPOE_TAG_VENDOR = 0x0105,
201  PPPOE_TAG_CREDITS = 0x0106,
203  PPPOE_TAG_METRICS = 0x0107,
205  PPPOE_TAG_SEQ_NUM = 0x0108,
207  PPPOE_TAG_CRED_SCALE = 0x0109,
209  PPPOE_TAG_RELAY_ID = 0x0110,
211  PPPOE_TAG_HURL = 0x0111,
213  PPPOE_TAG_MOTM = 0x0112,
215  PPPOE_TAG_MAX_PAYLD = 0x0120,
217  PPPOE_TAG_IP_RT_ADD = 0x0121,
219  PPPOE_TAG_SVC_ERR = 0x0201,
221  PPPOE_TAG_AC_ERR = 0x0202,
223  PPPOE_TAG_GENERIC_ERR= 0x0203
224  };
225 
230  struct PPPoETag
231  {
232  public:
233 
235  uint16_t tagType;
237  uint16_t tagDataLength;
239  uint8_t tagData[];
240 
250  template<typename T>
251  T getTagDataAs(int tagDataOffset = 0) const
252  {
253  T result;
254  memcpy(&result, tagData + tagDataOffset, sizeof(T));
255  return result;
256  }
257 
266  template<typename T>
267  void setTagData(T value, int tagDataOffset = 0)
268  {
269  memcpy(tagData+tagDataOffset, &value, sizeof(T));
270  }
271 
275  size_t getTagTotalSize() const;
276 
280  PPPoEDiscoveryLayer::PPPoETagTypes getType() const;
281  private:
282  // private c'tor which isn't implemented to make this struct impossible to construct
283  PPPoETag();
284  };
285 
293  PPPoEDiscoveryLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : PPPoELayer(data, dataLen, prevLayer, packet) { m_Protocol = PPPoEDiscovery; m_TagCount = -1; m_DataLen = getHeaderLen(); }
294 
302  PPPoEDiscoveryLayer(uint8_t version, uint8_t type, PPPoELayer::PPPoECode code, uint16_t sessionId) : PPPoELayer(version, type, code, sessionId) { m_Protocol = PPPoEDiscovery; m_TagCount = -1; }
303 
311  PPPoETag* getTag(PPPoEDiscoveryLayer::PPPoETagTypes tagType) const;
312 
317  PPPoETag* getFirstTag() const;
318 
326  PPPoETag* getNextTag(PPPoETag* tag) const;
327 
331  int getTagCount() const;
332 
341  PPPoETag* addTag(PPPoETagTypes tagType, uint16_t tagLength, const uint8_t* tagData);
342 
352  PPPoETag* addTagAfter(PPPoETagTypes tagType, uint16_t tagLength, const uint8_t* tagData, PPPoETag* prevTag);
353 
360  bool removeTag(PPPoEDiscoveryLayer::PPPoETagTypes tagType);
361 
366  bool removeAllTags();
367 
374  static inline bool isDataValid(const uint8_t* data, size_t dataLen);
375 
376  // abstract methods implementation
377 
381  virtual void parseNextLayer() {}
382 
386  virtual size_t getHeaderLen() const;
387 
388  virtual std::string toString() const { return "PPP-over-Ethernet Discovery (" + codeToString((PPPoELayer::PPPoECode)getPPPoEHeader()->code) + ")"; }
389 
390  private:
391  mutable int m_TagCount;
392 
393  PPPoETag* addTagAt(PPPoETagTypes tagType, uint16_t tagLength, const uint8_t* tagData, int offset);
394 
395  PPPoETag* castPtrToPPPoETag(uint8_t* ptr) const;
396 
397  std::string codeToString(PPPoECode code) const;
398  };
399 
400 
401  // implementation of inline methods
402 
403  bool PPPoESessionLayer::isDataValid(const uint8_t* data, size_t dataLen)
404  {
405  return dataLen >= sizeof(pppoe_header) + sizeof(uint16_t);
406  }
407 
408  bool PPPoEDiscoveryLayer::isDataValid(const uint8_t* data, size_t dataLen)
409  {
410  return dataLen >= sizeof(pppoe_header);
411  }
412 
413  // Copied from Wireshark: ppptypes.h
414 
416 #define PCPP_PPP_PADDING 0x1
417 
418 #define PCPP_PPP_ROHC_SCID 0x3
419 
420 #define PCPP_PPP_ROHC_LCID 0x5
421 
422 #define PCPP_PPP_IP 0x21
423 
424 #define PCPP_PPP_OSI 0x23
425 
426 #define PCPP_PPP_XNSIDP 0x25
427 
428 #define PCPP_PPP_DEC4 0x27
429 
430 #define PCPP_PPP_AT 0x29
431 
432 #define PCPP_PPP_IPX 0x2b
433 
434 #define PCPP_PPP_VJC_COMP 0x2d
435 
436 #define PCPP_PPP_VJC_UNCOMP 0x2f
437 
438 #define PCPP_PPP_BCP 0x31
439 
440 #define PCPP_PPP_ST 0x33
441 
442 #define PCPP_PPP_VINES 0x35
443 
444 #define PCPP_PPP_AT_EDDP 0x39
445 
446 #define PCPP_PPP_AT_SB 0x3b
447 
448 #define PCPP_PPP_MP 0x3d
449 
450 #define PCPP_PPP_NB 0x3f
451 
452 #define PCPP_PPP_CISCO 0x41
453 
454 #define PCPP_PPP_ASCOM 0x43
455 
456 #define PCPP_PPP_LBLB 0x45
457 
458 #define PCPP_PPP_RL 0x47
459 
460 #define PCPP_PPP_SDTP 0x49
461 
462 #define PCPP_PPP_LLC 0x4b
463 
464 #define PCPP_PPP_SNA 0x4d
465 
466 #define PCPP_PPP_IPV6HC 0x4f
467 
468 #define PCPP_PPP_KNX 0x51
469 
470 #define PCPP_PPP_ENCRYPT 0x53
471 
472 #define PCPP_PPP_ILE 0x55
473 
474 #define PCPP_PPP_IPV6 0x57
475 
476 #define PCPP_PPP_MUX 0x59
477 
478 #define PCPP_PPP_VSNP 0x5b
479 
480 #define PCPP_PPP_TNP 0x5d
481 
482 #define PCPP_PPP_RTP_FH 0x61
483 
484 #define PCPP_PPP_RTP_CTCP 0x63
485 
486 #define PCPP_PPP_RTP_CNTCP 0x65
487 
488 #define PCPP_PPP_RTP_CUDP8 0x67
489 
490 #define PCPP_PPP_RTP_CRTP8 0x69
491 
492 #define PCPP_PPP_STAMPEDE 0x6f
493 
494 #define PCPP_PPP_MPPLUS 0x73
495 
496 #define PCPP_PPP_NTCITS_IPI 0xc1
497 
498 #define PCPP_PPP_ML_SLCOMP 0xfb
499 
500 #define PCPP_PPP_COMP 0xfd
501 
502 #define PCPP_PPP_STP_HELLO 0x0201
503 
504 #define PCPP_PPP_IBM_SR 0x0203
505 
506 #define PCPP_PPP_DEC_LB 0x0205
507 
508 #define PCPP_PPP_CDP 0x0207
509 
510 #define PCPP_PPP_NETCS 0x0209
511 
512 #define PCPP_PPP_STP 0x020b
513 
514 #define PCPP_PPP_EDP 0x020d
515 
516 #define PCPP_PPP_OSCP 0x0211
517 
518 #define PCPP_PPP_OSCP2 0x0213
519 
520 #define PCPP_PPP_LUXCOM 0x0231
521 
522 #define PCPP_PPP_SIGMA 0x0233
523 
524 #define PCPP_PPP_ACSP 0x0235
525 
526 #define PCPP_PPP_MPLS_UNI 0x0281
527 
528 #define PCPP_PPP_MPLS_MULTI 0x0283
529 
530 #define PCPP_PPP_P12844 0x0285
531 
532 #define PCPP_PPP_TETRA 0x0287
533 
534 #define PCPP_PPP_MFTP 0x0289
535 
536 #define PCPP_PPP_RTP_CTCPND 0x2063
537 
538 #define PCPP_PPP_RTP_CS 0x2065
539 
540 #define PCPP_PPP_RTP_CUDP16 0x2067
541 
542 #define PCPP_PPP_RTP_CRDP16 0x2069
543 
544 #define PCPP_PPP_CCCP 0x4001
545 
546 #define PCPP_PPP_CDPD_MNRP 0x4003
547 
548 #define PCPP_PPP_EXPANDAP 0x4005
549 
550 #define PCPP_PPP_ODSICP 0x4007
551 
552 #define PCPP_PPP_DOCSIS 0x4009
553 
554 #define PCPP_PPP_CETACEANNDP 0x400b
555 
556 #define PCPP_PPP_LZS 0x4021
557 
558 #define PCPP_PPP_REFTEK 0x4023
559 
560 #define PCPP_PPP_FC 0x4025
561 
562 #define PCPP_PPP_EMIT 0x4027
563 
564 #define PCPP_PPP_VSP 0x405b
565 
566 #define PCPP_PPP_TLSP 0x405d
567 
568 #define PCPP_PPP_IPCP 0x8021
569 
570 #define PCPP_PPP_OSINLCP 0x8023
571 
572 #define PCPP_PPP_XNSIDPCP 0x8025
573 
574 #define PCPP_PPP_DECNETCP 0x8027
575 
576 #define PCPP_PPP_ATCP 0x8029
577 
578 #define PCPP_PPP_IPXCP 0x802b
579 
580 #define PCPP_PPP_BRIDGENCP 0x8031
581 
582 #define PCPP_PPP_SPCP 0x8033
583 
584 #define PCPP_PPP_BVCP 0x8035
585 
586 #define PCPP_PPP_MLCP 0x803d
587 
588 #define PCPP_PPP_NBCP 0x803f
589 
590 #define PCPP_PPP_CISCOCP 0x8041
591 
592 #define PCPP_PPP_ASCOMCP 0x8043
593 
594 #define PCPP_PPP_LBLBCP 0x8045
595 
596 #define PCPP_PPP_RLNCP 0x8047
597 
598 #define PCPP_PPP_SDCP 0x8049
599 
600 #define PCPP_PPP_LLCCP 0x804b
601 
602 #define PCPP_PPP_SNACP 0x804d
603 
604 #define PCPP_PPP_IP6HCCP 0x804f
605 
606 #define PCPP_PPP_KNXCP 0x8051
607 
608 #define PCPP_PPP_ECP 0x8053
609 
610 #define PCPP_PPP_ILECP 0x8055
611 
612 #define PCPP_PPP_IPV6CP 0x8057
613 
614 #define PCPP_PPP_MUXCP 0x8059
615 
616 #define PCPP_PPP_VSNCP 0x805b
617 
618 #define PCPP_PPP_TNCP 0x805d
619 
620 #define PCPP_PPP_STAMPEDECP 0x806f
621 
622 #define PCPP_PPP_MPPCP 0x8073
623 
624 #define PCPP_PPP_IPICP 0x80c1
625 
626 #define PCPP_PPP_SLCC 0x80fb
627 
628 #define PCPP_PPP_CCP 0x80fd
629 
630 #define PCPP_PPP_CDPCP 0x8207
631 
632 #define PCPP_PPP_NETCSCP 0x8209
633 
634 #define PCPP_PPP_STPCP 0x820b
635 
636 #define PCPP_PPP_EDPCP 0x820d
637 
638 #define PCPP_PPP_ACSPC 0x8235
639 
640 #define PCPP_PPP_MPLSCP 0x8281
641 
642 #define PCPP_PPP_P12844CP 0x8285
643 
644 #define PCPP_PPP_TETRACP 0x8287
645 
646 #define PCPP_PPP_MFTPCP 0x8289
647 
648 #define PCPP_PPP_LCP 0xc021
649 
650 #define PCPP_PPP_PAP 0xc023
651 
652 #define PCPP_PPP_LQR 0xc025
653 
654 #define PCPP_PPP_SPAP 0xc027
655 
656 #define PCPP_PPP_CBCP 0xc029
657 
658 #define PCPP_PPP_BACP 0xc02b
659 
660 #define PCPP_PPP_BAP 0xc02d
661 
662 #define PCPP_PPP_VSAP 0xc05b
663 
664 #define PCPP_PPP_CONTCP 0xc081
665 
666 #define PCPP_PPP_CHAP 0xc223
667 
668 #define PCPP_PPP_RSAAP 0xc225
669 
670 #define PCPP_PPP_EAP 0xc227
671 
672 #define PCPP_PPP_SIEP 0xc229
673 
674 #define PCPP_PPP_SBAP 0xc26f
675 
676 #define PCPP_PPP_PRPAP 0xc281
677 
678 #define PCPP_PPP_PRPAP2 0xc283
679 
680 #define PCPP_PPP_PRPNIAP 0xc481
681 
682 } // namespace pcpp
683 
684 #endif /* PACKETPP_PPPOE_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:253
PPPoETagTypes
Definition: PPPoELayer.h:186
const ProtocolType PPPoEDiscovery
Definition: ProtocolType.h:93
uint16_t tagType
Definition: PPPoELayer.h:235
Definition: PPPoELayer.h:115
Definition: PPPoELayer.h:180
Definition: ProtocolType.h:258
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: PPPoELayer.h:408
Definition: Layer.h:70
const ProtocolType PPPoESession
Definition: ProtocolType.h:88
Definition: PPPoELayer.h:230
Definition: PPPoELayer.h:51
Definition: Packet.h:26
void setTagData(T value, int tagDataOffset=0)
Definition: PPPoELayer.h:267
virtual void parseNextLayer()
Definition: PPPoELayer.h:381
uint8_t type
Definition: PPPoELayer.h:25
virtual size_t getHeaderLen() const
Definition: PPPoELayer.h:169
PPPoECode
Definition: PPPoELayer.h:57
PPPoEDiscoveryLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: PPPoELayer.h:293
PPPoESessionLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: PPPoELayer.h:126
OsiModelLayer getOsiModelLayer() const
Definition: PPPoELayer.h:98
uint16_t tagDataLength
Definition: PPPoELayer.h:237
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: PPPoELayer.h:403
PPPoEDiscoveryLayer(uint8_t version, uint8_t type, PPPoELayer::PPPoECode code, uint16_t sessionId)
Definition: PPPoELayer.h:302
virtual std::string toString() const
Definition: PPPoELayer.h:388
uint8_t code
Definition: PPPoELayer.h:29
pppoe_header * getPPPoEHeader() const
Definition: PPPoELayer.h:89
uint16_t sessionId
Definition: PPPoELayer.h:39
Definition: PPPoELayer.h:22
uint16_t payloadLength
Definition: PPPoELayer.h:41
uint8_t version
Definition: PPPoELayer.h:25
T getTagDataAs(int tagDataOffset=0) const
Definition: PPPoELayer.h:251
PPPoESessionLayer(uint8_t version, uint8_t type, uint16_t sessionId, uint16_t pppNextProtocol)
Definition: PPPoELayer.h:135