Removed linux kernel support

This commit is contained in:
Luca Deri
2015-10-24 12:47:23 +02:00
parent 27ea5c0026
commit 76c2fb3de7
8 changed files with 1 additions and 265 deletions
-4
View File
@@ -1,4 +0,0 @@
This package is a GPL implementation of an iptables and netfilter module for
nDPI integration into the Linux kernel.
https://github.com/ewildgoose/ndpi-netfilter
-2
View File
@@ -219,10 +219,8 @@ struct ndpi_ip6_ext
#define s6_addr32 u6_addr.u6_addr32 #define s6_addr32 u6_addr.u6_addr32
*/ */
#else #else
#ifndef __KERNEL__
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
#endif
struct ndpi_in6_addr { struct ndpi_in6_addr {
union { union {
-13
View File
@@ -218,12 +218,7 @@
#define NDPI_COMPARE_IPV6_ADDRESS_STRUCTS(x,y) \ #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])) ) ((((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 #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 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)) #define howmanybits(x, y) (((x)+((y)-1))/(y))
@@ -289,18 +284,10 @@
#define get_l32(X,O) get_u_int32_t(X,O) #define get_l32(X,O) get_u_int32_t(X,O)
#elif defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) #elif defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN)
/* convert the bytes from big to little 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_l16(X,O) bswap_16(get_u_int16_t(X,O))
# define get_l32(X,O) bswap_32(get_u_int32_t(X,O)) # define get_l32(X,O) bswap_32(get_u_int32_t(X,O))
#else #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 !" #error "__BYTE_ORDER MUST BE DEFINED !"
#endif /* __BYTE_ORDER */ #endif /* __BYTE_ORDER */
/* define memory callback function */ /* define memory callback function */
-13
View File
@@ -25,7 +25,6 @@
#ifndef __NDPI_MAIN_INCLUDE_FILE__ #ifndef __NDPI_MAIN_INCLUDE_FILE__
#define __NDPI_MAIN_INCLUDE_FILE__ #define __NDPI_MAIN_INCLUDE_FILE__
#ifndef __KERNEL__
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
@@ -35,33 +34,21 @@
#endif #endif
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
#endif
#ifndef WIN32 #ifndef WIN32
#ifndef __KERNEL__
#include <sys/time.h> #include <sys/time.h>
#endif
#if !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__ && !defined __OpenBSD__ #if !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__ && !defined __OpenBSD__
#ifndef __KERNEL__
#include <endian.h> #include <endian.h>
#include <byteswap.h> #include <byteswap.h>
#else
#include <asm/byteorder.h>
#include <linux/ctype.h>
#endif
#endif #endif
/* default includes */ /* default includes */
#ifndef __KERNEL__
#include <sys/param.h> #include <sys/param.h>
#include <limits.h> #include <limits.h>
#endif #endif
#endif
#include "ndpi_win32.h" #include "ndpi_win32.h"
#include "ndpi_unix.h" #include "ndpi_unix.h"
-7
View File
@@ -100,7 +100,6 @@ typedef union {
#ifdef NDPI_PROTOCOL_BITTORRENT #ifdef NDPI_PROTOCOL_BITTORRENT
#ifndef __KERNEL__
typedef struct spinlock { typedef struct spinlock {
volatile int val; volatile int val;
} spinlock_t; } spinlock_t;
@@ -108,8 +107,6 @@ typedef struct atomic {
volatile int counter; volatile int counter;
} atomic_t; } atomic_t;
#endif
struct hash_ip4p_node { struct hash_ip4p_node {
struct hash_ip4p_node *next,*prev; struct hash_ip4p_node *next,*prev;
time_t lchg; time_t lchg;
@@ -692,11 +689,7 @@ typedef struct ndpi_flow_struct {
that identifies the that identifies the
server of this connection server of this connection
*/ */
#ifndef __KERNEL__
u_char host_server_name[256]; /* HTTP host or DNS query */ 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 detected_os[32]; /* Via HTTP User-Agent */
u_char nat_ip[24]; /* Via HTTP X-Forwarded-For */ u_char nat_ip[24]; /* Via HTTP X-Forwarded-For */
-7
View File
@@ -38,16 +38,9 @@
#endif #endif
#ifndef WIN32 #ifndef WIN32
#ifndef __KERNEL__
#include <netinet/ip.h> #include <netinet/ip.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <netinet/udp.h> #include <netinet/udp.h>
#else
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#endif
#endif #endif
#endif /* __NDPI_UNIX_INCLUDE_FILE__ */ #endif /* __NDPI_UNIX_INCLUDE_FILE__ */
+1 -203
View File
@@ -23,30 +23,18 @@
*/ */
#ifndef __KERNEL__
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#endif
#include "ahocorasick.h" #include "ahocorasick.h"
#include "ndpi_api.h" #include "ndpi_api.h"
#ifndef __KERNEL__
#include "../../config.h" #include "../../config.h"
#endif
// #define DEBUG // #define DEBUG
#ifdef __KERNEL__
#include <linux/version.h>
#define printf printk
#else
#include <time.h> #include <time.h>
#ifndef WIN32 #ifndef WIN32
#include <unistd.h> #include <unistd.h>
#endif #endif
#endif
#include "ndpi_content_match.c.inc" #include "ndpi_content_match.c.inc"
#include "third_party/include/ndpi_patricia.h" #include "third_party/include/ndpi_patricia.h"
@@ -59,115 +47,6 @@
#endif #endif
#endif #endif
#ifdef __KERNEL__
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
static inline char _tolower(const char c)
{
return c | 0x20;
}
static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
{
unsigned long long acc;
int ok;
if(base == 0) {
if(s[0] == '0') {
if(_tolower(s[1]) == 'x' && isxdigit(s[2]))
base = 16;
else
base = 8;
} else
base = 10;
}
if(base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
s += 2;
acc = 0;
ok = 0;
while (*s) {
unsigned int val;
if('0' <= *s && *s <= '9')
val = *s - '0';
else if('a' <= _tolower(*s) && _tolower(*s) <= 'f')
val = _tolower(*s) - 'a' + 10;
else if(*s == '\n') {
if(*(s + 1) == '\0')
break;
else
return -EINVAL;
} else
return -EINVAL;
if(val >= base)
return -EINVAL;
if(acc > div_u64(ULLONG_MAX - val, base))
return -ERANGE;
acc = acc * base + val;
ok = 1;
s++;
}
if(!ok)
return -EINVAL;
*res = acc;
return 0;
}
int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
{
if(s[0] == '+')
s++;
return _kstrtoull(s, base, res);
}
int kstrtoll(const char *s, unsigned int base, long long *res)
{
unsigned long long tmp;
int rv;
if(s[0] == '-') {
rv = _kstrtoull(s + 1, base, &tmp);
if(rv < 0)
return rv;
if((long long)(-tmp) >= 0)
return -ERANGE;
*res = -tmp;
} else {
rv = kstrtoull(s, base, &tmp);
if(rv < 0)
return rv;
if((long long)tmp < 0)
return -ERANGE;
*res = tmp;
}
return 0;
}
int kstrtoint(const char *s, unsigned int base, int *res)
{
long long tmp;
int rv;
rv = kstrtoll(s, base, &tmp);
if(rv < 0)
return rv;
if(tmp != (long long)(int)tmp)
return -ERANGE;
*res = tmp;
return 0;
}
#endif
int atoi(const char *str) {
int rc;
if(kstrtoint(str, 0, &rc) == 0 /* Success */)
return(rc);
else
return(0);
}
#endif
/* ftp://ftp.cc.uoc.gr/mirrors/OpenBSD/src/lib/libc/stdlib/tsearch.c */ /* ftp://ftp.cc.uoc.gr/mirrors/OpenBSD/src/lib/libc/stdlib/tsearch.c */
/* find or insert datum into search tree */ /* find or insert datum into search tree */
void * void *
@@ -1966,54 +1845,6 @@ u_int16_t ndpi_guess_protocol_id(struct ndpi_detection_module_struct *ndpi_struc
/* ******************************************************************** */ /* ******************************************************************** */
#if 0
#ifndef __KERNEL__
static int add_proto_default_port(u_int16_t **ports, u_int16_t new_port,
ndpi_proto_defaults_t *def,
ndpi_default_ports_tree_node_t *root) {
u_int num_ports, i;
if(*ports == NULL) {
ndpi_port_range range = { new_port, new_port };
addDefaultPort(&range, def, &root);
return(0);
}
for(num_ports=0; (*ports)[num_ports] != 0; num_ports++)
;
if(num_ports >= MAX_DEFAULT_PORTS) {
printf("Too many ports defined: ignored port %d\n", new_port);
return(-1);
} else {
u_int16_t *new_ports = (u_int16_t*)ndpi_malloc(num_ports+1);
ndpi_port_range range;
if(new_ports == NULL) {
printf("Not enough memory\n");
return(-2);
}
for(i=0; i<num_ports; i++)
new_ports[i] = (*ports)[i];
new_ports[i++] = new_port;
new_ports[i++] = 0;
ndpi_free(*ports);
*ports = new_ports;
range.port_low = range.port_high = new_port;
addDefaultPort(&range, def, &root);
return(0);
}
}
#endif
#endif
/* ******************************************************************** */
u_int ndpi_get_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod) { u_int ndpi_get_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod) {
return(ndpi_mod->ndpi_num_supported_protocols); return(ndpi_mod->ndpi_num_supported_protocols);
} }
@@ -2135,9 +1966,6 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod, char* rule,
*/ */
int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char* path) { int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char* path) {
#ifdef __KERNEL__
return(0);
#else
FILE *fd = fopen(path, "r"); FILE *fd = fopen(path, "r");
int i; int i;
@@ -2162,14 +1990,6 @@ int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char
fclose(fd); fclose(fd);
#if 0
printf("\nTCP:\n");
ndpi_twalk(ndpi_mod->tcpRoot, ndpi_default_ports_tree_node_t_walker, NULL);
printf("\nUDP:\n");
ndpi_twalk(ndpi_mod->udpRoot, ndpi_default_ports_tree_node_t_walker, NULL);
#endif
#endif
return(0); return(0);
} }
@@ -3324,15 +3144,7 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
} }
flow->packet.tick_timestamp_l = current_tick_l; flow->packet.tick_timestamp_l = current_tick_l;
#ifdef __KERNEL__
{
u_int64_t d = current_tick_l;
do_div(d,1000);
flow->packet.tick_timestamp = d;
}
#else
flow->packet.tick_timestamp = (u_int32_t)current_tick_l/1000; flow->packet.tick_timestamp = (u_int32_t)current_tick_l/1000;
#endif
/* parse packet */ /* parse packet */
flow->packet.iph = (struct ndpi_iphdr *)packet; flow->packet.iph = (struct ndpi_iphdr *)packet;
@@ -4190,16 +4002,6 @@ u_int16_t ntohs_ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_ch
/* ****************************************************** */ /* ****************************************************** */
#if 0
#ifndef __KERNEL__
static u_int is_port(u_int16_t sport, u_int16_t dport, u_int16_t match_port) {
return(((match_port == sport) || (match_port == dport)) ? 1 : 0);
}
#endif
#endif
/* ****************************************************** */
ndpi_protocol ndpi_find_port_based_protocol(struct ndpi_detection_module_struct *ndpi_struct /* NOTUSED */, ndpi_protocol ndpi_find_port_based_protocol(struct ndpi_detection_module_struct *ndpi_struct /* NOTUSED */,
u_int8_t proto, u_int8_t proto,
u_int32_t shost, u_int16_t sport, u_int32_t shost, u_int16_t sport,
@@ -4504,11 +4306,7 @@ void ndpi_free_flow(struct ndpi_flow_struct *flow) {
/* ****************************************************** */ /* ****************************************************** */
#ifndef __KERNEL__ char* ndpi_revision() { return(NDPI_GIT_RELEASE); }
char* ndpi_revision() {
return(NDPI_GIT_RELEASE);
}
#endif
/* ****************************************************** */ /* ****************************************************** */
-16
View File
@@ -1,16 +0,0 @@
DNS 4 800 2
HTTP 10 1792 1
IMAPS 4 516 2
SSL 61 29323 2
ICMPV6 48 7862 3
1 TCP :443 <-> :53234 [proto: 91/SSL][33 pkts/13926 bytes]
2 UDP 2001:470:1f16:13f::2:6404 <-> 2a03:2880:fffe:b:face:b00c:0:99:53 [proto: 5/DNS][2 pkts/394 bytes]
3 TCP :443 <-> 2604:a880:1:20::224:b001:60205 [proto: 91/SSL][28 pkts/15397 bytes]
4 ICMPV6 2001:470:1f16:13f::2:0 <-> 2604:a880:1:20::224:b001:0 [proto: 102/ICMPV6][1 pkts/200 bytes]
5 ICMPV6 :0 <-> :0 [proto: 102/ICMPV6][1 pkts/1314 bytes]
6 TCP 2604:a880:1:20::224:b001:993 <-> :35610 [proto: 51/IMAPS][2 pkts/258 bytes]
7 ICMPV6 :0 <-> 2604:a880:1:20::224:b001:0 [proto: 102/ICMPV6][46 pkts/6348 bytes]
8 TCP 2604:a880:1:20::224:b001:993 <-> :56381 [proto: 51/IMAPS][2 pkts/258 bytes]
9 UDP 2001:470:1f16:13f::2:53959 <-> 2a03:2880:fffe:b:face:b00c:0:99:53 [proto: 5/DNS][2 pkts/406 bytes]
10 TCP :80 <-> 2604:a880:1:20::224:b001:41538 [proto: 7/HTTP][10 pkts/1792 bytes]