diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-03-28 18:48:25 +0100 |
---|---|---|
committer | Daniel Borkmann <dborkman@redhat.com> | 2013-03-28 18:48:25 +0100 |
commit | 367efea8c9ba557a81158a69ecee267706a520eb (patch) | |
tree | 461ddf127e076a99d792e59006fd599ad1704c01 /netsniff-ng.c | |
parent | b55fde49e9f3e772b62e175cdbbec8f9fcc77567 (diff) |
ring: purge timer before we unmap tx ring buffers
If we unmap TX ring buffers and still have timer shots that trigger
the kernel to traverse the TX_RING, it can send out random crap in
some situations. Prevent this by destroying the timer and flush the
TX_RING first in wait mode.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'netsniff-ng.c')
-rw-r--r-- | netsniff-ng.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c index 0f97acd..ecb9e9a 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -131,6 +131,21 @@ static void timer_elapsed(int unused) setitimer(ITIMER_REAL, &itimer, NULL); } +static void timer_purge(void) +{ + int ret; + + ret = pull_and_flush_tx_ring_wait(tx_sock); + if (unlikely(ret < 0)) { + if (errno != EBADF && errno != ENOBUFS) + panic("Flushing TX_RING failed: %s!\n", strerror(errno)); + } + + set_itimer_interval_value(&itimer, 0, 0); + setitimer(ITIMER_REAL, &itimer, NULL); +} + + static void timer_next_dump(int unused) { set_itimer_interval_value(&itimer, interval, 0); @@ -289,6 +304,8 @@ static void pcap_to_xmit(struct ctx *ctx) bug_on(gettimeofday(&end, NULL)); timersub(&end, &start, &diff); + timer_purge(); + bpf_release(&bpf_ops); dissector_cleanup_all(); @@ -455,6 +472,8 @@ static void receive_to_xmit(struct ctx *ctx) out: + timer_purge(); + sock_print_net_stats(rx_sock, 0); bpf_release(&bpf_ops); |