summaryrefslogtreecommitdiff
path: root/ring_rx.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2014-05-26 15:10:33 +0200
committerTobias Klauser <tklauser@distanz.ch>2014-08-14 08:48:15 +0200
commit97e6f994785ce5f3f486f8eddb62df964119d121 (patch)
treed8452eb956ec0eb98b13c0a931dd5abce71c3400 /ring_rx.c
parentfa32dcaddab2363cb01acc81bddf7dc3d42ab5b1 (diff)
netsniff-ng: Restore tpacket v2 capturing
Some older systems (e.g. RHEL 6) don't have tpacket v3 available, but only tpacket v2. However, since commit d8cdc6a ("ring: netsniff-ng: migrate capture only to TPACKET_V3") we solely rely on tpacket v3 for capturing packets. This patch restores the possibility to capture using tpacket v2. For now this is just a fallback if the configure script doesn't detect tpacket v3 (and thus HAVE_TPACKET3 isn't set). Thus, on most modern systems this shouldn't change anything and they will continue using tpacket v3. For now this fix contains quite a bit of ugly #ifdefery which should be cleaned up in the future. Fixes #76 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'ring_rx.c')
-rw-r--r--ring_rx.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/ring_rx.c b/ring_rx.c
index 7a3d21d..1b8dd23 100644
--- a/ring_rx.c
+++ b/ring_rx.c
@@ -58,6 +58,8 @@ static void setup_rx_ring_layout(int sock, struct ring *ring, size_t size,
ring->layout.tp_frame_nr = ring->layout.tp_block_size /
ring->layout.tp_frame_size *
ring->layout.tp_block_nr;
+
+#ifdef HAVE_TPACKET3
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) !=
@@ -70,6 +72,9 @@ static void setup_rx_ring_layout(int sock, struct ring *ring, size_t size,
ring->layout3.tp_feature_req_word = 0;
set_sockopt_tpacket_v3(sock);
+#else
+ if (0) {
+#endif /* HAVE_TPACKET3 */
} else {
set_sockopt_tpacket_v2(sock);
}
@@ -80,11 +85,17 @@ static void setup_rx_ring_layout(int sock, struct ring *ring, size_t size,
static void create_rx_ring(int sock, struct ring *ring, bool verbose)
{
int ret;
+#ifdef HAVE_TPACKET3
bool v3 = get_sockopt_tpacket(sock) == TPACKET_V3;
+ size_t layout_size = v3 ? sizeof(ring->layout3) : sizeof(ring->layout);
+#else
+ bool v3 = false;
+ size_t layout_size = sizeof(ring->layout);
+#endif /* HAVE_TPACKET3 */
retry:
ret = setsockopt(sock, SOL_PACKET, PACKET_RX_RING, &ring->raw,
- v3 ? sizeof(ring->layout3) : sizeof(ring->layout));
+ layout_size);
if (errno == ENOMEM && ring->layout.tp_block_nr > 1) {
ring->layout.tp_block_nr >>= 1;
@@ -115,11 +126,15 @@ static void alloc_rx_ring_frames(int sock, struct ring *ring)
{
int num;
size_t size;
+#if HAVE_TPACKET3
bool v3 = get_sockopt_tpacket(sock) == TPACKET_V3;
if (v3) {
num = ring->layout3.tp_block_nr;
size = ring->layout3.tp_block_size;
+#else
+ if (0) {
+#endif /* HAVE_TPACKET3 */
} else {
num = ring->layout.tp_frame_nr;
size = ring->layout.tp_frame_size;