Implemented custom category loading.
Modified ndpiReader with -c <file> (use mining_hosts.txt as example) for loading name-based categories
This commit is contained in:
@@ -0,0 +1,262 @@
|
|||||||
|
# NoCoin Filter List
|
||||||
|
# Blocking Web Browser Bitcoin Mining
|
||||||
|
#
|
||||||
|
# Homepage: https://github.com/hoshsadiq/adblock-nocoin-list/
|
||||||
|
# Contribute: https://github.com/hoshsadiq/adblock-nocoin-list/issues
|
||||||
|
# Changelog: https://github.com/hoshsadiq/adblock-nocoin-list/commits/master/hosts.txt
|
||||||
|
# License: https://mit-license.org/
|
||||||
|
#
|
||||||
|
# Last modified: 24 April 2018
|
||||||
|
#
|
||||||
|
|
||||||
|
cnhv.co 99
|
||||||
|
coin-hive.com 99
|
||||||
|
coinhive.com 99
|
||||||
|
authedmine.com 99
|
||||||
|
gus.host 99
|
||||||
|
load.jsecoin.com 99
|
||||||
|
miner.pr0gramm.com 99
|
||||||
|
minemytraffic.com 99
|
||||||
|
ppoi.org 99
|
||||||
|
projectpoi.com 99
|
||||||
|
crypto-loot.com 99
|
||||||
|
coinerra.com 99
|
||||||
|
coin-have.com 99
|
||||||
|
minero.pw 99
|
||||||
|
minero-proxy-01.now.sh 99
|
||||||
|
minero-proxy-02.now.sh 99
|
||||||
|
minero-proxy-03.now.sh 99
|
||||||
|
api.inwemo.com 99
|
||||||
|
rocks.io 99
|
||||||
|
adminer.com 99
|
||||||
|
ad-miner.com 99
|
||||||
|
jsccnn.com 99
|
||||||
|
jscdndel.com 99
|
||||||
|
coinhiveproxy.com 99
|
||||||
|
coinblind.com 99
|
||||||
|
coinnebula.com 99
|
||||||
|
monerominer.rocks 99
|
||||||
|
cdn.cloudcoins.co 99
|
||||||
|
coinlab.biz 99
|
||||||
|
go.megabanners.cf 99
|
||||||
|
baiduccdn1.com 99
|
||||||
|
wsp.marketgid.com 99
|
||||||
|
papoto.com 99
|
||||||
|
flare-analytics.com 99
|
||||||
|
www.sparechange.io 99
|
||||||
|
static.sparechange.io 99
|
||||||
|
miner.nablabee.com 99
|
||||||
|
m.anyfiles.ovh 99
|
||||||
|
www.freecontent.bid 99
|
||||||
|
www.freecontent.loan 99
|
||||||
|
www.freecontent.win 99
|
||||||
|
www.cryptonoter.com 99
|
||||||
|
www.mutuza.win 99
|
||||||
|
cryweb.github.io 99
|
||||||
|
crywebber.github.io 99
|
||||||
|
crypto-webminer.com 99
|
||||||
|
cdn.adless.io 99
|
||||||
|
hegrinhar.com 99
|
||||||
|
verresof.com 99
|
||||||
|
hemnes.win 99
|
||||||
|
tidafors.xyz 99
|
||||||
|
moneone.ga 99
|
||||||
|
plexcoin.info 99
|
||||||
|
www.monkeyminer.net 99
|
||||||
|
go2.mercy.ga 99
|
||||||
|
coinpirate.cf 99
|
||||||
|
d.cpufan.club 99
|
||||||
|
krb.devphp.org.ua 99
|
||||||
|
nfwebminer.com 99
|
||||||
|
cfcdist.gdn 99
|
||||||
|
node.cfcdist.gdn 99
|
||||||
|
webxmr.com 99
|
||||||
|
xmr.mining.best 99
|
||||||
|
webminepool.com 99
|
||||||
|
webminepool.tk 99
|
||||||
|
hive.tubetitties.com 99
|
||||||
|
playerassets.info 99
|
||||||
|
tokyodrift.ga 99
|
||||||
|
webassembly.stream 99
|
||||||
|
okeyletsgo.ml 99
|
||||||
|
candid.zone 99
|
||||||
|
webmine.pro 99
|
||||||
|
andlache.com 99
|
||||||
|
bablace.com 99
|
||||||
|
bewaslac.com 99
|
||||||
|
biberukalap.com 99
|
||||||
|
bowithow.com 99
|
||||||
|
butcalve.com 99
|
||||||
|
evengparme.com 99
|
||||||
|
gridiogrid.com 99
|
||||||
|
hatcalter.com 99
|
||||||
|
kedtise.com 99
|
||||||
|
ledinund.com 99
|
||||||
|
nathetsof.com 99
|
||||||
|
renhertfo.com 99
|
||||||
|
rintindown.com 99
|
||||||
|
sparnove.com 99
|
||||||
|
witthethim.com 99
|
||||||
|
1q2w3.fun 99
|
||||||
|
1q2w3.me 99
|
||||||
|
cryptoloot.pro 99
|
||||||
|
bjorksta.men 99
|
||||||
|
crypto.csgocpu.com 99
|
||||||
|
noblock.pro 99
|
||||||
|
miner.cryptobara.com 99
|
||||||
|
digger.cryptobara.com 99
|
||||||
|
dev.cryptobara.com 99
|
||||||
|
reservedoffers.club 99
|
||||||
|
mine.torrent.pw 99
|
||||||
|
host.d-ns.ga 99
|
||||||
|
abc.pema.cl 99
|
||||||
|
mine.nahnoji.cz 99
|
||||||
|
webmine.cz 99
|
||||||
|
intactoffers.club 99
|
||||||
|
analytics.blue 99
|
||||||
|
smectapop12.pl 99
|
||||||
|
berserkpl.net.pl 99
|
||||||
|
hodlers.party 99
|
||||||
|
hodling.faith 99
|
||||||
|
chainblock.science 99
|
||||||
|
minescripts.info 99
|
||||||
|
cdn.minescripts.info 99
|
||||||
|
miner.nablabee.com 99
|
||||||
|
wss.nablabee.com 99
|
||||||
|
clickwith.bid 99
|
||||||
|
dronml.ml 99
|
||||||
|
niematego.tk 99
|
||||||
|
tulip18.com 99
|
||||||
|
p.estream.to 99
|
||||||
|
didnkinrab.com 99
|
||||||
|
ledhenone.com 99
|
||||||
|
losital.ru 99
|
||||||
|
mebablo.com 99
|
||||||
|
moonsade.com 99
|
||||||
|
nebabrop.com 99
|
||||||
|
pearno.com 99
|
||||||
|
rintinwa.com 99
|
||||||
|
willacrit.com 99
|
||||||
|
www2.adfreetv.ch 99
|
||||||
|
minr.pw 99
|
||||||
|
new.minr.pw 99
|
||||||
|
test.minr.pw 99
|
||||||
|
staticsfs.host 99
|
||||||
|
cdn-code.host 99
|
||||||
|
g-content.bid 99
|
||||||
|
ad.g-content.bid 99
|
||||||
|
cdn.static-cnt.bid 99
|
||||||
|
cnt.statistic.date 99
|
||||||
|
cdn.jquery-uim.download 99
|
||||||
|
cdn-jquery.host 99
|
||||||
|
p1.interestingz.pw 99
|
||||||
|
kippbeak.cf 99
|
||||||
|
pasoherb.gq 99
|
||||||
|
axoncoho.tk 99
|
||||||
|
depttake.ga 99
|
||||||
|
flophous.cf 99
|
||||||
|
pr0gram.org 99
|
||||||
|
authedmine.eu 99
|
||||||
|
www.monero-miner.com 99
|
||||||
|
www.datasecu.download 99
|
||||||
|
www.jquery-cdn.download 99
|
||||||
|
www.etzbnfuigipwvs.ru 99
|
||||||
|
www.terethat.ru 99
|
||||||
|
freshrefresher.com 99
|
||||||
|
api.pzoifaum.info 99
|
||||||
|
ws.pzoifaum.info 99
|
||||||
|
api.bhzejltg.info 99
|
||||||
|
ws.bhzejltg.info 99
|
||||||
|
d.cfcnet.top 99
|
||||||
|
vip.cfcnet.top 99
|
||||||
|
eu.cfcnet.top 99
|
||||||
|
as.cfcnet.top 99
|
||||||
|
us.cfcnet.top 99
|
||||||
|
eu.cfcdist.loan 99
|
||||||
|
as.cfcdist.loan 99
|
||||||
|
us.cfcdist.loan 99
|
||||||
|
gustaver.ddns.net 99
|
||||||
|
worker.salon.com 99
|
||||||
|
s2.appelamule.com 99
|
||||||
|
mepirtedic.com 99
|
||||||
|
cdn.streambeam.io 99
|
||||||
|
adzjzewsma.cf 99
|
||||||
|
ffinwwfpqi.gq 99
|
||||||
|
ininmacerad.pro 99
|
||||||
|
mhiobjnirs.gq 99
|
||||||
|
open-hive-server-1.pp.ua 99
|
||||||
|
pool.hws.ru 99
|
||||||
|
pool.etn.spacepools.org 99
|
||||||
|
api.aalbbh84.info 99
|
||||||
|
www.aymcsx.ru 99
|
||||||
|
aeros01.tk 99
|
||||||
|
aeros02.tk 99
|
||||||
|
aeros03.tk 99
|
||||||
|
aeros04.tk 99
|
||||||
|
aeros05.tk 99
|
||||||
|
aeros06.tk 99
|
||||||
|
aeros07.tk 99
|
||||||
|
aeros08.tk 99
|
||||||
|
aeros09.tk 99
|
||||||
|
aeros10.tk 99
|
||||||
|
aeros11.tk 99
|
||||||
|
aeros12.tk 99
|
||||||
|
npcdn1.now.sh 99
|
||||||
|
mxcdn2.now.sh 99
|
||||||
|
sxcdn6.now.sh 99
|
||||||
|
mxcdn1.now.sh 99
|
||||||
|
sxcdn02.now.sh 99
|
||||||
|
sxcdn4.now.sh 99
|
||||||
|
jqcdn2.herokuapp.com 99
|
||||||
|
sxcdn1.herokuapp.com 99
|
||||||
|
sxcdn5.herokuapp.com 99
|
||||||
|
wpcdn1.herokuapp.com 99
|
||||||
|
jqcdn01.herokuapp.com 99
|
||||||
|
jqcdn03.herokuapp.com 99
|
||||||
|
1q2w3.website 99
|
||||||
|
video.videos.vidto.me 99
|
||||||
|
video.streaming.estream.to 99
|
||||||
|
eth-pocket.de 99
|
||||||
|
xvideosharing.site 99
|
||||||
|
bestcoinsignals.com 99
|
||||||
|
eucsoft.com 99
|
||||||
|
traviilo.com 99
|
||||||
|
wasm24.ru 99
|
||||||
|
xmr.cool 99
|
||||||
|
api.netflare.info 99
|
||||||
|
cdnjs.cloudflane.com 99
|
||||||
|
www.cloudflane.com 99
|
||||||
|
hide.ovh 99
|
||||||
|
graftpool.ovh 99
|
||||||
|
encoding.ovh 99
|
||||||
|
altavista.ovh 99
|
||||||
|
scaleway.ovh 99
|
||||||
|
nexttime.ovh 99
|
||||||
|
never.ovh 99
|
||||||
|
2giga.download 99
|
||||||
|
support.2giga.link 99
|
||||||
|
webminerpool.com 99
|
||||||
|
minercry.pt 99
|
||||||
|
adplusplus.fr 99
|
||||||
|
|
||||||
|
# Does not seem to work anymore, but keeping it here just in case it gets revived
|
||||||
|
azvjudwr.info 99
|
||||||
|
jroqvbvw.info 99
|
||||||
|
jyhfuqoh.info 99
|
||||||
|
kdowqlpt.info 99
|
||||||
|
xbasfbno.info 99
|
||||||
|
|
||||||
|
# These were Obfuscated
|
||||||
|
1beb2a44.space 99
|
||||||
|
300ca0d0.space 99
|
||||||
|
310ca263.space 99
|
||||||
|
320ca3f6.space 99
|
||||||
|
330ca589.space 99
|
||||||
|
340ca71c.space 99
|
||||||
|
360caa42.space 99
|
||||||
|
370cabd5.space 99
|
||||||
|
3c0cb3b4.space 99
|
||||||
|
3d0cb547.space 99
|
||||||
|
|
||||||
|
imageshack.us 99
|
||||||
|
img265.imageshack.us 99
|
||||||
+42
-3
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* ndpiReader.c
|
* ndpiReader.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011-17 - ntop.org
|
* Copyright (C) 2011-18 - ntop.org
|
||||||
*
|
*
|
||||||
* nDPI is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -67,6 +67,7 @@ static FILE *results_file = NULL;
|
|||||||
static char *results_path = NULL;
|
static char *results_path = NULL;
|
||||||
static char * bpfFilter = NULL; /**< bpf filter */
|
static char * bpfFilter = NULL; /**< bpf filter */
|
||||||
static char *_protoFilePath = NULL; /**< Protocol file path */
|
static char *_protoFilePath = NULL; /**< Protocol file path */
|
||||||
|
static char *_customCategoryFilePath= NULL; /**< Custom categories file path */
|
||||||
#ifdef HAVE_JSON_C
|
#ifdef HAVE_JSON_C
|
||||||
static char *_statsFilePath = NULL; /**< Top stats file path */
|
static char *_statsFilePath = NULL; /**< Top stats file path */
|
||||||
static char *_diagnoseFilePath = NULL; /**< Top stats file path */
|
static char *_diagnoseFilePath = NULL; /**< Top stats file path */
|
||||||
@@ -230,7 +231,7 @@ static void help(u_int long_help) {
|
|||||||
|
|
||||||
printf("ndpiReader -i <file|device> [-f <filter>][-s <duration>][-m <duration>]\n"
|
printf("ndpiReader -i <file|device> [-f <filter>][-s <duration>][-m <duration>]\n"
|
||||||
" [-p <protos>][-l <loops> [-q][-d][-h][-t][-v <level>]\n"
|
" [-p <protos>][-l <loops> [-q][-d][-h][-t][-v <level>]\n"
|
||||||
" [-n <threads>] [-w <file>] [-j <file>] [-x <file>] \n\n"
|
" [-n <threads>][-w <file>][-c <file>][-j <file>][-x <file>]\n\n"
|
||||||
"Usage:\n"
|
"Usage:\n"
|
||||||
" -i <file.pcap|device> | Specify a pcap file/playlist to read packets from or a\n"
|
" -i <file.pcap|device> | Specify a pcap file/playlist to read packets from or a\n"
|
||||||
" | device for live capture (comma-separated list)\n"
|
" | device for live capture (comma-separated list)\n"
|
||||||
@@ -249,6 +250,7 @@ static void help(u_int long_help) {
|
|||||||
" -q | Quiet mode\n"
|
" -q | Quiet mode\n"
|
||||||
" -t | Dissect GTP/TZSP tunnels\n"
|
" -t | Dissect GTP/TZSP tunnels\n"
|
||||||
" -r | Print nDPI version and git revision\n"
|
" -r | Print nDPI version and git revision\n"
|
||||||
|
" -c <path> | Load custom categories from the specified file\n"
|
||||||
" -w <path> | Write test output on the specified file. This is useful for\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"
|
" | testing purposes in order to compare results across runs\n"
|
||||||
" -h | This help\n"
|
" -h | This help\n"
|
||||||
@@ -449,7 +451,7 @@ static void parseOptions(int argc, char **argv) {
|
|||||||
if(trace) fprintf(trace, " #### %s #### \n", __FUNCTION__);
|
if(trace) fprintf(trace, " #### %s #### \n", __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, "df:g:i:hp:l:s:tv:V:n:j:rp:w:q0123:456:7:89:m:b:x:", longopts, &option_idx)) != EOF) {
|
while ((opt = getopt_long(argc, argv, "c:df:g:i:hp:l:s:tv:V:n:j:rp:w:q0123:456:7:89:m:b:x:", longopts, &option_idx)) != EOF) {
|
||||||
#ifdef DEBUG_TRACE
|
#ifdef DEBUG_TRACE
|
||||||
if(trace) fprintf(trace, " #### -%c [%s] #### \n", opt, optarg ? optarg : "");
|
if(trace) fprintf(trace, " #### -%c [%s] #### \n", opt, optarg ? optarg : "");
|
||||||
#endif
|
#endif
|
||||||
@@ -507,6 +509,10 @@ static void parseOptions(int argc, char **argv) {
|
|||||||
_protoFilePath = optarg;
|
_protoFilePath = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'c':
|
||||||
|
_customCategoryFilePath = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
capture_for = atoi(optarg);
|
capture_for = atoi(optarg);
|
||||||
capture_until = capture_for + time(NULL);
|
capture_until = capture_for + time(NULL);
|
||||||
@@ -1463,6 +1469,39 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
|
|||||||
|
|
||||||
if(_protoFilePath != NULL)
|
if(_protoFilePath != NULL)
|
||||||
ndpi_load_protocols_file(ndpi_thread_info[thread_id].workflow->ndpi_struct, _protoFilePath);
|
ndpi_load_protocols_file(ndpi_thread_info[thread_id].workflow->ndpi_struct, _protoFilePath);
|
||||||
|
|
||||||
|
if(_customCategoryFilePath) {
|
||||||
|
FILE *fd = fopen(_customCategoryFilePath, "r");
|
||||||
|
|
||||||
|
if(fd) {
|
||||||
|
while(fd) {
|
||||||
|
char buffer[512], *line, *name, *category;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if(!(line = fgets(buffer, sizeof(buffer), fd)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(((i = strlen(line)) <= 1) || (line[0] == '#'))
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
line[i-1] = '\0';
|
||||||
|
|
||||||
|
name = strtok(line, "\t");
|
||||||
|
if(name) {
|
||||||
|
category = strtok(NULL, "\t");
|
||||||
|
|
||||||
|
if(category) {
|
||||||
|
// printf("Loading %s\t%s\n", name, category);
|
||||||
|
ndpi_load_hostname_category(ndpi_thread_info[thread_id].workflow->ndpi_struct,
|
||||||
|
name, (ndpi_protocol_category_t)atoi(category));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ndpi_enable_loaded_categories(ndpi_thread_info[thread_id].workflow->ndpi_struct);
|
||||||
|
} else
|
||||||
|
printf("ERROR: Unable to read file %s\n", _customCategoryFilePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+10
-3
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* ndpi_util.c
|
* ndpi_util.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011-17 - ntop.org
|
* Copyright (C) 2011-18 - ntop.org
|
||||||
*
|
*
|
||||||
* This file is part of nDPI, an open source deep packet inspection
|
* This file is part of nDPI, an open source deep packet inspection
|
||||||
* library based on the OpenDPI and PACE technology by ipoque GmbH
|
* library based on the OpenDPI and PACE technology by ipoque GmbH
|
||||||
@@ -164,7 +164,8 @@ return 0;
|
|||||||
extern char *_debug_protocols;
|
extern char *_debug_protocols;
|
||||||
static int _debug_protocols_ok = 0;
|
static int _debug_protocols_ok = 0;
|
||||||
|
|
||||||
struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * prefs, pcap_t * pcap_handle) {
|
struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * prefs,
|
||||||
|
pcap_t * pcap_handle) {
|
||||||
set_ndpi_malloc(malloc_wrapper), set_ndpi_free(free_wrapper);
|
set_ndpi_malloc(malloc_wrapper), set_ndpi_free(free_wrapper);
|
||||||
set_ndpi_flow_malloc(NULL), set_ndpi_flow_free(NULL);
|
set_ndpi_flow_malloc(NULL), set_ndpi_flow_free(NULL);
|
||||||
/* TODO: just needed here to init ndpi malloc wrapper */
|
/* TODO: just needed here to init ndpi malloc wrapper */
|
||||||
@@ -187,12 +188,15 @@ struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * pre
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
_debug_protocols_ok = 1;
|
_debug_protocols_ok = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||||
NDPI_BITMASK_RESET(module->debug_bitmask);
|
NDPI_BITMASK_RESET(module->debug_bitmask);
|
||||||
if(_debug_protocols_ok)
|
if(_debug_protocols_ok)
|
||||||
module->debug_bitmask = debug_bitmask;
|
module->debug_bitmask = debug_bitmask;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *));
|
workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *));
|
||||||
|
|
||||||
return workflow;
|
return workflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,6 +518,8 @@ static struct ndpi_flow_info *get_ndpi_flow_info6(struct ndpi_workflow * workflo
|
|||||||
void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow) {
|
void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow) {
|
||||||
if(!flow->ndpi_flow) return;
|
if(!flow->ndpi_flow) return;
|
||||||
|
|
||||||
|
/* printf("CATEGORY %u\n", flow->detected_protocol.category); */
|
||||||
|
|
||||||
snprintf(flow->host_server_name, sizeof(flow->host_server_name), "%s",
|
snprintf(flow->host_server_name, sizeof(flow->host_server_name), "%s",
|
||||||
flow->ndpi_flow->host_server_name);
|
flow->ndpi_flow->host_server_name);
|
||||||
|
|
||||||
@@ -649,7 +655,8 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
|
|||||||
return(flow->detected_protocol);
|
return(flow->detected_protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
flow->detected_protocol = ndpi_detection_process_packet(workflow->ndpi_struct, ndpi_flow,
|
flow->detected_protocol =
|
||||||
|
ndpi_detection_process_packet(workflow->ndpi_struct, ndpi_flow,
|
||||||
iph ? (uint8_t *)iph : (uint8_t *)iph6,
|
iph ? (uint8_t *)iph : (uint8_t *)iph6,
|
||||||
ipsize, time, src, dst);
|
ipsize, time, src, dst);
|
||||||
|
|
||||||
|
|||||||
+31
-14
@@ -125,7 +125,8 @@ extern "C" {
|
|||||||
* @return the nDPI protocol ID
|
* @return the nDPI protocol ID
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, struct in_addr *pin);
|
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
struct in_addr *pin);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,7 +136,8 @@ extern "C" {
|
|||||||
* @par match = the struct passed to match the protocol
|
* @par match = the struct passed to match the protocol
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void ndpi_init_protocol_match(struct ndpi_detection_module_struct *ndpi_mod, ndpi_protocol_match *match);
|
void ndpi_init_protocol_match(struct ndpi_detection_module_struct *ndpi_mod,
|
||||||
|
ndpi_protocol_match *match);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new initialized detection module
|
* Returns a new initialized detection module
|
||||||
@@ -163,7 +165,8 @@ extern "C" {
|
|||||||
* @par port = unsigned int for the port number
|
* @par port = unsigned int for the port number
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void ndpi_enable_cache(struct ndpi_detection_module_struct *ndpi_mod, char* host, u_int port);
|
void ndpi_enable_cache(struct ndpi_detection_module_struct *ndpi_mod,
|
||||||
|
char* host, u_int port);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -193,7 +196,8 @@ extern "C" {
|
|||||||
const NDPI_PROTOCOL_BITMASK *detection_bitmask,
|
const NDPI_PROTOCOL_BITMASK *detection_bitmask,
|
||||||
const u_int32_t idx,
|
const u_int32_t idx,
|
||||||
u_int16_t ndpi_protocol_id,
|
u_int16_t ndpi_protocol_id,
|
||||||
void (*func) (struct ndpi_detection_module_struct *, struct ndpi_flow_struct *flow),
|
void (*func) (struct ndpi_detection_module_struct *,
|
||||||
|
struct ndpi_flow_struct *flow),
|
||||||
const NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_bitmask,
|
const NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_bitmask,
|
||||||
u_int8_t b_save_bitmask_unknow,
|
u_int8_t b_save_bitmask_unknow,
|
||||||
u_int8_t b_add_detection_bitmask);
|
u_int8_t b_add_detection_bitmask);
|
||||||
@@ -514,7 +518,8 @@ extern "C" {
|
|||||||
* @par proto = the struct ndpi_protocol contain the protocols name
|
* @par proto = the struct ndpi_protocol contain the protocols name
|
||||||
* @return the protocol category
|
* @return the protocol category
|
||||||
*/
|
*/
|
||||||
ndpi_protocol_category_t ndpi_get_proto_category(struct ndpi_detection_module_struct *ndpi_mod, ndpi_protocol proto);
|
ndpi_protocol_category_t ndpi_get_proto_category(struct ndpi_detection_module_struct *ndpi_mod,
|
||||||
|
ndpi_protocol proto);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the protocol name associated to the ID
|
* Get the protocol name associated to the ID
|
||||||
@@ -535,7 +540,8 @@ extern "C" {
|
|||||||
* @return the breed ID associated to the protocol
|
* @return the breed ID associated to the protocol
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
ndpi_protocol_breed_t ndpi_get_proto_breed(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t proto);
|
ndpi_protocol_breed_t ndpi_get_proto_breed(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
u_int16_t proto);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -546,7 +552,8 @@ extern "C" {
|
|||||||
* @return the string name of the breed ID
|
* @return the string name of the breed ID
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
char* ndpi_get_proto_breed_name(struct ndpi_detection_module_struct *ndpi_struct, ndpi_protocol_breed_t breed_id);
|
char* ndpi_get_proto_breed_name(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
ndpi_protocol_breed_t breed_id);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -594,7 +601,8 @@ extern "C" {
|
|||||||
* -1 else
|
* -1 else
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -623,7 +631,8 @@ extern "C" {
|
|||||||
* @par automa = the automa to match
|
* @par automa = the automa to match
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void ndpi_set_automa(struct ndpi_detection_module_struct *ndpi_struct, void* automa);
|
void ndpi_set_automa(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
void* automa);
|
||||||
|
|
||||||
|
|
||||||
#ifdef NDPI_PROTOCOL_HTTP
|
#ifdef NDPI_PROTOCOL_HTTP
|
||||||
@@ -635,7 +644,8 @@ extern "C" {
|
|||||||
* @return the HTTP method information about the flow
|
* @return the HTTP method information about the flow
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
ndpi_http_method ndpi_get_http_method(struct ndpi_detection_module_struct *ndpi_mod, struct ndpi_flow_struct *flow);
|
ndpi_http_method ndpi_get_http_method(struct ndpi_detection_module_struct *ndpi_mod,
|
||||||
|
struct ndpi_flow_struct *flow);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -646,7 +656,8 @@ extern "C" {
|
|||||||
* @return the HTTP method information about the flow
|
* @return the HTTP method information about the flow
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
char* ndpi_get_http_url(struct ndpi_detection_module_struct *ndpi_mod, struct ndpi_flow_struct *flow);
|
char* ndpi_get_http_url(struct ndpi_detection_module_struct *ndpi_mod,
|
||||||
|
struct ndpi_flow_struct *flow);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -657,7 +668,8 @@ extern "C" {
|
|||||||
* @return the HTTP method information about the flow
|
* @return the HTTP method information about the flow
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
char* ndpi_get_http_content_type(struct ndpi_detection_module_struct *ndpi_mod, struct ndpi_flow_struct *flow);
|
char* ndpi_get_http_content_type(struct ndpi_detection_module_struct *ndpi_mod,
|
||||||
|
struct ndpi_flow_struct *flow);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -737,6 +749,11 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
int ndpi_match_string(void *_automa, char *string_to_match);
|
int ndpi_match_string(void *_automa, char *string_to_match);
|
||||||
|
|
||||||
|
void ndpi_load_ip_category(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
char *ip_address_and_mask, ndpi_protocol_category_t category);
|
||||||
|
void ndpi_load_hostname_category(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
char *name, ndpi_protocol_category_t category);
|
||||||
|
void ndpi_enable_loaded_categories(struct ndpi_detection_module_struct *ndpi_struct);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a string to match to an automata
|
* Add a string to match to an automata
|
||||||
@@ -749,13 +766,13 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
int ndpi_match_string_id(void *_automa, char *string_to_match, unsigned long *id);
|
int ndpi_match_string_id(void *_automa, char *string_to_match, unsigned long *id);
|
||||||
|
|
||||||
|
|
||||||
/* Utility functions to set ndpi malloc/free/print wrappers */
|
/* Utility functions to set ndpi malloc/free/print wrappers */
|
||||||
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
|
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
|
||||||
void set_ndpi_free(void (*__ndpi_free)(void *ptr));
|
void set_ndpi_free(void (*__ndpi_free)(void *ptr));
|
||||||
void set_ndpi_flow_malloc(void* (*__ndpi_flow_malloc)(size_t size));
|
void set_ndpi_flow_malloc(void* (*__ndpi_flow_malloc)(size_t size));
|
||||||
void set_ndpi_flow_free(void (*__ndpi_flow_free)(void *ptr));
|
void set_ndpi_flow_free(void (*__ndpi_flow_free)(void *ptr));
|
||||||
void set_ndpi_debug_function(struct ndpi_detection_module_struct *ndpi_str, ndpi_debug_function_ptr ndpi_debug_printf);
|
void set_ndpi_debug_function(struct ndpi_detection_module_struct *ndpi_str,
|
||||||
|
ndpi_debug_function_ptr ndpi_debug_printf);
|
||||||
void * ndpi_malloc(size_t size);
|
void * ndpi_malloc(size_t size);
|
||||||
void * ndpi_calloc(unsigned long count, size_t size);
|
void * ndpi_calloc(unsigned long count, size_t size);
|
||||||
void ndpi_free(void *ptr);
|
void ndpi_free(void *ptr);
|
||||||
|
|||||||
@@ -820,6 +820,7 @@ typedef struct _ndpi_automa {
|
|||||||
|
|
||||||
typedef struct ndpi_proto {
|
typedef struct ndpi_proto {
|
||||||
u_int16_t master_protocol /* e.g. HTTP */, app_protocol /* e.g. FaceBook */;
|
u_int16_t master_protocol /* e.g. HTTP */, app_protocol /* e.g. FaceBook */;
|
||||||
|
ndpi_protocol_category_t category;
|
||||||
} ndpi_protocol;
|
} ndpi_protocol;
|
||||||
|
|
||||||
#define NDPI_PROTOCOL_NULL { NDPI_PROTOCOL_UNKNOWN , NDPI_PROTOCOL_UNKNOWN }
|
#define NDPI_PROTOCOL_NULL { NDPI_PROTOCOL_UNKNOWN , NDPI_PROTOCOL_UNKNOWN }
|
||||||
@@ -884,6 +885,11 @@ struct ndpi_detection_module_struct {
|
|||||||
subprotocol_automa, /* Used for HTTP subprotocol_detection */
|
subprotocol_automa, /* Used for HTTP subprotocol_detection */
|
||||||
bigrams_automa, impossible_bigrams_automa; /* TOR */
|
bigrams_automa, impossible_bigrams_automa; /* TOR */
|
||||||
|
|
||||||
|
struct {
|
||||||
|
ndpi_automa hostnames, hostnames_shadow;
|
||||||
|
void *ipAddresses, *ipAddresses_shadow; /* Patricia */
|
||||||
|
} custom_categories;
|
||||||
|
|
||||||
/* IP-based protocol detection */
|
/* IP-based protocol detection */
|
||||||
void *protocols_ptree;
|
void *protocols_ptree;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* ndpi_content_match.c
|
* ndpi_content_match.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011-2017 - ntop.org
|
* Copyright (C) 2011-18 - ntop.org
|
||||||
*
|
*
|
||||||
* nDPI is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
|||||||
+203
-21
@@ -655,9 +655,7 @@ static int removeDefaultPort(ndpi_port_range *range,
|
|||||||
|
|
||||||
static int ndpi_string_to_automa(struct ndpi_detection_module_struct *ndpi_struct,
|
static int ndpi_string_to_automa(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
ndpi_automa *automa,
|
ndpi_automa *automa,
|
||||||
char *value, int protocol_id,
|
char *value, int protocol_id) {
|
||||||
ndpi_protocol_breed_t breed)
|
|
||||||
{
|
|
||||||
AC_PATTERN_t ac_pattern;
|
AC_PATTERN_t ac_pattern;
|
||||||
|
|
||||||
if(protocol_id >= (NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS)) {
|
if(protocol_id >= (NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS)) {
|
||||||
@@ -682,24 +680,22 @@ static int ndpi_string_to_automa(struct ndpi_detection_module_struct *ndpi_struc
|
|||||||
|
|
||||||
static int ndpi_add_host_url_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
|
static int ndpi_add_host_url_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
char *value, int protocol_id,
|
char *value, int protocol_id,
|
||||||
ndpi_protocol_breed_t breed)
|
ndpi_protocol_breed_t breed /* UNUSED */)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
NDPI_LOG_DEBUG2(ndpi_struct, "[NDPI] Adding [%s][%d]\n", value, protocol_id);
|
NDPI_LOG_DEBUG2(ndpi_struct, "[NDPI] Adding [%s][%d]\n", value, protocol_id);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return(ndpi_string_to_automa(ndpi_struct, &ndpi_struct->host_automa,
|
return(ndpi_string_to_automa(ndpi_struct, &ndpi_struct->host_automa, value, protocol_id));
|
||||||
value, protocol_id, breed));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ****************************************************** */
|
/* ****************************************************** */
|
||||||
|
|
||||||
int ndpi_add_content_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
|
int ndpi_add_content_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
char *value, int protocol_id,
|
char *value, int protocol_id,
|
||||||
ndpi_protocol_breed_t breed)
|
ndpi_protocol_breed_t breed /* UNUSED */) {
|
||||||
{
|
|
||||||
return(ndpi_string_to_automa(ndpi_struct, &ndpi_struct->content_automa,
|
return(ndpi_string_to_automa(ndpi_struct, &ndpi_struct->content_automa,
|
||||||
value, protocol_id, breed));
|
value, protocol_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ****************************************************** */
|
/* ****************************************************** */
|
||||||
@@ -840,12 +836,12 @@ static void init_string_based_protocols(struct ndpi_detection_module_struct *ndp
|
|||||||
for(i=0; ndpi_en_bigrams[i] != NULL; i++)
|
for(i=0; ndpi_en_bigrams[i] != NULL; i++)
|
||||||
ndpi_string_to_automa(ndpi_mod, &ndpi_mod->bigrams_automa,
|
ndpi_string_to_automa(ndpi_mod, &ndpi_mod->bigrams_automa,
|
||||||
(char*)ndpi_en_bigrams[i],
|
(char*)ndpi_en_bigrams[i],
|
||||||
1, NDPI_PROTOCOL_UNRATED);
|
1);
|
||||||
|
|
||||||
for(i=0; ndpi_en_impossible_bigrams[i] != NULL; i++)
|
for(i=0; ndpi_en_impossible_bigrams[i] != NULL; i++)
|
||||||
ndpi_string_to_automa(ndpi_mod, &ndpi_mod->impossible_bigrams_automa,
|
ndpi_string_to_automa(ndpi_mod, &ndpi_mod->impossible_bigrams_automa,
|
||||||
(char*)ndpi_en_impossible_bigrams[i],
|
(char*)ndpi_en_impossible_bigrams[i],
|
||||||
1, NDPI_PROTOCOL_UNRATED);
|
1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ******************************************************************** */
|
/* ******************************************************************** */
|
||||||
@@ -1859,7 +1855,8 @@ static int fill_prefix_v4(prefix_t *p, struct in_addr *a, int b, int mb) {
|
|||||||
|
|
||||||
/* ******************************************* */
|
/* ******************************************* */
|
||||||
|
|
||||||
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, struct in_addr *pin /* network byte order */) {
|
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
struct in_addr *pin /* network byte order */) {
|
||||||
prefix_t prefix;
|
prefix_t prefix;
|
||||||
patricia_node_t *node;
|
patricia_node_t *node;
|
||||||
|
|
||||||
@@ -1943,8 +1940,7 @@ static int ndpi_add_host_ip_subprotocol(struct ndpi_detection_module_struct *ndp
|
|||||||
int bits = 32;
|
int bits = 32;
|
||||||
char *ptr = strrchr(value, '/');
|
char *ptr = strrchr(value, '/');
|
||||||
|
|
||||||
if (ptr)
|
if(ptr) {
|
||||||
{
|
|
||||||
ptr[0] = '\0';
|
ptr[0] = '\0';
|
||||||
ptr++;
|
ptr++;
|
||||||
if(atoi(ptr)>=0 && atoi(ptr)<=32)
|
if(atoi(ptr)>=0 && atoi(ptr)<=32)
|
||||||
@@ -2052,6 +2048,15 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(void) {
|
|||||||
ndpi_str->bigrams_automa.ac_automa = ac_automata_init(ac_match_handler);
|
ndpi_str->bigrams_automa.ac_automa = ac_automata_init(ac_match_handler);
|
||||||
ndpi_str->impossible_bigrams_automa.ac_automa = ac_automata_init(ac_match_handler);
|
ndpi_str->impossible_bigrams_automa.ac_automa = ac_automata_init(ac_match_handler);
|
||||||
|
|
||||||
|
ndpi_str->custom_categories.hostnames.ac_automa = ac_automata_init(ac_match_handler);
|
||||||
|
ndpi_str->custom_categories.hostnames_shadow.ac_automa = ac_automata_init(ac_match_handler);
|
||||||
|
ndpi_str->custom_categories.ipAddresses = ndpi_New_Patricia(32 /* IPv4 */);
|
||||||
|
ndpi_str->custom_categories.ipAddresses_shadow = ndpi_New_Patricia(32 /* IPv4 */);
|
||||||
|
|
||||||
|
if((ndpi_str->custom_categories.ipAddresses == NULL)
|
||||||
|
|| (ndpi_str->custom_categories.ipAddresses_shadow == NULL))
|
||||||
|
return(NULL);
|
||||||
|
|
||||||
ndpi_init_protocol_defaults(ndpi_str);
|
ndpi_init_protocol_defaults(ndpi_str);
|
||||||
|
|
||||||
for(i=0; i<NUM_CUSTOM_CATEGORIES; i++)
|
for(i=0; i<NUM_CUSTOM_CATEGORIES; i++)
|
||||||
@@ -2169,6 +2174,18 @@ void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_struct
|
|||||||
destroy_hyperscan(ndpi_struct);
|
destroy_hyperscan(ndpi_struct);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if(ndpi_struct->custom_categories.hostnames.ac_automa != NULL)
|
||||||
|
ac_automata_release((AC_AUTOMATA_t*)ndpi_struct->custom_categories.hostnames.ac_automa);
|
||||||
|
|
||||||
|
if(ndpi_struct->custom_categories.hostnames_shadow.ac_automa != NULL)
|
||||||
|
ac_automata_release((AC_AUTOMATA_t*)ndpi_struct->custom_categories.hostnames_shadow.ac_automa);
|
||||||
|
|
||||||
|
if(ndpi_struct->custom_categories.ipAddresses != NULL)
|
||||||
|
ndpi_Destroy_Patricia((patricia_tree_t*)ndpi_struct->custom_categories.ipAddresses, free_ptree_data);
|
||||||
|
|
||||||
|
if(ndpi_struct->custom_categories.ipAddresses_shadow != NULL)
|
||||||
|
ndpi_Destroy_Patricia((patricia_tree_t*)ndpi_struct->custom_categories.ipAddresses_shadow, free_ptree_data);
|
||||||
|
|
||||||
ndpi_free(ndpi_struct);
|
ndpi_free(ndpi_struct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3627,7 +3644,7 @@ static u_int16_t ndpi_guess_host_protocol_id(struct ndpi_detection_module_struct
|
|||||||
|
|
||||||
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_struct,
|
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow) {
|
struct ndpi_flow_struct *flow) {
|
||||||
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN };
|
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED };
|
||||||
|
|
||||||
if(flow == NULL) return(ret);
|
if(flow == NULL) return(ret);
|
||||||
|
|
||||||
@@ -3724,17 +3741,125 @@ void ndpi_process_extra_packet(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
|
|
||||||
/* ********************************************************************************* */
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
|
void ndpi_load_ip_category(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
char *ip_address_and_mask, ndpi_protocol_category_t category) {
|
||||||
|
patricia_node_t *node;
|
||||||
|
struct in_addr pin;
|
||||||
|
int bits = 32;
|
||||||
|
char *ptr = strrchr(ip_address_and_mask, '/');
|
||||||
|
|
||||||
|
if(ptr) {
|
||||||
|
ptr[0] = '\0';
|
||||||
|
ptr++;
|
||||||
|
if (atoi(ptr)>=0 && atoi(ptr)<=32)
|
||||||
|
bits = atoi(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inet_pton(AF_INET, ip_address_and_mask, &pin);
|
||||||
|
|
||||||
|
if((node = add_to_ptree(ndpi_struct->custom_categories.ipAddresses_shadow,
|
||||||
|
AF_INET, &pin, bits)) != NULL)
|
||||||
|
node->value.user_value = (int)category;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
|
void ndpi_load_hostname_category(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
char *name, ndpi_protocol_category_t category) {
|
||||||
|
AC_PATTERN_t ac_pattern;
|
||||||
|
|
||||||
|
if(name == NULL) return;
|
||||||
|
|
||||||
|
/* printf("===> Loading %s as %u\n", name, category); */
|
||||||
|
|
||||||
|
if(ndpi_struct->custom_categories.hostnames_shadow.ac_automa == NULL) return;
|
||||||
|
ac_pattern.astring = name, ac_pattern.length = strlen(ac_pattern.astring);
|
||||||
|
ac_pattern.rep.number = (int)category;
|
||||||
|
|
||||||
|
ac_automata_add(ndpi_struct->custom_categories.hostnames_shadow.ac_automa, &ac_pattern);
|
||||||
|
ac_automata_finalize(ndpi_struct->custom_categories.hostnames_shadow.ac_automa);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
|
void ndpi_enable_loaded_categories(struct ndpi_detection_module_struct *ndpi_struct) {
|
||||||
|
/* Free */
|
||||||
|
ac_automata_release((AC_AUTOMATA_t*)ndpi_struct->custom_categories.hostnames.ac_automa);
|
||||||
|
ndpi_Destroy_Patricia((patricia_tree_t*)ndpi_struct->custom_categories.ipAddresses, free_ptree_data);
|
||||||
|
|
||||||
|
/* Finalize */
|
||||||
|
ac_automata_finalize((AC_AUTOMATA_t*)ndpi_struct->custom_categories.hostnames_shadow.ac_automa);
|
||||||
|
|
||||||
|
/* Swap */
|
||||||
|
ndpi_struct->custom_categories.hostnames.ac_automa = ndpi_struct->custom_categories.hostnames_shadow.ac_automa;
|
||||||
|
ndpi_struct->custom_categories.ipAddresses = ndpi_struct->custom_categories.ipAddresses_shadow;
|
||||||
|
|
||||||
|
/* Realloc */
|
||||||
|
ndpi_struct->custom_categories.hostnames_shadow.ac_automa = ac_automata_init(ac_match_handler);
|
||||||
|
ndpi_struct->custom_categories.ipAddresses_shadow = ndpi_New_Patricia(32 /* IPv4 */);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
|
static void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
struct ndpi_flow_struct *flow,
|
||||||
|
ndpi_protocol *ret) {
|
||||||
|
if(flow->packet.iph) {
|
||||||
|
prefix_t prefix;
|
||||||
|
patricia_node_t *node;
|
||||||
|
|
||||||
|
/* Make sure all in network byte order otherwise compares wont work */
|
||||||
|
fill_prefix_v4(&prefix, (struct in_addr *)&flow->packet.iph->saddr,
|
||||||
|
32, ((patricia_tree_t*)ndpi_struct->protocols_ptree)->maxbits);
|
||||||
|
node = ndpi_patricia_search_best(ndpi_struct->custom_categories.ipAddresses, &prefix);
|
||||||
|
|
||||||
|
if(!node) {
|
||||||
|
fill_prefix_v4(&prefix, (struct in_addr *)&flow->packet.iph->daddr,
|
||||||
|
32, ((patricia_tree_t*)ndpi_struct->protocols_ptree)->maxbits);
|
||||||
|
node = ndpi_patricia_search_best(ndpi_struct->custom_categories.ipAddresses, &prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(node) {
|
||||||
|
ret->category = (ndpi_protocol_category_t)node->value.user_value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(flow->host_server_name[0] != '\0') {
|
||||||
|
unsigned long id;
|
||||||
|
int rc = ndpi_match_string_id(ndpi_struct->custom_categories.hostnames.ac_automa, (char *)flow->host_server_name, &id);
|
||||||
|
|
||||||
|
if(rc == 0) {
|
||||||
|
ret->category = (ndpi_protocol_category_t)id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(flow->protos.ssl.server_certificate[0] != '\0') {
|
||||||
|
unsigned long id;
|
||||||
|
int rc = ndpi_match_string_id(ndpi_struct->custom_categories.hostnames.ac_automa, (char *)flow->protos.ssl.server_certificate, &id);
|
||||||
|
|
||||||
|
if(rc == 0) {
|
||||||
|
ret->category = (ndpi_protocol_category_t)id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret->category = ndpi_get_proto_category(ndpi_struct, *ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct *ndpi_struct,
|
ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow,
|
struct ndpi_flow_struct *flow,
|
||||||
const unsigned char *packet,
|
const unsigned char *packet,
|
||||||
const unsigned short packetlen,
|
const unsigned short packetlen,
|
||||||
const u_int64_t current_tick_l,
|
const u_int64_t current_tick_l,
|
||||||
struct ndpi_id_struct *src,
|
struct ndpi_id_struct *src,
|
||||||
struct ndpi_id_struct *dst)
|
struct ndpi_id_struct *dst) {
|
||||||
{
|
|
||||||
NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_packet;
|
NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_packet;
|
||||||
u_int32_t a;
|
u_int32_t a;
|
||||||
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN };
|
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED };
|
||||||
|
|
||||||
if(ndpi_struct->ndpi_log_level >= NDPI_LOG_TRACE)
|
if(ndpi_struct->ndpi_log_level >= NDPI_LOG_TRACE)
|
||||||
NDPI_LOG(flow ? flow->detected_protocol_stack[0]:NDPI_PROTOCOL_UNKNOWN,
|
NDPI_LOG(flow ? flow->detected_protocol_stack[0]:NDPI_PROTOCOL_UNKNOWN,
|
||||||
@@ -3825,6 +3950,7 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
if(flow->guessed_protocol_id >= (NDPI_MAX_SUPPORTED_PROTOCOLS-1)) {
|
if(flow->guessed_protocol_id >= (NDPI_MAX_SUPPORTED_PROTOCOLS-1)) {
|
||||||
/* This is a custom protocol and it has priority over everything else */
|
/* This is a custom protocol and it has priority over everything else */
|
||||||
ret.master_protocol = NDPI_PROTOCOL_UNKNOWN, ret.app_protocol = flow->guessed_host_protocol_id;
|
ret.master_protocol = NDPI_PROTOCOL_UNKNOWN, ret.app_protocol = flow->guessed_host_protocol_id;
|
||||||
|
ndpi_fill_protocol_category(ndpi_struct, flow, &ret);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3835,6 +3961,7 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
ret = ndpi_detection_giveup(ndpi_struct, flow);
|
ret = ndpi_detection_giveup(ndpi_struct, flow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ndpi_fill_protocol_category(ndpi_struct, flow, &ret);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -3851,6 +3978,7 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
/* This is a custom protocol and it has priority over everything else */
|
/* This is a custom protocol and it has priority over everything else */
|
||||||
ret.master_protocol = NDPI_PROTOCOL_UNKNOWN, ret.app_protocol = flow->guessed_host_protocol_id;
|
ret.master_protocol = NDPI_PROTOCOL_UNKNOWN, ret.app_protocol = flow->guessed_host_protocol_id;
|
||||||
ndpi_check_flow_func(ndpi_struct, flow, &ndpi_selection_packet);
|
ndpi_check_flow_func(ndpi_struct, flow, &ndpi_selection_packet);
|
||||||
|
ndpi_fill_protocol_category(ndpi_struct, flow, &ret);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3878,9 +4006,12 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
} else
|
} else
|
||||||
ret.app_protocol = flow->detected_protocol_stack[0];
|
ret.app_protocol = flow->detected_protocol_stack[0];
|
||||||
|
|
||||||
|
ndpi_fill_protocol_category(ndpi_struct, flow, &ret);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
u_int32_t ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
u_int32_t ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
||||||
{
|
{
|
||||||
u_int32_t val;
|
u_int32_t val;
|
||||||
@@ -3896,6 +4027,8 @@ u_int32_t ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to
|
|||||||
return (val);
|
return (val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
u_int32_t ndpi_bytestream_dec_or_hex_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
u_int32_t ndpi_bytestream_dec_or_hex_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
||||||
{
|
{
|
||||||
u_int32_t val;
|
u_int32_t val;
|
||||||
@@ -3929,6 +4062,7 @@ u_int32_t ndpi_bytestream_dec_or_hex_to_number(const u_int8_t * str, u_int16_t m
|
|||||||
return (val);
|
return (val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
u_int64_t ndpi_bytestream_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
u_int64_t ndpi_bytestream_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
||||||
{
|
{
|
||||||
@@ -3945,6 +4079,8 @@ u_int64_t ndpi_bytestream_to_number64(const u_int8_t * str, u_int16_t max_chars_
|
|||||||
return (val);
|
return (val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
u_int64_t ndpi_bytestream_dec_or_hex_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
u_int64_t ndpi_bytestream_dec_or_hex_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
||||||
{
|
{
|
||||||
u_int64_t val;
|
u_int64_t val;
|
||||||
@@ -3978,6 +4114,7 @@ u_int64_t ndpi_bytestream_dec_or_hex_to_number64(const u_int8_t * str, u_int16_t
|
|||||||
return (val);
|
return (val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
u_int32_t ndpi_bytestream_to_ipv4(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
u_int32_t ndpi_bytestream_to_ipv4(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
||||||
{
|
{
|
||||||
@@ -4015,6 +4152,8 @@ u_int32_t ndpi_bytestream_to_ipv4(const u_int8_t * str, u_int16_t max_chars_to_r
|
|||||||
return htonl(val);
|
return htonl(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* internal function for every detection to parse one packet and to increase the info buffer */
|
/* internal function for every detection to parse one packet and to increase the info buffer */
|
||||||
void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struct,
|
void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow)
|
struct ndpi_flow_struct *flow)
|
||||||
@@ -4266,6 +4405,8 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_struct,
|
void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow)
|
struct ndpi_flow_struct *flow)
|
||||||
{
|
{
|
||||||
@@ -4309,6 +4450,7 @@ void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi_struct,
|
u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow, u_int16_t counter)
|
struct ndpi_flow_struct *flow, u_int16_t counter)
|
||||||
@@ -4391,6 +4533,8 @@ u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
void ndpi_debug_get_last_log_function_line(struct ndpi_detection_module_struct
|
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)
|
*ndpi_struct, const char **file, const char **func, u_int32_t * line)
|
||||||
{
|
{
|
||||||
@@ -4406,12 +4550,17 @@ void ndpi_debug_get_last_log_function_line(struct ndpi_detection_module_struct
|
|||||||
*line = ndpi_struct->ndpi_debug_print_line;
|
*line = ndpi_struct->ndpi_debug_print_line;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
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 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)
|
u_int8_t * l4_protocol_return, u_int32_t flags)
|
||||||
{
|
{
|
||||||
return ndpi_detection_get_l4_internal(NULL, l3, l3_len, l4_return, l4_len_return, l4_protocol_return, flags);
|
return ndpi_detection_get_l4_internal(NULL, l3, l3_len, l4_return, l4_len_return, l4_protocol_return, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
void ndpi_set_detected_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
void ndpi_set_detected_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow,
|
struct ndpi_flow_struct *flow,
|
||||||
u_int16_t upper_detected_protocol,
|
u_int16_t upper_detected_protocol,
|
||||||
@@ -4437,11 +4586,15 @@ void ndpi_set_detected_protocol(struct ndpi_detection_module_struct *ndpi_struct
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_detection_module_struct *ndpi_struct,
|
u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow) {
|
struct ndpi_flow_struct *flow) {
|
||||||
return(flow->detected_protocol_stack[1]);
|
return(flow->detected_protocol_stack[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
void ndpi_int_change_flow_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
void ndpi_int_change_flow_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow,
|
struct ndpi_flow_struct *flow,
|
||||||
u_int16_t upper_detected_protocol,
|
u_int16_t upper_detected_protocol,
|
||||||
@@ -4451,6 +4604,8 @@ void ndpi_int_change_flow_protocol(struct ndpi_detection_module_struct *ndpi_str
|
|||||||
flow->detected_protocol_stack[0] = upper_detected_protocol, flow->detected_protocol_stack[1] = lower_detected_protocol;
|
flow->detected_protocol_stack[0] = upper_detected_protocol, flow->detected_protocol_stack[1] = lower_detected_protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow,
|
struct ndpi_flow_struct *flow,
|
||||||
u_int16_t upper_detected_protocol,
|
u_int16_t upper_detected_protocol,
|
||||||
@@ -4464,9 +4619,12 @@ void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_s
|
|||||||
if(!packet)
|
if(!packet)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
packet->detected_protocol_stack[0] = upper_detected_protocol, packet->detected_protocol_stack[1] = lower_detected_protocol;
|
packet->detected_protocol_stack[0] = upper_detected_protocol,
|
||||||
|
packet->detected_protocol_stack[1] = lower_detected_protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* generic function for changing the protocol
|
/* generic function for changing the protocol
|
||||||
*
|
*
|
||||||
* what it does is:
|
* what it does is:
|
||||||
@@ -4490,6 +4648,8 @@ void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
upper_detected_protocol, lower_detected_protocol);
|
upper_detected_protocol, lower_detected_protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* change protocol only if guessing is active */
|
/* change protocol only if guessing is active */
|
||||||
/* void ndpi_guess_change_protocol(struct ndpi_detection_module_struct *ndpi_struct, */
|
/* void ndpi_guess_change_protocol(struct ndpi_detection_module_struct *ndpi_struct, */
|
||||||
/* struct ndpi_flow_struct *flow) */
|
/* struct ndpi_flow_struct *flow) */
|
||||||
@@ -4509,6 +4669,8 @@ void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
/* } */
|
/* } */
|
||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* turns a packet back to unknown */
|
/* turns a packet back to unknown */
|
||||||
void ndpi_int_reset_packet_protocol(struct ndpi_packet_struct *packet) {
|
void ndpi_int_reset_packet_protocol(struct ndpi_packet_struct *packet) {
|
||||||
int a;
|
int a;
|
||||||
@@ -4517,6 +4679,8 @@ void ndpi_int_reset_packet_protocol(struct ndpi_packet_struct *packet) {
|
|||||||
packet->detected_protocol_stack[a] = NDPI_PROTOCOL_UNKNOWN;
|
packet->detected_protocol_stack[a] = NDPI_PROTOCOL_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
void ndpi_int_reset_protocol(struct ndpi_flow_struct *flow) {
|
void ndpi_int_reset_protocol(struct ndpi_flow_struct *flow) {
|
||||||
if(flow) {
|
if(flow) {
|
||||||
int a;
|
int a;
|
||||||
@@ -4527,16 +4691,22 @@ void ndpi_int_reset_protocol(struct ndpi_flow_struct *flow) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
void NDPI_PROTOCOL_IP_clear(ndpi_ip_addr_t * ip) {
|
void NDPI_PROTOCOL_IP_clear(ndpi_ip_addr_t * ip) {
|
||||||
memset(ip, 0, sizeof(ndpi_ip_addr_t));
|
memset(ip, 0, sizeof(ndpi_ip_addr_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* NTOP */
|
/* NTOP */
|
||||||
int NDPI_PROTOCOL_IP_is_set(const ndpi_ip_addr_t * ip)
|
int NDPI_PROTOCOL_IP_is_set(const ndpi_ip_addr_t * ip)
|
||||||
{
|
{
|
||||||
return memcmp(ip, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(ndpi_ip_addr_t)) != 0;
|
return memcmp(ip, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(ndpi_ip_addr_t)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* check if the source ip address in packet and ip are equal */
|
/* check if the source ip address in packet and ip are equal */
|
||||||
/* NTOP */
|
/* NTOP */
|
||||||
int ndpi_packet_src_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip)
|
int ndpi_packet_src_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip)
|
||||||
@@ -4563,6 +4733,8 @@ int ndpi_packet_src_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_i
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* check if the destination ip address in packet and ip are equal */
|
/* check if the destination ip address in packet and ip are equal */
|
||||||
int ndpi_packet_dst_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip)
|
int ndpi_packet_dst_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip)
|
||||||
{
|
{
|
||||||
@@ -4588,6 +4760,8 @@ int ndpi_packet_dst_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_i
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* get the source ip address from packet and put it into ip */
|
/* get the source ip address from packet and put it into ip */
|
||||||
/* NTOP */
|
/* NTOP */
|
||||||
void ndpi_packet_src_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip)
|
void ndpi_packet_src_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip)
|
||||||
@@ -4611,6 +4785,8 @@ void ndpi_packet_src_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_add
|
|||||||
ip->ipv4 = packet->iph->saddr;
|
ip->ipv4 = packet->iph->saddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* get the destination ip address from packet and put it into ip */
|
/* get the destination ip address from packet and put it into ip */
|
||||||
/* NTOP */
|
/* NTOP */
|
||||||
void ndpi_packet_dst_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip)
|
void ndpi_packet_dst_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip)
|
||||||
@@ -4633,6 +4809,8 @@ void ndpi_packet_dst_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_add
|
|||||||
ip->ipv4 = packet->iph->daddr;
|
ip->ipv4 = packet->iph->daddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||||
/* get the string representation of ip
|
/* get the string representation of ip
|
||||||
* returns a pointer to a static string
|
* returns a pointer to a static string
|
||||||
@@ -4663,6 +4841,7 @@ char *ndpi_get_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* get the string representation of the source ip address from packet */
|
/* get the string representation of the source ip address from packet */
|
||||||
char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
|
char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
@@ -4673,6 +4852,8 @@ char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_st
|
|||||||
return ndpi_get_ip_string(ndpi_struct, &ip);
|
return ndpi_get_ip_string(ndpi_struct, &ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
/* get the string representation of the destination ip address from packet */
|
/* get the string representation of the destination ip address from packet */
|
||||||
char *ndpi_get_packet_dst_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
|
char *ndpi_get_packet_dst_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
const struct ndpi_packet_struct *packet)
|
const struct ndpi_packet_struct *packet)
|
||||||
@@ -4685,7 +4866,8 @@ char *ndpi_get_packet_dst_ip_string(struct ndpi_detection_module_struct *ndpi_st
|
|||||||
|
|
||||||
/* ****************************************************** */
|
/* ****************************************************** */
|
||||||
|
|
||||||
u_int16_t ntohs_ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
u_int16_t ntohs_ndpi_bytestream_to_number(const u_int8_t * str,
|
||||||
|
u_int16_t max_chars_to_read, u_int16_t * bytes_read)
|
||||||
{
|
{
|
||||||
u_int16_t val = ndpi_bytestream_to_number(str, max_chars_to_read, bytes_read);
|
u_int16_t val = ndpi_bytestream_to_number(str, max_chars_to_read, bytes_read);
|
||||||
return ntohs(val);
|
return ntohs(val);
|
||||||
@@ -4711,7 +4893,7 @@ ndpi_protocol ndpi_guess_undetected_protocol(struct ndpi_detection_module_struct
|
|||||||
u_int32_t dhost /* host byte order */, u_int16_t dport) {
|
u_int32_t dhost /* host byte order */, u_int16_t dport) {
|
||||||
u_int32_t rc;
|
u_int32_t rc;
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN };
|
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED };
|
||||||
u_int8_t user_defined_proto;
|
u_int8_t user_defined_proto;
|
||||||
|
|
||||||
if((proto == IPPROTO_TCP) || (proto == IPPROTO_UDP)) {
|
if((proto == IPPROTO_TCP) || (proto == IPPROTO_UDP)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user