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