]> git.ipfire.org Git - people/ms/network.git/commitdiff
Move offloading code into an own file
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Sep 2018 12:50:12 +0000 (14:50 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Sep 2018 12:50:12 +0000 (14:50 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/functions/functions.constants
src/functions/functions.device
src/functions/functions.offloading [new file with mode: 0644]
src/hooks/ports/bonding
src/hooks/ports/ethernet

index 612c0bd5fb1a73a53daa246aad1e19652c0ab36f..05877438a8984c227a4d839b23535a15dfe45215 100644 (file)
@@ -167,6 +167,7 @@ dist_network_DATA = \
        src/functions/functions.logging \
        src/functions/functions.macros \
        src/functions/functions.modem \
+       src/functions/functions.offloading \
        src/functions/functions.phy \
        src/functions/functions.ports \
        src/functions/functions.ppp \
index 63c5cad29abfca0eda18f0be98fda8da269f655a..0d6cdd2fba47fa4db933b054496ed95cd3d905f3 100644 (file)
@@ -94,30 +94,6 @@ DISCOVER_NOT_SUPPORTED=2
 # Default MTU
 DEFAULT_MTU=1500
 
-# A list of supported device offloading mechanisms
-# that are being mapped to the ethtool command
-declare -A DEVICE_SUPPORTED_OFFLOADINGS=(
-       [generic-receive-offload]="gro"
-       [generic-segmentation-offload]="gso"
-       [large-receive-offload]="lro"
-       [rx-checksumming]="rx"
-       [scatter-gather]="sg"
-       [tcp-segmentation-offload]="tso"
-       [tx-checksumming]="tx"
-       [udp-fragmentation-offload]="ufo"
-)
-
-# These offloadings will automatically be enabled (if supported)
-DEVICE_AUTO_OFFLOADINGS=(
-       generic-receive-offload
-       generic-segmentation-offload
-       rx-checksumming
-       scatter-gather
-       tcp-segmentation-offload
-       tx-checksumming
-       udp-fragmentation-offload
-)
-
 # The user is able to create zones that begin
 # with these names followed by a number.
 ZONE_LOCAL="net"
index e8fdc826e9e9db27547aefd427ab1a9a074e246c..8384273d057d775ec9cbdda30d867bf1ce688eab 100644 (file)
@@ -974,47 +974,6 @@ device_get_link_string() {
        print "${s}"
 }
 
-device_auto_offloading() {
-       local device="${1}"
-       assert isset device
-
-       # Enable all offloadings that we consider a good default
-       local offloading
-       for offloading in ${DEVICE_AUTO_OFFLOADINGS[@]}; do
-               device_set_offloading "${device}" "${offloading}" "on"
-       done
-
-       return ${EXIT_OK}
-}
-
-device_set_offloading() {
-       local device="${1}"
-       assert isset device
-
-       local offloading="${2}"
-       assert isoneof offloading ${!DEVICE_SUPPORTED_OFFLOADINGS[@]}
-
-       local value="${3}"
-       assert isoneof value on off
-
-       # Translate to ethool option
-       local mode="${DEVICE_SUPPORTED_OFFLOADINGS[${offloading}]}"
-       if ! isset mode; then
-               error "Unsupported offloading mode: ${offloading}"
-               return ${EXIT_ERROR}
-       fi
-
-       # Run ethtool
-       if ! cmd_quiet ethtool --offload "${device}" "${mode}" "${value}"; then
-               log DEBUG "Could not set ${offloading} on ${device} to ${value}"
-               return ${EXIT_ERROR}
-       fi
-
-       log DEBUG "Set ${offloading} on ${device} to ${value}"
-
-       return ${EXIT_OK}
-}
-
 device_auto_configure_smp_affinity() {
        assert [ $# -eq 1 ]
 
diff --git a/src/functions/functions.offloading b/src/functions/functions.offloading
new file mode 100644 (file)
index 0000000..d59b83a
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2018 IPFire Network Development Team                          #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+# A list of supported device offloading mechanisms
+# that are being mapped to the ethtool command
+declare -A SUPPORTED_OFFLOADINGS=(
+       [generic-receive-offload]="gro"
+       [generic-segmentation-offload]="gso"
+       [large-receive-offload]="lro"
+       [rx-checksumming]="rx"
+       [scatter-gather]="sg"
+       [tcp-segmentation-offload]="tso"
+       [tx-checksumming]="tx"
+       [udp-fragmentation-offload]="ufo"
+)
+
+# These offloadings will automatically be enabled (if supported)
+AUTO_OFFLOADINGS=(
+       generic-receive-offload
+       generic-segmentation-offload
+       rx-checksumming
+       scatter-gather
+       tcp-segmentation-offload
+       tx-checksumming
+       udp-fragmentation-offload
+)
+
+offloading_auto() {
+       local device="${1}"
+       assert isset device
+
+       # Enable all offloadings that we consider a good default
+       local offloading
+       for offloading in ${AUTO_OFFLOADINGS[@]}; do
+               offloading_set "${device}" "${offloading}" "on"
+       done
+
+       return ${EXIT_OK}
+}
+
+offloading_set() {
+       local device="${1}"
+       assert isset device
+
+       local offloading="${2}"
+       assert isoneof offloading ${!SUPPORTED_OFFLOADINGS[@]}
+
+       local value="${3}"
+       assert isoneof value on off
+
+       # Translate to ethool option
+       local mode="${SUPPORTED_OFFLOADINGS[${offloading}]}"
+       if ! isset mode; then
+               error "Unsupported offloading mode: ${offloading}"
+               return ${EXIT_ERROR}
+       fi
+
+       # Run ethtool
+       if ! cmd_quiet ethtool --offload "${device}" "${mode}" "${value}"; then
+               log DEBUG "Could not set ${offloading} on ${device} to ${value}"
+               return ${EXIT_ERROR}
+       fi
+
+       log DEBUG "Set ${offloading} on ${device} to ${value}"
+
+       return ${EXIT_OK}
+}
index d8bc58391db90d7eeb1cf1f83c711781bb1614d9..e93c6117ef00fe54cc9764d5cc18c247285b84a9 100644 (file)
@@ -175,8 +175,8 @@ hook_up() {
 
        port_settings_read "${port}" ${HOOK_SETTINGS}
 
-       # Enable hardware offloading
-       device_auto_offloading "${port}"
+       # Auto-enable hardware offloading
+       offloading_auto "${port}"
 
        # Execute the default action
        hook_default_up "${port}"
index c7750f9d122d57bf29106a54e8af789af0aeea21..823090d78a2a953bc1ff853f7732f2de5e304ff4 100644 (file)
@@ -117,8 +117,8 @@ hook_up() {
                device_advertise_link_speeds "${port}" ${ADVERTISED_LINK_SPEEDS}
        fi
 
-       # Enable hardware offloading
-       device_auto_offloading "${port}"
+       # Auto-enable hardware offloading
+       offloading_auto "${port}"
 
        # Bring up the device
        device_set_up "${port}"