summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ring.c21
-rw-r--r--ring.h3
-rw-r--r--ring_rx.c17
-rw-r--r--ring_tx.c16
4 files changed, 28 insertions, 29 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,
diff --git a/ring.h b/ring.h
index a195f74..0ac72bb 100644
--- a/ring.h
+++ b/ring.h
@@ -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.
*/
@@ -196,6 +197,8 @@ static inline int get_sockopt_tpacket(int sock)
return val;
}
+extern void setup_ring_layout_generic(int sock, struct ring *ring, size_t size,
+ bool jumbo_support);
extern void mmap_ring_generic(int sock, 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, bool tx_only);
diff --git a/ring_rx.c b/ring_rx.c
index 11d1d08..1df7eb3 100644
--- a/ring_rx.c
+++ b/ring_rx.c
@@ -1,7 +1,7 @@
/*
* netsniff-ng - the packet sniffing beast
* Copyright 2009, 2010 Daniel Borkmann.
- * Copyright 2014 Tobias Klauser.
+ * Copyright 2014, 2015 Tobias Klauser.
* Subject to the GPL, version 2.
*/
@@ -142,20 +142,7 @@ void destroy_rx_ring(int sock, struct ring *ring)
static void setup_rx_ring_layout(int sock, struct ring *ring, size_t size,
bool jumbo_support, bool v3)
{
- 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;
+ setup_ring_layout_generic(sock, ring, size, jumbo_support);
if (v3) {
setup_rx_ring_layout_v3(ring);
diff --git a/ring_tx.c b/ring_tx.c
index 27afe8b..aee1307 100644
--- a/ring_tx.c
+++ b/ring_tx.c
@@ -2,6 +2,7 @@
* netsniff-ng - the packet sniffing beast
* Copyright 2009, 2010 Daniel Borkmann.
* Copyright 2009, 2010 Emmanuel Roullit.
+ * Copyright 2014, 2015 Tobias Klauser.
* Subject to the GPL, version 2.
*/
@@ -48,20 +49,7 @@ void destroy_tx_ring(int sock, struct ring *ring)
static void setup_tx_ring_layout(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;
+ setup_ring_layout_generic(sock, ring, size, jumbo_support);
set_sockopt_tpacket_v2(sock);