Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
F #277 Fix onegate proxy static route for real
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 committed May 11, 2023
1 parent 1c08a2f commit 0288d75
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
17 changes: 8 additions & 9 deletions src/etc/one-context.d/loc-10-network.d/functions
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ initialize_network()
[ "${action}" = 'configure' ] || return 0

export onegate_proxy_route_missing="yes" # flag route not setup

_context_interfaces=$(get_context_interfaces)
_iface_mac=$(get_interface_mac)

Expand Down Expand Up @@ -595,16 +595,15 @@ is_link_local() {
}

get_onegate_ip() {
if [[ -n $ONEGATE_ENDPOINT ]]; then
# Regular expression to match an IPv4 address
ipv4_regex="([0-9]{1,3}\.){3}[0-9]{1,3}"

export onegate_host=$(echo "$ONEGATE_ENDPOINT" | grep -oE "$ipv4_regex")
if [[ -n $ONEGATE_ENDPOINT ]]; then
#Regular expression to match an IPv4 address
ipv4_regex="([0-9]{1,3}\.){3}[0-9]{1,3}"

echo "$onegate_host"
fi
export onegate_host
onegate_host=$(echo "$ONEGATE_ENDPOINT" | grep -oE "$ipv4_regex")
fi
}

add_onegate_proxy_route?() {
is_link_local "$(get_onegate_ip)" && [[ $onegate_proxy_route_missing == "yes" ]]
is_link_local "$onegate_host" && [[ $onegate_proxy_route_missing == "yes" ]]
}
3 changes: 2 additions & 1 deletion src/etc/one-context.d/loc-10-network.d/netcfg-bsd
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ gen_iface_conf()
fi

# Add ONEGATE Proxy static route
if [[ $(add_onegate_proxy_route?) ]]; then
get_onegate_ip
if add_onegate_proxy_route?; then
route_name="r_onegateproxy"

sed -i "s/${route_names}/${route_names} ${route_name}/g" "$routes_conf_path"
Expand Down
3 changes: 2 additions & 1 deletion src/etc/one-context.d/loc-10-network.d/netcfg-interfaces
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ EOT
fi

# Add ONEGATE Proxy static route
if [[ $(add_onegate_proxy_route?) ]]; then
get_onegate_ip
if add_onegate_proxy_route?; then
echo " up ip route replace ${onegate_host} dev ${dev}"

# Will make proxy static route only applicable to 1st interface
Expand Down
3 changes: 2 additions & 1 deletion src/etc/one-context.d/loc-10-network.d/netcfg-netplan
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ EOT
fi

# Add ONEGATE Proxy static route
if [[ $(add_onegate_proxy_route?) ]]; then
get_onegate_ip
if add_onegate_proxy_route?; then
# ip route replace 169.254.16.9/32 via eth0
cat <<EOT
- to: "${onegate_host}"
Expand Down
3 changes: 2 additions & 1 deletion src/etc/one-context.d/loc-10-network.d/netcfg-networkd
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ EOT
fi

# Add ONEGATE Proxy static route
if [[ $(add_onegate_proxy_route?) ]]; then
get_onegate_ip
if add_onegate_proxy_route?; then
# ip route replace 169.254.16.9/32 via eth0
echo "[Route]"
echo "Destination=${onegate_host}"
Expand Down
3 changes: 2 additions & 1 deletion src/etc/one-context.d/loc-10-network.d/netcfg-nm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ gen_iface_conf()
fi

# Add ONEGATE Proxy static route
if [[ $(add_onegate_proxy_route?) ]]; then
get_onegate_ip
if add_onegate_proxy_route?; then
# ip route replace 169.254.16.9/32 via eth0
nmcli con mod "$dev" +ipv4.routes "$onegate_host"

Expand Down
3 changes: 2 additions & 1 deletion src/etc/one-context.d/loc-10-network.d/netcfg-scripts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ EOT
fi

# Add ONEGATE Proxy static route
if [[ $(add_onegate_proxy_route?) ]]; then
get_onegate_ip
if add_onegate_proxy_route?; then
route="${onegate_host} dev ${dev}"
echo "$route" >> "${config_path}/route-${dev}"

Expand Down

0 comments on commit 0288d75

Please sign in to comment.