From 2b2984dae9d418d869952dde01642e56bf617f1e Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 21 Jun 2016 07:59:51 +0200 Subject: [PATCH] offloading: implement restoring settings for BSD --- src/runmode-netmap.c | 14 +++++------ src/util-ioctl.c | 60 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/runmode-netmap.c b/src/runmode-netmap.c index 88d2de3f60..3ea6c7a55c 100644 --- a/src/runmode-netmap.c +++ b/src/runmode-netmap.c @@ -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; } diff --git a/src/util-ioctl.c b/src/util-ioctl.c index ff6646adc5..6a84816055 100644 --- a/src/util-ioctl.c +++ b/src/util-ioctl.c @@ -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 } }