diff --git a/src/etc/one-context.d/loc-10-network.d/netcfg-bsd b/src/etc/one-context.d/loc-10-network.d/netcfg-bsd index 01deafb..32ed772 100644 --- a/src/etc/one-context.d/loc-10-network.d/netcfg-bsd +++ b/src/etc/one-context.d/loc-10-network.d/netcfg-bsd @@ -117,8 +117,45 @@ gen_iface_conf() ### + routing_conf="/etc/rc.conf.d/routing" + if [ -n "${gateway}" ]; then - echo "defaultrouter=\"${gateway}\"" >> /etc/rc.conf.d/routing + echo "defaultrouter=\"${gateway}\"" >> $routing_conf + fi + + # Add static routes + if [ -n "${ROUTES}" ]; then + + # TODO: Validate possible comma with spaces + IFS=',' read -r -a routes <<< "$ROUTES" + + route_names="" + routes_info=() + + for index in "${!routes[@]}" + do + route_name="lan${index}" + route_names="${route_names}${route_name} " + + IFS=' via ' read -r -a route_args <<< "${routes[index]}" + + subnet=${route_args[0]} + static_gw=${route_args[1]} + out_iface=${route_args[2]} + + route_info="${route_name}=\"-net${subnet} ${static_gw}\"" + [ -n "${out_iface}" ] && route_info=" ${route_info} -iface ${dev}" + + routes_info+=(route_info) + done + + echo -e "${route_names}\n" >> $routing_conf + + for route_info in "${routes_info[@]}" + do + echo -e "${route_info}\n" >> $routing_conf + done + fi } diff --git a/src/etc/one-context.d/loc-10-network.d/netcfg-interfaces b/src/etc/one-context.d/loc-10-network.d/netcfg-interfaces index 90667f5..98027e4 100644 --- a/src/etc/one-context.d/loc-10-network.d/netcfg-interfaces +++ b/src/etc/one-context.d/loc-10-network.d/netcfg-interfaces @@ -158,6 +158,21 @@ EOT fi fi + # Add static routes + if [ -n "${ROUTES}" ]; then + + # TODO: Validate possible comma with spaces + IFS=',' read -r -a routes <<< "$ROUTES" + + for route in "${routes[@]}" + do + if [[ "$route" == *"${dev}"* ]] || [[ "$dev" == "eth0" && "$route" != *"dev"* ]]; then + echo " up ip route add $route" + fi + done + + fi + if [ -n "$mtu" ]; then echo " mtu ${mtu}" fi diff --git a/src/etc/one-context.d/loc-10-network.d/netcfg-netplan b/src/etc/one-context.d/loc-10-network.d/netcfg-netplan index 15b924a..bfc3ad1 100644 --- a/src/etc/one-context.d/loc-10-network.d/netcfg-netplan +++ b/src/etc/one-context.d/loc-10-network.d/netcfg-netplan @@ -135,6 +135,8 @@ gen_routes() via: ${gateway} EOT + + # Force default Linux IPv4 metric (man 8 route) to override # automatic metrics calculation done by NetworkManager and unify # behavior among different renderers. @@ -145,6 +147,25 @@ EOT fi fi + # Add static routes + if [ -n "${ROUTES}" ]; then + + # TODO: Validate possible comma with spaces + IFS=',' read -r -a routes <<< "$ROUTES" + + for route in "${routes[@]}" + do + if [[ "$route" == *"${dev}"* ]] || [[ "$dev" == "eth0" && "$route" != *"dev"* ]]; then + IFS=' via ' read -r -a route_args <<< "$route" + cat <> "${config_path}/route-${dev}" + # The route with no target iface will be set to eth0 + elif [[ "$dev" == "eth0" && "$route" != *"dev"* ]]; then + echo "$route" >> "${config_path}/route-eth0" + fi + done + + fi + if [ -n "${mtu}" ]; then echo "MTU=${mtu}" fi