From: Florian Eckert Date: Thu, 9 Jul 2026 12:51:24 +0000 (+0200) Subject: strongswan: move strongswan ignore_routing_tables check into subfunction X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=f744090ad9438486ff8b2251a3bde76ae49d822b;p=openwrt-packages.git strongswan: move strongswan ignore_routing_tables check into subfunction This makes the generation process clearer and more extensible. While we're at it, the option 'ignore_routing_tables' is changed to a list of elements. For the migration, the '/etc/uci-defaults/strongswan' migration script is be extended with the new function 'migrate_ignore_routing_tables', which handles the migration from an 'option' element to a 'list' elements. Signed-off-by: Florian Eckert --- diff --git a/net/strongswan/files/etc/uci-defaults/strongswan b/net/strongswan/files/etc/uci-defaults/strongswan index e9d3121c1..b2e2d6f9a 100644 --- a/net/strongswan/files/etc/uci-defaults/strongswan +++ b/net/strongswan/files/etc/uci-defaults/strongswan @@ -10,8 +10,25 @@ migrate_ipsec() { uci -q commit ipsec } +migrate_ignore_routing_tables() { + local tables table count + + # Check whether we still have the old config option ( not a 'list') + count="$(grep -c -E "^[[:space:]]*option ignore_routing_tables" /etc/config/ipsec)" + [ "$count" = "0" ] && return + + tables="$(uci -q get "ipsec.globals.ignore_routing_tables")" + uci -q delete "ipsec.globals.ignore_routing_tables" + for table in $tables; do + uci add_list "ipsec.globals.ignore_routing_tables=${table}" + done + + uci commit ipsec +} + main() { migrate_ipsec + migrate_ignore_routing_tables } main diff --git a/net/strongswan/files/swanctl.init b/net/strongswan/files/swanctl.init index a041b5c63..2a927d678 100644 --- a/net/strongswan/files/swanctl.init +++ b/net/strongswan/files/swanctl.init @@ -652,6 +652,26 @@ config_remote() { swanctl_xappend0 "" } +config_charon_ignore_routing_tables() { + local conf="$1" + + local routing_table_list routing_table ignore_routing_tables + + config_list_foreach "$conf" ignore_routing_tables append_var routing_table_list + for routing_table in $routing_table_list; do + local routing_table_id + if [ "$routing_table" -ge 0 ] 2>/dev/null; then + routing_table_id=$routing_table + else + routing_table_id=$(sed -n '/[ \t]*[0-9]\+[ \t]\+'$routing_table'[ \t]*$/s/[ \t]*\([0-9]\+\).*/\1/p' /etc/iproute2/rt_tables) + fi + + [ -n "$routing_table_id" ] && append ignore_routing_tables "$routing_table_id" + done + + [ -n "$ignore_routing_tables" ] && swan_xappend1 "ignore_routing_tables = $ignore_routing_tables" +} + config_charon_install_routes() { local conf="$1" @@ -666,26 +686,13 @@ config_charon_install_routes() { config_strongswan_generate() { local conf="$1" - local debug routing_tables_ignored device_list + local debug device_list - local routing_table - local routing_table_id local interface local interface_list config_get debug "$conf" debug 0 - # prepare extra charon config option ignore_routing_tables - for routing_table in $(config_get "$conf" "ignore_routing_tables"); do - if [ "$routing_table" -ge 0 ] 2>/dev/null; then - routing_table_id=$routing_table - else - routing_table_id=$(sed -n '/[ \t]*[0-9]\+[ \t]\+'$routing_table'[ \t]*$/s/[ \t]*\([0-9]\+\).*/\1/p' /etc/iproute2/rt_tables) - fi - - [ -n "$routing_table_id" ] && append routing_tables_ignored "$routing_table_id" - done - config_list_foreach "$conf" interface append_var interface_list if [ -z "$interface_list" ]; then @@ -700,7 +707,7 @@ config_strongswan_generate() { swan_xappend0 "charon {" config_charon_install_routes "$conf" - [ -n "$routing_tables_ignored" ] && swan_xappend1 "ignore_routing_tables = $routing_tables_ignored" + config_charon_ignore_routing_tables "$conf" [ -n "$device_list" ] && swan_xappend1 "interfaces_use = $device_list" swan_xappend1 "start-scripts {" swan_xappend2 "load-all = /usr/sbin/swanctl --load-all --noprompt"