]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
offloading: preparation for disabling offload on BSD
authorVictor Julien <victor@inliniac.net>
Mon, 20 Jun 2016 18:11:55 +0000 (20:11 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 22 Sep 2016 11:36:27 +0000 (13:36 +0200)
Add functions for setting IFCAP flags.

src/util-ioctl.c
src/util-ioctl.h

index cfca00b3a4b205e153f83fddfbc4a61902efe471..5eb7b408c1f8803fdee2004f572b132a1099da69 100644 (file)
@@ -236,6 +236,33 @@ int GetIfaceCaps(const char *ifname)
     return ifr.ifr_curcap;
 }
 #endif
+#ifdef SIOCSIFCAP
+int SetIfaceCaps(const char *ifname, int caps)
+{
+    struct ifreq ifr;
+
+    int fd = socket(AF_INET, SOCK_DGRAM, 0);
+    if (fd < 0) {
+        return -1;
+    }
+
+    memset(&ifr, 0, sizeof(ifr));
+    strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+    ifr.ifr_reqcap = caps;
+
+    if (ioctl(fd, SIOCSIFCAP, &ifr) == -1) {
+        SCLogError(SC_ERR_SYSCALL,
+                   "Unable to set caps for iface \"%s\": %s",
+                   ifname, strerror(errno));
+        close(fd);
+        return -1;
+    }
+
+    close(fd);
+    return 0;
+}
+#endif
+
 
 #if defined HAVE_LINUX_ETHTOOL_H && defined SIOCETHTOOL
 static int GetEthtoolValue(const char *dev, int cmd, uint32_t *value)
@@ -384,6 +411,40 @@ static int GetIfaceOffloadingBSD(const char *ifname)
 }
 #endif
 
+#ifdef SIOCSIFCAP
+static int DisableIfaceOffloadingBSD(const char *ifname)
+{
+    int ret = 0;
+    int if_caps = GetIfaceCaps(ifname);
+    int set_caps = if_caps;
+    if (if_caps == -1) {
+        return -1;
+    }
+    SCLogDebug("if_caps %X", if_caps);
+
+    if (if_caps & IFCAP_RXCSUM) {
+        SCLogInfo("%s: disabling rxcsum offloading", ifname);
+        set_caps &= ~IFCAP_RXCSUM;
+    }
+
+#ifdef IFCAP_TOE
+    if (if_caps & (IFCAP_TSO|IFCAP_TOE|IFCAP_LRO)) {
+        SCLogInfo("%s: disabling tso|toe|lro offloading", ifname);
+        set_caps &= ~(IFCAP_TSO|IFCAP_LRO);
+    }
+#else
+    if (if_caps & (IFCAP_TSO|IFCAP_LRO)) {
+        SCLogInfo("%s: disabling tso|lro offloading", ifname);
+        set_caps &= ~(IFCAP_TSO|IFCAP_LRO);
+    }
+#endif
+    if (set_caps != if_caps) {
+        SetIfaceCaps(ifname, set_caps);
+    }
+    return ret;
+}
+#endif
+
 /**
  * \brief output offloading status of the link
  *
@@ -409,6 +470,16 @@ int GetIfaceOffloading(const char *dev, int csum, int other)
 #endif
 }
 
+int DisableIfaceOffloading(const char *dev, int csum, int other)
+{
+#if defined SIOCSIFCAP
+    return DisableIfaceOffloadingBSD(dev);
+#else
+    return 0;
+#endif
+
+}
+
 int GetIfaceRSSQueuesNum(const char *pcap_dev)
 {
 #if defined HAVE_LINUX_ETHTOOL_H && defined ETHTOOL_GRXRINGS
index 79018754b0c4f5ec86d88f49f9483cf3c03dee62..da3bd616911d6ab9a44aed3cf902467374178261 100644 (file)
@@ -34,3 +34,4 @@ int SetIfaceFlags(const char *ifname, int flags);
 #ifdef SIOCGIFCAP
 int GetIfaceCaps(const char *ifname);
 #endif
+int DisableIfaceOffloading(const char *dev, int csum, int other);