From 238ff23111f78073c4ebefe9fc1de72ea54a74d3 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Mon, 17 Mar 2014 13:58:06 +0100 Subject: [PATCH] af-packet: move packet fanout code The sooner is the better for that caode as these means we will get all sockets binded to fanout group as fast as possible. --- src/source-af-packet.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/source-af-packet.c b/src/source-af-packet.c index 654145a6d7..a059b1f80e 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -1397,6 +1397,23 @@ static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose) goto frame_err; } +#ifdef HAVE_PACKET_FANOUT + /* add binded socket to fanout group */ + if (ptv->threads > 1) { + uint32_t option = 0; + uint16_t mode = ptv->cluster_type; + uint16_t id = ptv->cluster_id; + option = (mode << 16) | (id & 0xffff); + r = setsockopt(ptv->socket, SOL_PACKET, PACKET_FANOUT,(void *)&option, sizeof(option)); + if (r < 0) { + SCLogError(SC_ERR_AFP_CREATE, + "Coudn't set fanout mode, error %s", + strerror(errno)); + goto frame_err; + } + } +#endif + int if_flags = AFPGetDevFlags(ptv->socket, ptv->iface); if (if_flags == -1) { if (verbose) { @@ -1503,22 +1520,6 @@ static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose) SCLogInfo("Using interface '%s' via socket %d", (char *)devname, ptv->socket); -#ifdef HAVE_PACKET_FANOUT - /* add binded socket to fanout group */ - if (ptv->threads > 1) { - uint32_t option = 0; - uint16_t mode = ptv->cluster_type; - uint16_t id = ptv->cluster_id; - option = (mode << 16) | (id & 0xffff); - r = setsockopt(ptv->socket, SOL_PACKET, PACKET_FANOUT,(void *)&option, sizeof(option)); - if (r < 0) { - SCLogError(SC_ERR_AFP_CREATE, - "Coudn't set fanout mode, error %s", - strerror(errno)); - goto frame_err; - } - } -#endif ptv->datalink = AFPGetDevLinktype(ptv->socket, ptv->iface); switch (ptv->datalink) { -- 2.47.2