From 2b56ae9745bf27ae627444e5305e7192e4e337dd Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Sun, 6 Jan 2013 00:37:04 +0100 Subject: [PATCH] ring: remove macro with ptr dereference Signed-off-by: Daniel Borkmann --- src/netsniff-ng.c | 29 ++++++++++++++++++++++------- src/ring.h | 7 ------- src/trafgen.c | 5 ++++- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/netsniff-ng.c b/src/netsniff-ng.c index 15226b16..1d8f0d89 100644 --- a/src/netsniff-ng.c +++ b/src/netsniff-ng.c @@ -301,7 +301,10 @@ static void pcap_to_xmit(struct ctx *ctx) ctx->link_type, ctx->print_mode); kernel_may_pull_from_tx(&hdr->tp_h); - next_slot(&it, &tx_ring); + + it++; + if (it >= tx_ring.layout.tp_frame_nr) + it = 0; if (unlikely(sigint == 1)) break; @@ -439,8 +442,11 @@ static void receive_to_xmit(struct ctx *ctx) likely(!sigint);) { if (ctx->randomize) next_rnd_slot(&it_out, &tx_ring); - else - next_slot(&it_out, &tx_ring); + else { + it_out++; + if (it_out >= tx_ring.layout.tp_frame_nr) + it_out = 0; + } hdr_out = tx_ring.frames[it_out].iov_base; out = ((uint8_t *) hdr_out) + TPACKET2_HDRLEN - sizeof(struct sockaddr_ll); @@ -452,8 +458,11 @@ static void receive_to_xmit(struct ctx *ctx) kernel_may_pull_from_tx(&hdr_out->tp_h); if (ctx->randomize) next_rnd_slot(&it_out, &tx_ring); - else - next_slot(&it_out, &tx_ring); + else { + it_out++; + if (it_out >= tx_ring.layout.tp_frame_nr) + it_out = 0; + } show_frame_hdr(hdr_in, ctx->print_mode, RING_MODE_INGRESS); @@ -470,7 +479,10 @@ static void receive_to_xmit(struct ctx *ctx) next: kernel_may_pull_from_rx(&hdr_in->tp_h); - next_slot(&it_in, &rx_ring); + + it_in++; + if (it_in >= rx_ring.layout.tp_frame_nr) + it_in = 0; if (unlikely(sigint == 1)) goto out; @@ -929,7 +941,10 @@ static void recv_only_or_dump(struct ctx *ctx) next: kernel_may_pull_from_rx(&hdr->tp_h); - next_slot(&it, &rx_ring); + + it++; + if (it >= rx_ring.layout.tp_frame_nr) + it = 0; if (unlikely(sigint == 1)) break; diff --git a/src/ring.h b/src/ring.h index bff11435..f0599210 100644 --- a/src/ring.h +++ b/src/ring.h @@ -47,13 +47,6 @@ struct ring { struct sockaddr_ll s_ll; }; -static inline void next_slot(unsigned int *it, struct ring *ring) -{ - (*it)++; - if (*it >= ring->layout.tp_frame_nr) - *it = 0; -} - static inline void next_rnd_slot(unsigned int *it, struct ring *ring) { *it = rand() % ring->layout.tp_frame_nr; diff --git a/src/trafgen.c b/src/trafgen.c index 4976c74e..b334a467 100644 --- a/src/trafgen.c +++ b/src/trafgen.c @@ -439,7 +439,10 @@ static void xmit_fastpath_or_die(struct ctx *ctx) i = rand() % plen; kernel_may_pull_from_tx(&hdr->tp_h); - next_slot(&it, &tx_ring); + + it++; + if (it >= tx_ring.layout.tp_frame_nr) + it = 0; if (ctx->num > 0) num--; -- 2.11.4.GIT