/src/ndpi/src/lib/protocols/pfcp.c
Line | Count | Source |
1 | | /* |
2 | | * pfcp.c |
3 | | * |
4 | | * Packet Forwarding Control 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_PFCP |
30 | | |
31 | | #include "ndpi_api.h" |
32 | | #include "ndpi_private.h" |
33 | | |
34 | | static void ndpi_search_pfcp(struct ndpi_detection_module_struct *ndpi_struct, |
35 | | struct ndpi_flow_struct *flow) |
36 | 533k | { |
37 | 533k | struct ndpi_packet_struct const * const packet = &ndpi_struct->packet; |
38 | | |
39 | 533k | NDPI_LOG_DBG(ndpi_struct, "search PFCP\n"); |
40 | | |
41 | 533k | if (packet->payload_packet_len > 12 && |
42 | 456k | (ntohs(packet->udp->dest) == 8805 || ntohs(packet->udp->source) == 8805)) |
43 | 1.68k | { |
44 | 1.68k | u_int8_t version = packet->payload[0] & 0x0F; |
45 | | /* Values from 18 to 49, 58 to 99 and 100 to 255 are reserved for future use |
46 | | * and aren't used now. */ |
47 | 1.68k | u_int8_t message_type = packet->payload[1]; |
48 | 1.68k | if (version == 1 && (message_type <= 17 || (message_type - 50) <= 7) && |
49 | 1.68k | ntohs(get_u_int16_t(packet->payload, 2)) == (u_int16_t)(packet->payload_packet_len-4)) |
50 | 97 | { |
51 | 97 | NDPI_LOG_INFO(ndpi_struct, "found PFCP\n"); |
52 | 97 | ndpi_set_detected_protocol(ndpi_struct, flow, |
53 | 97 | NDPI_PROTOCOL_PFCP, NDPI_PROTOCOL_UNKNOWN, |
54 | 97 | NDPI_CONFIDENCE_DPI); |
55 | 97 | return; |
56 | 97 | } |
57 | 1.68k | } |
58 | | |
59 | 533k | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
60 | 533k | } |
61 | | void init_pfcp_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
62 | 7.96k | { |
63 | 7.96k | register_dissector("PFCP", ndpi_struct, |
64 | 7.96k | ndpi_search_pfcp, |
65 | 7.96k | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD, |
66 | 7.96k | 1, NDPI_PROTOCOL_PFCP); |
67 | 7.96k | } |