/src/PcapPlusPlus/Packet++/header/VxlanLayer.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef PACKETPP_VXLAN_LAYER |
2 | | #define PACKETPP_VXLAN_LAYER |
3 | | |
4 | | #include "Layer.h" |
5 | | |
6 | | /// @file |
7 | | |
8 | | namespace pcpp |
9 | | { |
10 | | |
11 | | /** |
12 | | * @struct vxlan_header |
13 | | * Represents a VXLAN protocol header |
14 | | */ |
15 | | #pragma pack(push, 1) |
16 | | struct vxlan_header |
17 | | { |
18 | | #if(BYTE_ORDER == LITTLE_ENDIAN) |
19 | | /** Reserved bits */ |
20 | | uint16_t reserved6_8:3; |
21 | | /** VNI present flag */ |
22 | | uint16_t vniPresentFlag:1; |
23 | | /** Reserved bits */ |
24 | | uint16_t reserved2_4:3; |
25 | | /** GBP flag */ |
26 | | uint16_t gbpFlag:1; |
27 | | /** Reserved bits */ |
28 | | uint16_t reserved14_16:3; |
29 | | /** Policy applied flag */ |
30 | | uint16_t policyAppliedFlag:1; |
31 | | /** Reserved bits */ |
32 | | uint16_t reserved11_12:2; |
33 | | /** Don't learn flag */ |
34 | | uint16_t dontLearnFlag:1; |
35 | | /** Reserved bits */ |
36 | | uint16_t reserved9:1; |
37 | | #else |
38 | | /** Reserved bits */ |
39 | | uint16_t reserved9:1; |
40 | | /** Don't learn flag */ |
41 | | uint16_t dontLearnFlag:1; |
42 | | /** Reserved bits */ |
43 | | uint16_t reserved11_12:2; |
44 | | /** Policy applied flag */ |
45 | | uint16_t policyAppliedFlag:1; |
46 | | /** Reserved bits */ |
47 | | uint16_t reserved14_16:3; |
48 | | /** GBP flag */ |
49 | | uint16_t gbpFlag:1; |
50 | | /** Reserved bits */ |
51 | | uint16_t reserved2_4:3; |
52 | | /** VNI present flag */ |
53 | | uint16_t vniPresentFlag:1; |
54 | | /** Reserved bits */ |
55 | | uint16_t reserved6_8:3; |
56 | | #endif |
57 | | |
58 | | /** Group Policy ID */ |
59 | | uint16_t groupPolicyID; |
60 | | |
61 | | /** VXLAN Network ID (VNI) */ |
62 | | uint32_t vni:24; |
63 | | /** Reserved bits */ |
64 | | uint32_t pad:8; |
65 | | }; |
66 | | #pragma pack(pop) |
67 | | |
68 | | |
69 | | /** |
70 | | * @class VxlanLayer |
71 | | * Represents a VXLAN (Virtual eXtensible Local Area Network) protocol layer |
72 | | */ |
73 | | class VxlanLayer : public Layer |
74 | | { |
75 | | public: |
76 | | /** A constructor that creates the layer from an existing packet raw data |
77 | | * @param[in] data A pointer to the raw data |
78 | | * @param[in] dataLen Size of the data in bytes |
79 | | * @param[in] prevLayer A pointer to the previous layer |
80 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
81 | | */ |
82 | 99 | VxlanLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = VXLAN; } |
83 | | |
84 | | /** |
85 | | * A constructor that creates a new VXLAN header and allocates the data. Note: the VNI present flag is set automatically |
86 | | * @param[in] vni VNI (VXLAN Network ID) to set. Optional parameter (default is 0) |
87 | | * @param[in] groupPolicyID Group Policy ID to set. Optional parameter (default is 0) |
88 | | * @param[in] setGbpFlag Set GBP flag. Optional parameter (default is false) |
89 | | * @param[in] setPolicyAppliedFlag Set Policy Applied flag. Optional parameter (default is false) |
90 | | * @param[in] setDontLearnFlag Set Don't Learn flag. Optional parameter (default is false) |
91 | | */ |
92 | | VxlanLayer(uint32_t vni = 0, uint16_t groupPolicyID = 0, bool setGbpFlag = false, bool setPolicyAppliedFlag = false, bool setDontLearnFlag = false); |
93 | | |
94 | 0 | ~VxlanLayer() {} |
95 | | |
96 | | /** |
97 | | * Get a pointer to the VXLAN header. Notice this points directly to the data, so every change will change the actual packet data |
98 | | * @return A pointer to the vxlan_header |
99 | | */ |
100 | 0 | vxlan_header* getVxlanHeader() const { return (vxlan_header*)m_Data; } |
101 | | |
102 | | /** |
103 | | * @return The VXLAN Network ID (VNI) value |
104 | | */ |
105 | | uint32_t getVNI() const; |
106 | | |
107 | | /** |
108 | | * Set VXLAN Network ID (VNI) value |
109 | | * @param[in] vni VNI value to set |
110 | | */ |
111 | | void setVNI(uint32_t vni); |
112 | | |
113 | | /** |
114 | | * A static method that checks whether the port is considered as VxLAN |
115 | | * @param[in] port The port number to be checked |
116 | | */ |
117 | 129k | static bool isVxlanPort(uint16_t port) { return port == 4789; } |
118 | | |
119 | | |
120 | | // implement abstract methods |
121 | | |
122 | | /** |
123 | | * Next layer for VXLAN is always Ethernet |
124 | | */ |
125 | | void parseNextLayer(); |
126 | | |
127 | | /** |
128 | | * @return Size of vxlan_header |
129 | | */ |
130 | 0 | size_t getHeaderLen() const { return sizeof(vxlan_header); } |
131 | | |
132 | | /** |
133 | | * Does nothing for this layer |
134 | | */ |
135 | 0 | void computeCalculateFields() {} |
136 | | |
137 | | std::string toString() const; |
138 | | |
139 | 99 | OsiModelLayer getOsiModelLayer() const { return OsiModelDataLinkLayer; } |
140 | | |
141 | | }; |
142 | | |
143 | | } |
144 | | |
145 | | #endif // PACKETPP_VXLAN_LAYER |