From 1891a290e007889e8437849b097604bb51305350 Mon Sep 17 00:00:00 2001 From: Sean Khan Date: Sun, 28 Apr 2024 13:10:58 -0400 Subject: [PATCH] nss-ecm: switch to using named sections in uci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The way ECM uci config is handled is pretty ugly due to it not specifying a named section for 'general'. Current: ``` ➤ uci show ecm ecm.global=ecm ecm.global.acceleration_engine='nss' ecm.@general[0]=general ecm.@general[0].enable_bridge_filtering='0' ecm.@general[0].disable_offloads='0' ecm.@general[0].disable_flow_control='0' ecm.@general[0].disable_interrupt_moderation='0' ecm.@general[0].disable_gro='0' ``` None of the options require the use of unnamed sections (like /etc/config/dhcp does when defining configs for multiple hosts) With this change the config would produce: ``` ecm.global=ecm ecm.global.acceleration_engine='nss' ecm.general=ecm ecm.general.enable_bridge_filtering='0' ecm.general.disable_offloads='0' ecm.general.disable_flow_control='0' ecm.general.disable_interrupt_moderation='0' ecm.general.disable_gro='0' ``` Which is a lot easier to read, and access programmatically. We can also merge `global` and `general` into a single section as it doesn't really make sense why we need global/general when it's technically "ALL" globally applied. For now, to ease users on the change, let's just stick to 2 sections. **PLEASE NOTE: For users building their own images, and storing their** **configs in 'files/etc/config/ecm' you will need to manually update the** **config before compiling.** For users using **sysupgrade** or installing without custom config at build time 'files/etc/config/ecm' should be OK. The following can be run manually on the config file 'ecm' ```sh conf=/etc/config/ecm uci -q show ecm.general || { echo "Converting 'ECM' config to new format." sed -i "s/config.*general.*/config ecm 'general'/g" "$conf" } ``` Signed-off-by: Sean Khan --- qca-nss-ecm/Makefile | 2 +- qca-nss-ecm/files/disable_offloads.sh | 19 +++++++------------ qca-nss-ecm/files/qca-nss-ecm.defaults | 21 ++++++--------------- qca-nss-ecm/files/qca-nss-ecm.init | 15 ++++++++------- qca-nss-ecm/files/qca-nss-ecm.uci | 2 +- 5 files changed, 23 insertions(+), 36 deletions(-) diff --git a/qca-nss-ecm/Makefile b/qca-nss-ecm/Makefile index 120f52b..3e50211 100644 --- a/qca-nss-ecm/Makefile +++ b/qca-nss-ecm/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=qca-nss-ecm -PKG_RELEASE:=4 +PKG_RELEASE:=5 PKG_SOURCE_URL:=https://git.codelinaro.org/clo/qsdk/oss/lklm/qca-nss-ecm.git PKG_SOURCE_PROTO:=git diff --git a/qca-nss-ecm/files/disable_offloads.sh b/qca-nss-ecm/files/disable_offloads.sh index 9f8a477..e58a1e7 100755 --- a/qca-nss-ecm/files/disable_offloads.sh +++ b/qca-nss-ecm/files/disable_offloads.sh @@ -1,5 +1,5 @@ #!/bin/sh -# shellcheck disable=3014 +# shellcheck disable=3014,3043,2086,1091,2154 # # Helper script which uses ethtool to disable (most) # interface offloads, if possible. @@ -172,19 +172,14 @@ disable_interrupt_moderation() { fi } -parse_opt() { - local cfg="$1" - - config_get_bool enable_bridge_filtering "$cfg" enable_bridge_filtering 0 - config_get_bool disable_offloads "$cfg" disable_offloads 0 - config_get_bool disable_flow_control "$cfg" disable_flow_control 0 - config_get_bool disable_interrupt_moderation "$cfg" disable_interrupt_moderation 0 - config_get_bool disable_gro "$cfg" disable_gro 0 -} - disable_offload() { config_load ecm - config_foreach parse_opt general + + config_get_bool enable_bridge_filtering ecm enable_bridge_filtering 0 + config_get_bool disable_offloads ecm disable_offloads 0 + config_get_bool disable_flow_control ecm disable_flow_control 0 + config_get_bool disable_interrupt_moderation ecm disable_interrupt_moderation 0 + config_get_bool disable_gro ecm disable_gro 0 [ -z $1 ] && interface=$(echo /sys/class/net/*) || interface=$* diff --git a/qca-nss-ecm/files/qca-nss-ecm.defaults b/qca-nss-ecm/files/qca-nss-ecm.defaults index 60f7406..40a5c4f 100644 --- a/qca-nss-ecm/files/qca-nss-ecm.defaults +++ b/qca-nss-ecm/files/qca-nss-ecm.defaults @@ -1,19 +1,10 @@ #!/bin/sh -# -# Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# + +# convert old ecm config to new format +uci -q show ecm.general || { + echo "Converting 'ECM' config to new format." + sed -i "s/config.*general.*/config ecm 'general'/g" /etc/config/ecm +} uci -q batch << EOF delete firewall.qcanssecm diff --git a/qca-nss-ecm/files/qca-nss-ecm.init b/qca-nss-ecm/files/qca-nss-ecm.init index e57c573..c1598a0 100644 --- a/qca-nss-ecm/files/qca-nss-ecm.init +++ b/qca-nss-ecm/files/qca-nss-ecm.init @@ -1,4 +1,5 @@ #!/bin/sh /etc/rc.common +# shellcheck disable=3043,3060,2086,2034 # # Copyright (c) 2014, 2019-2020 The Linux Foundation. All rights reserved. # @@ -22,9 +23,11 @@ START=26 sysctl_update() { local name value file + name=${1//\//\\/} value=${2//\//\\/} file=${3:-/etc/sysctl.d/qca-nss-ecm.conf} + sed -i -e '/^#\?\(\s*'"${name}"'\s*=\s*\).*/{s//\1'"${value}"'/;:a;n;ba;q}' \ -e '$a'"${name}"'='"${value}" "${file}" sysctl -w ${name}=${value} @@ -32,8 +35,10 @@ sysctl_update() { get_front_end_mode() { config_load "ecm" + config_get front_end global acceleration_engine "auto" + # shellcheck disable=2154 case $front_end in auto) echo '0' @@ -75,6 +80,7 @@ load_ecm() { echo 1 > /sys/kernel/debug/ecm/ecm_classifier_default/accel_delay_pkts } + # shellcheck disable=1091 . /lib/netifd/offload/disable_offloads.sh disable_offload @@ -119,12 +125,6 @@ unload_ecm() { fi } -parse_opt() { - local cfg="$1" - - config_get_bool enable_bridge_filtering "$cfg" enable_bridge_filtering 0 -} - start() { load_ecm @@ -133,8 +133,9 @@ start() { # If bridge filtering is enabled, apply and persist the sysctl flags config_load ecm - config_foreach parse_opt general + config_get enable_bridge_filtering general enable_bridge_filtering "0" + # shellcheck disable=2154 if [ "$enable_bridge_filtering" -eq 1 ]; then echo "Bridge filtering is enabled in the ECM config, this will cause issues with NAT loopback!" enable_bridge_filtering diff --git a/qca-nss-ecm/files/qca-nss-ecm.uci b/qca-nss-ecm/files/qca-nss-ecm.uci index 2e5b91e..ebfb2cb 100644 --- a/qca-nss-ecm/files/qca-nss-ecm.uci +++ b/qca-nss-ecm/files/qca-nss-ecm.uci @@ -1,7 +1,7 @@ config ecm 'global' option acceleration_engine 'auto' -config general +config ecm 'general' option enable_bridge_filtering '0' option disable_offloads '0' option disable_flow_control '0'