diff options
author | Yunchih Chen <yunchih.cat@gmail.com> | 2017-12-06 00:13:16 +0800 |
---|---|---|
committer | Yunchih Chen <yunchih.cat@gmail.com> | 2017-12-06 00:13:16 +0800 |
commit | bfe4f8470c744766bda97ec19f71ac1ae1acebea (patch) | |
tree | 56be30bfc4fd42ac213f30c2fdf6373efbb5cf80 | |
parent | 0503266b60eb42a3714f0c29afec0b9f282558a9 (diff) | |
download | nfcollect-bfe4f8470c744766bda97ec19f71ac1ae1acebea.tar.gz nfcollect-bfe4f8470c744766bda97ec19f71ac1ae1acebea.tar.zst nfcollect-bfe4f8470c744766bda97ec19f71ac1ae1acebea.zip |
Add entry counter inside the packet handler
-rw-r--r-- | main.h | 3 | ||||
-rw-r--r-- | nflog.c | 8 |
2 files changed, 9 insertions, 2 deletions
@@ -52,6 +52,9 @@ fprintf(stdout, format "\n", ##__VA_ARGS__); \ } +#define likely(x) __builtin_expect((x),1) +#define unlikely(x) __builtin_expect((x),0) + #define CEILING(a,b) ((a)%(b) == 0 ? ((a)/(b)) : ((a)/(b)+1)) #define TRUNK_SIZE (4096 * 150) @@ -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); |