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

Commit cf5fd72

Browse files
authored
F #277 Fix onegate proxy static route (#293)
1 parent 3f036ae commit cf5fd72

7 files changed

Lines changed: 22 additions & 18 deletions

File tree

src/etc/one-context.d/loc-10-network.d/functions

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ initialize_network()
5454
# shellcheck disable=SC2154
5555
[ "${action}" = 'configure' ] || return 0
5656

57+
export onegate_proxy_route_missing="yes" # flag route not setup
58+
5759
_context_interfaces=$(get_context_interfaces)
5860
_iface_mac=$(get_interface_mac)
5961

@@ -593,16 +595,14 @@ is_link_local() {
593595
}
594596

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

602-
echo "$onegate_host"
603-
fi
602+
export onegate_host=$(echo "$ONEGATE_ENDPOINT" | grep -oE "$ipv4_regex")
603+
fi
604604
}
605605

606606
add_onegate_proxy_route?() {
607-
is_link_local "$(get_onegate_ip)" && [[ $onegate_proxy_route_missing == "yes" ]]
607+
is_link_local "$onegate_host" && [[ $onegate_proxy_route_missing == "yes" ]]
608608
}

src/etc/one-context.d/loc-10-network.d/netcfg-bsd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ gen_iface_conf()
163163
fi
164164

165165
# Add ONEGATE Proxy static route
166-
if [[ $(add_onegate_proxy_route?) ]]; then
166+
get_onegate_ip
167+
if add_onegate_proxy_route?; then
167168
route_name="r_onegateproxy"
168169

169170
sed -i "s/${route_names}/${route_names} ${route_name}/g" "$routes_conf_path"

src/etc/one-context.d/loc-10-network.d/netcfg-interfaces

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ EOT
175175
fi
176176

177177
# Add ONEGATE Proxy static route
178-
if [[ $(add_onegate_proxy_route?) ]]; then
179-
echo " up ip route replace ${onegate_host} via ${dev}"
178+
get_onegate_ip
179+
if add_onegate_proxy_route?; then
180+
echo " up ip route replace ${onegate_host} dev ${dev}"
180181

181182
# Will make proxy static route only applicable to 1st interface
182183
unset onegate_proxy_route_missing
@@ -375,8 +376,6 @@ EOT
375376

376377
_context_interfaces=$(get_context_interfaces)
377378

378-
export onegate_proxy_route_missing="yes" # flag route not setup
379-
380379
for _iface in $_context_interfaces; do
381380
setup_iface_vars "$_iface"
382381

src/etc/one-context.d/loc-10-network.d/netcfg-netplan

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ EOT
167167
fi
168168

169169
# Add ONEGATE Proxy static route
170-
if [[ $(add_onegate_proxy_route?) ]]; then
170+
get_onegate_ip
171+
if add_onegate_proxy_route?; then
171172
# ip route replace 169.254.16.9/32 via eth0
172173
cat <<EOT
173174
- to: "${onegate_host}"

src/etc/one-context.d/loc-10-network.d/netcfg-networkd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ EOT
137137
fi
138138

139139
# Add ONEGATE Proxy static route
140-
if [[ $(add_onegate_proxy_route?) ]]; then
140+
get_onegate_ip
141+
if add_onegate_proxy_route?; then
141142
# ip route replace 169.254.16.9/32 via eth0
142143
echo "[Route]"
143144
echo "Destination=${onegate_host}"

src/etc/one-context.d/loc-10-network.d/netcfg-nm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ gen_iface_conf()
140140
fi
141141

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

src/etc/one-context.d/loc-10-network.d/netcfg-scripts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ EOT
141141
fi
142142

143143
# Add ONEGATE Proxy static route
144-
if [[ $(add_onegate_proxy_route?) ]]; then
145-
route="${onegate_host} via ${dev}"
144+
get_onegate_ip
145+
if add_onegate_proxy_route?; then
146+
route="${onegate_host} dev ${dev}"
146147
echo "$route" >> "${config_path}/route-${dev}"
147148

148149
# Will make proxy static route only applicable to 1st interface

0 commit comments

Comments
 (0)