Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove redefinition to vxlanhdr struct in vxlan dissector #1911

Merged
merged 2 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ PACK_ON
struct ndpi_vxlanhdr {
u_int16_t flags;
u_int16_t groupPolicy;
u_int32_t vni;
u_int8_t vni[3];
u_int8_t reserved;
} PACK_OFF;

/* ************************************************************ */
Expand Down
29 changes: 14 additions & 15 deletions src/lib/protocols/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,26 @@

/* This code handles VXLAN as per RFC 7348 */

struct vxlan_header {
u_int8_t flags[4]; /* the first byte is flags, other three are reserved */
u_int8_t vni[4]; /* the first three bytes are VNI, the last byte is reserved */
};

static void ndpi_check_vxlan(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int32_t payload_len = packet->payload_packet_len;

if((packet->udp != NULL) && (payload_len >= sizeof(struct vxlan_header))) {
u_int32_t vxlan_dst_port = ntohs(4789);
u_int32_t expected_flags = 0x08; /* only one bit should be set in the first byte */

struct vxlan_header *vxlan = (struct vxlan_header *)packet->payload;
if((packet->udp != NULL) && (packet->payload_packet_len >= sizeof(struct ndpi_vxlanhdr))) {

/*
*rfc-7348 vxlan header
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|R|R|R|R|I|R|R|R| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| VXLAN Network Identifier (VNI) | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
u_int32_t vxlan_dst_port = ntohs(4789);
struct ndpi_vxlanhdr *vxlanhdr = (struct ndpi_vxlanhdr *)packet->payload;
if((packet->udp->dest == vxlan_dst_port) &&
(vxlan->flags[0] == expected_flags) && (vxlan->flags[1] == 0x0) &&
(vxlan->flags[2] == 0x0) && (vxlan->flags[3] == 0x0) &&
(vxlan->vni[3] == 0x0)) {

(vxlanhdr->flags == ntohs(0x0800)) &&
(vxlanhdr->groupPolicy == 0x0) &&
(vxlanhdr->reserved == 0x0)) {
NDPI_LOG_INFO(ndpi_struct, "found vxlan\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_VXLAN, NDPI_PROTOCOL_VXLAN, NDPI_CONFIDENCE_DPI);
return;
Expand Down