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

Commit 0b9f88f

Browse files
authored
F #277 Fix SUSE static routing (#295)
1 parent e24f2a7 commit 0b9f88f

1 file changed

Lines changed: 34 additions & 28 deletions

File tree

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

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
is_network_supported()
2424
{
25-
# Red Hat family
2625
if [ -x /etc/sysconfig/network-scripts/ifup ]; then
2726
# On EL8, the network-scripts (package) is legacy
2827
# and network service is not even enabled by default.
@@ -38,8 +37,7 @@ is_network_supported()
3837
return 0
3938
fi
4039

41-
# SUSE family
42-
elif [ -d /etc/sysconfig/network/ ]; then
40+
elif is_net_suse; then
4341
return 0
4442
fi
4543

@@ -105,22 +103,22 @@ NETMASK="${mask}"
105103
IPADDR="${ip}"
106104
EOT
107105

108-
### SUSE family ###
109-
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
106+
if is_net_suse; then
110107
echo 'BOOTPROTO=static'
111108

109+
config_path_routes="${config_path}/ifroute-${dev}"
110+
112111
if [ -n "${gateway}" ]; then
113-
echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" \
114-
>> "${config_path}/ifroute-${dev}"
112+
echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" >> "$config_path_routes"
115113
fi
116114

117-
### Red Hat family ###
118115
else
119116
echo 'BOOTPROTO=none'
120117

118+
config_path_routes="${config_path}/route-${dev}"
119+
121120
if [ -n "${gateway}" ]; then
122-
echo "default via ${gateway} dev ${dev} ${metric:+metric ${metric}}" \
123-
>> "${config_path}/route-${dev}"
121+
echo "default via ${gateway} dev ${dev} ${metric:+metric ${metric}}" >> "$config_path_routes"
124122
fi
125123
fi
126124

@@ -135,15 +133,24 @@ EOT
135133
dst="${rsplit[0]}"
136134
gw="${rsplit[2]}"
137135

138-
echo "$route" >> "${config_path}/route-${dev}"
136+
if is_net_suse; then
137+
echo "${dst} ${gw} - ${dev}" >> "$config_path_routes"
138+
else
139+
echo "$route" >> "$config_path_routes"
140+
fi
139141
done
140142

141143
fi
142144

143145
# Add ONEGATE Proxy static route ip route replace 169.254.16.9 dev eth0
144146
if missing_onegate_proxy_route; then
145-
route="${onegate_host} dev ${dev}"
146-
echo "$route" >> "${config_path}/route-${dev}"
147+
if is_net_suse; then
148+
route="${onegate_host} - - ${dev}"
149+
else
150+
route="${onegate_host} dev ${dev}"
151+
fi
152+
153+
echo "$route" >> "$config_path_routes"
147154

148155
unset onegate_proxy_route_missing
149156
fi
@@ -155,15 +162,13 @@ EOT
155162

156163
gen_dhcp_conf()
157164
{
158-
### SUSE family ###
159-
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
165+
if is_net_suse; then
160166
if [ "${ip6_method}" = 'dhcp' ]; then
161167
echo 'BOOTPROTO=dhcp'
162168
else
163169
echo 'BOOTPROTO=dhcp4'
164170
fi
165171

166-
### Red Hat family ###
167172
else
168173
cat <<EOT
169174
BOOTPROTO=dhcp
@@ -185,8 +190,7 @@ EOT
185190

186191
gen_iface6_conf()
187192
{
188-
### SUSE family ###
189-
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
193+
if is_net_suse; then
190194
echo "IPADDR_6A=${ip6}/${ip6_prefix_length:-64}"
191195

192196
cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}"
@@ -205,7 +209,6 @@ net.ipv6.conf.\$SYSCTL_IF.mtu = ${mtu}
205209
EOT
206210
fi
207211

208-
### Red Hat family ###
209212
else
210213
cat <<EOT
211214
IPV6INIT=yes
@@ -239,8 +242,7 @@ EOT
239242

240243
gen_dhcp6_conf()
241244
{
242-
### SUSE family ###
243-
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
245+
if is_net_suse; then
244246
# On SUSE the BOOTPROTO is shared for both IPv4/6,
245247
# in case IPv4 is not dhcp we configure DHCPv6 only here
246248
# (if IPv4 is static, we unforunately overwrite that)
@@ -265,7 +267,6 @@ net.ipv6.conf.\$SYSCTL_IF.mtu = ${mtu}
265267
EOT
266268
fi
267269

268-
### Red Hat family ###
269270
else
270271
if [ "${ip6_method}" = "auto" ] ; then
271272
cat <<EOT
@@ -307,8 +308,7 @@ gen_alias6_conf()
307308

308309
gen_network_configuration()
309310
{
310-
### Red Hat family ###
311-
if [ -d /etc/sysconfig/network-scripts ]; then
311+
if is_net_rhel; then
312312
config_path=/etc/sysconfig/network-scripts
313313

314314
# if disabled, enable networking via network scripts
@@ -319,8 +319,7 @@ gen_network_configuration()
319319
echo 'NETWORKING=yes' >>/etc/sysconfig/network
320320
fi
321321

322-
### SUSE family ###
323-
elif [ -d /etc/sysconfig/network ]; then
322+
elif is_net_suse; then
324323
config_path=/etc/sysconfig/network
325324
fi
326325

@@ -351,8 +350,7 @@ NM_CONTROLLED=no
351350
TYPE=Ethernet
352351
EOT
353352

354-
# SUSE family
355-
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
353+
if is_net_suse; then
356354
echo "STARTMODE=auto"
357355
else
358356
echo "ONBOOT=yes"
@@ -415,3 +413,11 @@ EOT
415413

416414
done
417415
}
416+
417+
is_net_rhel() {
418+
[ -d /etc/sysconfig/network-scripts ]
419+
}
420+
421+
is_net_suse() {
422+
[ -d /etc/sysconfig/network ]
423+
}

0 commit comments

Comments
 (0)