summaryrefslogtreecommitdiff
path: root/ring_rx.c
diff options
context:
space:
mode:
authorMichał Purzyński <michalpurzynski1@gmail.com>2015-04-21 11:12:44 +0200
committerDaniel Borkmann <daniel@iogearbox.net>2015-04-21 11:48:38 +0200
commitf00d4d54f28c0374cc57e6ca07dd648d7684c69c (patch)
tree3670c9ad317a1fd65da88f0515c84fcd06c392c9 /ring_rx.c
parentfb1c7820fd6a30224f98175b481b981efadf7673 (diff)
netsniff-ng: add packet fanout support
This work adds packet fanout support to netsniff-ng. Multiple netsniff-ng instances can join the same fanout group with a particular id in order to improve scaling. Based on different fanout disciplines, e.g. distribute to fanout member by packet hash, round-robin, by arrival cpu, by random, by socket rollover (if one members socket queue is full, switch to next one, etc), by hardware queue mapping, traffic can be distributed to one of the fanout members. Moreover, we also allow the user to specify additional aux arguments, e.g. whether to defrag incoming traffic for the fanout group or not, and whether to roll over a socket in case other disciplines than socket rollover have been used. All that is configurable via command line option. Signed-off-by: Michał Purzyński <michalpurzynski1@gmail.com> [ dbkm made some bigger changes to get this upstream ready ] Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'ring_rx.c')
-rw-r--r--ring_rx.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/ring_rx.c b/ring_rx.c
index 8ad64d1..32d3f6d 100644
--- a/ring_rx.c
+++ b/ring_rx.c
@@ -209,9 +209,25 @@ static void alloc_rx_ring_frames(int sock, struct ring *ring)
rx_ring_get_size(ring, v3));
}
+void join_fanout_group(int sock, uint32_t fanout_group, uint32_t fanout_type)
+{
+ uint32_t fanout_opt = 0;
+ int ret;
+
+ if (fanout_group == 0)
+ return;
+
+ fanout_opt = (fanout_group & 0xffff) | (fanout_type << 16);
+
+ ret = setsockopt(sock, SOL_PACKET, PACKET_FANOUT, &fanout_opt,
+ sizeof(fanout_opt));
+ if (ret < 0)
+ panic("Cannot set fanout ring mode!\n");
+}
+
void ring_rx_setup(struct ring *ring, int sock, size_t size, int ifindex,
struct pollfd *poll, bool v3, bool jumbo_support,
- bool verbose)
+ bool verbose, uint32_t fanout_group, uint32_t fanout_type)
{
fmemset(ring, 0, sizeof(*ring));
setup_rx_ring_layout(sock, ring, size, jumbo_support, v3);
@@ -219,6 +235,7 @@ void ring_rx_setup(struct ring *ring, int sock, size_t size, int ifindex,
mmap_ring_generic(sock, ring);
alloc_rx_ring_frames(sock, ring);
bind_ring_generic(sock, ring, ifindex, false);
+ join_fanout_group(sock, fanout_group, fanout_type);
prepare_polling(sock, poll);
}