/src/ndpi/src/lib/protocols/ldp.c
Line | Count | Source |
1 | | /* |
2 | | * ldp.c |
3 | | * |
4 | | * Label Distribution Protocol |
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_LDP |
30 | | |
31 | | #include "ndpi_api.h" |
32 | | #include "ndpi_private.h" |
33 | | |
34 | | enum ldp_message_types |
35 | | { |
36 | | LDP_INITIALIZATION = 0x0200, |
37 | | LDP_KEEPALIVE = 0x0201, |
38 | | LDP_CAPABILITY = 0x0202, |
39 | | LDP_ADDRESS = 0x0300, |
40 | | LDP_ADDRESS_WITHDRAWAL = 0x0301, |
41 | | LDP_LABEL_MAPPING = 0x0400, |
42 | | LDP_LABEL_REQUEST = 0x0401, |
43 | | LDP_LABEL_WITHDRAWAL = 0x0402, |
44 | | LDP_LABEL_RELEASE = 0x0403, |
45 | | LDP_LABEL_ABORT_REQUEST = 0x0404, |
46 | | LDP_CALL_SETUP = 0x0500, |
47 | | LDP_CALL_RELEASE = 0x0501, |
48 | | LDP_RG_CONNECT_MESSAGE = 0x0700, |
49 | | LDP_RG_DISCONNECT_MESSAGE = 0x0701, |
50 | | LDP_RG_NOTIFICATION_MESSAGE = 0x0702, |
51 | | LDP_RG_APPLICATION_DATA_MESSAGE = 0x0703 |
52 | | }; |
53 | | |
54 | | static void ndpi_int_ldp_add_connection(struct ndpi_detection_module_struct *ndpi_struct, |
55 | | struct ndpi_flow_struct *flow) |
56 | 719 | { |
57 | 719 | NDPI_LOG_INFO(ndpi_struct, "found LDP\n"); |
58 | 719 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_LDP, |
59 | 719 | NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
60 | 719 | } |
61 | | |
62 | | static void ndpi_search_ldp(struct ndpi_detection_module_struct *ndpi_struct, |
63 | | struct ndpi_flow_struct *flow) |
64 | 2.75M | { |
65 | 2.75M | struct ndpi_packet_struct const * const packet = &ndpi_struct->packet; |
66 | | |
67 | 2.75M | NDPI_LOG_DBG(ndpi_struct, "search LDP\n"); |
68 | | |
69 | 2.75M | if (packet->payload_packet_len > 19 && |
70 | 2.75M | ntohs(get_u_int16_t(packet->payload, 0)) == 1 && |
71 | 2.75M | ntohs(get_u_int16_t(packet->payload, 2)) == (u_int16_t)(packet->payload_packet_len-4)) |
72 | 3.17k | { |
73 | | /* LDP Hello Message */ |
74 | 3.17k | if (packet->udp != NULL && |
75 | 3.17k | ntohs(get_u_int16_t(packet->payload, 10)) == 0x0100) |
76 | 148 | { |
77 | 148 | ndpi_int_ldp_add_connection(ndpi_struct, flow); |
78 | 148 | return; |
79 | 148 | } |
80 | 3.02k | else if (packet->tcp != NULL) { |
81 | 682 | u_int16_t ldp_msg_type = ntohs(get_u_int16_t(packet->payload, 10)); |
82 | | |
83 | | /* Vendor defined message types */ |
84 | 682 | if (ldp_msg_type >= 0x3E00 && ldp_msg_type <= 0x3EFF) { |
85 | 40 | ndpi_int_ldp_add_connection(ndpi_struct, flow); |
86 | 40 | return; |
87 | 40 | } |
88 | | |
89 | 642 | switch (ldp_msg_type) { |
90 | 61 | case LDP_INITIALIZATION: |
91 | 94 | case LDP_KEEPALIVE: |
92 | 119 | case LDP_CAPABILITY: |
93 | 169 | case LDP_ADDRESS: |
94 | 207 | case LDP_ADDRESS_WITHDRAWAL: |
95 | 248 | case LDP_LABEL_MAPPING: |
96 | 284 | case LDP_LABEL_REQUEST: |
97 | 306 | case LDP_LABEL_WITHDRAWAL: |
98 | 326 | case LDP_LABEL_RELEASE: |
99 | 354 | case LDP_LABEL_ABORT_REQUEST: |
100 | 385 | case LDP_CALL_SETUP: |
101 | 407 | case LDP_CALL_RELEASE: |
102 | 444 | case LDP_RG_CONNECT_MESSAGE: |
103 | 473 | case LDP_RG_DISCONNECT_MESSAGE: |
104 | 501 | case LDP_RG_NOTIFICATION_MESSAGE: |
105 | 531 | case LDP_RG_APPLICATION_DATA_MESSAGE: |
106 | 531 | ndpi_int_ldp_add_connection(ndpi_struct, flow); |
107 | 531 | return; |
108 | 111 | default: |
109 | 111 | break; |
110 | 642 | } |
111 | 642 | } |
112 | 3.17k | } |
113 | | |
114 | 2.75M | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
115 | 2.75M | } |
116 | | |
117 | | void init_ldp_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
118 | 8.35k | { |
119 | 8.35k | register_dissector("LDP", ndpi_struct, |
120 | 8.35k | ndpi_search_ldp, |
121 | 8.35k | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, |
122 | 8.35k | 1, NDPI_PROTOCOL_LDP); |
123 | 8.35k | } |