diff options
-rw-r--r-- | src/include/ndpi_protocol_ids.h | 3 | ||||
-rw-r--r-- | src/include/ndpi_protocols.h | 2 | ||||
-rw-r--r-- | src/include/ndpi_typedefs.h | 4 | ||||
-rw-r--r-- | src/lib/Makefile.am | 1 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 11 | ||||
-rw-r--r-- | src/lib/protocols/rx.c | 130 | ||||
-rw-r--r-- | tests/pcap/rx.pcap | bin | 0 -> 31116 bytes | |||
-rw-r--r-- | tests/result/rx.pcap.out | 7 |
8 files changed, 157 insertions, 1 deletions
diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h index cfc0ad56d..f6ddec191 100644 --- a/src/include/ndpi_protocol_ids.h +++ b/src/include/ndpi_protocol_ids.h @@ -271,8 +271,9 @@ #define NDPI_SERVICE_CLOUDFLARE 220 #define NDPI_SERVICE_MS_ONE_DRIVE 221 #define NDPI_PROTOCOL_MQTT 222 +#define NDPI_PROTOCOL_RX 223 /* RX: RPC protocol used by AFS */ /* UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE */ -#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_PROTOCOL_MQTT +#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_PROTOCOL_RX #define NDPI_MAX_SUPPORTED_PROTOCOLS (NDPI_LAST_IMPLEMENTED_PROTOCOL + 1) #define NDPI_MAX_NUM_CUSTOM_PROTOCOLS (NDPI_NUM_BITS-NDPI_LAST_IMPLEMENTED_PROTOCOL) diff --git a/src/include/ndpi_protocols.h b/src/include/ndpi_protocols.h index b5df1c937..1672ee178 100644 --- a/src/include/ndpi_protocols.h +++ b/src/include/ndpi_protocols.h @@ -198,6 +198,7 @@ void ndpi_search_starcraft(struct ndpi_detection_module_struct *ndpi_struct, str void ndpi_search_ubntac2(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_coap(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); +void ndpi_search_rx(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); /* --- INIT FUNCTIONS --- */ void init_afp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_aimini_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); @@ -337,4 +338,5 @@ void init_stracraft_dissector(struct ndpi_detection_module_struct *ndpi_struct, void init_ubntac2_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_coap_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_mqtt_dissector (struct ndpi_detection_module_struct *ndpi_struct,u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); +void init_rx_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); #endif /* __NDPI_PROTOCOLS_H__ */ diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h index ed74b9a07..de0201bde 100644 --- a/src/include/ndpi_typedefs.h +++ b/src/include/ndpi_typedefs.h @@ -622,6 +622,10 @@ struct ndpi_flow_udp_struct { u_int8_t eaq_pkt_id; u_int32_t eaq_sequence; #endif +#ifdef NDPI_PROTOCOL_RX + u_int32_t rx_conn_epoch; + u_int32_t rx_conn_id; +#endif } #ifndef WIN32 __attribute__ ((__packed__)) diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index abda7ede1..d83fdd5c0 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -154,6 +154,7 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \ protocols/zeromq.c \ protocols/coap.c \ protocols/mqtt.c \ + protocols/rx.c \ third_party/include/actypes.h \ third_party/include/ahocorasick.h \ third_party/include/node.h \ diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 8fe3a54d7..f76f9f333 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -1528,6 +1528,14 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp no_master, "MQTT", ndpi_build_default_ports(ports_a, 1883, 8883, 0, 0, 0), /* TCP */ ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0)); /* UDP */ + ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0); + ports_b[0].port_low = 7000; + ports_b[0].port_high = 7032; /* See https://www-01.ibm.com/support/docview.wss?uid=swg21044407 */ + ndpi_set_proto_defaults(ndpi_mod,NDPI_PROTOCOL_ACCEPTABLE,NDPI_PROTOCOL_RX, + no_master, + no_master, "RX", + ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0), /* TCP */ + ports_b); /* UDP */ /* calling function for host and content matched protocols */ init_string_based_protocols(ndpi_mod); @@ -2495,6 +2503,9 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n /* MQTT */ init_mqtt_dissector(ndpi_struct, &a, detection_bitmask); + /* RX */ + init_rx_dissector(ndpi_struct, &a, detection_bitmask); + /* Put false-positive sensitive protocols at the end */ /* SKYPE */ diff --git a/src/lib/protocols/rx.c b/src/lib/protocols/rx.c new file mode 100644 index 000000000..07d4b5985 --- /dev/null +++ b/src/lib/protocols/rx.c @@ -0,0 +1,130 @@ +/* + * rx.c + * + * Copyright (C) 2012-16 - ntop.org + * + * Giovanni Mascellani <gio@debian.org> + * + * This file is part of nDPI, an open source deep packet inspection + * library based on the OpenDPI and PACE technology by ipoque GmbH + * + * nDPI is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * nDPI is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with nDPI. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include "ndpi_api.h" + +#ifdef NDPI_PROTOCOL_RX + +/* See http://web.mit.edu/kolya/afs/rx/rx-spec for procotol description. */ + +/* The should be no need for explicit packing, but just in case... */ +struct __attribute__((__packed__)) ndpi_rx_header { + u_int32_t conn_epoch; + u_int32_t conn_id; + u_int32_t call_number; + u_int32_t sequence_number; + u_int32_t serial_number; + u_int8_t type; + u_int8_t flags; + u_int8_t status; + u_int8_t security; + u_int16_t checksum; + u_int16_t service_id; +}; + +void ndpi_check_rx(struct ndpi_detection_module_struct *ndpi_struct, + struct ndpi_flow_struct *flow) +{ + struct ndpi_packet_struct *packet = &flow->packet; + u_int32_t payload_len = packet->payload_packet_len; + int exclude = 0; + int found = 0; + + NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "RX: pck: %d, dir[0]: %d, dir[1]: %d\n", + flow->packet_counter, flow->packet_direction_counter[0], flow->packet_direction_counter[1]); + + /* Check that packet is long enough. */ + if (payload_len < sizeof(struct ndpi_rx_header)) { + NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "short packet\n"); + exclude = 1; + goto end; + } + + /* Check whether the packet has counters beginning from one; the + Sequence Number can be zero if the packet is just an ACK. */ + struct ndpi_rx_header *header = (struct ndpi_rx_header*) packet->payload; + if ((ntohl(header->sequence_number) | 1) != 1 || ntohl(header->serial_number) != 1) { + NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "wrong counters\n"); + exclude = 1; + goto end; + } + + /* If we have already seen one packet in the other direction, then + the two must have matching connection numbers. Otherwise store + them. */ + if (flow->packet_direction_counter[!packet->packet_direction] != 0) { + if (flow->l4.udp.rx_conn_epoch == header->conn_epoch && + flow->l4.udp.rx_conn_id == header->conn_id) { + found = 1; + /* In theory we could inspect the service_id field of the header + to know exactly which service is being used; see + https://www.central.org/frameless/numbers/rxservice.html. */ + } else { + NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "IDs not matching\n"); + exclude = 1; + } + goto end; + } else { + flow->l4.udp.rx_conn_epoch = header->conn_epoch; + flow->l4.udp.rx_conn_id = header->conn_id; + } + + end: + if (found) { + NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "found RX\n"); + ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RX, NDPI_PROTOCOL_UNKNOWN); + } + else if (exclude) { + NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n"); + NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX); + } +} + +void ndpi_search_rx(struct ndpi_detection_module_struct *ndpi_struct, + struct ndpi_flow_struct *flow) +{ + struct ndpi_packet_struct *packet = &flow->packet; + + NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "entering RX search\n"); + if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_RX) { + ndpi_check_rx(ndpi_struct, flow); + } +} + +void init_rx_dissector(struct ndpi_detection_module_struct *ndpi_struct, + u_int32_t *id, + NDPI_PROTOCOL_BITMASK *detection_bitmask) +{ + ndpi_set_bitmask_protocol_detection("RX", ndpi_struct, detection_bitmask, *id, + NDPI_PROTOCOL_RX, + ndpi_search_rx, + NDPI_SELECTION_BITMASK_PROTOCOL_UDP_WITH_PAYLOAD, + SAVE_DETECTION_BITMASK_AS_UNKNOWN, + ADD_TO_DETECTION_BITMASK); + + *id += 1; +} + +#endif diff --git a/tests/pcap/rx.pcap b/tests/pcap/rx.pcap Binary files differnew file mode 100644 index 000000000..68fd825ac --- /dev/null +++ b/tests/pcap/rx.pcap diff --git a/tests/result/rx.pcap.out b/tests/result/rx.pcap.out new file mode 100644 index 000000000..1339732cb --- /dev/null +++ b/tests/result/rx.pcap.out @@ -0,0 +1,7 @@ +RX 132 26475 5 + + 1 UDP 192.167.206.124:7002 <-> 131.114.219.168:38331 [proto: 223/RX][3 pkts/519 bytes] + 2 UDP 192.167.206.124:7002 <-> 131.114.219.168:41559 [proto: 223/RX][3 pkts/519 bytes] + 3 UDP 192.167.206.124:7003 <-> 131.114.219.168:7001 [proto: 223/RX][27 pkts/9919 bytes] + 4 UDP 131.114.219.168:7001 <-> 192.167.206.241:7000 [proto: 223/RX][79 pkts/12376 bytes] + 5 UDP 192.167.206.124:7000 <-> 131.114.219.168:7001 [proto: 223/RX][20 pkts/3142 bytes] |