summaryrefslogtreecommitdiff
path: root/ring_rx.c
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-05-30 18:11:08 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-05-30 18:11:08 +0200
commit9be74e71213ab2a8d449d1cc6cfa4d533fce0d0f (patch)
treeff2981355231f8f59917d1d5bab55a6f1e1ba5d1 /ring_rx.c
parentc3fec06db030445563d3945eec6320afa9a3db62 (diff)
ring: prepare setup_rx_ring_layout for support in v2/v3
Prepare setup_rx_ring_layout for both, v2 and v3. Also do some checks during compile time if offsets stay the same as we operate on different union mappings. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'ring_rx.c')
-rw-r--r--ring_rx.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/ring_rx.c b/ring_rx.c
index 27c87d3..12ce086 100644
--- a/ring_rx.c
+++ b/ring_rx.c
@@ -36,7 +36,7 @@ void destroy_rx_ring(int sock, struct ring *ring)
}
void setup_rx_ring_layout(int sock, struct ring *ring, unsigned int size,
- int jumbo_support)
+ int jumbo_support, bool v3)
{
fmemset(&ring->layout, 0, sizeof(ring->layout));
@@ -50,17 +50,25 @@ void setup_rx_ring_layout(int sock, struct ring *ring, unsigned int size,
ring->layout.tp_frame_nr = ring->layout.tp_block_size /
ring->layout.tp_frame_size *
ring->layout.tp_block_nr;
+ if (v3) {
+ /* Pass out, if this will ever change and we do crap on it! */
+ build_bug_on(offsetof(struct tpacket_req, tp_frame_nr) !=
+ offsetof(struct tpacket_req3, tp_frame_nr) &&
+ sizeof(struct tpacket_req) !=
+ offsetof(struct tpacket_req3, tp_retire_blk_tov));
+
+ set_sockopt_tpacket_v3(sock);
+ } else {
+ set_sockopt_tpacket_v2(sock);
+ }
- bug_on(ring->layout.tp_block_size < ring->layout.tp_frame_size);
- bug_on((ring->layout.tp_block_size % ring->layout.tp_frame_size) != 0);
- bug_on((ring->layout.tp_block_size % getpagesize()) != 0);
+ ring_verify_layout(ring);
}
void create_rx_ring(int sock, struct ring *ring, int verbose)
{
int ret;
- set_sockopt_tpacket_v2(sock);
retry:
ret = setsockopt(sock, SOL_PACKET, PACKET_RX_RING, &ring->layout,
sizeof(ring->layout));