From: Victor Julien Date: Thu, 2 Jun 2016 08:49:35 +0000 (+0200) Subject: netmap: get offloading settings and warn if needed X-Git-Tag: suricata-3.1RC1~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4369161b9265ab3586a4cf762d46a1d7ecab9b6c;p=thirdparty%2Fsuricata.git netmap: get offloading settings and warn if needed Add FreeBSD lookup function and use the existing code on Linux. --- diff --git a/src/source-netmap.c b/src/source-netmap.c index fff2b26e27..096e7594bb 100644 --- a/src/source-netmap.c +++ b/src/source-netmap.c @@ -247,6 +247,55 @@ static int NetmapGetIfaceFlags(int fd, const char *ifname) #endif } +#ifdef SIOCGIFCAP +static int NetmapGetIfaceCaps(int fd, const char *ifname) +{ + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifr)); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + if (ioctl(fd, SIOCGIFCAP, &ifr) == -1) { + SCLogError(SC_ERR_NETMAP_CREATE, + "Unable to get caps for iface \"%s\": %s", + ifname, strerror(errno)); + return -1; + } + + return ifr.ifr_curcap; +} +#endif + +static void NetmapCheckOffloading(int fd, const char *ifname) +{ +#ifdef SIOCGIFCAP + int if_caps = NetmapGetIfaceCaps(fd, ifname); + if (if_caps == -1) { + return; + } + SCLogDebug("if_caps %X", if_caps); + + if (if_caps & IFCAP_RXCSUM) { + SCLogWarning(SC_ERR_NETMAP_CREATE, + "Using NETMAP with RXCSUM activated can lead to capture " + "problems: ifconfig %s -rxcsum", ifname); + } + if (if_caps & (IFCAP_TSO|IFCAP_TOE|IFCAP_LRO)) { + SCLogWarning(SC_ERR_NETMAP_CREATE, + "Using NETMAP with TSO, TOE or LRO activated can lead to " + "capture problems: ifconfig %s -tso -toe -lro", ifname); + } +#else + if (GetIfaceOffloading(ifname) == 1) { + SCLogWarning(SC_ERR_NETMAP_CREATE, + "Using NETMAP with GRO or LRO activated can lead to " + "capture problems: " + "ethtool -K %s rx off sg off gro off gso off tso off", + ifname); + } +#endif +} + /** * \brief Set interface flags. * \param fd Network susbystem file descritor. @@ -393,6 +442,8 @@ static int NetmapOpen(char *ifname, int promisc, NetmapDevice **pdevice, int ver if_flags |= IFF_PROMISC; NetmapSetIfaceFlags(if_fd, ifname, if_flags); } + + NetmapCheckOffloading(if_fd, ifname); close(if_fd); /* query netmap info */