/src/ndpi/src/lib/protocols/bfd.c
Line | Count | Source |
1 | | /* |
2 | | * bfd.c |
3 | | * |
4 | | * Bidirectional Forwarding Detection |
5 | | * |
6 | | * Copyright (C) 2024 - ntop.org |
7 | | * Copyright (C) 2024 - V.G <v.gavrilov@securitycode.ru> |
8 | | * |
9 | | * This file is part of nDPI, an open source deep packet inspection |
10 | | * library based on the OpenDPI and PACE technology by ipoque GmbH |
11 | | * |
12 | | * nDPI is free software: you can redistribute it and/or modify |
13 | | * it under the terms of the GNU Lesser General Public License as published by |
14 | | * the Free Software Foundation, either version 3 of the License, or |
15 | | * (at your option) any later version. |
16 | | * |
17 | | * nDPI is distributed in the hope that it will be useful, |
18 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | | * GNU Lesser General Public License for more details. |
21 | | * |
22 | | * You should have received a copy of the GNU Lesser General Public License |
23 | | * along with nDPI. If not, see <http://www.gnu.org/licenses/>. |
24 | | * |
25 | | */ |
26 | | |
27 | | #include "ndpi_protocol_ids.h" |
28 | | |
29 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_BFD |
30 | | |
31 | | #include "ndpi_api.h" |
32 | | #include "ndpi_private.h" |
33 | | |
34 | | static void ndpi_int_bfd_add_connection(struct ndpi_detection_module_struct *ndpi_struct, |
35 | | struct ndpi_flow_struct *flow) |
36 | 0 | { |
37 | 0 | NDPI_LOG_INFO(ndpi_struct, "found BFD\n"); |
38 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BFD, |
39 | 0 | NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
40 | 0 | } |
41 | | |
42 | | static void ndpi_search_bfd(struct ndpi_detection_module_struct *ndpi_struct, |
43 | | struct ndpi_flow_struct *flow) |
44 | 0 | { |
45 | 0 | struct ndpi_packet_struct const * const packet = &ndpi_struct->packet; |
46 | | |
47 | | /* BFD echo message */ |
48 | 0 | if (packet->payload_packet_len == 12 && ntohs(packet->udp->dest) == 3785) { |
49 | 0 | if (ndpi_ntohll(get_u_int64_t(packet->payload, 0)) == 1 && |
50 | 0 | ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len-2)) == 0) |
51 | 0 | { |
52 | 0 | ndpi_int_bfd_add_connection(ndpi_struct, flow); |
53 | 0 | return; |
54 | 0 | } |
55 | 0 | } |
56 | | |
57 | | /* BFD control message */ |
58 | 0 | if ((packet->payload_packet_len > 23 && packet->payload_packet_len <= 100) && |
59 | 0 | ntohs(packet->udp->dest) == 3784) |
60 | 0 | { |
61 | 0 | if (((packet->payload[0] & 0xE0) >> 5) < 2 && |
62 | 0 | packet->payload[3] == (u_int8_t)packet->payload_packet_len) |
63 | 0 | { |
64 | 0 | ndpi_int_bfd_add_connection(ndpi_struct, flow); |
65 | 0 | return; |
66 | 0 | } |
67 | 0 | } |
68 | | |
69 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
70 | 0 | } |
71 | | void init_bfd_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
72 | 0 | { |
73 | 0 | register_dissector("BFD", ndpi_struct, |
74 | 0 | ndpi_search_bfd, |
75 | 0 | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD, |
76 | 0 | 1, NDPI_PROTOCOL_BFD); |
77 | 0 | } |