Compare commits

...
12 Commits
Author SHA1 Message Date
Michele Campus 625ed3d4e4 Merge pull request #478 from hvanderheide/1.7-stable
Add ndpi_includes.h to include headers
2017-10-23 11:57:13 +02:00
Hidde van der Heide 16fc15fba2 Add ndpi_includes.h to include headers
Add this header file to the proper variable so it gets installed to the
system
2017-10-19 17:12:16 +02:00
Michele Campus 5b140565b1 Merge pull request #285 from vpiserchia/1.7-stable
Fix KAKAOTALK VOICE MACRO name
2016-11-03 15:11:10 +01:00
Vito Piserchia cc83d808de Fix KAKAOTALK VOICE MACRO name 2016-11-03 15:06:46 +01:00
Luca Deri a121161480 Added missing HEP initialization 2015-12-04 21:34:26 +01:00
Luca Deri e4fd4bc9f9 Typedef refresh 2015-11-30 18:46:52 +01:00
Luca Deri ff04ff42fe Merge pull request #105 from vel21ripn/1.7-stable
ndpi_search_dns: fix potential buffer overflow
2015-10-09 14:59:25 +02:00
Vitaly Lavrov 8c4fada42f ndpi_search_mail_smtp_tcp: minor fix for starttls command 2015-10-09 15:15:34 +03:00
Vitaly Lavrov 4e5b7f625d ndpi_search_dns: fix potential buffer overflow 2015-10-09 14:45:16 +03:00
Luca Deri a3d66b0777 Fixes #83. Critical fix: due to an invalid endianess conversion some protocol were not properly indetified 2015-08-26 16:15:54 +02:00
Luca Deri 49983c07b8 Updated formula for 1.7 release 2015-08-18 11:57:36 +02:00
Luca Deri 431b139e44 Sync formula with homebrew 2015-08-18 11:32:34 +02:00
24 changed files with 1187 additions and 1107 deletions
+375 -173
View File
@@ -42,18 +42,50 @@
#include <pcap.h>
#include <signal.h>
#include <pthread.h>
#include <sys/socket.h>
#include "../config.h"
#include "ndpi_api.h"
#ifdef HAVE_JSON_C
#include <json.h>
#endif
#include "ndpi_api.h"
#include <sys/socket.h>
#define MAX_NUM_READER_THREADS 16
#define IDLE_SCAN_PERIOD 10 /* msec (use detection_tick_resolution = 1000) */
#define MAX_IDLE_TIME 30000
#define IDLE_SCAN_BUDGET 1024
#define NUM_ROOTS 512
#define GTP_U_V1_PORT 2152
#define TZSP_PORT 37008
#define MAX_NDPI_FLOWS 200000000
#ifndef ETH_P_IP
#define ETH_P_IP 0x0800 /* IPv4 */
#endif
#ifndef ETH_P_IPv6
#define ETH_P_IPV6 0x86dd /* IPv6 */
#endif
#define SLARP 0x8035 /* Cisco Slarp */
#define CISCO_D_PROTO 0x2000 /* Cisco Discovery Protocol */
#define VLAN 0x8100
#define MPLS_UNI 0x8847
#define MPLS_MULTI 0x8848
#define PPPoE 0x8864
#define SNAP 0xaa
/* mask for FCF */
#define WIFI_DATA 0x2 /* 0000 0010 */
#define FCF_TYPE(fc) (((fc) >> 2) & 0x3) /* 0000 0011 = 0x3 */
#define FCF_SUBTYPE(fc) (((fc) >> 4) & 0xF) /* 0000 1111 = 0xF */
#define FCF_TO_DS(fc) ((fc) & 0x0100)
#define FCF_FROM_DS(fc) ((fc) & 0x0200)
/* mask for Bad FCF presence */
#define BAD_FCS 0x50 /* 0101 0000 */
/**
* @brief Set main components necessary to the detection
@@ -100,12 +132,6 @@ static u_int32_t detection_tick_resolution = 1000;
static time_t capture_for = 0;
static time_t capture_until = 0;
#define IDLE_SCAN_PERIOD 10 /* msec (use detection_tick_resolution = 1000) */
#define MAX_IDLE_TIME 30000
#define IDLE_SCAN_BUDGET 1024
#define NUM_ROOTS 512
static u_int32_t num_flows;
struct thread_stats {
@@ -143,21 +169,15 @@ struct reader_thread {
static struct reader_thread ndpi_thread_info[MAX_NUM_READER_THREADS];
#define GTP_U_V1_PORT 2152
#define MAX_NDPI_FLOWS 200000000
/**
* @brief ID tracking
*/
typedef struct ndpi_id {
u_int8_t ip[4]; //< Ip address
struct ndpi_id_struct *ndpi_id; //< nDpi worker structure
u_int8_t ip[4]; // Ip address
struct ndpi_id_struct *ndpi_id; // nDpi worker structure
} ndpi_id_t;
static u_int32_t size_id_struct = 0; //< ID tracking structure size
#ifndef ETH_P_IP
#define ETH_P_IP 0x0800
#endif
static u_int32_t size_id_struct = 0; // ID tracking structure size
// flow tracking
typedef struct ndpi_flow {
@@ -168,10 +188,9 @@ typedef struct ndpi_flow {
u_int8_t detection_completed, protocol;
u_int16_t vlan_id;
struct ndpi_flow_struct *ndpi_flow;
char lower_name[32], upper_name[32];
char lower_name[48], upper_name[48];
u_int8_t ip_version;
u_int64_t last_seen;
u_int64_t bytes;
u_int32_t packets;
@@ -207,7 +226,7 @@ static void help(u_int long_help) {
#endif
" -d | Disable protocol guess and use only DPI\n"
" -q | Quiet mode\n"
" -t | Dissect GTP tunnels\n"
" -t | Dissect GTP/TZSP tunnels\n"
" -r | Print nDPI version and git revision\n"
" -w <path> | Write test output on the specified file. This is useful for\n"
" | testing purposes in order to compare results across runs\n"
@@ -476,19 +495,18 @@ static void printFlow(u_int16_t thread_id, struct ndpi_flow *flow) {
FILE *out = results_file ? results_file : stdout;
if(!json_flag) {
#if 0
fprintf(out, "\t%s [VLAN: %u] %s:%u <-> %s:%u\n",
ipProto2Name(flow->protocol), flow->vlan_id,
flow->lower_name, ntohs(flow->lower_port),
flow->upper_name, ntohs(flow->upper_port));
#else
fprintf(out, "\t%u", ++num_flows);
fprintf(out, "\t%s %s:%u <-> %s:%u ",
ipProto2Name(flow->protocol),
flow->lower_name, ntohs(flow->lower_port),
flow->upper_name, ntohs(flow->upper_port));
fprintf(out, "\t%s %s%s%s:%u <-> %s%s%s:%u ",
ipProto2Name(flow->protocol),
(flow->ip_version == 6) ? "[" : "",
flow->lower_name,
(flow->ip_version == 6) ? "]" : "",
ntohs(flow->lower_port),
(flow->ip_version == 6) ? "[" : "",
flow->upper_name,
(flow->ip_version == 6) ? "]" : "",
ntohs(flow->upper_port));
if(flow->vlan_id > 0) fprintf(out, "[VLAN: %u]", flow->vlan_id);
@@ -505,14 +523,13 @@ static void printFlow(u_int16_t thread_id, struct ndpi_flow *flow) {
ndpi_get_proto_name(ndpi_thread_info[thread_id].ndpi_struct, flow->detected_protocol.protocol));
fprintf(out, "[%u pkts/%llu bytes]",
flow->packets, (long long unsigned int)flow->bytes);
flow->packets, (long long unsigned int)flow->bytes);
if(flow->host_server_name[0] != '\0') fprintf(out, "[Host: %s]", flow->host_server_name);
if(flow->ssl.client_certificate[0] != '\0') fprintf(out, "[SSL client: %s]", flow->ssl.client_certificate);
if(flow->ssl.server_certificate[0] != '\0') fprintf(out, "[SSL server: %s]", flow->ssl.server_certificate);
fprintf(out, "\n");
#endif
} else {
#ifdef HAVE_JSON_C
jObj = json_object_new_object();
@@ -633,16 +650,6 @@ static void node_proto_guess_walker(const void *node, ndpi_VISIT which, int dept
struct ndpi_flow *flow = *(struct ndpi_flow **) node;
u_int16_t thread_id = *((u_int16_t *) user_data);
#if 0
printf("<%d>Walk on node %s (%p)\n",
depth,
which == preorder?"preorder":
which == postorder?"postorder":
which == endorder?"endorder":
which == leaf?"leaf": "unknown",
flow);
#endif
if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
if(enable_protocol_guess) {
if(flow->detected_protocol.protocol == NDPI_PROTOCOL_UNKNOWN) {
@@ -706,23 +713,27 @@ static struct ndpi_flow *get_ndpi_flow(u_int16_t thread_id,
const u_int8_t version,
u_int16_t vlan_id,
const struct ndpi_iphdr *iph,
const struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
u_int16_t ipsize,
u_int16_t l4_packet_len,
struct ndpi_tcphdr **tcph,
struct ndpi_udphdr **udph,
u_int16_t *sport, u_int16_t *dport,
struct ndpi_id_struct **src,
struct ndpi_id_struct **dst,
u_int8_t *proto,
const struct ndpi_ip6_hdr *iph6) {
u_int8_t **payload,
u_int16_t *payload_len,
u_int8_t *src_to_dst_direction) {
u_int32_t idx, l4_offset;
struct ndpi_tcphdr *tcph = NULL;
struct ndpi_udphdr *udph = NULL;
u_int32_t lower_ip;
u_int32_t upper_ip;
u_int16_t lower_port;
u_int16_t upper_port;
struct ndpi_flow flow;
void *ret;
u_int8_t *l3;
u_int8_t *l3, *l4;
/*
Note: to keep things simple (ndpiReader is just a demo app)
@@ -739,7 +750,7 @@ static struct ndpi_flow *get_ndpi_flow(u_int16_t thread_id,
l4_offset = iph->ihl * 4;
l3 = (u_int8_t*)iph;
} else {
l4_offset = sizeof(struct ndpi_ip6_hdr);
l4_offset = sizeof(struct ndpi_ipv6hdr);
l3 = (u_int8_t*)iph6;
}
@@ -768,19 +779,25 @@ static struct ndpi_flow *get_ndpi_flow(u_int16_t thread_id,
}
*proto = iph->protocol;
l4 = ((u_int8_t *) l3 + l4_offset);
if(iph->protocol == 6 && l4_packet_len >= 20) {
u_int tcp_len;
ndpi_thread_info[thread_id].stats.tcp_count++;
// tcp
tcph = (struct ndpi_tcphdr *) ((u_int8_t *) l3 + l4_offset);
*tcph = (struct ndpi_tcphdr *)l4;
*sport = ntohs((*tcph)->source), *dport = ntohs((*tcph)->dest);
if(iph->saddr < iph->daddr) {
lower_port = tcph->source;
upper_port = tcph->dest;
lower_port = (*tcph)->source, upper_port = (*tcph)->dest;
*src_to_dst_direction = 1;
} else {
lower_port = tcph->dest;
upper_port = tcph->source;
lower_port = (*tcph)->dest;
upper_port = (*tcph)->source;
*src_to_dst_direction = 0;
if(iph->saddr == iph->daddr) {
if(lower_port > upper_port) {
u_int16_t p = lower_port;
@@ -790,18 +807,38 @@ static struct ndpi_flow *get_ndpi_flow(u_int16_t thread_id,
}
}
}
tcp_len = ndpi_min(4*(*tcph)->doff, l4_packet_len);
*payload = &l4[tcp_len];
*payload_len = ndpi_max(0, l4_packet_len-4*(*tcph)->doff);
} else if(iph->protocol == 17 && l4_packet_len >= 8) {
// udp
ndpi_thread_info[thread_id].stats.udp_count++;
udph = (struct ndpi_udphdr *) ((u_int8_t *) l3 + l4_offset);
*udph = (struct ndpi_udphdr *)l4;
*sport = ntohs((*udph)->source), *dport = ntohs((*udph)->dest);
*payload = &l4[sizeof(struct ndpi_udphdr)];
*payload_len = ndpi_max(0, l4_packet_len-sizeof(struct ndpi_udphdr));
if(iph->saddr < iph->daddr) {
lower_port = udph->source;
upper_port = udph->dest;
lower_port = (*udph)->source, upper_port = (*udph)->dest;
*src_to_dst_direction = 1;
} else {
lower_port = udph->dest;
upper_port = udph->source;
lower_port = (*udph)->dest, upper_port = (*udph)->source;
*src_to_dst_direction = 0;
if(iph->saddr == iph->daddr) {
if(lower_port > upper_port) {
u_int16_t p = lower_port;
lower_port = upper_port;
upper_port = p;
}
}
}
*sport = ntohs(lower_port), *dport = ntohs(upper_port);
} else {
// non tcp/udp protocols
lower_port = 0;
@@ -835,6 +872,7 @@ static struct ndpi_flow *get_ndpi_flow(u_int16_t thread_id,
newflow->protocol = iph->protocol, newflow->vlan_id = vlan_id;
newflow->lower_ip = lower_ip, newflow->upper_ip = upper_ip;
newflow->lower_port = lower_port, newflow->upper_port = upper_port;
newflow->ip_version = version;
if(version == 4) {
inet_ntop(AF_INET, &lower_ip, newflow->lower_name, sizeof(newflow->lower_name));
@@ -871,8 +909,7 @@ static struct ndpi_flow *get_ndpi_flow(u_int16_t thread_id,
*src = newflow->src_id, *dst = newflow->dst_id;
// printFlow(thread_id, newflow);
return newflow ;
return newflow;
}
} else {
struct ndpi_flow *flow = *(struct ndpi_flow**)ret;
@@ -891,29 +928,36 @@ static struct ndpi_flow *get_ndpi_flow(u_int16_t thread_id,
static struct ndpi_flow *get_ndpi_flow6(u_int16_t thread_id,
u_int16_t vlan_id,
const struct ndpi_ip6_hdr *iph6,
const struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
struct ndpi_tcphdr **tcph,
struct ndpi_udphdr **udph,
u_int16_t *sport, u_int16_t *dport,
struct ndpi_id_struct **src,
struct ndpi_id_struct **dst,
u_int8_t *proto) {
u_int8_t *proto,
u_int8_t **payload,
u_int16_t *payload_len,
u_int8_t *src_to_dst_direction) {
struct ndpi_iphdr iph;
memset(&iph, 0, sizeof(iph));
iph.version = 4;
iph.saddr = iph6->ip6_src.__u6_addr.__u6_addr32[2] + iph6->ip6_src.__u6_addr.__u6_addr32[3];
iph.daddr = iph6->ip6_dst.__u6_addr.__u6_addr32[2] + iph6->ip6_dst.__u6_addr.__u6_addr32[3];
iph.saddr = iph6->ip6_src.u6_addr.u6_addr32[2] + iph6->ip6_src.u6_addr.u6_addr32[3];
iph.daddr = iph6->ip6_dst.u6_addr.u6_addr32[2] + iph6->ip6_dst.u6_addr.u6_addr32[3];
iph.protocol = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
if(iph.protocol == 0x3C /* IPv6 destination option */) {
u_int8_t *options = (u_int8_t*)iph6 + sizeof(const struct ndpi_ip6_hdr);
u_int8_t *options = (u_int8_t*)iph6 + sizeof(const struct ndpi_ipv6hdr);
iph.protocol = options[0];
}
return(get_ndpi_flow(thread_id, 6, vlan_id, &iph, ip_offset,
sizeof(struct ndpi_ip6_hdr),
return(get_ndpi_flow(thread_id, 6, vlan_id, &iph, iph6, ip_offset,
sizeof(struct ndpi_ipv6hdr),
ntohs(iph6->ip6_ctlun.ip6_un1.ip6_un1_plen),
src, dst, proto, iph6));
tcph, udph, sport, dport,
src, dst, proto, payload, payload_len, src_to_dst_direction));
}
/* ***************************************************** */
@@ -938,8 +982,8 @@ static void setupDetection(u_int16_t thread_id) {
ndpi_set_protocol_detection_bitmask2(ndpi_thread_info[thread_id].ndpi_struct, &all);
// allocate memory for id and flow tracking
size_id_struct = ndpi_detection_get_sizeof_ndpi_id_struct();
size_flow_struct = ndpi_detection_get_sizeof_ndpi_flow_struct();
size_id_struct = sizeof(struct ndpi_id_struct);
size_flow_struct = sizeof(struct ndpi_flow_struct);
// clear memory for results
memset(ndpi_thread_info[thread_id].stats.protocol_counter, 0, sizeof(ndpi_thread_info[thread_id].stats.protocol_counter));
@@ -970,20 +1014,31 @@ static unsigned int packet_processing(u_int16_t thread_id,
const u_int64_t time,
u_int16_t vlan_id,
const struct ndpi_iphdr *iph,
struct ndpi_ip6_hdr *iph6,
struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
u_int16_t ipsize, u_int16_t rawsize) {
struct ndpi_id_struct *src, *dst;
struct ndpi_flow *flow;
struct ndpi_flow_struct *ndpi_flow = NULL;
u_int8_t proto;
struct ndpi_tcphdr *tcph = NULL;
struct ndpi_udphdr *udph = NULL;
u_int16_t sport, dport, payload_len;
u_int8_t *payload;
u_int8_t src_to_dst_direction= 1;
if(iph)
flow = get_ndpi_flow(thread_id, 4, vlan_id, iph, ip_offset, ipsize,
flow = get_ndpi_flow(thread_id, 4, vlan_id, iph, NULL,
ip_offset, ipsize,
ntohs(iph->tot_len) - (iph->ihl * 4),
&src, &dst, &proto, NULL);
&tcph, &udph, &sport, &dport,
&src, &dst, &proto,
&payload, &payload_len, &src_to_dst_direction);
else
flow = get_ndpi_flow6(thread_id, vlan_id, iph6, ip_offset, &src, &dst, &proto);
flow = get_ndpi_flow6(thread_id, vlan_id, iph6, ip_offset,
&tcph, &udph, &sport, &dport,
&src, &dst, &proto,
&payload, &payload_len, &src_to_dst_direction);
if(flow != NULL) {
ndpi_thread_info[thread_id].stats.ip_packet_count++;
@@ -1000,7 +1055,7 @@ static unsigned int packet_processing(u_int16_t thread_id,
flow->detected_protocol = ndpi_detection_process_packet(ndpi_thread_info[thread_id].ndpi_struct, ndpi_flow,
iph ? (uint8_t *)iph : (uint8_t *)iph6,
ipsize, time, src, dst);
if((flow->detected_protocol.protocol != NDPI_PROTOCOL_UNKNOWN)
|| ((proto == IPPROTO_UDP) && (flow->packets > 8))
|| ((proto == IPPROTO_TCP) && (flow->packets > 10))) {
@@ -1016,31 +1071,6 @@ static unsigned int packet_processing(u_int16_t thread_id,
snprintf(flow->ssl.server_certificate, sizeof(flow->ssl.server_certificate), "%s", flow->ndpi_flow->protos.ssl.server_certificate);
}
#if 0
if(verbose > 1) {
if(ndpi_is_proto(flow->detected_protocol, NDPI_PROTOCOL_HTTP)) {
char *method;
printf("[URL] %s\n", ndpi_get_http_url(ndpi_thread_info[thread_id].ndpi_struct, ndpi_flow));
printf("[Content-Type] %s\n", ndpi_get_http_content_type(ndpi_thread_info[thread_id].ndpi_struct, ndpi_flow));
switch(ndpi_get_http_method(ndpi_thread_info[thread_id].ndpi_struct, ndpi_flow)) {
case HTTP_METHOD_OPTIONS: method = "HTTP_METHOD_OPTIONS"; break;
case HTTP_METHOD_GET: method = "HTTP_METHOD_GET"; break;
case HTTP_METHOD_HEAD: method = "HTTP_METHOD_HEAD"; break;
case HTTP_METHOD_POST: method = "HTTP_METHOD_POST"; break;
case HTTP_METHOD_PUT: method = "HTTP_METHOD_PUT"; break;
case HTTP_METHOD_DELETE: method = "HTTP_METHOD_DELETE"; break;
case HTTP_METHOD_TRACE: method = "HTTP_METHOD_TRACE"; break;
case HTTP_METHOD_CONNECT: method = "HTTP_METHOD_CONNECT"; break;
default: method = "HTTP_METHOD_UNKNOWN"; break;
}
printf("[Method] %s\n", method);
}
}
#endif
free_ndpi_flow(flow);
if(verbose > 1) {
@@ -1055,11 +1085,6 @@ static unsigned int packet_processing(u_int16_t thread_id,
}
}
#if 0
if(ndpi_flow->l4.tcp.host_server_name[0] != '\0')
printf("%s\n", ndpi_flow->l4.tcp.host_server_name);
#endif
if(live_capture) {
if(ndpi_thread_info[thread_id].last_idle_scan_time + IDLE_SCAN_PERIOD < ndpi_thread_info[thread_id].last_time) {
/* scan for idle flows */
@@ -1525,86 +1550,229 @@ static void openPcapFileOrDevice(u_int16_t thread_id) {
/* ***************************************************** */
static void pcap_packet_callback(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) {
static void pcap_packet_callback(u_char *args,
const struct pcap_pkthdr *header,
const u_char *packet) {
/*
* Declare pointers to packet headers
*/
/* --- Ethernet header --- */
const struct ndpi_ethhdr *ethernet;
/* --- Ethernet II header --- */
const struct ndpi_ethhdr *ethernet_2;
/* --- LLC header --- */
const struct ndpi_llc_header *llc;
/* --- Cisco HDLC header --- */
const struct ndpi_chdlc *chdlc;
/* --- SLARP frame --- */
struct ndpi_slarp *slarp;
/* --- CDP --- */
struct ndpi_cdp *cdp;
/* --- Radio Tap header --- */
const struct ndpi_radiotap_header *radiotap;
/* --- Wifi header --- */
const struct ndpi_wifi_header *wifi;
/* --- MPLS header --- */
struct ndpi_mpls_header *mpls;
/** --- IP header --- **/
struct ndpi_iphdr *iph;
struct ndpi_ip6_hdr *iph6;
/** --- IPv6 header --- **/
struct ndpi_ipv6hdr *iph6;
/* lengths and offsets */
u_int16_t eth_offset = 0;
u_int16_t radio_len;
u_int16_t fc;
u_int16_t type;
int wifi_len;
int llc_off;
int pyld_eth_len = 0;
int check;
u_int32_t fcs;
u_int64_t time;
u_int16_t type, ip_offset, ip_len;
u_int16_t ip_offset, ip_len, ip6_offset;
u_int16_t frag_off = 0, vlan_id = 0;
u_int8_t proto = 0, vlan_packet = 0;
u_int8_t proto = 0;
u_int32_t label;
u_int16_t thread_id = *((u_int16_t*)args);
// printf("[ndpiReader] pcap_packet_callback : [%u.%u.%u.%u.%u -> %u.%u.%u.%u.%u]\n", ethernet->h_dest[1],ethernet->h_dest[2],ethernet->h_dest[3],ethernet->h_dest[4],ethernet->h_dest[5],ethernet->h_source[1],ethernet->h_source[2],ethernet->h_source[3],ethernet->h_source[4],ethernet->h_source[5]);
/* counters */
u_int8_t malformed_pkts = 0, vlan_packet = 0;
u_int8_t slarp_pkts = 0, cdp_pkts = 0;
/* Increment raw packet counter */
ndpi_thread_info[thread_id].stats.raw_packet_count++;
if((capture_until != 0) && (header->ts.tv_sec >= capture_until)) {
if(ndpi_thread_info[thread_id]._pcap_handle != NULL)
pcap_breakloop(ndpi_thread_info[thread_id]._pcap_handle);
return;
}
/* Check if capture is live or not */
if (!live_capture) {
if (!pcap_start.tv_sec) pcap_start.tv_sec = header->ts.tv_sec, pcap_start.tv_usec = header->ts.tv_usec;
pcap_end.tv_sec = header->ts.tv_sec, pcap_end.tv_usec = header->ts.tv_usec;
}
/* setting time */
time = ((uint64_t) header->ts.tv_sec) * detection_tick_resolution +
header->ts.tv_usec / (1000000 / detection_tick_resolution);
if(ndpi_thread_info[thread_id].last_time > time) { /* safety check */
// printf("\nWARNING: timestamp bug in the pcap file (ts delta: %llu, repairing)\n", ndpi_thread_info[thread_id].last_time - time);
/* safety check */
if(ndpi_thread_info[thread_id].last_time > time) {
/* printf("\nWARNING: timestamp bug in the pcap file (ts delta: %llu, repairing)\n", ndpi_thread_info[thread_id].last_time - time); */
time = ndpi_thread_info[thread_id].last_time;
}
/* update last time value */
ndpi_thread_info[thread_id].last_time = time;
if(ndpi_thread_info[thread_id]._pcap_datalink_type == DLT_NULL) {
if(ntohl(*((u_int32_t*)packet)) == 2)
type = ETH_P_IP;
else
type = 0x86DD; /* IPv6 */
/*** check Data Link type ***/
int datalink_type = ndpi_thread_info[thread_id]._pcap_datalink_type;
ip_offset = 4;
} else if(ndpi_thread_info[thread_id]._pcap_datalink_type == DLT_EN10MB) {
ethernet = (struct ndpi_ethhdr *) packet;
ip_offset = sizeof(struct ndpi_ethhdr);
type = ntohs(ethernet->h_proto);
} else if(ndpi_thread_info[thread_id]._pcap_datalink_type == 113 /* Linux Cooked Capture */) {
type = (packet[14] << 8) + packet[15];
ip_offset = 16;
} else
return;
datalink_check:
switch(datalink_type) {
while(1) {
if(type == 0x8100 /* VLAN */) {
vlan_id = ((packet[ip_offset] << 8) + packet[ip_offset+1]) & 0xFFF;
type = (packet[ip_offset+2] << 8) + packet[ip_offset+3];
ip_offset += 4;
vlan_packet = 1;
} else if(type == 0x8847 /* MPLS */) {
u_int32_t label = ntohl(*((u_int32_t*)&packet[ip_offset]));
case DLT_NULL :
if(ntohl(*((u_int32_t*)&packet[eth_offset])) == 2)
type = ETH_P_IP;
else
type = ETH_P_IPV6;
ndpi_thread_info[thread_id].stats.mpls_count++;
type = 0x800, ip_offset += 4;
ip_offset = 4 + eth_offset;
while((label & 0x100) != 0x100) {
ip_offset += 4;
label = ntohl(*((u_int32_t*)&packet[ip_offset]));
}
} else if(type == 0x8864 /* PPPoE */) {
ndpi_thread_info[thread_id].stats.pppoe_count++;
type = 0x0800;
ip_offset += 8;
} else
/* Cisco PPP in HDLC-like framing - 50 */
case DLT_PPP_SERIAL:
chdlc = (struct ndpi_chdlc *) &packet[eth_offset];
ip_offset = sizeof(struct ndpi_chdlc); /* CHDLC_OFF = 4 */
type = ntohs(chdlc->proto_code);
break;
}
/* Cisco PPP with HDLC framing - 104 */
case DLT_C_HDLC:
chdlc = (struct ndpi_chdlc *) &packet[eth_offset];
ip_offset = sizeof(struct ndpi_chdlc); /* CHDLC_OFF = 4 */
type = ntohs(chdlc->proto_code);
break;
/* IEEE 802.3 Ethernet - 1 */
case DLT_EN10MB :
ethernet = (struct ndpi_ethhdr *) &packet[eth_offset];
ip_offset = sizeof(struct ndpi_ethhdr) + eth_offset;
check = ntohs(ethernet->h_proto);
if(check <= 1500)
pyld_eth_len = check;
else if (check >= 1536)
type = check;
if(pyld_eth_len != 0) {
/* check for LLC layer with SNAP extension */
if(packet[ip_offset] == SNAP) {
llc = (struct ndpi_llc_header *)(&packet[ip_offset]);
type = llc->snap.proto_ID;
ip_offset += + 8;
}
}
break;
/* Linux Cooked Capture - 113 */
case DLT_LINUX_SLL :
type = (packet[eth_offset+14] << 8) + packet[eth_offset+15];
ip_offset = 16 + eth_offset;
break;
/* Radiotap link-layer - 127 */
case DLT_IEEE802_11_RADIO :
radiotap = (struct ndpi_radiotap_header *) &packet[eth_offset];
radio_len = radiotap->len;
/* Check Bad FCS presence */
if((radiotap->flags & BAD_FCS) == BAD_FCS) {
malformed_pkts += 1;
ndpi_thread_info[thread_id].stats.total_discarded_bytes += header->len;
return;
}
fcs = header->len - 4;
/* Calculate 802.11 header length (variable) */
wifi = (struct ndpi_wifi_header*)( packet + eth_offset + radio_len);
fc = wifi->fc;
/* check wifi data presence */
if(FCF_TYPE(fc) == WIFI_DATA) {
if((FCF_TO_DS(fc) && FCF_FROM_DS(fc) == 0x0) ||
(FCF_TO_DS(fc) == 0x0 && FCF_FROM_DS(fc)))
wifi_len = 26; /* + 4 byte fcs */
} else /* no data frames */
break;
/* Check ether_type from LLC */
llc = (struct ndpi_llc_header*)(packet + eth_offset + wifi_len + radio_len);
if(llc->dsap == SNAP)
type = ntohs(llc->snap.proto_ID);
/* Set IP header offset */
ip_offset = wifi_len + radio_len + sizeof(struct ndpi_llc_header) + eth_offset;
break;
default:
return;
}
/* check ether type */
if(type == VLAN) {
vlan_id = ((packet[ip_offset] << 8) + packet[ip_offset+1]) & 0xFFF;
type = (packet[ip_offset+2] << 8) + packet[ip_offset+3];
ip_offset += 4;
vlan_packet = 1;
}
else if(type == MPLS_UNI || type == MPLS_MULTI) {
mpls = (struct ndpi_mpls_header *) &packet[ip_offset];
label = ntohl(mpls->label);
/* label = ntohl(*((u_int32_t*)&packet[ip_offset])); */
ndpi_thread_info[thread_id].stats.mpls_count++;
type = ETH_P_IP, ip_offset += 4;
while((label & 0x100) != 0x100) {
ip_offset += 4;
label = ntohl(mpls->label);
}
}
else if(type == SLARP) {
slarp = (struct ndpi_slarp *) &packet[ip_offset];
if(slarp->slarp_type == 0x02 || slarp->slarp_type == 0x00 || slarp->slarp_type == 0x01) {
/* TODO if info are needed */
}
slarp_pkts++;
}
else if(type == CISCO_D_PROTO) {
cdp = (struct ndpi_cdp *) &packet[ip_offset];
cdp_pkts++;
}
else if(type == PPPoE) {
ndpi_thread_info[thread_id].stats.pppoe_count++;
type = ETH_P_IP;
ip_offset += 8;
}
ndpi_thread_info[thread_id].stats.vlan_count += vlan_packet;
iph_check:
/* Check and set IP header size and total packet length */
iph = (struct ndpi_iphdr *) &packet[ip_offset];
// just work on Ethernet packets that contain IP
/* just work on Ethernet packets that contain IP */
if(type == ETH_P_IP && header->caplen >= ip_offset) {
frag_off = ntohs(iph->frag_off);
@@ -1623,10 +1791,15 @@ static void pcap_packet_callback(u_char *args, const struct pcap_pkthdr *header,
ip_len = ((u_short)iph->ihl * 4);
iph6 = NULL;
if(iph->protocol == 41) {
ip_offset += ip_len;
goto iph_check;
}
if((frag_off & 0x3FFF) != 0) {
static u_int8_t ipv4_frags_warning_used = 0;
ndpi_thread_info[thread_id].stats.fragmented_count++;
if(ipv4_frags_warning_used == 0) {
if((!json_flag) && (!quiet_mode)) printf("\n\nWARNING: IPv4 fragments are not handled by this demo (nDPI supports them)\n");
ipv4_frags_warning_used = 1;
@@ -1636,27 +1809,27 @@ static void pcap_packet_callback(u_char *args, const struct pcap_pkthdr *header,
return;
}
} else if(iph->version == 6) {
iph6 = (struct ndpi_ip6_hdr *)&packet[ip_offset];
iph6 = (struct ndpi_ipv6hdr *)&packet[ip_offset];
proto = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
ip_len = sizeof(struct ndpi_ip6_hdr);
ip_len = sizeof(struct ndpi_ipv6hdr);
if(proto == 0x3C /* IPv6 destination option */) {
u_int8_t *options = (u_int8_t*)&packet[ip_offset+ip_len];
u_int8_t *options = (u_int8_t*)&packet[ip_offset+ip_len];
proto = options[0];
ip_len += 8 * (options[1] + 1);
}
iph = NULL;
} else {
static u_int8_t ipv4_warning_used = 0;
v4_warning:
if(ipv4_warning_used == 0) {
if((!json_flag) && (!quiet_mode)) printf("\n\nWARNING: only IPv4/IPv6 packets are supported in this demo (nDPI supports both IPv4 and IPv6), all other packets will be discarded\n\n");
if((!json_flag) && (!quiet_mode))
printf("\n\nWARNING: only IPv4/IPv6 packets are supported in this demo (nDPI supports both IPv4 and IPv6), all other packets will be discarded\n\n");
ipv4_warning_used = 1;
}
ndpi_thread_info[thread_id].stats.total_discarded_bytes += header->len;
return;
}
@@ -1671,9 +1844,10 @@ static void pcap_packet_callback(u_char *args, const struct pcap_pkthdr *header,
u_int8_t flags = packet[offset];
u_int8_t message_type = packet[offset+1];
if((((flags & 0xE0) >> 5) == 1 /* GTPv1 */) && (message_type == 0xFF /* T-PDU */)) {
ip_offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr)+8 /* GTPv1 header len */;
if((((flags & 0xE0) >> 5) == 1 /* GTPv1 */) &&
(message_type == 0xFF /* T-PDU */)) {
ip_offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr)+8; /* GTPv1 header len */
if(flags & 0x04) ip_offset += 1; /* next_ext_header is present */
if(flags & 0x02) ip_offset += 4; /* sequence_number is present (it also includes next_ext_header and pdu_number) */
if(flags & 0x01) ip_offset += 1; /* pdu_number is present */
@@ -1685,10 +1859,48 @@ static void pcap_packet_callback(u_char *args, const struct pcap_pkthdr *header,
goto v4_warning;
}
}
} else if((sport == TZSP_PORT) || (dport == TZSP_PORT)) {
/* https://en.wikipedia.org/wiki/TZSP */
u_int offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr);
u_int8_t version = packet[offset];
u_int8_t type = packet[offset+1];
u_int16_t encapsulates = ntohs(*((u_int16_t*)&packet[offset+2]));
if((version == 1) && (type == 0) && (encapsulates == 1)) {
u_int8_t stop = 0;
offset += 4;
while((!stop) && (offset < header->caplen)) {
u_int8_t tag_type = packet[offset];
u_int8_t tag_len;
switch(tag_type) {
case 0: /* PADDING Tag */
tag_len = 1;
break;
case 1: /* END Tag */
tag_len = 1, stop = 1;
break;
default:
tag_len = packet[offset+1];
break;
}
offset += tag_len;
if(offset >= header->caplen)
return; /* Invalid packet */
else {
eth_offset = offset;
goto datalink_check;
}
}
}
}
}
// process the packet
/* process the packet */
packet_processing(thread_id, time, vlan_id, iph, iph6,
ip_offset, header->len - ip_offset, header->len);
}
@@ -1823,16 +2035,6 @@ struct timezone {
/* ***************************************************** */
#if 0
int gettimeofday(struct timeval *tv, void *notUsed) {
tv->tv_sec = time(NULL);
tv->tv_usec = 0;
return(0);
}
#endif
/* ***************************************************** */
int gettimeofday(struct timeval *tv, struct timezone *tz) {
FILETIME ft;
LARGE_INTEGER li;
+13 -6
View File
@@ -1,9 +1,15 @@
require "formula"
class Ndpi < Formula
desc "Deep Packet Inspection (DPI) library"
homepage "http://www.ntop.org/products/ndpi/"
url "https://downloads.sourceforge.net/project/ntop/nDPI/libndpi-1.5.1.tar.gz"
sha1 "0a6ed585545ab6611f3f0ac9efd9eb36bb5481dd"
url "https://downloads.sourceforge.net/project/ntop/nDPI/nDPI-1.7.tar.gz"
sha256 "714b745103a072462130b0e14cf31b2eb5270f580b7c839da5cf5ea75150262d"
bottle do
cellar :any
sha256 "e9464d314479ba3e7a91422e0bc606cfd5f6e72e94d6441cc4fa30e9c925da5c" => :yosemite
sha256 "1d6b1d860669b42766baa276ed948c342e2fa4fd28663ba64a90fd0e200ba9c4" => :mavericks
sha256 "b814918b4fb9588de7126061ce4ac3eb41a5c3eee27c7432b669f6dc6921bfde" => :mountain_lion
end
depends_on "autoconf" => :build
depends_on "automake" => :build
@@ -12,12 +18,13 @@ class Ndpi < Formula
depends_on "json-c"
def install
system "./configure","--prefix=#{prefix}"
system "./autogen.sh"
system "./configure", "--prefix=#{prefix}"
system "make"
system "make", "install"
end
test do
system "#{bin}/ndpiReader","-h"
system "#{bin}/ndpiReader", "-i", test_fixtures("test.pcap")
end
end
+7 -6
View File
@@ -1,9 +1,10 @@
library_includedir=$(includedir)/libndpi-1.4/libndpi
library_include_HEADERS = ndpi_api.h \
ndpi_debug_functions.h \
ndpi_define.h \
ndpi_macros.h \
ndpi_protocols_osdpi.h \
ndpi_public_functions.h
ndpi_define.h \
ndpi_typedefs.h \
ndpi_main.h \
ndpi_protocol_ids.h \
ndpi_protocols.h \
ndpi_win32.h \
ndpi_includes.h
-188
View File
@@ -1,188 +0,0 @@
/*
* linux_compat.h
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-15 - ntop.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/>.
*
*/
#ifndef __NDPI_LINUX_COMPAT_H__
#define __NDPI_LINUX_COMPAT_H__
#include "ndpi_define.h"
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <machine/endian.h>
#if _BYTE_ORDER == _LITTLE_ENDIAN
#ifndef __LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__ 1
#endif
#else
#ifndef __BIG_ENDIAN__
#define __BIG_ENDIAN__ 1
#endif
#endif
#endif
#pragma pack(push, 1) /* push current alignment to stack */
#pragma pack(1) /* set alignment to 1 byte boundary */
#pragma pack(pop) /* restore original alignment from stack */
struct ndpi_ethhdr {
u_char h_dest[6]; /* destination eth addr */
u_char h_source[6]; /* source ether addr */
u_int16_t h_proto; /* packet type ID field */
};
struct ndpi_80211q {
u_int16_t vlanId;
u_int16_t protoType;
};
struct ndpi_iphdr {
#if defined(__LITTLE_ENDIAN__)
u_int8_t ihl:4, version:4;
#elif defined(__BIG_ENDIAN__)
u_int8_t version:4, ihl:4;
#else
# error "Byte order must be defined"
#endif
u_int8_t tos;
u_int16_t tot_len;
u_int16_t id;
u_int16_t frag_off;
u_int8_t ttl;
u_int8_t protocol;
u_int16_t check;
u_int32_t saddr;
u_int32_t daddr;
};
#ifdef WIN32
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int uint;
typedef unsigned long u_long;
typedef u_char u_int8_t;
typedef u_short u_int16_t;
typedef uint u_int32_t;
#define _WS2TCPIP_H_ /* Avoid compilation problems */
#define HAVE_SIN6_LEN
/* IPv6 address */
/* Already defined in WS2tcpip.h */
struct ndpi_win_in6_addr
{
union
{
u_int8_t u6_addr8[16];
u_int16_t u6_addr16[8];
u_int32_t u6_addr32[4];
} in6_u;
#ifdef s6_addr
#undef s6_addr
#endif
#ifdef s6_addr16
#undef s6_addr16
#endif
#ifdef s6_addr32
#undef s6_addr32
#endif
#define s6_addr in6_u.u6_addr8
// #define s6_addr16 in6_u.u6_addr16
// #define s6_addr32 in6_u.u6_addr32
};
#define in6_addr win_in6_addr
/* Generic extension header. */
struct ndpi_ip6_ext
{
u_int8_t ip6e_nxt; /* next header. */
u_int8_t ip6e_len; /* length in units of 8 octets. */
};
#define s6_addr16 __u6_addr.__u6_addr16
#define s6_addr32 __u6_addr.__u6_addr32
#else
#ifndef __KERNEL__
#include <arpa/inet.h>
#endif
#endif
struct ndpi_in6_addr {
union {
u_int8_t __u6_addr8[16];
u_int16_t __u6_addr16[8];
u_int32_t __u6_addr32[4];
} __u6_addr; /* 128-bit IP6 address */
};
struct ndpi_ip6_hdr {
union {
struct ndpi_ip6_hdrctl {
u_int32_t ip6_un1_flow;
u_int16_t ip6_un1_plen;
u_int8_t ip6_un1_nxt;
u_int8_t ip6_un1_hlim;
} ip6_un1;
u_int8_t ip6_un2_vfc;
} ip6_ctlun;
struct ndpi_in6_addr ip6_src;
struct ndpi_in6_addr ip6_dst;
};
struct ndpi_tcphdr {
u_int16_t source;
u_int16_t dest;
u_int32_t seq;
u_int32_t ack_seq;
#if defined(__LITTLE_ENDIAN__)
u_int16_t res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1;
#elif defined(__BIG_ENDIAN__)
u_int16_t doff:4, res1:4, cwr:1, ece:1, urg:1, ack:1, psh:1, rst:1, syn:1, fin:1;
#else
# error "Byte order must be defined"
#endif
u_int16_t window;
u_int16_t check;
u_int16_t urg_ptr;
};
struct ndpi_udphdr {
u_int16_t source;
u_int16_t dest;
u_int16_t len;
u_int16_t check;
};
#endif
+16 -23
View File
@@ -23,8 +23,8 @@
*/
#ifndef __NDPI_PUBLIC_FUNCTIONS_H__
#define __NDPI_PUBLIC_FUNCTIONS_H__
#ifndef __NDPI_API_H__
#define __NDPI_API_H__
#include "ndpi_main.h"
@@ -32,26 +32,26 @@
extern "C" {
#endif
/**
* This function returns the size of the flow struct
* @return the size of the flow struct
/**
* This function returns the size of the flow struct
* @return the size of the flow struct
*/
u_int32_t ndpi_detection_get_sizeof_ndpi_flow_struct(void);
/**
* This function returns the size of the id struct
* @return the size of the id struct
/**
* This function returns the size of the id struct
* @return the size of the id struct
*/
u_int32_t ndpi_detection_get_sizeof_ndpi_id_struct(void);
/* Public malloc/free */
void* ndpi_malloc(unsigned long size);
void* ndpi_calloc(unsigned long count, unsigned long size);
void ndpi_free(void *ptr);
void *ndpi_realloc(void *ptr, size_t old_size, size_t new_size);
char *ndpi_strdup(const char *s);
/*
/**
* Find the first occurrence of find in s, where the search is limited to the
* first slen characters of s.
*/
@@ -70,7 +70,7 @@ extern "C" {
/**
* This function returns a new initialized detection module.
* @param ticks_per_second the timestamp resolution per second (like 1000 for millisecond resolution)
* @param ndpi_malloc function pointer to a memory allocator
* @param __ndpi_malloc function pointer to a memory allocator
* @param ndpi_debug_printf a function pointer to a debug output function, use NULL in productive envionments
* @return the initialized detection module
*/
@@ -88,8 +88,8 @@ extern "C" {
/**
* This function enables cache support in nDPI used for some protocol such as Skype
* @param cache host name
* @param cache port
* @param host host name
* @param port port number
*/
void ndpi_enable_cache(struct ndpi_detection_module_struct *ndpi_mod, char* host, u_int port);
@@ -150,14 +150,6 @@ extern "C" {
*/
u_int8_t ndpi_detection_get_l4(const u_int8_t * l3, u_int16_t l3_len, const u_int8_t ** l4_return, u_int16_t * l4_len_return,
u_int8_t * l4_protocol_return, u_int32_t flags);
/**
* returns the real protocol for the flow of the last packet given to the detection.
* if no real protocol could be found, the unknown protocol will be returned.
*
* @param ndpi_struct the detection module
* @return the protocol id of the last real protocol found in the protocol history of the flow
*/
/* u_int16_t ndpi_detection_get_real_protocol_of_flow(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); */
/**
* returns true if the protocol history of the flow of the last packet given to the detection
@@ -244,4 +236,5 @@ extern "C" {
#ifdef __cplusplus
}
#endif
#endif
#endif /* __NDPI_API_H__ */
+17 -31
View File
@@ -42,15 +42,22 @@
#endif/* BYTE_ORDER */
#endif/* __OPENBSD__ */
#if 0
#ifndef NDPI_ENABLE_DEBUG_MESSAGES
#define NDPI_ENABLE_DEBUG_MESSAGES
#if __BYTE_ORDER == __LITTLE_ENDIAN
#ifndef __LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__
#endif
#else
#ifndef __BIG_ENDIAN__
#define __BIG_ENDIAN__
#endif
#endif
#ifdef WIN32
#ifndef __LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__ 1
#endif
#endif
#if !(defined(__LITTLE_ENDIAN__) || defined(__BIG_ENDIAN__))
#if defined(__mips__)
@@ -59,13 +66,6 @@
#define __BIG_ENDIAN__
#endif
/* Kernel modules */
#if defined(__LITTLE_ENDIAN)
#define __LITTLE_ENDIAN__
#endif
#if defined(__BIG_ENDIAN)
#define __BIG_ENDIAN__
#endif
/* Everything else */
#if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__))
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -165,11 +165,6 @@
#define MAX_PACKET_COUNTER 65000
#define MAX_DEFAULT_PORTS 5
/**********************
* detection features *
**********************/
/* #define NDPI_SELECT_DETECTION_WITH_REAL_PROTOCOL ( 1 << 0 ) */
#define NDPI_DIRECTCONNECT_CONNECTION_IP_TICK_TIMEOUT 600
#define NDPI_IRC_CONNECTION_TIMEOUT 120
#define NDPI_GNUTELLA_CONNECTION_TIMEOUT 60
@@ -199,7 +194,7 @@
#else /* NDPI_ENABLE_DEBUG_MESSAGES */
#if defined(WIN32)
#ifdef WIN32
#define NDPI_LOG(...) {}
#else
#define NDPI_LOG(proto, mod, log_level, args...) {}
@@ -218,12 +213,7 @@
#define NDPI_COMPARE_IPV6_ADDRESS_STRUCTS(x,y) \
((((u_int64_t *)(x))[0]) < (((u_int64_t *)(y))[0]) || ( (((u_int64_t *)(x))[0]) == (((u_int64_t *)(y))[0]) && (((u_int64_t *)(x))[1]) < (((u_int64_t *)(y))[1])) )
#if !defined(__KERNEL__) && !defined(NDPI_IPTABLES_EXT)
#define NDPI_NUM_BITS 256
#else
/* custom protocols not supported */
#define NDPI_NUM_BITS 192
#endif
#define NDPI_BITS /* 32 */ (sizeof(ndpi_ndpi_mask) * 8 /* number of bits in a byte */) /* bits per mask */
#define howmanybits(x, y) (((x)+((y)-1))/(y))
@@ -238,7 +228,7 @@
#define NDPI_NUM_FDS_BITS howmanybits(NDPI_NUM_BITS, NDPI_BITS)
#define NDPI_PROTOCOL_BITMASK ndpi_protocol_bitmask_struct_t
#define NDPI_BITMASK_ADD(a,b) NDPI_SET(&a,b)
#define NDPI_BITMASK_DEL(a,b) NDPI_CLR(&a,b)
#define NDPI_BITMASK_RESET(a) NDPI_ZERO(&a)
@@ -246,7 +236,7 @@
#define NDPI_BITMASK_SET(a, b) { memcpy(&a, &b, sizeof(NDPI_PROTOCOL_BITMASK)); }
/* this is a very very tricky macro *g*,
* the compiler will remove all shifts here if the protocol is static...
* the compiler will remove all shifts here if the protocol is static...
*/
#define NDPI_ADD_PROTOCOL_TO_BITMASK(bmask,value) NDPI_SET(&bmask,value)
#define NDPI_DEL_PROTOCOL_FROM_BITMASK(bmask,value) NDPI_CLR(&bmask,value)
@@ -289,21 +279,17 @@
#define get_l32(X,O) get_u_int32_t(X,O)
#elif defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN)
/* convert the bytes from big to little endian */
#ifndef __KERNEL__
# define get_l16(X,O) bswap_16(get_u_int16_t(X,O))
# define get_l32(X,O) bswap_32(get_u_int32_t(X,O))
#else
# define get_l16(X,O) __cpu_to_le16(get_u_int16_t(X,O))
# define get_l32(X,O) __cpu_to_le32(get_u_int32_t(X,O))
#endif
#else
#error "__BYTE_ORDER MUST BE DEFINED !"
#endif /* __BYTE_ORDER */
/* define memory callback function */
#define match_first_bytes(payload,st) (memcmp((payload),(st),(sizeof(st)-1))==0)
#if defined(WIN32) && !defined(snprintf)
#define snprintf _snprintf
#endif
#endif /* __NDPI_DEFINE_INCLUDE_FILE__ */
+68
View File
@@ -0,0 +1,68 @@
/*
* ndpi_includes.h
*
* Copyright (C) 2011-15 - ntop.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/>.
*
*/
#ifndef __NDPI_INCLUDES_H__
#define __NDPI_INCLUDES_H__
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <limits.h>
#ifdef WIN32
#include "ndpi_win32.h"
#else
#include <sys/param.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#if !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__ && !defined __OpenBSD__
#include <endian.h>
#include <byteswap.h>
#if defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
#include <netinet/in.h>
#if defined __NetBSD__ || defined __OpenBSD__
#include <netinet/in_systm.h>
#ifdef __OpenBSD__
#include <pthread.h>
#endif
#endif
#endif
#endif
#endif /* Win32 */
#endif /* __NDPI_INCLUDES_H__ */
+19 -69
View File
@@ -22,53 +22,15 @@
*
*/
#ifndef __NDPI_MAIN_INCLUDE_FILE__
#define __NDPI_MAIN_INCLUDE_FILE__
#ifndef __NDPI_MAIN_H__
#define __NDPI_MAIN_H__
#ifndef __KERNEL__
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#ifndef WIN32
#include <pthread.h>
#endif
#include <ctype.h>
#include <time.h>
#endif
#ifndef WIN32
#ifndef __KERNEL__
#include <sys/time.h>
#endif
#if !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__ && !defined __OpenBSD__
#ifndef __KERNEL__
#include <endian.h>
#include <byteswap.h>
#else
#include <asm/byteorder.h>
#include <linux/ctype.h>
#endif
#endif
/* default includes */
#ifndef __KERNEL__
#include <sys/param.h>
#include <limits.h>
#endif
#endif
#include "ndpi_win32.h"
#include "ndpi_unix.h"
#include "ndpi_includes.h"
#include "ndpi_define.h"
#include "ndpi_protocol_ids.h"
#include "ndpi_typedefs.h"
#include "ndpi_protocols.h"
#include "ndpi_api.h"
void *ndpi_tdelete(const void * __restrict, void ** __restrict,
@@ -103,58 +65,46 @@ void ndpi_set_detected_protocol(struct ndpi_detection_module_struct *ndpi_struct
u_int16_t upper_detected_protocol,
u_int16_t lower_detected_protocol);
/* function to parse a packet which has line based information into a line based structure
* this function will also set some well known line pointers like:
* - host, user agent, empty line,....
*/
extern void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
extern void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
extern u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow, u_int16_t counter);
extern void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
extern void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow,
u_int16_t upper_detected_protocol,
u_int16_t lower_detected_protocol);
extern void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
extern void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow,
u_int16_t upper_detected_protocol,
u_int16_t lower_detected_protocol);
extern void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol_breed_t protoBreed, u_int16_t protoId,
u_int16_t tcp_alias_protoId[2], u_int16_t udp_alias_protoId[2],
char *protoName,
extern void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod, ndpi_protocol_breed_t protoBreed, u_int16_t protoId,
u_int16_t tcp_alias_protoId[2], u_int16_t udp_alias_protoId[2], char *protoName,
ndpi_port_range *tcpDefPorts, ndpi_port_range *udpDefPorts);
extern void ndpi_int_reset_packet_protocol(struct ndpi_packet_struct *packet);
extern void ndpi_int_reset_protocol(struct ndpi_flow_struct *flow);
extern int ndpi_packet_src_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip);
extern int ndpi_packet_dst_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip);
extern void ndpi_packet_src_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip);
extern void ndpi_packet_dst_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip);
extern char *ndpi_get_ip_string(struct ndpi_detection_module_struct *ndpi_struct, const ndpi_ip_addr_t * ip);
extern char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
const struct ndpi_packet_struct *packet);
extern char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_struct, const struct ndpi_packet_struct *packet);
extern char* ndpi_get_proto_by_id(struct ndpi_detection_module_struct *ndpi_mod, u_int id);
extern u_int16_t ndpi_guess_protocol_id(struct ndpi_detection_module_struct *ndpi_struct,
u_int8_t proto, u_int16_t sport, u_int16_t dport);
extern u_int8_t ndpi_is_proto(ndpi_protocol p, u_int16_t proto);
extern u_int16_t ndpi_get_lower_proto(ndpi_protocol p);
extern int ndpi_get_protocol_id_master_proto(struct ndpi_detection_module_struct *ndpi_struct,
u_int16_t protocol_id,
extern int ndpi_get_protocol_id_master_proto(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t protocol_id,
u_int16_t** tcp_master_proto,
u_int16_t** udp_master_proto);
extern u_int8_t ndpi_net_match(u_int32_t ip_to_check,
u_int32_t net,
u_int32_t num_bits);
extern u_int8_t ndpi_ips_match(u_int32_t src, u_int32_t dst,
u_int32_t net, u_int32_t num_bits);
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
void ndpi_debug_get_last_log_function_line(struct ndpi_detection_module_struct *ndpi_struct,
const char **file, const char **func, u_int32_t * line);
#endif
#include "ndpi_api.h"
#endif /* __NDPI_MAIN_INCLUDE_FILE__ */
#endif /* __NDPI_MAIN_H__ */
+7 -2
View File
@@ -23,7 +23,7 @@
*/
#ifndef __NDPI_API_INCLUDE_FILE__
#ifndef __NDPI_API_H__
#endif
@@ -201,6 +201,11 @@
#define NDPI_PROTOCOL_WHATSAPP_VOICE 189
#define NDPI_PROTOCOL_STARCRAFT 213 /* Matteo Bracci <matteobracci1@gmail.com> */
#define NDPI_PROTOCOL_TEREDO 214
#define NDPI_PROTOCOL_HEP 216 /* Sipcapture.org QXIP BV */
#define NDPI_PROTOCOL_UBNTAC2 217 /* Ubiquity UBNT AirControl 2 - Thomas Fjellstrom <thomas+ndpi@fjellstrom.ca> */
#define NDPI_PROTOCOL_MS_LYNC 218
#define NDPI_CONTENT_AVI 39
#define NDPI_CONTENT_FLASH 40
@@ -263,7 +268,7 @@
#define NDPI_SERVICE_HOTSPOT_SHIELD 215
/* UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE */
#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_SERVICE_HOTSPOT_SHIELD
#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_PROTOCOL_MS_LYNC
#define NDPI_MAX_SUPPORTED_PROTOCOLS (NDPI_LAST_IMPLEMENTED_PROTOCOL + 1)
#define NDPI_MAX_NUM_CUSTOM_PROTOCOLS (NDPI_NUM_BITS-NDPI_LAST_IMPLEMENTED_PROTOCOL)
+7 -3
View File
@@ -23,8 +23,8 @@
*/
#ifndef __NDPI_PROTOCOLS_INCLUDE_FILE__
#define __NDPI_PROTOCOLS_INCLUDE_FILE__
#ifndef __NDPI_PROTOCOLS_H__
#define __NDPI_PROTOCOLS_H__
#include "ndpi_main.h"
@@ -72,6 +72,7 @@ void ndpi_search_oscar(struct ndpi_detection_module_struct *ndpi_struct, struct
void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_sip(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_hep(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_direct_download_link_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mail_pop_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
@@ -195,6 +196,7 @@ void ndpi_search_eaq(struct ndpi_detection_module_struct *ndpi_struct, struct nd
void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mpegts(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_starcraft(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ubntac2(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
/* --- INIT FUNCTIONS --- */
@@ -288,6 +290,7 @@ void init_rtsp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int
void init_sflow_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_shoutcast_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_sip_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_hep_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_skinny_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_skype_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_smb_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
@@ -332,5 +335,6 @@ void init_yahoo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_in
void init_zattoo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_zmq_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_stracraft_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_ubntac2_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
#endif /* __NDPI_PROTOCOLS_INCLUDE_FILE__ */
#endif /* __NDPI_PROTOCOLS_H__ */
+282 -97
View File
@@ -22,94 +22,280 @@
*
*/
#ifndef __NDPI_TYPEDEFS_FILE__
#define __NDPI_TYPEDEFS_FILE__
#ifndef __NDPI_TYPEDEFS_H__
#define __NDPI_TYPEDEFS_H__
typedef enum {
NDPI_LOG_ERROR,
NDPI_LOG_TRACE,
NDPI_LOG_DEBUG
} ndpi_log_level_t;
#include "ndpi_define.h"
typedef void (*ndpi_debug_function_ptr) (u_int32_t protocol,
void *module_struct, ndpi_log_level_t log_level,
const char *format, ...);
#define BT_ANNOUNCE
#define SNAP_EXT
typedef enum {
ndpi_preorder,
ndpi_postorder,
ndpi_endorder,
ndpi_leaf
} ndpi_VISIT;
typedef struct node_t {
/* NDPI_LOG_LEVEL */
typedef enum
{
NDPI_LOG_ERROR,
NDPI_LOG_TRACE,
NDPI_LOG_DEBUG
} ndpi_log_level_t;
/* NDPI_VISIT */
typedef enum
{
ndpi_preorder,
ndpi_postorder,
ndpi_endorder,
ndpi_leaf
} ndpi_VISIT;
/* NDPI_NODE */
typedef struct node_t
{
char *key;
struct node_t *left, *right;
} ndpi_node;
/* NDPI_MASK_SIZE */
typedef u_int32_t ndpi_ndpi_mask;
typedef struct ndpi_protocol_bitmask_struct {
ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS];
/* NDPI_PROTO_BITMASK_STRUCT */
typedef struct ndpi_protocol_bitmask_struct
{
ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS];
} ndpi_protocol_bitmask_struct_t;
#ifdef NDPI_DETECTION_SUPPORT_IPV6
struct ndpi_ip6_addr {
union {
u_int8_t u6_addr8[16];
u_int16_t u6_addr16[8];
u_int32_t u6_addr32[4];
u_int64_t u6_addr64[2];
} ndpi_v6_u;
/* NDPI_DEBUG_FUNCTION_PTR (cast) */
typedef void (*ndpi_debug_function_ptr) (u_int32_t protocol, void *module_struct,
ndpi_log_level_t log_level, const char *format, ...);
#define ndpi_v6_addr ndpi_v6_u.u6_addr8
#define ndpi_v6_addr16 ndpi_v6_u.u6_addr16
#define ndpi_v6_addr32 ndpi_v6_u.u6_addr32
#define ndpi_v6_addr64 ndpi_v6_u.u6_addr64
};
struct ndpi_ipv6hdr {
/* use userspace and kernelspace compatible compile parameters */
/* ************************************************************ */
/* ******************* NDPI NETWORKS HEADERS ****************** */
/* ************************************************************ */
/* ++++++++++++++++++++++++ Cisco headers +++++++++++++++++++++ */
/* Cisco HDLC */
#ifdef _MSC_VER
/* Windows */
#define PACK_ON __pragma(pack(push, 1))
#define PACK_OFF __pragma(pack(pop))
#elif defined(__GNUC__)
/* GNU C */
#define PACK_ON
#define PACK_OFF __attribute__((packed))
#endif
PACK_ON
struct ndpi_chdlc
{
u_int8_t addr; /* 0x0F (Unicast) - 0x8F (Broadcast) */
u_int8_t ctrl; /* always 0x00 */
u_int16_t proto_code; /* protocol type (e.g. 0x0800 IP) */
} PACK_OFF;
/* SLARP - Serial Line ARP http://tinyurl.com/qa54e95 */
PACK_ON
struct ndpi_slarp
{
/* address requests (0x00)
address replies (0x01)
keep-alive (0x02)
*/
u_int32_t slarp_type;
u_int32_t addr_1;
u_int32_t addr_2;
} PACK_OFF;
/* Cisco Discovery Protocol http://tinyurl.com/qa6yw9l */
PACK_ON
struct ndpi_cdp
{
u_int8_t version;
u_int8_t ttl;
u_int16_t checksum;
u_int16_t type;
u_int16_t length;
} PACK_OFF;
/* +++++++++++++++ Ethernet header (IEEE 802.3) +++++++++++++++ */
PACK_ON
struct ndpi_ethhdr
{
u_char h_dest[6]; /* destination eth addr */
u_char h_source[6]; /* source ether addr */
u_int16_t h_proto; /* data length (<= 1500) or type ID proto (>=1536) */
} PACK_OFF;
/* +++++++++++++++++++ LLC header (IEEE 802.2) ++++++++++++++++ */
PACK_ON
struct ndpi_snap_extension
{
u_int16_t oui;
u_int8_t oui2;
u_int16_t proto_ID;
} PACK_OFF;
PACK_ON
struct ndpi_llc_header
{
u_int8_t dsap;
u_int8_t ssap;
u_int8_t ctrl;
#ifdef SNAP_EXT
struct ndpi_snap_extension snap;
#endif
} PACK_OFF;
/* ++++++++++ RADIO TAP header (for IEEE 802.11) +++++++++++++ */
PACK_ON
struct ndpi_radiotap_header
{
u_int8_t version; /* set to 0 */
u_int8_t pad;
u_int16_t len;
u_int32_t present;
u_int64_t MAC_timestamp;
u_int8_t flags;
} PACK_OFF;
/* ++++++++++++ Wireless header (IEEE 802.11) ++++++++++++++++ */
PACK_ON
struct ndpi_wifi_header
{
u_int16_t fc;
u_int16_t duration;
u_char rcvr[6];
u_char trsm[6];
u_char dest[6];
u_int16_t seq_ctrl;
/* u_int64_t ccmp - for data encription only - check fc.flag */
} PACK_OFF;
/* +++++++++++++++++++++++ MPLS header +++++++++++++++++++++++ */
PACK_ON
struct ndpi_mpls_header
{
u_int32_t label:20, exp:3, s:1, ttl:8;
} PACK_OFF;
/* ++++++++++++++++++++++++ IP header ++++++++++++++++++++++++ */
PACK_ON
struct ndpi_iphdr {
#if defined(__LITTLE_ENDIAN__)
u_int8_t priority:4, version:4;
u_int8_t ihl:4, version:4;
#elif defined(__BIG_ENDIAN__)
u_int8_t version:4, priority:4;
u_int8_t version:4, ihl:4;
#else
# error "Byte order must be defined"
#endif
u_int8_t tos;
u_int16_t tot_len;
u_int16_t id;
u_int16_t frag_off;
u_int8_t ttl;
u_int8_t protocol;
u_int16_t check;
u_int32_t saddr;
u_int32_t daddr;
} PACK_OFF;
u_int8_t flow_lbl[3];
/* +++++++++++++++++++++++ IPv6 header +++++++++++++++++++++++ */
/* rfc3542 */
u_int16_t payload_len;
u_int8_t nexthdr;
u_int8_t hop_limit;
struct ndpi_ip6_addr saddr;
struct ndpi_ip6_addr daddr;
struct ndpi_in6_addr
{
union
{
u_int8_t u6_addr8[16];
u_int16_t u6_addr16[8];
u_int32_t u6_addr32[4];
} u6_addr; /* 128-bit IP6 address */
};
#endif
typedef union {
PACK_ON
struct ndpi_ipv6hdr
{
union
{
struct ndpi_ip6_hdrctl
{
u_int32_t ip6_un1_flow;
u_int16_t ip6_un1_plen;
u_int8_t ip6_un1_nxt;
u_int8_t ip6_un1_hlim;
} ip6_un1;
u_int8_t ip6_un2_vfc;
} ip6_ctlun;
struct ndpi_in6_addr ip6_src;
struct ndpi_in6_addr ip6_dst;
} PACK_OFF;
/* +++++++++++++++++++++++ TCP header +++++++++++++++++++++++ */
PACK_ON
struct ndpi_tcphdr
{
u_int16_t source;
u_int16_t dest;
u_int32_t seq;
u_int32_t ack_seq;
#if defined(__LITTLE_ENDIAN__)
u_int16_t res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1;
#elif defined(__BIG_ENDIAN__)
u_int16_t doff:4, res1:4, cwr:1, ece:1, urg:1, ack:1, psh:1, rst:1, syn:1, fin:1;
#else
# error "Byte order must be defined"
#endif
u_int16_t window;
u_int16_t check;
u_int16_t urg_ptr;
} PACK_OFF;
/* +++++++++++++++++++++++ UDP header +++++++++++++++++++++++ */
PACK_ON
struct ndpi_udphdr
{
u_int16_t source;
u_int16_t dest;
u_int16_t len;
u_int16_t check;
} PACK_OFF;
PACK_ON
struct ndpi_dns_packet_header {
u_int16_t transaction_id, flags, num_queries, answer_rrs, authority_rrs, additional_rrs;
} PACK_OFF;
typedef union
{
u_int32_t ipv4;
u_int8_t ipv4_u_int8_t[4];
#ifdef NDPI_DETECTION_SUPPORT_IPV6
struct ndpi_ip6_addr ipv6;
struct ndpi_in6_addr ipv6;
#endif
} ndpi_ip_addr_t;
/* ************************************************************ */
/* ******************* ********************* ****************** */
/* ************************************************************ */
#ifdef NDPI_PROTOCOL_BITTORRENT
#ifndef __KERNEL__
typedef struct spinlock {
volatile int val;
} spinlock_t;
typedef struct atomic {
volatile int counter;
} atomic_t;
#endif
struct hash_ip4p_node {
struct hash_ip4p_node *next,*prev;
time_t lchg;
@@ -155,16 +341,12 @@ typedef enum {
} ndpi_http_method;
typedef struct ndpi_id_struct {
/* detected_protocol_bitmask:
* access this bitmask to find out whether an id has used skype or not
* if a flag is set here, it will not be resetted
* to compare this, use:
* if (NDPI_BITMASK_COMPARE(id->detected_protocol_bitmask,
* NDPI_PROTOCOL_BITMASK_XXX) != 0)
* {
* // protocol XXX detected on this id
* }
*/
/**
detected_protocol_bitmask:
access this bitmask to find out whether an id has used skype or not
if a flag is set here, it will not be resetted
to compare this, use:
**/
NDPI_PROTOCOL_BITMASK detected_protocol_bitmask;
#ifdef NDPI_PROTOCOL_RTSP
ndpi_ip_addr_t rtsp_ip_address;
@@ -310,7 +492,7 @@ struct ndpi_flow_tcp_struct {
u_int32_t http_stage:2;
u_int32_t http_empty_line_seen:1;
u_int32_t http_wait_for_retransmission:1;
#endif
#endif
#ifdef NDPI_PROTOCOL_GNUTELLA
u_int32_t gnutella_stage:2; // 0 - 2
#endif
@@ -390,7 +572,7 @@ struct ndpi_flow_tcp_struct {
u_char prev_zmq_pkt[10];
#endif
}
#if !defined(WIN32)
#ifndef WIN32
__attribute__ ((__packed__))
#endif
;
@@ -439,7 +621,7 @@ struct ndpi_flow_udp_struct {
u_int32_t eaq_sequence;
#endif
}
#if !defined(WIN32)
#ifndef WIN32
__attribute__ ((__packed__))
#endif
;
@@ -468,10 +650,10 @@ typedef struct ndpi_packet_struct {
u_int8_t detected_subprotocol_stack[NDPI_PROTOCOL_HISTORY_SIZE];
#if !defined(WIN32)
__attribute__ ((__packed__))
#ifndef WIN32
__attribute__ ((__packed__))
#endif
u_int16_t protocol_stack_info;
u_int16_t protocol_stack_info;
struct ndpi_int_one_line_struct line[NDPI_MAX_PARSE_LINES_PER_PACKET];
struct ndpi_int_one_line_struct host_line;
@@ -574,7 +756,7 @@ typedef struct ndpi_detection_module_struct {
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
void *user_data;
#endif
/* callback function buffer */
struct ndpi_call_function_struct callback_buffer[NDPI_MAX_SUPPORTED_PROTOCOLS + 1];
u_int32_t callback_buffer_size;
@@ -666,43 +848,45 @@ typedef struct ndpi_detection_module_struct {
typedef struct ndpi_flow_struct {
u_int16_t detected_protocol_stack[NDPI_PROTOCOL_HISTORY_SIZE];
#if !defined(WIN32)
__attribute__ ((__packed__))
#ifndef WIN32
__attribute__ ((__packed__))
#endif
u_int16_t protocol_stack_info;
u_int16_t protocol_stack_info;
/* init parameter, internal used to set up timestamp,... */
u_int16_t guessed_protocol_id;
u_int16_t guessed_protocol_id, guessed_host_proto_id;
u_int8_t protocol_id_already_guessed:1;
u_int8_t init_finished:1;
u_int8_t setup_packet_direction:1;
u_int8_t packet_direction:1; /* if ndpi_struct->direction_detect_disable == 1 */
/* tcp sequence number connection tracking */
u_int8_t protocol_id_already_guessed:1, host_already_guessed:1, init_finished:1, setup_packet_direction:1, packet_direction:1;
/*
if ndpi_struct->direction_detect_disable == 1
tcp sequence number connection tracking
*/
u_int32_t next_tcp_seq_nr[2];
/* the tcp / udp / other l4 value union
* this is used to reduce the number of bytes for tcp or udp protocol states
* */
/*
the tcp / udp / other l4 value union
used to reduce the number of bytes for tcp or udp protocol states
*/
union {
struct ndpi_flow_tcp_struct tcp;
struct ndpi_flow_udp_struct udp;
} l4;
struct ndpi_id_struct *server_id; /*
Pointer to src or dst
that identifies the
server of this connection
*/
#ifndef __KERNEL__
u_char host_server_name[256]; /* HTTP host or DNS query */
#else
u_char host_server_name[160];
#endif
u_char detected_os[32]; /* Via HTTP User-Agent */
u_char nat_ip[24]; /* Via HTTP X-Forwarded-For */
/*
Pointer to src or dst
that identifies the
server of this connection
*/
struct ndpi_id_struct *server_id;
/* HTTP host or DNS query */
u_char host_server_name[256];
/* Via HTTP User-Agent */
u_char detected_os[32];
/* Via HTTP X-Forwarded-For */
u_char nat_ip[24];
/*
/*
This structure below will not not stay inside the protos
structure below as HTTP is used by many subprotocols
such as FaceBook, Google... so it is hard to know
@@ -710,7 +894,7 @@ typedef struct ndpi_flow_struct {
time being.
*/
struct {
ndpi_http_method method;
ndpi_http_method method;
char *url, *content_type;
} http;
@@ -720,17 +904,18 @@ typedef struct ndpi_flow_struct {
u_int8_t bad_packet /* the received packet looks bad */;
u_int16_t query_type, query_class, rsp_type;
} dns;
struct {
u_int8_t request_code;
u_int8_t version;
} ntp;
struct {
char client_certificate[48], server_certificate[48];
} ssl;
} protos;
/* ALL protocol specific 64 bit variables here */
/*** ALL protocol specific 64 bit variables here ***/
/* protocols which have marked a connection as this connection cannot be protocol XXX, multiple u_int64_t */
NDPI_PROTOCOL_BITMASK excluded_protocol_bitmask;
@@ -756,7 +941,7 @@ typedef struct ndpi_flow_struct {
#endif
#ifdef NDPI_PROTOCOL_HTTP
u_int32_t http_detected:1;
#endif
#endif
#ifdef NDPI_PROTOCOL_RTSP
u_int32_t rtsprdt_stage:2;
u_int32_t rtsp_control_flow:1;
@@ -820,4 +1005,4 @@ typedef struct ndpi_flow_struct {
struct ndpi_id_struct *dst;
} ndpi_flow_struct_t;
#endif/* __NDPI_TYPEDEFS_FILE__ */
#endif/* __NDPI_TYPEDEFS_H__ */
-9
View File
@@ -25,8 +25,6 @@
#ifndef __NDPI_UNIX_INCLUDE_FILE__
#define __NDPI_UNIX_INCLUDE_FILE__
#include "linux_compat.h"
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <netinet/in.h>
#if defined(__NetBSD__) || defined(__OpenBSD__)
@@ -38,16 +36,9 @@
#endif
#ifndef WIN32
#ifndef __KERNEL__
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#else
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#endif
#endif
#endif /* __NDPI_UNIX_INCLUDE_FILE__ */
+17 -21
View File
@@ -22,36 +22,34 @@
*
*/
#ifndef __NDPI_WIN32_INCLUDE_FILE__
#define __NDPI_WIN32_INCLUDE_FILE__
#ifndef __NDPI_WIN32_H__
#define __NDPI_WIN32_H__
#ifdef WIN32
#include <Winsock2.h> /* winsock.h is included automatically */
#include <winsock2.h>
#include <ws2tcpip.h>
#include <process.h>
#include <io.h>
#include <getopt.h> /* getopt from: http://www.pwilson.net/sample.html. */
#include <process.h> /* for getpid() and the exec..() family */
#include <getopt.h> /* getopt from: http://www.pwilson.net/sample.html. */
#include <process.h> /* for getpid() and the exec..() family */
#include <stdint.h>
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#define snprintf _snprintf
extern char* strsep(char **stringp, const char *delim);
#define _WS2TCPIP_H_ /* Avoid compilation problems */
extern char* strsep(char **sp, const char *sep);
#define __attribute__(x)
#include <stdint.h>
#ifndef __GNUC__
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int uint;
typedef unsigned long u_long;
#endif
typedef u_char u_int8_t;
typedef u_short u_int16_t;
typedef unsigned int u_int32_t;
typedef unsigned __int64 u_int64_t;
typedef u_char u_int8_t;
typedef u_short u_int16_t;
typedef uint u_int32_t;
typedef uint u_int;
typedef unsigned __int64 u_int64_t;
#define pthread_t HANDLE
#define pthread_mutex_t HANDLE
@@ -62,12 +60,10 @@ typedef unsigned __int64 u_int64_t;
#define pthread_rwlock_unlock pthread_mutex_unlock
#define pthread_rwlock_destroy pthread_mutex_destroy
#define gmtime_r(a, b) gmtime(a) /* Already thread safe on windows */
#define gmtime_r(a, b) memcpy(b, gmtime(a), sizeof(struct tm))
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
#define sleep(a /* sec */) waitForNextEvent(1000*a /* ms */)
#endif /* Win32 */
#endif /* __NDPI_WIN32_INCLUDE_FILE__ */
#endif /* __NDPI_WIN32_H__ */
+1 -3
View File
@@ -7,14 +7,12 @@ libndpi_la_LDFLAGS = -version-info 1:0:0 -export-symbols $(top_srcdir)/libndpi.s
libndpi_la_includedir = $(includedir)/libndpi-@VERSION@/libndpi
libndpi_la_include_HEADERS = ../include/ndpi_api.h \
../include/linux_compat.h \
../include/ndpi_define.h \
../include/ndpi_main.h \
../include/ndpi_protocol_ids.h \
../include/ndpi_protocols.h \
../include/ndpi_typedefs.h \
../include/ndpi_unix.h \
../include/ndpi_win32.h
../include/ndpi_includes.h
libndpi_la_SOURCES = ndpi_content_match.c.inc \
ndpi_main.c \
+263 -380
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -250,7 +250,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
char a_buf[32];
int i;
for(i=0; i<num_a_records; i++) {
for(i=0; j < sizeof(flow->host_server_name)-1 && i < num_a_records; i++) {
j += snprintf((char*)&flow->host_server_name[j], sizeof(flow->host_server_name)-1-j, "%s%s",
(i == 0) ? "@" : ";",
ndpi_intoa_v4(a_record[i], a_buf, sizeof(a_buf)));
+1 -1
View File
@@ -56,7 +56,7 @@ void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struc
}
}
NDPI_LOG(NDPI_PROTOCOL_KAKAOTALK_VOICE, ndpi_struct, NDPI_LOG_DEBUG, "Exclude kakaotalk_voice.\n");
NDPI_LOG(NDPI_SERVICE_KAKAOTALK_VOICE, ndpi_struct, NDPI_LOG_DEBUG, "Exclude kakaotalk_voice.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_SERVICE_KAKAOTALK_VOICE);
}
+4 -4
View File
@@ -117,10 +117,10 @@ void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct
&& (packet->line[a].ptr[1] == 'T' || packet->line[a].ptr[1] == 't')
&& (packet->line[a].ptr[2] == 'A' || packet->line[a].ptr[2] == 'a')
&& (packet->line[a].ptr[3] == 'R' || packet->line[a].ptr[3] == 'r')
&& (packet->line[a].ptr[4] == 'T' || packet->line[a].ptr[0] == 't')
&& (packet->line[a].ptr[5] == 'T' || packet->line[a].ptr[1] == 't')
&& (packet->line[a].ptr[6] == 'L' || packet->line[a].ptr[2] == 'l')
&& (packet->line[a].ptr[7] == 'S' || packet->line[a].ptr[3] == 's')) {
&& (packet->line[a].ptr[4] == 'T' || packet->line[a].ptr[4] == 't')
&& (packet->line[a].ptr[5] == 'T' || packet->line[a].ptr[5] == 't')
&& (packet->line[a].ptr[6] == 'L' || packet->line[a].ptr[6] == 'l')
&& (packet->line[a].ptr[7] == 'S' || packet->line[a].ptr[7] == 's')) {
flow->l4.tcp.smtp_command_bitmask |= SMTP_BIT_STARTTLS;
}
}
+73 -73
View File
@@ -37,108 +37,108 @@ static void ndpi_int_mdns_add_connection(struct ndpi_detection_module_struct
}
static int ndpi_int_check_mdns_payload(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
*ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
struct ndpi_packet_struct *packet = &flow->packet;
if ((packet->payload[2] & 0x80) == 0 &&
ntohs(get_u_int16_t(packet->payload, 4)) <= NDPI_MAX_MDNS_REQUESTS &&
ntohs(get_u_int16_t(packet->payload, 6)) <= NDPI_MAX_MDNS_REQUESTS) {
if ((packet->payload[2] & 0x80) == 0 &&
ntohs(get_u_int16_t(packet->payload, 4)) <= NDPI_MAX_MDNS_REQUESTS &&
ntohs(get_u_int16_t(packet->payload, 6)) <= NDPI_MAX_MDNS_REQUESTS) {
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with question query.\n");
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with question query.\n");
return 1;
} else if ((packet->payload[2] & 0x80) != 0 &&
ntohs(get_u_int16_t(packet->payload, 4)) == 0 &&
ntohs(get_u_int16_t(packet->payload, 6)) <= NDPI_MAX_MDNS_REQUESTS &&
ntohs(get_u_int16_t(packet->payload, 6)) != 0) {
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with answer query.\n");
return 1;
} else if ((packet->payload[2] & 0x80) != 0 &&
ntohs(get_u_int16_t(packet->payload, 4)) == 0 &&
ntohs(get_u_int16_t(packet->payload, 6)) <= NDPI_MAX_MDNS_REQUESTS &&
ntohs(get_u_int16_t(packet->payload, 6)) != 0) {
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with answer query.\n");
return 1;
}
return 1;
}
return 0;
return 0;
}
void ndpi_search_mdns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
u_int16_t dport;
// const u_int16_t sport=ntohs(packet->udp->source);
u_int16_t dport;
// const u_int16_t sport=ntohs(packet->udp->source);
/* check if UDP and */
if (packet->udp != NULL) {
/*read destination port */
dport = ntohs(packet->udp->dest);
/* check if UDP and */
if (packet->udp != NULL) {
/*read destination port */
dport = ntohs(packet->udp->dest);
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "MDNS udp start \n");
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "MDNS udp start \n");
/*check standard MDNS to port 5353 */
/*took this information from http://www.it-administrator.de/lexikon/multicast-dns.html */
/*check standard MDNS to port 5353 */
/*took this information from http://www.it-administrator.de/lexikon/multicast-dns.html */
if (dport == 5353 && packet->payload_packet_len >= 12) {
if (dport == 5353 && packet->payload_packet_len >= 12) {
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with destination port 5353\n");
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with destination port 5353\n");
/* MDNS header is similar to dns header */
/* dns header
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ID |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR| Opcode |AA|TC|RD|RA| Z | RCODE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QDCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ANCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| NSCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ARCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
* dns query check: query: QR set, ancount = 0, nscount = 0, QDCOUNT < MAX_MDNS, ARCOUNT < MAX_MDNS
*
*/
/* MDNS header is similar to dns header */
/* dns header
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ID |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR| Opcode |AA|TC|RD|RA| Z | RCODE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QDCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ANCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| NSCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ARCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
* dns query check: query: QR set, ancount = 0, nscount = 0, QDCOUNT < MAX_MDNS, ARCOUNT < MAX_MDNS
*
*/
/* mdns protocol must have destination address 224.0.0.251 */
/* took this information from http://www.it-administrator.de/lexikon/multicast-dns.html */
/* mdns protocol must have destination address 224.0.0.251 */
/* took this information from http://www.it-administrator.de/lexikon/multicast-dns.html */
if (packet->iph != NULL && ntohl(packet->iph->daddr) == 0xe00000fb) {
if (packet->iph != NULL && ntohl(packet->iph->daddr) == 0xe00000fb) {
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct,
NDPI_LOG_DEBUG, "found MDNS with destination address 224.0.0.251 (=0xe00000fb)\n");
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct,
NDPI_LOG_DEBUG, "found MDNS with destination address 224.0.0.251 (=0xe00000fb)\n");
if (ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
ndpi_int_mdns_add_connection(ndpi_struct, flow);
return;
}
}
if (ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
ndpi_int_mdns_add_connection(ndpi_struct, flow);
return;
}
}
#ifdef NDPI_DETECTION_SUPPORT_IPV6
if (packet->iphv6 != NULL) {
const u_int32_t *daddr = packet->iphv6->daddr.ndpi_v6_u.u6_addr32;
if (daddr[0] == htonl(0xff020000) && daddr[1] == 0 && daddr[2] == 0 && daddr[3] == htonl(0xfb)) {
if (packet->iphv6 != NULL) {
const u_int32_t *daddr = packet->iphv6->ip6_dst.u6_addr.u6_addr32;
if (daddr[0] == htonl(0xff020000) && daddr[1] == 0 && daddr[2] == 0 && daddr[3] == htonl(0xfb)) {
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct,
NDPI_LOG_DEBUG, "found MDNS with destination address ff02::fb\n");
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct,
NDPI_LOG_DEBUG, "found MDNS with destination address ff02::fb\n");
if (ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
ndpi_int_mdns_add_connection(ndpi_struct, flow);
return;
}
}
}
if (ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
ndpi_int_mdns_add_connection(ndpi_struct, flow);
return;
}
}
}
#endif
}
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MDNS);
}
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MDNS);
}
+2 -2
View File
@@ -40,8 +40,8 @@ u_int8_t is_skype_flow(struct ndpi_detection_module_struct *ndpi_struct,
Skype connections are identified by some SSL-like communications
without SSL certificate being exchanged
*/
if(is_skype_host(ndpi_struct, ntohl(packet->iph->saddr))
|| is_skype_host(ndpi_struct, ntohl(packet->iph->daddr))) {
if(is_skype_host(ndpi_struct, packet->iph->saddr)
|| is_skype_host(ndpi_struct, packet->iph->daddr)) {
return(1);
}
}
+6 -3
View File
@@ -37,9 +37,9 @@ u_int ndpi_search_tcp_or_udp_raw(struct ndpi_detection_module_struct *ndpi_struc
}
}
if((rc = ndpi_host_ptree_match(ndpi_struct, saddr)) != NDPI_PROTOCOL_UNKNOWN) return(rc);
if((rc = ndpi_host_ptree_match(ndpi_struct, htonl(saddr))) != NDPI_PROTOCOL_UNKNOWN) return(rc);
return(ndpi_host_ptree_match(ndpi_struct, daddr));
return(ndpi_host_ptree_match(ndpi_struct, htonl(daddr)));
}
void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -48,6 +48,9 @@ void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, st
u_int proto;
struct ndpi_packet_struct *packet = &flow->packet;
if(flow->host_server_name[0] != '\0')
return;
if(ndpi_is_tor_flow(ndpi_struct, flow)) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_TOR, NDPI_PROTOCOL_UNKNOWN);
return;
@@ -61,7 +64,7 @@ void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, st
proto = ndpi_search_tcp_or_udp_raw(ndpi_struct,
flow->packet.iph ? flow->packet.iph->protocol :
#ifdef NDPI_DETECTION_SUPPORT_IPV6
flow->packet.iphv6->nexthdr,
flow->packet.iphv6->ip6_ctlun.ip6_un1.ip6_un1_nxt,
#else
0,
#endif
+2 -2
View File
@@ -1,3 +1,3 @@
NTP 1 90 1
Quic 1 90 1
1 UDP 78.46.76.2:80 <-> 175.144.140.29:123 [proto: 9/NTP][1 pkts/90 bytes]
1 UDP 78.46.76.2:80 <-> 175.144.140.29:123 [proto: 188/Quic][1 pkts/90 bytes]
-5
View File
@@ -1,5 +0,0 @@
Place here test results for pcaps used for regressions testing
Example
for pcap/myprotocol.pcap add result/myprotocol.result
+6 -5
View File
@@ -4,7 +4,8 @@ HTTP 450 294880 19
SSDP 11 4984 1
WorldOfWarcraft 9 880 1
IGMP 2 120 1
SSL 43 2903 13
SSL 27 1803 9
Skype 16 1100 4
Google 12 1467 2
Quic 6 475 1
Starcraft 236 51494 6
@@ -27,10 +28,10 @@ Starcraft 236 51494 6
16 TCP 192.168.1.100:3530 <-> 2.228.46.112:80 [proto: 7/HTTP][29 pkts/25102 bytes][Host: bnetcmsus-a.akamaihd.net]
17 TCP 192.168.1.100:3532 <-> 2.228.46.112:80 [proto: 7/HTTP][4 pkts/386 bytes]
18 TCP 192.168.1.100:3534 <-> 2.228.46.112:80 [proto: 7/HTTP][1 pkts/66 bytes]
19 TCP 192.168.1.100:3489 <-> 2.228.46.104:443 [proto: 91/SSL][4 pkts/275 bytes]
19 TCP 192.168.1.100:3489 <-> 2.228.46.104:443 [proto: 125/Skype][4 pkts/275 bytes]
20 TCP 192.168.1.100:3481 <-> 2.228.46.114:443 [proto: 91/SSL][4 pkts/275 bytes]
21 TCP 192.168.1.100:3479 <-> 2.228.46.114:443 [proto: 91/SSL][4 pkts/275 bytes]
22 TCP 192.168.1.100:3491 <-> 2.228.46.104:443 [proto: 91/SSL][4 pkts/275 bytes]
22 TCP 192.168.1.100:3491 <-> 2.228.46.104:443 [proto: 125/Skype][4 pkts/275 bytes]
23 TCP 80.239.186.26:80 <-> 192.168.1.100:3515 [proto: 7/HTTP][10 pkts/1224 bytes][Host: nydus.battle.net]
24 TCP 80.239.186.21:80 <-> 192.168.1.100:3519 [proto: 7/HTTP][9 pkts/979 bytes][Host: eu.launcher.battle.net]
25 TCP 80.239.186.26:80 <-> 192.168.1.100:3521 [proto: 7/HTTP][10 pkts/1224 bytes][Host: nydus.battle.net]
@@ -54,8 +55,8 @@ Starcraft 236 51494 6
43 TCP 192.168.1.100:3529 <-> 2.228.46.112:80 [proto: 7/HTTP][29 pkts/25102 bytes][Host: bnetcmsus-a.akamaihd.net]
44 TCP 192.168.1.100:3531 <-> 2.228.46.112:80 [proto: 7/HTTP][29 pkts/25102 bytes][Host: bnetcmsus-a.akamaihd.net]
45 TCP 192.168.1.100:3533 <-> 2.228.46.112:80 [proto: 7/HTTP][4 pkts/386 bytes]
46 TCP 192.168.1.100:3492 <-> 2.228.46.104:443 [proto: 91/SSL][4 pkts/275 bytes]
47 TCP 192.168.1.100:3490 <-> 2.228.46.104:443 [proto: 91/SSL][4 pkts/275 bytes]
46 TCP 192.168.1.100:3492 <-> 2.228.46.104:443 [proto: 125/Skype][4 pkts/275 bytes]
47 TCP 192.168.1.100:3490 <-> 2.228.46.104:443 [proto: 125/Skype][4 pkts/275 bytes]
48 TCP 192.168.1.100:3482 <-> 2.228.46.114:443 [proto: 91/SSL][4 pkts/275 bytes]
49 TCP 192.168.1.100:3480 <-> 2.228.46.114:443 [proto: 91/SSL][4 pkts/275 bytes]
50 TCP 12.129.222.54:80 <-> 192.168.1.100:3512 [proto: 7.76/HTTP.WorldOfWarcraft][9 pkts/880 bytes][Host: us.scan.worldofwarcraft.com]