]> git.ipfire.org Git - people/ms/network.git/blame - src/functions/functions.offloading
hostapd: Dump config file in debug mode
[people/ms/network.git] / src / functions / functions.offloading
CommitLineData
3608f641
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2018 IPFire Network Development Team #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
22# A list of supported device offloading mechanisms
23# that are being mapped to the ethtool command
24declare -A SUPPORTED_OFFLOADINGS=(
25 [generic-receive-offload]="gro"
26 [generic-segmentation-offload]="gso"
27 [large-receive-offload]="lro"
28 [rx-checksumming]="rx"
29 [scatter-gather]="sg"
30 [tcp-segmentation-offload]="tso"
31 [tx-checksumming]="tx"
32 [udp-fragmentation-offload]="ufo"
33)
34
35# These offloadings will automatically be enabled (if supported)
36AUTO_OFFLOADINGS=(
37 generic-receive-offload
38 generic-segmentation-offload
39 rx-checksumming
40 scatter-gather
41 tcp-segmentation-offload
42 tx-checksumming
43 udp-fragmentation-offload
44)
45
46offloading_auto() {
47 local device="${1}"
48 assert isset device
49
50 # Enable all offloadings that we consider a good default
51 local offloading
52 for offloading in ${AUTO_OFFLOADINGS[@]}; do
53 offloading_set "${device}" "${offloading}" "on"
54 done
55
56 return ${EXIT_OK}
57}
58
59offloading_set() {
60 local device="${1}"
61 assert isset device
62
63 local offloading="${2}"
64 assert isoneof offloading ${!SUPPORTED_OFFLOADINGS[@]}
65
66 local value="${3}"
67 assert isoneof value on off
68
69 # Translate to ethool option
70 local mode="${SUPPORTED_OFFLOADINGS[${offloading}]}"
71 if ! isset mode; then
72 error "Unsupported offloading mode: ${offloading}"
73 return ${EXIT_ERROR}
74 fi
75
76 # Run ethtool
77 if ! cmd_quiet ethtool --offload "${device}" "${mode}" "${value}"; then
78 log DEBUG "Could not set ${offloading} on ${device} to ${value}"
79 return ${EXIT_ERROR}
80 fi
81
82 log DEBUG "Set ${offloading} on ${device} to ${value}"
83
84 return ${EXIT_OK}
85}
085a89dc
MT
86
87offloading_disable_all() {
88 local device="${1}"
89 assert isset device
90
91 local offloading
92 for offloading in ${!SUPPORTED_OFFLOADINGS[@]}; do
93 offloading_set "${device}" "${offloading}" "off"
94 done
95
96 return ${EXIT_OK}
97}