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

Commit e24f2a7

Browse files
authored
F #277 cleaner code, fix nm static routes (#294)
1 parent cf5fd72 commit e24f2a7

7 files changed

Lines changed: 21 additions & 28 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ initialize_network()
5555
[ "${action}" = 'configure' ] || return 0
5656

5757
export onegate_proxy_route_missing="yes" # flag route not setup
58+
get_onegate_ip
5859

5960
_context_interfaces=$(get_context_interfaces)
6061
_iface_mac=$(get_interface_mac)
@@ -596,13 +597,13 @@ is_link_local() {
596597

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

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

606-
add_onegate_proxy_route?() {
607+
missing_onegate_proxy_route() {
607608
is_link_local "$onegate_host" && [[ $onegate_proxy_route_missing == "yes" ]]
608609
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ gen_iface_conf()
153153
index+=1
154154
done
155155

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

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

163163
fi
164164

165-
# Add ONEGATE Proxy static route
166-
get_onegate_ip
167-
if add_onegate_proxy_route?; then
165+
# Add ONEGATE Proxy static route ip route replace 169.254.16.9 dev eth0
166+
if missing_onegate_proxy_route; then
168167
route_name="r_onegateproxy"
169168

170169
sed -i "s/${route_names}/${route_names} ${route_name}/g" "$routes_conf_path"
171-
# ip route replace 169.254.16.9/32 via eth0
172170
route_conf="route_${route_name}=\"-host ${onegate_host} -iface ${dev}\""
173171

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

176-
# Will make proxy static route only applicable to 1st interface
177174
unset onegate_proxy_route_missing
178175
fi
179176
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,10 @@ EOT
174174

175175
fi
176176

177-
# Add ONEGATE Proxy static route
178-
get_onegate_ip
179-
if add_onegate_proxy_route?; then
177+
# Add ONEGATE Proxy static route ip route replace 169.254.16.9 dev eth0
178+
if missing_onegate_proxy_route; then
180179
echo " up ip route replace ${onegate_host} dev ${dev}"
181180

182-
# Will make proxy static route only applicable to 1st interface
183181
unset onegate_proxy_route_missing
184182
fi
185183

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,8 @@ EOT
166166

167167
fi
168168

169-
# Add ONEGATE Proxy static route
170-
get_onegate_ip
171-
if add_onegate_proxy_route?; then
172-
# ip route replace 169.254.16.9/32 via eth0
169+
# Add ONEGATE Proxy static route ip route replace 169.254.16.9 dev eth0
170+
if missing_onegate_proxy_route; then
173171
cat <<EOT
174172
- to: "${onegate_host}"
175173
scope: link

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@ EOT
136136

137137
fi
138138

139-
# Add ONEGATE Proxy static route
140-
get_onegate_ip
141-
if add_onegate_proxy_route?; then
142-
# ip route replace 169.254.16.9/32 via eth0
139+
# Add ONEGATE Proxy static route ip route replace 169.254.16.9 dev eth0
140+
if missing_onegate_proxy_route; then
143141
echo "[Route]"
144142
echo "Destination=${onegate_host}"
145143
echo "Scope=link"

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,8 @@ gen_iface_conf()
139139

140140
fi
141141

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

148146
unset onegate_proxy_route_missing
@@ -263,6 +261,11 @@ gen_network_configuration()
263261
{
264262
_context_interfaces=$(get_context_interfaces)
265263

264+
# nm renderer is required_context_type=online and it skips initialize_network
265+
# this flag is set for all other renderers in there
266+
export onegate_proxy_route_missing="yes" # flag route not setup
267+
get_onegate_ip
268+
266269
for _iface in $_context_interfaces; do
267270
setup_iface_vars "$_iface"
268271

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,11 @@ EOT
140140

141141
fi
142142

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

149-
# Will make proxy static route only applicable to 1st interface
150148
unset onegate_proxy_route_missing
151149
fi
152150

0 commit comments

Comments
 (0)