#include #include #include #include #include static int enobufs_err, total_enobufs; static uint64_t events, total_events; static time_t prev, start, stop; static int event_cb(enum nf_conntrack_msg_type type, struct nf_conntrack *ct, void *data) { time_t current, diff; events++; current = time(NULL); diff = current - prev; if (diff >= 1) { prev = current; printf("events/s %u; enobufs/s=%u\n", events/diff, enobufs_err/diff); total_enobufs += enobufs_err; total_events += events; events = 0; enobufs_err = 0; } return NFCT_CB_CONTINUE; } static void sighandler(int foo) { time_t total_time; stop = time(NULL); total_time = stop - start; printf("AVG events/s %u; enobufs/s=%u; in %lu seconds\n", (unsigned int) total_events/total_time, (unsigned int) total_enobufs/total_time, total_time); exit(1); } int main() { int ret; u_int8_t family = AF_INET; struct nfct_handle *h; struct nf_conntrack *ct; signal(SIGINT, sighandler); h = nfct_open(CONNTRACK, NFCT_ALL_CT_GROUPS); if (!h) { perror("nfct_open"); return 0; } nfct_callback_register(h, NFCT_T_ALL, event_cb, NULL); printf("waiting for events...\n"); prev = start = time(NULL); while (1) { ret = nfct_catch(h); if (ret == -1) { if (errno == ENOBUFS) enobufs_err++; } } nfct_close(h); }