summaryrefslogtreecommitdiff
path: root/ring.c
diff options
context:
space:
mode:
Diffstat (limited to 'ring.c')
-rw-r--r--ring.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/ring.c b/ring.c
index e42828e..26de18e 100644
--- a/ring.c
+++ b/ring.c
@@ -1,6 +1,7 @@
/*
* netsniff-ng - the packet sniffing beast
* Copyright 2009, 2010 Daniel Borkmann.
+ * Copyright 2014, 2015 Tobias Klauser
* Subject to the GPL, version 2.
*/
@@ -19,6 +20,26 @@
#include "ring.h"
#include "built_in.h"
+void setup_ring_layout_generic(int sock, struct ring *ring, size_t size,
+ bool jumbo_support)
+{
+ fmemset(&ring->layout, 0, sizeof(ring->layout));
+
+ ring->layout.tp_block_size = (jumbo_support ?
+ RUNTIME_PAGE_SIZE << 4 :
+ RUNTIME_PAGE_SIZE << 2);
+
+ ring->layout.tp_frame_size = (jumbo_support ?
+ TPACKET_ALIGNMENT << 12 :
+ TPACKET_ALIGNMENT << 7);
+
+ ring->layout.tp_block_nr = size / ring->layout.tp_block_size;
+ ring->layout.tp_frame_nr = ring->layout.tp_block_size /
+ ring->layout.tp_frame_size *
+ ring->layout.tp_block_nr;
+
+}
+
void mmap_ring_generic(int sock, struct ring *ring)
{
ring->mm_space = mmap(NULL, ring->mm_len, PROT_READ | PROT_WRITE,