Skip to content

Commit 969e6e6

Browse files
committed
chg: [pibs] Moved frame processing related to SYN tracking to synseen.c
1 parent 0512a82 commit 969e6e6

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

bin/pibs.c

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ void process_frame(pibs_t* pibs, wtap *wth,
2424
uint8_t *eth)
2525
{
2626
struct ip* ipv4;
27-
uint32_t ip;
2827
struct tcphdr* tcp;
29-
int_fast64_t lastseen;
3028
unsigned char* buf;
3129
size_t length;
32-
struct pcap_pkthdr pchdr;
3330

3431
buf = eth+14;
3532
length = wth->rec.rec_header.packet_header.caplen-14;
@@ -46,37 +43,9 @@ void process_frame(pibs_t* pibs, wtap *wth,
4643

4744
tcp = (struct tcphdr*)(buf+sizeof(struct ip));
4845

49-
memcpy(&ip, &ipv4->ip_src, 4);
50-
// Record only source ips where syn flag is set
51-
// TODO check other connection establishment alternatives
52-
if (tcp->th_flags == 2 ){
53-
insert_ip(pibs, ip, wth->rec.ts.secs);
54-
return;
55-
}
46+
synseen_process_frame(pibs, wth, eth, ipv4, tcp);
5647

57-
lastseen = get_last_timestamp(pibs, ip);
58-
59-
if (lastseen > 0){
60-
HDBG("IP %x %s was already seen before at %ld. Time difference %ld.\n"
61-
, ip, inet_ntoa(ipv4->ip_src), lastseen, wth->rec.ts.secs-lastseen);
62-
return;
63-
}
64-
// TODO keep these IPs in a hashtable and rank them
65-
if (pibs->show_backscatter) {
66-
printf("%ld,%s,%d,%d\n",
67-
wth->rec.ts.secs, inet_ntoa(ipv4->ip_src), tcp->th_flags,
68-
ntohs(tcp->th_sport));
69-
}
70-
//TODO relative time
71-
//Purge old ips?
72-
if (pibs->should_writepcap) {
73-
pchdr.ts.tv_sec = wth->rec.ts.secs;
74-
//TODO other part of the timestamp
75-
pchdr.ts.tv_usec = wth->rec.ts.nsecs / 1000;
76-
pchdr.caplen = wth->rec.rec_header.packet_header.caplen;
77-
pchdr.len = wth->rec.rec_header.packet_header.len;
78-
pcap_dump((u_char*)pibs->dumper, &pchdr, eth);
79-
}
48+
//Put other frame processing activities here
8049
}
8150

8251
void process_file(pibs_t* pibs)

bin/pibs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,7 @@ void process_file(pibs_t* pibs);
123123
void pibs_dump_raw(pibs_t* pibs);
124124
void pibs_dump_stats(pibs_t* pibs);
125125
void process_redis_list(pibs_t* pibs);
126+
void synseen_process_frame(pibs_t *pibs, wtap *wth, uint8_t* eth,
127+
struct ip* ipv4, struct tcphdr* tcp);
128+
126129
#endif

bin/synseen.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,42 @@ void pibs_dump_stats(pibs_t* pibs)
136136
}
137137
printf("#Number of unique IP addresses: %ld\n", sum);
138138
}
139+
140+
void synseen_process_frame(pibs_t *pibs, wtap *wth, uint8_t* eth,
141+
struct ip* ipv4, struct tcphdr* tcp)
142+
{
143+
int_fast64_t lastseen;
144+
uint32_t ip;
145+
struct pcap_pkthdr pchdr;
146+
memcpy(&ip, &ipv4->ip_src, 4);
147+
// Record only source ips where syn flag is set
148+
// TODO check other connection establishment alternatives
149+
if (tcp->th_flags == 2 ){
150+
insert_ip(pibs, ip, wth->rec.ts.secs);
151+
return;
152+
}
153+
154+
lastseen = get_last_timestamp(pibs, ip);
155+
156+
if (lastseen > 0){
157+
HDBG("IP %x %s was already seen before at %ld. Time difference %ld.\n"
158+
, ip, inet_ntoa(ipv4->ip_src), lastseen, wth->rec.ts.secs-lastseen);
159+
return;
160+
}
161+
// TODO keep these IPs in a hashtable and rank them
162+
if (pibs->show_backscatter) {
163+
printf("%ld,%s,%d,%d\n",
164+
wth->rec.ts.secs, inet_ntoa(ipv4->ip_src), tcp->th_flags,
165+
ntohs(tcp->th_sport));
166+
}
167+
//TODO relative time
168+
//Purge old ips?
169+
if (pibs->should_writepcap) {
170+
pchdr.ts.tv_sec = wth->rec.ts.secs;
171+
//TODO other part of the timestamp
172+
pchdr.ts.tv_usec = wth->rec.ts.nsecs / 1000;
173+
pchdr.caplen = wth->rec.rec_header.packet_header.caplen;
174+
pchdr.len = wth->rec.rec_header.packet_header.len;
175+
pcap_dump((u_char*)pibs->dumper, &pchdr, eth);
176+
}
177+
}

0 commit comments

Comments
 (0)