Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Arne Øslebø
mapi
Commits
36722936
Commit
36722936
authored
Nov 09, 2005
by
Browse files
top almost finished
git-svn-id:
file:///home/svn/mapi/trunk@246
8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent
cf013663
Changes
3
Hide whitespace changes
Inline
Side-by-side
stdlib/mapidstdflib.c
View file @
36722936
//Tue
Oct 4 09:30:43
2005
//Tue
Nov 8 17:24:20
2005
//This file was created automatically by createlib.pl
#include <stdio.h>
#include "mapidflib.h"
#include "debug.h"
char
libname
[]
=
"stdlib"
;
char
libname
[]
=
"
mapid
std
f
lib"
;
__attribute__
((
constructor
))
void
init
();
__attribute__
((
destructor
))
void
fini
();
mapidflib_functionlist_t
functions
[
2
2
];
mapidflib_functionlist_t
functions
[
2
3
];
extern
mapidflib_function_def_t
*
binop_get_funct_info
();
extern
mapidflib_function_def_t
*
bpf_get_funct_info
();
...
...
@@ -34,6 +34,7 @@ extern mapidflib_function_def_t * threshold_get_funct_info();
extern
mapidflib_function_def_t
*
to_tcpdump_get_funct_info
();
extern
mapidflib_function_def_t
*
toba_get_funct_info
();
extern
mapidflib_function_def_t
*
tobuffer_get_funct_info
();
extern
mapidflib_function_def_t
*
topx_get_funct_info
();
mapidflib_functionlist_t
*
mapidflib_get_function_list
()
{
...
...
@@ -123,7 +124,11 @@ mapidflib_functionlist_t* mapidflib_get_function_list()
functions
[
21
].
def
=
tobuffer_get_funct_info
();
functions
[
21
].
def
->
libname
=
libname
;
functions
[
21
].
next
=
NULL
;
functions
[
21
].
next
=&
functions
[
22
];
functions
[
22
].
def
=
topx_get_funct_info
();
functions
[
22
].
def
->
libname
=
libname
;
functions
[
22
].
next
=
NULL
;
return
&
functions
[
0
];
}
...
...
@@ -135,12 +140,12 @@ char *mapidflib_get_libname() {
__attribute__
((
constructor
))
void
init
()
{
DEBUG_CMD
(
printf
(
"Library stdlib loaded
\n
"
));
DEBUG_CMD
(
printf
(
"Library
mapid
std
f
lib loaded
\n
"
));
}
__attribute__
((
destructor
))
void
fini
()
{
DEBUG_CMD
(
printf
(
"Library stdlib unloaded
\n
"
));
DEBUG_CMD
(
printf
(
"Library
mapid
std
f
lib unloaded
\n
"
));
}
stdlib/top.c
View file @
36722936
...
...
@@ -9,13 +9,19 @@
#include "fhelp.h"
#include "topx.h"
#include "protocols.h"
#include <netinet/in.h>
struct
topx_field
{
void
*
pointer
;
char
needs_reverse
;
unsigned
int
len
;
};
void
extract_field
(
struct
topx_field
*
field
,
unsigned
char
*
dev_pkt
,
int
protocol
,
int
pfield
);
struct
topx_hash_node
*
hash_lookup
(
unsigned
int
value
,
struct
topx_data
*
data
);
void
check_for_shift
(
struct
topx_data
*
data
,
struct
topx_list_node
*
node
);
void
add_to_hashtable_and_list
(
struct
topx_data
*
data
,
unsigned
int
value
);
void
add_field_to_list
(
struct
topx_field
*
field
,
struct
topx_data
*
data
);
void
extract_field
(
struct
topx_field
*
field
,
unsigned
char
*
dev_pkt
,
int
protocol
,
int
pfield
)
{
...
...
@@ -31,6 +37,8 @@ void extract_field(struct topx_field *field, unsigned char *dev_pkt,int protocol
ip
=
(
ip_header
*
)(
dev_pkt
+
ether_len
);
ip_len
=
(
ip
->
ver_ihl
&
0xf
)
*
4
;
field
->
needs_reverse
=
0
;
switch
(
protocol
)
{
case
TOPX_IP
:
switch
(
pfield
)
{
...
...
@@ -77,10 +85,12 @@ void extract_field(struct topx_field *field, unsigned char *dev_pkt,int protocol
//tcp_len = tcp->off * 4;
switch
(
pfield
)
{
case
TOPX_TCP_SRCPORT
:
field
->
needs_reverse
=
1
;
field
->
pointer
=&
(
tcp
->
sport
);
field
->
len
=
2
;
break
;
case
TOPX_TCP_DSTPORT
:
field
->
needs_reverse
=
1
;
field
->
pointer
=&
(
tcp
->
dport
);
field
->
len
=
2
;
break
;
...
...
@@ -135,6 +145,114 @@ void extract_field(struct topx_field *field, unsigned char *dev_pkt,int protocol
}
}
struct
topx_hash_node
*
hash_lookup
(
unsigned
int
value
,
struct
topx_data
*
data
)
{
unsigned
int
pos
;
struct
topx_hash_node
*
tmp
;
pos
=
value
%
TOPX_HASH_SIZE
;
tmp
=
data
->
hashtable
[
pos
];
while
(
tmp
)
{
if
(
tmp
->
value
==
value
)
return
tmp
;
tmp
=
tmp
->
next
;
}
return
NULL
;
}
void
check_for_shift
(
struct
topx_data
*
data
,
struct
topx_list_node
*
node
)
{
struct
topx_list_node
*
previous
;
if
((
!
(
node
->
previous
))
||
(
node
->
previous
->
count
>
node
->
count
))
return
;
previous
=
node
->
previous
;
//delete node from its current place
previous
->
next
=
node
->
next
;
if
(
node
->
next
)
node
->
next
->
previous
=
previous
;
else
{
data
->
list_tail
=
previous
;
}
node
->
next
=
previous
;
if
(
previous
->
previous
)
previous
->
previous
->
next
=
node
;
else
data
->
list_head
=
node
;
node
->
previous
=
previous
->
previous
;
previous
->
previous
=
node
;
}
void
add_to_hashtable_and_list
(
struct
topx_data
*
data
,
unsigned
int
value
)
{
unsigned
int
pos
;
struct
topx_list_node
*
newlistnode
;
struct
topx_hash_node
*
newhashnode
;
newlistnode
=
(
struct
topx_list_node
*
)
malloc
(
sizeof
(
struct
topx_list_node
));
newlistnode
->
value
=
value
;
newlistnode
->
count
=
1
;
newlistnode
->
next
=
newlistnode
->
previous
=
NULL
;
//add to list
data
->
list_size
++
;
if
(
data
->
list_tail
==
NULL
)
{
data
->
list_head
=
data
->
list_tail
=
newlistnode
;
}
else
{
data
->
list_tail
->
next
=
newlistnode
;
newlistnode
->
previous
=
data
->
list_tail
;
data
->
list_tail
=
newlistnode
;
}
pos
=
value
%
TOPX_HASH_SIZE
;
newhashnode
=
(
struct
topx_hash_node
*
)
malloc
(
sizeof
(
struct
topx_hash_node
));
newhashnode
->
value
=
value
;
newhashnode
->
node
=
newlistnode
;
newhashnode
->
next
=
data
->
hashtable
[
pos
];
data
->
hashtable
[
pos
]
=
newhashnode
;
}
void
add_field_to_list
(
struct
topx_field
*
field
,
struct
topx_data
*
data
)
{
struct
topx_hash_node
*
lookup
;
unsigned
int
value
;
switch
(
field
->
len
)
{
case
1
:
value
=
(
unsigned
int
)(
*
((
unsigned
char
*
)(
field
->
pointer
)));
break
;
case
2
:
if
(
field
->
needs_reverse
==
1
)
value
=
(
unsigned
int
)(
ntohs
(
*
((
unsigned
short
*
)(
field
->
pointer
))));
else
value
=
(
unsigned
int
)(
*
((
unsigned
short
*
)(
field
->
pointer
)));
break
;
case
4
:
if
(
field
->
needs_reverse
==
1
)
value
=
ntohl
((
*
((
unsigned
int
*
)(
field
->
pointer
))));
else
value
=
(
*
((
unsigned
int
*
)(
field
->
pointer
)));
break
;
}
lookup
=
hash_lookup
(
value
,
data
);
if
(
lookup
==
NULL
)
{
add_to_hashtable_and_list
(
data
,
value
);
}
else
{
lookup
->
node
->
count
++
;
check_for_shift
(
data
,
lookup
->
node
);
}
}
int
pktcnt
=
0
;
static
int
topx_process
(
mapidflib_function_instance_t
*
instance
,
MAPI_UNUSED
const
unsigned
char
*
dev_pkt
,
MAPI_UNUSED
const
unsigned
char
*
link_pkt
,
...
...
@@ -143,11 +261,26 @@ static int topx_process(mapidflib_function_instance_t *instance,
unsigned
char
*
packet
=
link_pkt
;
struct
topx_field
field
;
struct
topx_data
*
data
=
(
struct
topx_data
*
)(
instance
->
internal_data
);
extract_field
(
&
field
,
packet
,
data
->
protocol
,
data
->
field
);
//printf("data: %u len: %d\n",ntohs(*((unsigned short *)(field.pointer))),field.len);
add_field_to_list
(
&
field
,
data
);
pktcnt
++
;
if
(
pktcnt
%
10000
)
{
struct
topx_list_node
*
tmp
;
int
i
=
0
;
tmp
=
data
->
list_head
;
while
(
tmp
&&
i
<
data
->
x
)
{
printf
(
"(%d,%d)->"
,
tmp
->
value
,
tmp
->
count
);
tmp
=
tmp
->
next
;
i
++
;
}
printf
(
"
\n
"
);
}
return
1
;
}
...
...
@@ -178,6 +311,9 @@ static int topx_init(mapidflib_function_instance_t *instance,
((
struct
topx_data
*
)(
instance
->
internal_data
))
->
x
=
x
;
((
struct
topx_data
*
)(
instance
->
internal_data
))
->
protocol
=
protocol
;
((
struct
topx_data
*
)(
instance
->
internal_data
))
->
field
=
field
;
((
struct
topx_data
*
)(
instance
->
internal_data
))
->
list_head
=
NULL
;
((
struct
topx_data
*
)(
instance
->
internal_data
))
->
list_tail
=
NULL
;
memset
(((
struct
topx_data
*
)(
instance
->
internal_data
))
->
hashtable
,
0
,
TOPX_HASH_SIZE
*
sizeof
(
struct
topx_hash_node
*
));
return
0
;
}
...
...
stdlib/topx.h
View file @
36722936
#define TOPX_HASH_SIZE 4096
struct
topx_list_node
{
unsigned
int
value
;
unsigned
int
count
;
struct
topx_list_node
*
next
;
struct
topx_list_node
*
previous
;
};
struct
topx_hash_node
{
unsigned
int
value
;
struct
topx_list_node
*
node
;
struct
topx_hash_node
*
next
;
};
struct
topx_data
{
int
x
;
int
protocol
;
int
field
;
int
list_size
;
struct
topx_list_node
*
list_head
;
struct
topx_list_node
*
list_tail
;
struct
topx_hash_node
*
hashtable
[
TOPX_HASH_SIZE
];
};
#define TOPX_IP 1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment