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

Commit

Permalink
F #277 cleaner code, fix nm static routes (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 authored May 19, 2023
1 parent cf5fd72 commit e24f2a7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 28 deletions.
5 changes: 3 additions & 2 deletions src/etc/one-context.d/loc-10-network.d/functions
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ initialize_network()
[ "${action}" = 'configure' ] || return 0

export onegate_proxy_route_missing="yes" # flag route not setup
get_onegate_ip

_context_interfaces=$(get_context_interfaces)
_iface_mac=$(get_interface_mac)
Expand Down Expand Up @@ -596,13 +597,13 @@ is_link_local() {

get_onegate_ip() {
if [[ -n $ONEGATE_ENDPOINT ]]; then
#Regular expression to match an IPv4 address
# 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")
fi
}

add_onegate_proxy_route?() {
missing_onegate_proxy_route() {
is_link_local "$onegate_host" && [[ $onegate_proxy_route_missing == "yes" ]]
}
9 changes: 3 additions & 6 deletions src/etc/one-context.d/loc-10-network.d/netcfg-bsd
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ gen_iface_conf()
index+=1
done

# remove last whitespace
# remove last whitespace
echo -e "static_routes=\"$(echo "$route_names" | xargs)\"" >>$routes_conf_path

for route_conf in "${routes_conf[@]}"; do
Expand All @@ -162,18 +162,15 @@ gen_iface_conf()

fi

# Add ONEGATE Proxy static route
get_onegate_ip
if add_onegate_proxy_route?; then
# Add ONEGATE Proxy static route ip route replace 169.254.16.9 dev eth0
if missing_onegate_proxy_route; then
route_name="r_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_host} -iface ${dev}\""

echo -e "$route_conf\n" >> $routes_conf_path

# Will make proxy static route only applicable to 1st interface
unset onegate_proxy_route_missing
fi
}
Expand Down
6 changes: 2 additions & 4 deletions src/etc/one-context.d/loc-10-network.d/netcfg-interfaces
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,10 @@ EOT

fi

# Add ONEGATE Proxy static route
get_onegate_ip
if add_onegate_proxy_route?; then
# Add ONEGATE Proxy static route ip route replace 169.254.16.9 dev eth0
if missing_onegate_proxy_route; then
echo " up ip route replace ${onegate_host} dev ${dev}"

# Will make proxy static route only applicable to 1st interface
unset onegate_proxy_route_missing
fi

Expand Down
6 changes: 2 additions & 4 deletions src/etc/one-context.d/loc-10-network.d/netcfg-netplan
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,8 @@ EOT

fi

# Add ONEGATE Proxy static route
get_onegate_ip
if add_onegate_proxy_route?; then
# ip route replace 169.254.16.9/32 via eth0
# Add ONEGATE Proxy static route ip route replace 169.254.16.9 dev eth0
if missing_onegate_proxy_route; then
cat <<EOT
- to: "${onegate_host}"
scope: link
Expand Down
6 changes: 2 additions & 4 deletions src/etc/one-context.d/loc-10-network.d/netcfg-networkd
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,8 @@ EOT

fi

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

fi

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

unset onegate_proxy_route_missing
Expand Down Expand Up @@ -263,6 +261,11 @@ gen_network_configuration()
{
_context_interfaces=$(get_context_interfaces)

# nm renderer is required_context_type=online and it skips initialize_network
# this flag is set for all other renderers in there
export onegate_proxy_route_missing="yes" # flag route not setup
get_onegate_ip

for _iface in $_context_interfaces; do
setup_iface_vars "$_iface"

Expand Down
6 changes: 2 additions & 4 deletions src/etc/one-context.d/loc-10-network.d/netcfg-scripts
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,11 @@ EOT

fi

# Add ONEGATE Proxy static route
get_onegate_ip
if add_onegate_proxy_route?; then
# Add ONEGATE Proxy static route ip route replace 169.254.16.9 dev eth0
if missing_onegate_proxy_route; then
route="${onegate_host} dev ${dev}"
echo "$route" >> "${config_path}/route-${dev}"

# Will make proxy static route only applicable to 1st interface
unset onegate_proxy_route_missing
fi

Expand Down

0 comments on commit e24f2a7

Please sign in to comment.