]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
offloading: implement restoring settings for BSD
authorVictor Julien <victor@inliniac.net>
Tue, 21 Jun 2016 05:59:51 +0000 (07:59 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 22 Sep 2016 11:36:27 +0000 (13:36 +0200)
src/runmode-netmap.c
src/util-ioctl.c

index 88d2de3f60fafed79e49523820a478a62122c90a..3ea6c7a55cd7747071183e45a66a2a1fb80b5ec1 100644 (file)
@@ -207,6 +207,13 @@ finalize:
         ns->threads = 1;
     }
 
+    /* netmap needs all offloading to be disabled */
+    if (LiveGetOffload() == 0) {
+        (void)GetIfaceOffloading(ns->iface, 1, 1);
+    } else {
+        DisableIfaceOffloading(LiveGetDevice(ns->iface), 1, 1);
+    }
+
     return 0;
 }
 
@@ -269,13 +276,6 @@ static void *ParseNetmapConfig(const char *iface_name)
     SCLogPerf("Using %d threads for interface %s", aconf->in.threads,
             aconf->iface_name);
 
-    /* netmap needs all offloading to be disabled */
-    if (LiveGetOffload() == 0) {
-        (void)GetIfaceOffloading(aconf->in.iface, 1, 1);
-    } else {
-        DisableIfaceOffloading(LiveGetDevice(aconf->in.iface), 1, 1);
-    }
-
     return aconf;
 }
 
index ff6646adc5181c9ac954f6cdd1ec47e253c4b8da..6a84816055bff3c160a8bd00a45a8d52cc37a707 100644 (file)
@@ -564,9 +564,14 @@ static int GetIfaceOffloadingBSD(const char *ifname)
 #endif
 
 #ifdef SIOCSIFCAP
-static int DisableIfaceOffloadingBSD(const char *ifname)
+static int DisableIfaceOffloadingBSD(LiveDevice *ldev)
 {
     int ret = 0;
+
+    if (ldev == NULL)
+        return -1;
+
+    const char *ifname = ldev->dev;
     int if_caps = GetIfaceCaps(ifname);
     int set_caps = if_caps;
     if (if_caps == -1) {
@@ -590,6 +595,57 @@ static int DisableIfaceOffloadingBSD(const char *ifname)
         set_caps &= ~(IFCAP_TSO|IFCAP_LRO);
     }
 #endif
+    if (set_caps != if_caps) {
+        if (if_caps & IFCAP_RXCSUM)
+            ldev->offload_orig |= OFFLOAD_FLAG_RXCSUM;
+        if (if_caps & IFCAP_TSO)
+            ldev->offload_orig |= OFFLOAD_FLAG_TSO;
+#ifdef IFCAP_TOE
+        if (if_caps & IFCAP_TOE)
+            ldev->offload_orig |= OFFLOAD_FLAG_TOE;
+#endif
+        if (if_caps & IFCAP_LRO)
+            ldev->offload_orig |= OFFLOAD_FLAG_LRO;
+
+        SetIfaceCaps(ifname, set_caps);
+    }
+    return ret;
+}
+
+static int RestoreIfaceOffloadingBSD(LiveDevice *ldev)
+{
+    int ret = 0;
+
+    if (ldev == NULL)
+        return -1;
+
+    const char *ifname = ldev->dev;
+    int if_caps = GetIfaceCaps(ifname);
+    int set_caps = if_caps;
+    if (if_caps == -1) {
+        return -1;
+    }
+    SCLogDebug("if_caps %X", if_caps);
+
+    if (ldev->offload_orig & OFFLOAD_FLAG_RXCSUM) {
+        SCLogInfo("%s: restoring rxcsum offloading", ifname);
+        set_caps |= IFCAP_RXCSUM;
+    }
+    if (ldev->offload_orig & OFFLOAD_FLAG_TSO) {
+        SCLogInfo("%s: restoring tso offloading", ifname);
+        set_caps |= IFCAP_TSO;
+    }
+#ifdef IFCAP_TOE
+    if (ldev->offload_orig & OFFLOAD_FLAG_TOE) {
+        SCLogInfo("%s: restoring toe offloading", ifname);
+        set_caps |= IFCAP_TOE;
+    }
+#endif
+    if (ldev->offload_orig & OFFLOAD_FLAG_LRO) {
+        SCLogInfo("%s: restoring lro offloading", ifname);
+        set_caps |= IFCAP_LRO;
+    }
+
     if (set_caps != if_caps) {
         SetIfaceCaps(ifname, set_caps);
     }
@@ -639,6 +695,8 @@ void RestoreIfaceOffloading(LiveDevice *dev)
     if (dev->offload_orig != 0) {
 #if defined HAVE_LINUX_ETHTOOL_H && defined SIOCETHTOOL
         RestoreIfaceOffloadingLinux(dev);
+#elif defined SIOCSIFCAP
+        RestoreIfaceOffloadingBSD(dev);
 #endif
     }
 }