Coverage Report

Created: 2024-02-25 06:29

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