Coverage Report

Created: 2025-07-18 07:07

/src/ndpi/src/lib/protocols/vxlan.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * vxlan.c
3
 *
4
 * Copyright (C) 2011-25 - ntop.org
5
 *
6
 * nDPI is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * nDPI is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 */
20
21
#include "ndpi_protocol_ids.h"
22
23
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_VXLAN
24
25
#include "ndpi_api.h"
26
#include "ndpi_private.h"
27
28
/* This code handles VXLAN as per RFC 7348 */
29
30
static void ndpi_check_vxlan(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
31
660
{
32
660
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
33
34
660
  if(packet->payload_packet_len >= sizeof(struct ndpi_vxlanhdr)) {
35
36
    /*
37
    *rfc-7348 vxlan header
38
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39
    |R|R|R|R|I|R|R|R|            Reserved                           |
40
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41
    |                VXLAN Network Identifier (VNI) |   Reserved    |
42
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43
    */
44
645
    u_int32_t vxlan_dst_port  = ntohs(4789);
45
645
    struct ndpi_vxlanhdr *vxlanhdr = (struct ndpi_vxlanhdr *)packet->payload;
46
645
    if((packet->udp->dest == vxlan_dst_port) &&
47
645
      (vxlanhdr->flags == ntohs(0x0800)) &&
48
645
      (vxlanhdr->groupPolicy == 0x0) &&
49
645
      (vxlanhdr->reserved == 0x0)) {
50
0
      NDPI_LOG_INFO(ndpi_struct, "found vxlan\n");
51
0
      ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_VXLAN, NDPI_PROTOCOL_VXLAN, NDPI_CONFIDENCE_DPI);
52
0
      return;
53
0
    }
54
645
  }
55
56
660
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
57
660
  return;
58
660
}
59
60
static void ndpi_search_vxlan(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
61
660
{
62
660
  NDPI_LOG_DBG(ndpi_struct, "search vxlan\n");
63
64
660
  ndpi_check_vxlan(ndpi_struct, flow);
65
660
}
66
67
void init_vxlan_dissector(struct ndpi_detection_module_struct *ndpi_struct)
68
7.49k
{
69
7.49k
  register_dissector("VXLAN", ndpi_struct,
70
7.49k
                     ndpi_search_vxlan,
71
7.49k
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
72
7.49k
                     1, NDPI_PROTOCOL_VXLAN);
73
7.49k
}