From 1bed8dab31d3b333416c7c7a361318def24f7d35 Mon Sep 17 00:00:00 2001 From: Sean Khan Date: Tue, 8 Apr 2025 12:53:42 -0400 Subject: [PATCH] nss-ecm: Improve ECM module configuration handling This commit fixes two issues with how ECM module options are configured: 1. `/etc/modules.conf` was modified on every ECM start/restart, even when no changes were needed. 2. If any other ECM parameters were set in `/etc/modules.conf` it would overwrite them as the entire line was replaced. The solution extracts configuration logic into a dedicated function that only modifies what's necessary, properly handling all cases (updating existing parameters, appending to existing options, or creating new options). Signed-off-by: Sean Khan --- qca-nss-ecm/files/qca-nss-ecm.init | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/qca-nss-ecm/files/qca-nss-ecm.init b/qca-nss-ecm/files/qca-nss-ecm.init index b27ff2c..8bc7977 100644 --- a/qca-nss-ecm/files/qca-nss-ecm.init +++ b/qca-nss-ecm/files/qca-nss-ecm.init @@ -92,13 +92,30 @@ enable_bridge_filtering() { fi } +set_front_end() { + local get_front_end_mode=${1:-0} + local module_conf=/etc/modules.conf + [ ! -r "$module_conf" ] && touch "$module_conf" + # If "options ecm" exists, modify or append front_end_selection + if grep -q "^options ecm" "$module_conf"; then + if grep -q "front_end_selection=" "$module_conf"; then + sed -i -E "s/(options ecm.*)front_end_selection=[0-9]+/\1front_end_selection=$get_front_end_mode/" "$module_conf" + else + # Append front_end_selection if missing + sed -i -E "s/^(options ecm.*)/\1 front_end_selection=$get_front_end_mode/" "$module_conf" + fi + else + # Add new "options ecm" line + echo "options ecm front_end_selection=$get_front_end_mode" >> "$module_conf" + fi +} + load_ecm() { [ -d /sys/module/ecm ] || { local get_front_end_mode get_front_end_mode="$(get_front_end_mode)" modinfo ecm | awk '/depends/{gsub(",","\n",$NF);print $NF}' | xargs -r -n 1 modprobe - touch /etc/modules.conf - grep -q "options ecm" /etc/modules.conf || echo "options ecm front_end_selection=$get_front_end_mode" >> /etc/modules.conf + set_front_end $get_front_end_mode modprobe ecm echo 1 > /sys/kernel/debug/ecm/ecm_classifier_default/accel_delay_pkts }