diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-05-31 12:11:09 +0200 |
---|---|---|
committer | Daniel Borkmann <dborkman@redhat.com> | 2013-05-31 12:11:09 +0200 |
commit | cacb34f95fb7937e81b1fe8add7b5dca91e3a4c5 (patch) | |
tree | 607d72816c4d810050996f37f2acef583757cd8b | |
parent | 0f765f49ac231d99f493f00c0f0986fbeff2615d (diff) |
ring: setup frame structure for v2/v3 in a generic way
Prepare TPACKET_V3 for allowing to transparently setting up the
frame structure such that we do not need to change much in the
netsniff-ng/trafgen code.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
-rw-r--r-- | netsniff-ng.c | 8 | ||||
-rw-r--r-- | ring.c | 11 | ||||
-rw-r--r-- | ring.h | 2 | ||||
-rw-r--r-- | ring_rx.c | 16 | ||||
-rw-r--r-- | ring_rx.h | 2 | ||||
-rw-r--r-- | ring_tx.c | 5 | ||||
-rw-r--r-- | ring_tx.h | 2 | ||||
-rw-r--r-- | trafgen.c | 2 |
8 files changed, 30 insertions, 18 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c index 76fafed..e5e91ed 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -226,7 +226,7 @@ static void pcap_to_xmit(struct ctx *ctx) setup_tx_ring_layout(tx_sock, &tx_ring, size, ctx->jumbo); create_tx_ring(tx_sock, &tx_ring, ctx->verbose); mmap_tx_ring(tx_sock, &tx_ring); - alloc_tx_ring_frames(&tx_ring); + alloc_tx_ring_frames(tx_sock, &tx_ring); bind_tx_ring(tx_sock, &tx_ring, ifindex); dissector_init_all(ctx->print_mode); @@ -375,7 +375,7 @@ static void receive_to_xmit(struct ctx *ctx) setup_rx_ring_layout(rx_sock, &rx_ring, size_in, ctx->jumbo, false); create_rx_ring(rx_sock, &rx_ring, ctx->verbose); mmap_rx_ring(rx_sock, &rx_ring); - alloc_rx_ring_frames(&rx_ring); + alloc_rx_ring_frames(rx_sock, &rx_ring); bind_rx_ring(rx_sock, &rx_ring, ifindex_in); prepare_polling(rx_sock, &rx_poll); @@ -383,7 +383,7 @@ static void receive_to_xmit(struct ctx *ctx) setup_tx_ring_layout(tx_sock, &tx_ring, size_out, ctx->jumbo); create_tx_ring(tx_sock, &tx_ring, ctx->verbose); mmap_tx_ring(tx_sock, &tx_ring); - alloc_tx_ring_frames(&tx_ring); + alloc_tx_ring_frames(tx_sock, &tx_ring); bind_tx_ring(tx_sock, &tx_ring, ifindex_out); dissector_init_all(ctx->print_mode); @@ -854,7 +854,7 @@ static void recv_only_or_dump(struct ctx *ctx) setup_rx_ring_layout(sock, &rx_ring, size, ctx->jumbo, false); create_rx_ring(sock, &rx_ring, ctx->verbose); mmap_rx_ring(sock, &rx_ring); - alloc_rx_ring_frames(&rx_ring); + alloc_rx_ring_frames(sock, &rx_ring); bind_rx_ring(sock, &rx_ring, ifindex); prepare_polling(sock, &rx_poll); @@ -27,18 +27,17 @@ void mmap_ring_generic(int sock, struct ring *ring) panic("Cannot mmap {TX,RX}_RING!\n"); } -void alloc_ring_frames_generic(struct ring *ring) +void alloc_ring_frames_generic(struct ring *ring, int num, size_t size) { int i; - size_t len = ring->layout.tp_frame_nr * sizeof(*ring->frames); + size_t len = num * sizeof(*ring->frames); ring->frames = xmalloc_aligned(len, CO_CACHE_LINE_SIZE); fmemset(ring->frames, 0, len); - for (i = 0; i < ring->layout.tp_frame_nr; ++i) { - ring->frames[i].iov_len = ring->layout.tp_frame_size; - ring->frames[i].iov_base = ring->mm_space + - (i * ring->layout.tp_frame_size); + for (i = 0; i < num; ++i) { + ring->frames[i].iov_len = size; + ring->frames[i].iov_base = ring->mm_space + (i * size); } } @@ -142,7 +142,7 @@ static inline int get_sockopt_tpacket(int sock) } extern void mmap_ring_generic(int sock, struct ring *ring); -extern void alloc_ring_frames_generic(struct ring *ring); +extern void alloc_ring_frames_generic(struct ring *ring, int num, size_t size); extern void bind_ring_generic(int sock, struct ring *ring, int ifindex); #endif /* RING_H */ @@ -104,9 +104,21 @@ void mmap_rx_ring(int sock, struct ring *ring) mmap_ring_generic(sock, ring); } -void alloc_rx_ring_frames(struct ring *ring) +void alloc_rx_ring_frames(int sock, struct ring *ring) { - alloc_ring_frames_generic(ring); + int num; + size_t size; + bool v3 = get_sockopt_tpacket(sock) == TPACKET_V3; + + if (v3) { + num = ring->layout3.tp_block_nr; + size = ring->layout3.tp_block_size; + } else { + num = ring->layout.tp_frame_nr; + size = ring->layout.tp_frame_size; + } + + alloc_ring_frames_generic(ring, num, size); } void bind_rx_ring(int sock, struct ring *ring, int ifindex) @@ -13,7 +13,7 @@ extern void destroy_rx_ring(int sock, struct ring *ring); extern void create_rx_ring(int sock, struct ring *ring, int verbose); extern void mmap_rx_ring(int sock, struct ring *ring); -extern void alloc_rx_ring_frames(struct ring *ring); +extern void alloc_rx_ring_frames(int sock, struct ring *ring); extern void bind_rx_ring(int sock, struct ring *ring, int ifindex); extern void setup_rx_ring_layout(int sock, struct ring *ring, unsigned int size, bool jumbo_support, bool v3); @@ -100,9 +100,10 @@ void mmap_tx_ring(int sock, struct ring *ring) mmap_ring_generic(sock, ring); } -void alloc_tx_ring_frames(struct ring *ring) +void alloc_tx_ring_frames(int sock __maybe_unused, struct ring *ring) { - alloc_ring_frames_generic(ring); + alloc_ring_frames_generic(ring, ring->layout.tp_frame_nr, + ring->layout.tp_frame_size); } void bind_tx_ring(int sock, struct ring *ring, int ifindex) @@ -16,7 +16,7 @@ extern void destroy_tx_ring(int sock, struct ring *ring); extern void create_tx_ring(int sock, struct ring *ring, int verbose); extern void mmap_tx_ring(int sock, struct ring *ring); -extern void alloc_tx_ring_frames(struct ring *ring); +extern void alloc_tx_ring_frames(int sock, struct ring *ring); extern void bind_tx_ring(int sock, struct ring *ring, int ifindex); extern void setup_tx_ring_layout(int sock, struct ring *ring, unsigned int size, bool jumbo_support); @@ -620,7 +620,7 @@ static void xmit_fastpath_or_die(struct ctx *ctx, int cpu, unsigned long orig_nu setup_tx_ring_layout(sock, &tx_ring, size, ctx->jumbo_support); create_tx_ring(sock, &tx_ring, ctx->verbose); mmap_tx_ring(sock, &tx_ring); - alloc_tx_ring_frames(&tx_ring); + alloc_tx_ring_frames(sock, &tx_ring); bind_tx_ring(sock, &tx_ring, ifindex); drop_privileges(ctx->enforce, ctx->uid, ctx->gid); |