-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_port.c
76 lines (62 loc) · 1.14 KB
/
table_port.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "config.h"
#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/list.h>
#include <linux/rbtree.h>
#include <linux/types.h>
#include "table_port.h"
#include "portsDB.h"
#include "pcap_monitoring.h"
struct rb_root db;
extern struct local_addresses_list *local_list;
int insertPort(struct packetInfo *lpi)
{
int ret=1;
#ifdef MY_DEBUG
if(lpi == NULL){
return -1;
}
//debugFunc(lpi);
#endif
if(lpi->port == 0 || lpi->protocol == 0)
{
#ifdef MY_DEBUG_INFO
//my_print_debug("some info is zero port %d address %d.%d.%d.%d and protocol %hu",lpi->port,NIPQUAD(lpi->address), lpi->protocol);
#endif
return -1;
}
ret = my_insert(&db,lpi);
return ret;
}
int deletePort(struct packetInfo *pi)
{
#ifdef MY_DEBUG_INFO
//my_print_debug( "deleting port %hu",pi->port);
#endif
my_erase(&db,pi);
return 0;
}
int searchPort(struct packetInfo *pi){
if( my_search(&db,pi) != NULL)
return 1;
else
return 0;
}
void clearInfo(void){
clearAllInfo(&db);
}
void printTree(void){
printAll(&db);
}
int init_DB(void)
{
#ifdef MY_DEBUG
init_db_debug();
#endif
return 0;
}
void exit_DB(void)
{
clearInfo();
}