From 135aa3eece1561eab68f57f39b99da72ba34099c Mon Sep 17 00:00:00 2001 From: Daniel Clavijo Coca Date: Thu, 23 Mar 2023 15:56:36 -0600 Subject: [PATCH] F OpenNebula/one-context-linux#281: ONEGATE Proxy static automatic static routing --- .../one-context.d/loc-10-network.d/functions | 5 ++++ .../one-context.d/loc-10-network.d/netcfg-bsd | 23 ++++++++++---- .../loc-10-network.d/netcfg-interfaces | 6 ++++ .../loc-10-network.d/netcfg-netplan | 30 ++++++++++++------- .../loc-10-network.d/netcfg-networkd | 12 +++++++- .../one-context.d/loc-10-network.d/netcfg-nm | 7 +++++ .../loc-10-network.d/netcfg-scripts | 7 +++++ 7 files changed, 73 insertions(+), 17 deletions(-) diff --git a/src/etc/one-context.d/loc-10-network.d/functions b/src/etc/one-context.d/loc-10-network.d/functions index 014caec..561c65e 100644 --- a/src/etc/one-context.d/loc-10-network.d/functions +++ b/src/etc/one-context.d/loc-10-network.d/functions @@ -597,4 +597,9 @@ get_route_info() { fi echo "$dst $gw $iface" +} + +# 0 if https://en.wikipedia.org/wiki/Link-local_address +is_link_local() { + [[ $1 == "169.254."* ]] } \ No newline at end of file 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 b720f0a..60103ea 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 @@ -124,15 +124,15 @@ gen_iface_conf() fi # Add static routes - if [ -n "${ROUTES}" ]; then - # static_routes="lan mumoffice foo" - # route_lan="-net 192.168.1.0/24 192.168.1.254" - # route_mumoffice="-net 10.0.0.0/8 10.30.110.5" - # route_foo="-host 169.254.1.1 -iface lo0" + # static_routes="lan mumoffice foo" + # route_lan="-net 192.168.1.0/24 192.168.1.254" + # route_mumoffice="-net 10.0.0.0/8 10.30.110.5" + # route_foo="-host 169.254.1.1 -iface lo0" + route_names="" + if [ -n "${ROUTES}" ]; then IFS=',' read -r -a routes <<< "$ROUTES" - route_names="" routes_conf=() for index in "${!routes[@]}" @@ -160,6 +160,17 @@ gen_iface_conf() done fi + + # Add ONEGATE Proxy static route + if is_link_local "${ONEGATE_ENDPOINT}"; then + route_name="onegateproxy" + + sed -i "s/${route_names}/${route_names} ${route_name}/g" "$routes_conf_path" + # ip route replace 169.254.16.9/32 via eth0 + route_conf="route_${route_name}=\"-host ${ONEGATE_ENDPOINT} -iface ${dev}\"" + + echo -e "$route_conf\n" >> $routes_conf_path + fi } gen_dhcp_conf() 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 833f858..a5c1536 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 @@ -173,6 +173,12 @@ EOT fi + # Add ONEGATE Proxy static route + if is_link_local "${ONEGATE_ENDPOINT}"; then + # ip route replace 169.254.16.9/32 via eth0 + echo " up ip route replace ${ONEGATE_ENDPOINT}/32 via ${dev}" + 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 398c310..5ebb447 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 @@ -148,29 +148,39 @@ EOT fi # Add static routes - if [ -n "${ROUTES}" ]; then + if [ -n "${ROUTES}" ]; then - IFS=',' read -r -a routes <<< "$ROUTES" + IFS=',' read -r -a routes <<< "$ROUTES" - for route in "${routes[@]}" - do - # Apply every route except the ones specified for other devices - if [[ "$route" == *"${dev}"* ]] || [[ "$dev" == "eth0" && "$route" != *"dev"* ]]; then + for route in "${routes[@]}" + do + # Apply every route except the ones specified for other devices + if [[ "$route" == *"${dev}"* ]] || [[ "$dev" == "eth0" && "$route" != *"dev"* ]]; then - IFS=' ' read -r -a route_info <<< "$(get_route_info "$route")" + IFS=' ' read -r -a route_info <<< "$(get_route_info "$route")" - dst=${route_info[0]} + dst=${route_info[0]} gw=${route_info[1]} cat <> "${config_path}/route-${dev}" + fi + if [ -n "${mtu}" ]; then echo "MTU=${mtu}" fi