summaryrefslogtreecommitdiff
path: root/ring_rx.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2014-08-14 15:20:51 +0200
committerTobias Klauser <tklauser@distanz.ch>2014-08-14 15:20:51 +0200
commit9b166a9f769392dd0326a1c41864312bd22df07b (patch)
tree8b2a6c66f117600eb764f9c5aa77e522b35f4133 /ring_rx.c
parent5bc19d0b84d0d1c448cd4e4ba0e3e7da3503434a (diff)
netsniff-ng: Clean up HAVE_TPACKET3 #ifdefs
Instead of having #ifdef HAVE_TPACKET3 spread all over the code, encapsulate the functionality depending on it inside inline functions: the existing is_tpacket_v3() introduced in commit 5bc19d0b84d0 ("netsniff-ng: Only use TPACKET_V3 if HAVE_TPACKET3 is defined") and the newly introduced get_ring_layout_size() to get the ring layout size depending on the tpacket version available and the version actually in use. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'ring_rx.c')
-rw-r--r--ring_rx.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/ring_rx.c b/ring_rx.c
index 72587fd..6c81fdb 100644
--- a/ring_rx.c
+++ b/ring_rx.c
@@ -1,6 +1,7 @@
/*
* netsniff-ng - the packet sniffing beast
* Copyright 2009, 2010 Daniel Borkmann.
+ * Copyright 2014 Tobias Klauser.
* Subject to the GPL, version 2.
*/
@@ -25,12 +26,22 @@ static inline bool is_tpacket_v3(int sock)
{
return get_sockopt_tpacket(sock) == TPACKET_V3;
}
+
+static inline size_t get_ring_layout_size(struct ring *ring, bool v3)
+{
+ return v3 ? sizeof(ring->layout3) : sizeof(ring->layout);
+}
#else
static inline bool is_tpacket_v3(int sock __maybe_unused)
{
return false;
}
-#endif
+
+static inline size_t get_ring_layout_size(struct ring *ring, bool v3 __maybe_unused)
+{
+ return sizeof(ring->layout);
+}
+#endif /* HAVE_TPACKET3 */
void destroy_rx_ring(int sock, struct ring *ring)
{
@@ -71,7 +82,6 @@ static void setup_rx_ring_layout(int sock, struct ring *ring, size_t 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) !=
@@ -84,9 +94,6 @@ 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);
}
@@ -98,11 +105,7 @@ static void create_rx_ring(int sock, struct ring *ring, bool verbose)
{
int ret;
bool v3 = is_tpacket_v3(sock);
-#ifdef HAVE_TPACKET3
- size_t layout_size = v3 ? sizeof(ring->layout3) : sizeof(ring->layout);
-#else
- size_t layout_size = sizeof(ring->layout);
-#endif /* HAVE_TPACKET3 */
+ size_t layout_size = get_ring_layout_size(ring, v3);
retry:
ret = setsockopt(sock, SOL_PACKET, PACKET_RX_RING, &ring->raw,