summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netsniff-ng.c8
-rw-r--r--ring.c11
-rw-r--r--ring.h2
-rw-r--r--ring_rx.c16
-rw-r--r--ring_rx.h2
-rw-r--r--ring_tx.c5
-rw-r--r--ring_tx.h2
-rw-r--r--trafgen.c2
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);
diff --git a/ring.c b/ring.c
index 2899df3..c5d2d99 100644
--- a/ring.c
+++ b/ring.c
@@ -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);
}
}
diff --git a/ring.h b/ring.h
index 93edb01..be04cf0 100644
--- a/ring.h
+++ b/ring.h
@@ -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 */
diff --git a/ring_rx.c b/ring_rx.c
index de19568..0d1f828 100644
--- a/ring_rx.c
+++ b/ring_rx.c
@@ -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)
diff --git a/ring_rx.h b/ring_rx.h
index 0a2701f..9c72cda 100644
--- a/ring_rx.h
+++ b/ring_rx.h
@@ -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);
diff --git a/ring_tx.c b/ring_tx.c
index 18216ac..549f89c 100644
--- a/ring_tx.c
+++ b/ring_tx.c
@@ -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)
diff --git a/ring_tx.h b/ring_tx.h
index 6f626d1..23caa35 100644
--- a/ring_tx.h
+++ b/ring_tx.h
@@ -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);
diff --git a/trafgen.c b/trafgen.c
index 9fa43fc..bbce64c 100644
--- a/trafgen.c
+++ b/trafgen.c
@@ -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);