summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-03-16 14:25:20 +0100
committerDaniel Borkmann <dborkman@redhat.com>2013-03-16 14:25:20 +0100
commitd040e1715d0afb74a474bcf1552e250cbceb8966 (patch)
treeadd26ad6639c1a89cc32c67fe92c86ba31521e69
parent79a5df56848ccacf1ab0202e969a8a5206ecaafe (diff)
netsniff-ng trafgen: check return value of pull_and_flush_ring
Let us check the return value when the timer triggers a TX flush request to the kernel. However, ignore the case of BADFS and NOBUFS. The socket could already have been closed before the timer triggers in the first case, and in the second, we just let the next timer continue processing if currently the buffer space is exhausted. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
-rw-r--r--netsniff-ng.c13
-rw-r--r--trafgen.c13
2 files changed, 24 insertions, 2 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c
index 94fb313..6f7c4c2 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -115,8 +115,19 @@ static void signal_handler(int number)
static void timer_elapsed(int unused)
{
+ int ret;
+
set_itimer_interval_value(&itimer, 0, interval);
- pull_and_flush_tx_ring(tx_sock);
+
+ ret = pull_and_flush_tx_ring(tx_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));
+ }
+
setitimer(ITIMER_REAL, &itimer, NULL);
}
diff --git a/trafgen.c b/trafgen.c
index 03c12c5..02aa2df 100644
--- a/trafgen.c
+++ b/trafgen.c
@@ -127,8 +127,19 @@ static void signal_handler(int number)
static void timer_elapsed(int number)
{
+ int ret;
+
set_itimer_interval_value(&itimer, 0, interval);
- pull_and_flush_tx_ring(sock);
+
+ 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));
+ }
+
setitimer(ITIMER_REAL, &itimer, NULL);
}