F OpenNebula/one-context-linux#281: ONEGATE Proxy static automatic static routing

static_routes
Daniel Clavijo Coca 2 years ago
parent 693844189a
commit 135aa3eece
No known key found for this signature in database
GPG Key ID: 073626228D14586A

@ -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."* ]]
}

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

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

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

@ -140,12 +140,22 @@ EOT
echo "Gateway=$gw"
echo "Destination=$dst"
echo "GatewayOnlink=yes"
fi
done
echo ""
fi
# Add ONEGATE Proxy static route
if is_link_local "${ONEGATE_ENDPOINT}"; then
cat <<EOT
[Route]
EOT
# ip route replace 169.254.16.9/32 via eth0
echo " up ip route replace ${ONEGATE_ENDPOINT}/32 via ${dev}"
echo "Destination=${ONEGATE_ENDPOINT}"
echo "Scope=link"
fi
}
gen_dhcp_conf()

@ -139,6 +139,13 @@ gen_iface_conf()
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}"
nmcli con mod "$dev" ipv4.routes "$dst" type=local
fi
if [ -n "$metric" ]; then
nmcli con mod "${dev}" ipv4.route-metric "${metric}"
else

@ -142,6 +142,13 @@ EOT
fi
# Add ONEGATE Proxy static route
if is_link_local "${ONEGATE_ENDPOINT}"; then
# ip route replace 169.254.16.9/32 via eth0
route="${ONEGATE_ENDPOINT}/32 via ${dev}"
echo "$route" >> "${config_path}/route-${dev}"
fi
if [ -n "${mtu}" ]; then
echo "MTU=${mtu}"
fi

Loading…
Cancel
Save