static_routes
Daniel Clavijo Coca 2 years ago
parent f1bc2c4fc0
commit 1c60bf0292
No known key found for this signature in database
GPG Key ID: 073626228D14586A

@ -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
}

@ -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

@ -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 <<EOT
- to: "${route_args[0]}"
via: "${route_args[1]}"
EOT
fi
done
fi
if [ -n "${ip6_gateway}" ] && { [ -z "${ip6_method}" ] || [ "${ip6_method}" = 'static' ]; }; then
cat <<EOT
- to: "::/0"

@ -120,6 +120,29 @@ EOT
fi
echo ""
# Add static routes
if [ -n "${ROUTES}" ]; then
cat <<EOT
[Route]
EOT
# TODO: Validate possible comma with spaces
IFS=',' read -r -a routes <<< "$ROUTES"
for route in "${routes[@]}"
do
# The route is targeted to the $dev iface
if [[ "$route" == *"${dev}"* ]] || [[ "$dev" == "eth0" && "$route" != *"dev"* ]]; then
IFS=' via ' read -r -a route_args <<< "$route"
echo "Gateway=${route_args[1]}"
echo "Destination=${route_args[0]}"
echo "GatewayOnlink=yes"
fi
done
echo ""
fi
}
gen_dhcp_conf()

@ -119,6 +119,23 @@ gen_iface_conf()
nmcli con mod "${dev}" ipv4.gateway ""
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
IFS=' via ' read -r -a route_args <<< "$route"
if [[ "$route" == *"${dev}"* ]] || [[ "$dev" == "eth0" && "$route" != *"dev"* ]]; then
nmcli con mod "${dev}" ipv4.routes "${route_args[0]} ${route_args[1]}"
fi
done
fi
if [ -n "$metric" ]; then
nmcli con mod "${dev}" ipv4.route-metric "${metric}"
else

@ -124,6 +124,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
# The route is targeted to the $dev iface
if [[ "$route" == *"${dev}"* ]]; then
echo "$route" >> "${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

Loading…
Cancel
Save