Skip to content

Commit 7cbaeb3

Browse files
committed
feat: Support for static routes
1 parent abe0ac9 commit 7cbaeb3

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎system/cuos/init.sh‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,23 @@ configure_network() {
197197
[ -n "$NTP" ] && echo " ntp-servers $NTP"
198198
echo
199199
fi
200+
# Static routes
201+
if echo "$config" | jq -e 'has("routes")' >/dev/null 2>&1; then
202+
# Emit one line per route as: up ip route add <dest> [via <gw>] dev <iface> [metric <m>] [table <t>]
203+
echo "$config" | jq -r '
204+
.routes // empty |
205+
(if type=="array" then .[] else . end) |
206+
(.destination // .to // .network) as $d |
207+
(.gateway // .via) as $g |
208+
[$d, ($g // "")] | @tsv' |
209+
while IFS=$'\t' read -r RDEST RGW; do
210+
if [ -z "$RDEST" ] || [ "$RDEST" = "null" ]; then
211+
continue
212+
fi
213+
echo " up ip route add $RDEST via $RGW dev $IFACE"
214+
echo " down ip route del $RDEST via $RGW dev $IFACE"
215+
done
216+
fi
200217
elif [ "$i" -eq 0 ]; then
201218
# No config for the first interface, set to DHCP with metric
202219
echo "auto $IFACE"

0 commit comments

Comments
 (0)