Skip to content

Commit

Permalink
F OpenNebula#277 Fix SUSE static routing (OpenNebula#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 authored May 23, 2023
1 parent e24f2a7 commit 0b9f88f
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions src/etc/one-context.d/loc-10-network.d/netcfg-scripts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

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

# SUSE family
elif [ -d /etc/sysconfig/network/ ]; then
elif is_net_suse; then
return 0
fi

Expand Down Expand Up @@ -105,22 +103,22 @@ NETMASK="${mask}"
IPADDR="${ip}"
EOT

### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
if is_net_suse; then
echo 'BOOTPROTO=static'

config_path_routes="${config_path}/ifroute-${dev}"

if [ -n "${gateway}" ]; then
echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" \
>> "${config_path}/ifroute-${dev}"
echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" >> "$config_path_routes"
fi

### Red Hat family ###
else
echo 'BOOTPROTO=none'

config_path_routes="${config_path}/route-${dev}"

if [ -n "${gateway}" ]; then
echo "default via ${gateway} dev ${dev} ${metric:+metric ${metric}}" \
>> "${config_path}/route-${dev}"
echo "default via ${gateway} dev ${dev} ${metric:+metric ${metric}}" >> "$config_path_routes"
fi
fi

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

echo "$route" >> "${config_path}/route-${dev}"
if is_net_suse; then
echo "${dst} ${gw} - ${dev}" >> "$config_path_routes"
else
echo "$route" >> "$config_path_routes"
fi
done

fi

# 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}"
if is_net_suse; then
route="${onegate_host} - - ${dev}"
else
route="${onegate_host} dev ${dev}"
fi

echo "$route" >> "$config_path_routes"

unset onegate_proxy_route_missing
fi
Expand All @@ -155,15 +162,13 @@ EOT

gen_dhcp_conf()
{
### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
if is_net_suse; then
if [ "${ip6_method}" = 'dhcp' ]; then
echo 'BOOTPROTO=dhcp'
else
echo 'BOOTPROTO=dhcp4'
fi

### Red Hat family ###
else
cat <<EOT
BOOTPROTO=dhcp
Expand All @@ -185,8 +190,7 @@ EOT

gen_iface6_conf()
{
### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
if is_net_suse; then
echo "IPADDR_6A=${ip6}/${ip6_prefix_length:-64}"

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

### Red Hat family ###
else
cat <<EOT
IPV6INIT=yes
Expand Down Expand Up @@ -239,8 +242,7 @@ EOT

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

### Red Hat family ###
else
if [ "${ip6_method}" = "auto" ] ; then
cat <<EOT
Expand Down Expand Up @@ -307,8 +308,7 @@ gen_alias6_conf()

gen_network_configuration()
{
### Red Hat family ###
if [ -d /etc/sysconfig/network-scripts ]; then
if is_net_rhel; then
config_path=/etc/sysconfig/network-scripts

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

### SUSE family ###
elif [ -d /etc/sysconfig/network ]; then
elif is_net_suse; then
config_path=/etc/sysconfig/network
fi

Expand Down Expand Up @@ -351,8 +350,7 @@ NM_CONTROLLED=no
TYPE=Ethernet
EOT

# SUSE family
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
if is_net_suse; then
echo "STARTMODE=auto"
else
echo "ONBOOT=yes"
Expand Down Expand Up @@ -415,3 +413,11 @@ EOT

done
}

is_net_rhel() {
[ -d /etc/sysconfig/network-scripts ]
}

is_net_suse() {
[ -d /etc/sysconfig/network ]
}

0 comments on commit 0b9f88f

Please sign in to comment.