From 367efea8c9ba557a81158a69ecee267706a520eb Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Thu, 28 Mar 2013 18:48:25 +0100 Subject: 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 --- trafgen.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'trafgen.c') diff --git a/trafgen.c b/trafgen.c index dc0c54b..fb41f45 100644 --- a/trafgen.c +++ b/trafgen.c @@ -127,11 +127,24 @@ static void signal_handler(int number) static void timer_elapsed(int number) { - int ret; + int ret = pull_and_flush_tx_ring(sock); + if (unlikely(ret < 0)) { + /* We could hit EBADF if the socket has been closed before + * the timer was triggered. + */ + if (errno != EBADF && errno != ENOBUFS) + panic("Flushing TX_RING failed: %s!\n", strerror(errno)); + } set_itimer_interval_value(&itimer, 0, interval); + setitimer(ITIMER_REAL, &itimer, NULL); +} - ret = pull_and_flush_tx_ring(sock); +static void timer_purge(void) +{ + int ret; + + ret = pull_and_flush_tx_ring_wait(sock); if (unlikely(ret < 0)) { /* We could hit EBADF if the socket has been closed before * the timer was triggered. @@ -140,6 +153,7 @@ static void timer_elapsed(int number) panic("Flushing TX_RING failed: %s!\n", strerror(errno)); } + set_itimer_interval_value(&itimer, 0, 0); setitimer(ITIMER_REAL, &itimer, NULL); } @@ -669,6 +683,8 @@ static void xmit_fastpath_or_die(struct ctx *ctx, int cpu, unsigned long orig_nu bug_on(gettimeofday(&end, NULL)); timersub(&end, &start, &diff); + timer_purge(); + destroy_tx_ring(sock, &tx_ring); stats[cpu].tx_packets = tx_packets; -- cgit v1.2.3-54-g00ecf