]> git.99rst.org Git - openwrt-packages.git/commitdiff
strongswan: move strongswan ignore_routing_tables check into subfunction
authorFlorian Eckert <redacted>
Thu, 9 Jul 2026 12:51:24 +0000 (14:51 +0200)
committerPhilip Prindeville <redacted>
Thu, 16 Jul 2026 20:27:36 +0000 (14:27 -0600)
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 <redacted>
net/strongswan/files/etc/uci-defaults/strongswan
net/strongswan/files/swanctl.init

index e9d3121c195526c862123a36ccda8f4d6591b809..b2e2d6f9ac1370d721d4f1b296075d034e3137fb 100644 (file)
@@ -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
index a041b5c635e8d0971bbb03aa3a324fd00d074980..2a927d678f46f9a3e166be0cd9a5610f7da43587 100644 (file)
@@ -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"
git clone https://git.99rst.org/PROJECT