aboutsummaryrefslogtreecommitdiffstats
path: root/nflog.c
diff options
context:
space:
mode:
authorYunchih Chen <yunchih.cat@gmail.com>2017-12-06 00:13:16 +0800
committerYunchih Chen <yunchih.cat@gmail.com>2017-12-06 00:13:16 +0800
commitbfe4f8470c744766bda97ec19f71ac1ae1acebea (patch)
tree56be30bfc4fd42ac213f30c2fdf6373efbb5cf80 /nflog.c
parent0503266b60eb42a3714f0c29afec0b9f282558a9 (diff)
downloadnfcollect-bfe4f8470c744766bda97ec19f71ac1ae1acebea.tar.gz
nfcollect-bfe4f8470c744766bda97ec19f71ac1ae1acebea.tar.zst
nfcollect-bfe4f8470c744766bda97ec19f71ac1ae1acebea.zip
Add entry counter inside the packet handler
Diffstat (limited to 'nflog.c')
-rw-r--r--nflog.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/nflog.c b/nflog.c
index 051c904..ff9480b 100644
--- a/nflog.c
+++ b/nflog.c
@@ -53,7 +53,9 @@ static int handle_packet(struct nflog_g_handle *gh, struct nfgenmsg *nfmsg,
nflog_state_t *nf = (nflog_state_t *)_nf;
// only process ipv4 packet
- if (payload_len < 0 || ((payload[0] & 0xf0) != 0x40))
+ if (unlikely(payload_len < 0) || ((payload[0] & 0xf0) != 0x40))
+ return 1;
+ if (unlikely(nf->header->n_entries >= nf->header->max_n_entries))
return 1;
iph = (struct iphdr *)payload;
@@ -88,13 +90,14 @@ static int handle_packet(struct nflog_g_handle *gh, struct nfgenmsg *nfmsg,
time(&entry->timestamp);
nf->header->n_entries++;
- debug("Recv packet info: "
+ debug("Recv packet info entry #%d: "
"timestamp:\t%ld\t"
"daddr:\t%d\t"
"transfer:\t%s\t"
"uid:\t%d\t"
"sport:\t%d\t"
"dport:\t%d",
+ nf->header->n_entries,
entry->timestamp, entry->daddr,
iph->protocol == IPPROTO_TCP ? "TCP" : "UDP",
entry->uid, entry->sport, entry->dport);
@@ -147,6 +150,7 @@ void *nflog_worker(void *targs) {
}
}
+ debug("Recv worker #%u: finish recv", nf->header->id);
time(&nf->header->end_time);
nfl_cleanup(nf);
nfl_commit(nf);