F #227, #86: Various fixes

pull/252/head
Vlastimil Holer 3 years ago committed by GitHub
parent 25690dc21f
commit 962153d817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
NETWORK=${NETWORK:-yes}
SERVICES=${SERVICES:-one-context-local one-context-online one-context} SERVICES=${SERVICES:-one-context-local one-context-online one-context}
TIMERS=${TIMERS:-one-context-reconfigure.timer} TIMERS=${TIMERS:-one-context-reconfigure.timer}
@ -73,8 +72,8 @@ fi
### Cleanup network configuration ########################## ### Cleanup network configuration ##########################
if [ "${NETWORK}" != 'yes' ]; then if [ -f /etc/sysctl.d/50-one-context.conf ]; then
exit rm -f /etc/sysctl.d/50-one-context.conf
fi fi
# Debian based distros # Debian based distros
@ -82,7 +81,6 @@ if [ -d /etc/network ]; then
# Prepare network files # Prepare network files
cp /etc/network/interfaces "/etc/network/interfaces.$(date '+%s')" cp /etc/network/interfaces "/etc/network/interfaces.$(date '+%s')"
rm -rf /etc/network/interfaces.d rm -rf /etc/network/interfaces.d
rm -rf /etc/netplan/*
cat > /etc/network/interfaces <<EOT cat > /etc/network/interfaces <<EOT
# The loopback network interface # The loopback network interface
@ -98,17 +96,17 @@ EOT
# fi # fi
fi fi
# RedHat based distros # Red Hat based distros
if [ -d /etc/sysconfig/network-scripts ]; then if [ -d /etc/sysconfig/network-scripts/ ]; then
# Prepare network files # Prepare network files
find /etc/sysconfig/network-scripts -type f \ find /etc/sysconfig/network-scripts -type f \
\( -name 'ifcfg-*' -o -name 'route-*' \) \ \( -name 'ifcfg-*' -o -name 'route-*' -o -name 'route6-*' \) \
! -name 'ifcfg-lo' ! -name 'route-lo' \ ! -name 'ifcfg-lo' ! -name 'route-lo' ! -name 'route6-lo' \
-exec rm -f {} \; -exec rm -f {} \;
fi fi
# openSUSE based distros # openSUSE based distros
if [ -d /etc/sysconfig/network ]; then if [ -d /etc/sysconfig/network/ ]; then
# Prepare network files # Prepare network files
find /etc/sysconfig/network -type f \ find /etc/sysconfig/network -type f \
\( -name 'ifcfg-*' -o -name 'ifroute-*' -o -name 'ifsysctl-*' \) \ \( -name 'ifcfg-*' -o -name 'ifroute-*' -o -name 'ifsysctl-*' \) \
@ -117,10 +115,27 @@ if [ -d /etc/sysconfig/network ]; then
rm -f /etc/sysconfig/network/routes /etc/sysconfig/network/ifsysctl rm -f /etc/sysconfig/network/routes /etc/sysconfig/network/ifsysctl
sed -i '/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/="/' /etc/sysconfig/network/config sed -i '/^NETCONFIG_DNS_STATIC_SERVERS=/ s/=.*$/=""/' /etc/sysconfig/network/config
sed -i '/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=""/' /etc/sysconfig/network/config sed -i '/^NETCONFIG_DNS_STATIC_SEARCHLIST=/ s/=.*$/=""/' /etc/sysconfig/network/config
fi fi
# Netplan
if [ -d /etc/netplan/ ]; then
rm -f /etc/netplan/*
fi
# NetworkManager
if [ -d /etc/NetworkManager/system-connections/ ]; then
rm -f /etc/NetworkManager/system-connections/*
fi
# systemd-networkd
if [ -d /etc/systemd/network/ ]; then
rm -f \
/etc/systemd/networkd/*.network \
/etc/systemd/networkd/*.link
fi
# FreeBSD based distros # FreeBSD based distros
#TODO: pfsense paths? #TODO: pfsense paths?
if [ -x /bin/freebsd-version ]; then if [ -x /bin/freebsd-version ]; then

@ -0,0 +1,44 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# -------------------------------------------------------------------------- #
# As of Netplan 0.102, the NetworkManager renderer can only enable
# IPv6 privacy if ipv6-privacy == true, but doesn't disable it if false.
# Instead of enforcing any global defaults, we set IPv6 privacy via sysctl
# on Netplan described interfaces in case the current settings is -1 (unknown),
# i.e. not explicitly configured. This is a forward compatible workaround, once
# Netplan properly sets NM ipv6.ip6-privacy=0, this code won't be effective.
case "${CONNECTION_ID}" in
netplan-*)
IP6_PRIVACY=$(nmcli -g ipv6.ip6-privacy con show "${CONNECTION_UUID}")
# overwrite only unknown state
if [ "${IP6_PRIVACY}" = '-1' ]; then
sysctl -q -w "net.ipv6.conf.${DEVICE_IFACE}.use_tempaddr=0"
# delete any existing temporary IPv6 addresses
ip -6 address show dev "${DEVICE_IFACE}" | \
grep 'inet6.*temporary' | \
tr -s ' ' | \
cut -d' ' -f 3 | \
xargs -r -n1 ip -6 address del dev "${DEVICE_IFACE}"
fi
;;
esac
exit 0

@ -42,8 +42,8 @@ if [ -z "${NETCFG_TYPE}" ] ; then
fedora|centos|rhel|almalinux|ol|rocky) fedora|centos|rhel|almalinux|ol|rocky)
NETCFG_TYPE='scripts nm networkd' NETCFG_TYPE='scripts nm networkd'
;; ;;
opensuse*) opensuse*|sles|sled)
NETCFG_TYPE='scripts nm networkd' NETCFG_TYPE='scripts'
;; ;;
freebsd) freebsd)
NETCFG_TYPE='bsd' NETCFG_TYPE='bsd'
@ -52,13 +52,44 @@ if [ -z "${NETCFG_TYPE}" ] ; then
NETCFG_TYPE='none' NETCFG_TYPE='none'
;; ;;
esac esac
else
# trim and lowercase
NETCFG_TYPE=$(echo "$NETCFG_TYPE" | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
tr '[:upper:]' '[:lower:]')
# support alternative names for some configuration renderers
case "${NETCFG_TYPE}" in
networkmanager)
NETCFG_TYPE='nm'
;;
systemd-networkd|systemd-network|systemd)
NETCFG_TYPE='networkd'
;;
redhat)
NETCFG_TYPE='scripts'
;;
debian)
NETCFG_TYPE='interfaces'
;;
freebsd)
NETCFG_TYPE='bsd'
;;
esac
fi fi
if [ "${NETCFG_TYPE}" != 'none' ] ; then if [ "${NETCFG_TYPE}" != 'none' ] ; then
_found_valid_netcfg='no' _found_valid_netcfg='no'
# from a space separated list of $NECFG_TYPE candidates check one
# by one and select the first suitable one for current environment
for _cfgtype in ${NETCFG_TYPE} ; do for _cfgtype in ${NETCFG_TYPE} ; do
if [ -e "/etc/one-context.d/loc-10-network.d/netcfg-${_cfgtype}" ] ; then _cfgtype_file="/etc/one-context.d/loc-10-network.d/netcfg-$(basename "${_cfgtype}")"
. "/etc/one-context.d/loc-10-network.d/netcfg-${_cfgtype}"
if [ -e "${_cfgtype_file}" ] ; then
# reload functions to reset back any overrides from prev. netcfg-X
. /etc/one-context.d/loc-10-network.d/functions
. "${_cfgtype_file}"
else else
echo "ERROR [!]: Requested network type is not implemented: ${_cfgtype}" >&2 echo "ERROR [!]: Requested network type is not implemented: ${_cfgtype}" >&2
exit 1 exit 1
@ -121,6 +152,7 @@ case "$action" in
reconfigure) reconfigure)
configure_network configure_network
reload_network reload_network
# wait_online
;; ;;
*) *)
echo "ERROR [!]: Unknown ACTION: ${action}" >&2 echo "ERROR [!]: Unknown ACTION: ${action}" >&2

@ -63,7 +63,6 @@ for pci in $PCI_INTERFACES; do
GATEWAY=$(get_iface_var "GATEWAY") GATEWAY=$(get_iface_var "GATEWAY")
METRIC=$(get_iface_var "METRIC") METRIC=$(get_iface_var "METRIC")
MTU=$(get_iface_var "MTU") MTU=$(get_iface_var "MTU")
MTU=${MTU:-1500}
VLAN_ID=$(get_iface_var "VLAN_ID") VLAN_ID=$(get_iface_var "VLAN_ID")
IP6=$(get_iface_var "IP6") IP6=$(get_iface_var "IP6")

@ -38,8 +38,8 @@ initialize_network()
;; ;;
*) *)
mkdir -p /etc/sysctl.d/ mkdir -p /etc/sysctl.d/
rm -f /etc/sysctl.d/00-opennebula-netcfg.conf rm -f /etc/sysctl.d/50-one-context.conf
sysctl -p sysctl --system 2>/dev/null || sysctl -p
;; ;;
esac esac
@ -64,14 +64,17 @@ initialize_network()
# network-scripts # network-scripts
rm -f \ rm -f \
"/etc/sysconfig/network-scripts/route-${dev}" \ "/etc/sysconfig/network-scripts/route-${dev}" \
"/etc/sysconfig/network-scripts/route6-${dev}" \
"/etc/sysconfig/network-scripts/ifcfg-${dev}" \
"/etc/sysconfig/network/ifroute-${dev}" \ "/etc/sysconfig/network/ifroute-${dev}" \
"/etc/sysconfig/network/ifsysctl-${dev}" \ "/etc/sysconfig/network/ifsysctl-${dev}" \
"/etc/sysconfig/network-scripts/ifcfg-${dev}" \
"/etc/sysconfig/network/ifcfg-${dev}" \ "/etc/sysconfig/network/ifcfg-${dev}" \
; ;
# networkd # networkd
rm -f "/etc/systemd/network/${dev}.network" rm -f \
"/etc/systemd/network/${dev}.network" \
"/etc/systemd/network/${dev}.link"
# nm (on RH systems it was deleted with ifcfg-*) # nm (on RH systems it was deleted with ifcfg-*)
for _nm_con in /etc/NetworkManager/system-connections/* ; do for _nm_con in /etc/NetworkManager/system-connections/* ; do
@ -81,13 +84,70 @@ initialize_network()
done done
done done
# To avoid clashes when running legacy network-scripts and
# NetworkManager/networkd, we disable old-style networking
# on Red Hats and enable later back only if needed.
if [ -d /etc/sysconfig/network-scripts/ ]; then
touch /etc/sysconfig/network
sed -i -e '/^NETWORKING=/d' /etc/sysconfig/network
echo 'NETWORKING=no' >>/etc/sysconfig/network
fi
# interfaces # interfaces
if [ -e /etc/network/interfaces ] ; then if [ -e /etc/network/interfaces ] ; then
cat /dev/null > /etc/network/interfaces cat <<EOT >/etc/network/interfaces
# Generated by one-context
auto lo
iface lo inet loopback
EOT
case "${os_id}" in
debian|ubuntu|devuan)
echo "source /etc/network/interfaces.d/*.cfg" >> /etc/network/interfaces
;;
esac
fi fi
# netplan # netplan
rm -f /etc/netplan/00-opennebula-generated-network.yaml rm -f /etc/netplan/50-one-context.yaml
nm_disable
}
nm_disable() {
if [ -d /etc/NetworkManager/conf.d/ ] &&
! [ -e /etc/NetworkManager/conf.d/50-unmanaged-devices.conf ];
then
cat - <<EOF >/etc/NetworkManager/conf.d/50-unmanaged-devices.conf
# Generated by one-context
# NOTE: NetworkManager was dynamically disabled by OpenNebula
# contextualization scripts because interfaces are managed by
# different network service!
[keyfile]
unmanaged-devices=*
EOF
if command -v systemctl >/dev/null; then
systemctl --no-block try-reload-or-restart NetworkManager.service 2>/dev/null
else
service NetworkManager reload 2>/dev/null
fi
fi
}
nm_enable() {
if [ -e /etc/NetworkManager/conf.d/50-unmanaged-devices.conf ]; then
rm -f /etc/NetworkManager/conf.d/50-unmanaged-devices.conf
if command -v systemctl >/dev/null; then
systemctl --no-block try-reload-or-restart NetworkManager.service 2>/dev/null
else
service NetworkManager reload 2>/dev/null
fi
fi
} }
configure_network() configure_network()
@ -141,6 +201,14 @@ detect_os()
# shellcheck disable=SC1091 # shellcheck disable=SC1091
. /etc/os-release . /etc/os-release
echo "$ID" | tr '[:upper:]' '[:lower:]' echo "$ID" | tr '[:upper:]' '[:lower:]'
# check for legacy RHEL/CentOS 6
elif [ -f /etc/centos-release ]; then
echo 'centos'
elif [ -f /etc/redhat-release ]; then
echo 'redhat'
# fallback to uname (returns Linux, FreeBSD, ...)
else else
uname | tr '[:upper:]' '[:lower:]' uname | tr '[:upper:]' '[:lower:]'
fi fi
@ -160,8 +228,42 @@ disable_ipv6()
echo "ERROR [!]: Disabling of IPv6 on '${os_id}' is not supported" >&2 echo "ERROR [!]: Disabling of IPv6 on '${os_id}' is not supported" >&2
;; ;;
*) *)
echo "net.ipv6.conf.${1}.disable_ipv6 = 1" >> /etc/sysctl.d/00-opennebula-netcfg.conf # VH-TODO: do we suport runtime enable?
sysctl -w "net.ipv6.conf.${1}.disable_ipv6=1" for S in \
"net.ipv6.conf.${1}.disable_ipv6=1" \
"net.ipv6.conf.${1}.autoconf=0" \
"net.ipv6.conf.${1}.accept_ra=0";
do
# don't duplicate entries on recontextualization
if ! grep -Fxq "${S}" /etc/sysctl.d/50-one-context.conf 2>/dev/null; then
echo "${S}" >> /etc/sysctl.d/50-one-context.conf
fi
sysctl -w "${S}" >/dev/null
done
;;
esac
)
# arg: <iface>
disable_ipv6_privacy()
(
case "${os_id}" in
freebsd)
echo "ERROR [!]: Disabling of IPv6 privacy on '${os_id}' is not supported" >&2
;;
*)
# shellcheck disable=SC2066
for S in \
"net.ipv6.conf.${1}.use_tempaddr=0";
do
# don't duplicate entries on recontextualization
if ! grep -Fxq "${S}" /etc/sysctl.d/50-one-context.conf 2>/dev/null; then
echo "${S}" >> /etc/sysctl.d/50-one-context.conf
fi
sysctl -w "${S}" >/dev/null
done
;; ;;
esac esac
) )
@ -186,13 +288,13 @@ skip_interface()
_skip4=no _skip4=no
;; ;;
*) *)
echo "ERROR [!]: Unknown IPv4 method: ${method}" >&2 echo "ERROR [!]: Unknown IPv4 method: ${method}, skipping" >&2
exit 1 _skip4=yes
;; ;;
esac esac
_skip6= _skip6=
case "${method6}" in case "${ip6_method}" in
''|static) ''|static)
if [ -z "${ip6}" ] ; then if [ -z "${ip6}" ] ; then
_skip6=yes _skip6=yes
@ -203,7 +305,7 @@ skip_interface()
skip) skip)
_skip6=yes _skip6=yes
;; ;;
disabled) disable)
disable_ipv6 "${dev}" disable_ipv6 "${dev}"
_skip6=yes _skip6=yes
;; ;;
@ -211,8 +313,8 @@ skip_interface()
_skip6=no _skip6=no
;; ;;
*) *)
echo "ERROR [!]: Unknown IPv4 method: ${method6}" >&2 echo "ERROR [!]: Unknown IPv6 method: ${ip6_method}" >&2
exit 1 _skip6=yes
;; ;;
esac esac
@ -296,6 +398,7 @@ get_mask()
# arg: <iface> # arg: <iface>
get_mtu() get_mtu()
( (
# VH_TODO: drop default 1500, nekde se spoleha na tento default!
_mtu=$(get_iface_var "$1" "MTU") _mtu=$(get_iface_var "$1" "MTU")
echo "${_mtu:-1500}" echo "${_mtu:-1500}"
) )
@ -391,14 +494,21 @@ setup_iface_vars()
export mac=$(get_iface_var "$1" "MAC") export mac=$(get_iface_var "$1" "MAC")
export dev=$(get_dev "$_iface_mac" "$mac") export dev=$(get_dev "$_iface_mac" "$mac")
export mtu=$(get_mtu "$1") #export mtu=$(get_mtu "$1")
export mtu=$(get_iface_var "$1" "MTU")
export gateway=$(get_gateway "$1") export gateway=$(get_gateway "$1")
export gateway6=$(get_gateway6 "$1") export gateway6=$(get_gateway6 "$1")
export metric=$(get_iface_var "$1" "METRIC") export metric=$(get_iface_var "$1" "METRIC")
export ip6_metric=$(get_iface_var "$1" "IP6_METRIC")
export dns=$(get_dns "$1") export dns=$(get_dns "$1")
export search_domains=$(get_search_domain "$1") export search_domains=$(get_search_domain "$1")
export method=$(get_iface_var "$1" "METHOD") export method=$(get_iface_var "$1" "METHOD")
export method6=$(get_iface_var "$1" "IP6_METHOD") export ip6_method=$(get_iface_var "$1" "IP6_METHOD")
# defaults
[ -z "$ip6_metric" ] && ip6_metric="${metric}"
[ -z "$method" ] && method='static'
[ -z "$ip6_method" ] && ip6_method="${method}"
setup_ipadr_vars "$1" setup_ipadr_vars "$1"
setup_ip6adr_vars "$1" setup_ip6adr_vars "$1"

@ -79,8 +79,9 @@ export mtu
export gateway export gateway
export gateway6 export gateway6
export method export method
export method6 export ip6_method
export metric export metric
export ip6_metric
export dns export dns
export search_domains export search_domains
export external export external
@ -106,6 +107,12 @@ gen_iface_conf()
echo -n " mtu ${mtu}" echo -n " mtu ${mtu}"
fi fi
# WARNING: On FreeBSD the interface metrics are used only
# by routing daemons (see man 8 ifconfig)
if [ -n "${metric}" ]; then
echo -n " metric ${metric}"
fi
echo "\"" echo "\""
### ###
@ -120,7 +127,7 @@ gen_dhcp_conf()
echo -n "ifconfig_${dev}=\"DHCP" echo -n "ifconfig_${dev}=\"DHCP"
if [ -n "${mtu}" ]; then if [ -n "${mtu}" ]; then
echo -n " mtu ${mtu}" echo -n " inet mtu ${mtu}"
fi fi
echo "\"" echo "\""
@ -140,6 +147,12 @@ gen_iface6_conf()
echo -n " mtu ${mtu}" echo -n " mtu ${mtu}"
fi fi
# WARNING: On FreeBSD the interface metrics are used only
# by routing daemons (see man 8 ifconfig)
if [ -n "${ip6_metric}" ]; then
echo -n " metric ${ip6_metric}"
fi
echo " -accept_rtadv\"" echo " -accept_rtadv\""
if [ -n "${ip6_ula}" ]; then if [ -n "${ip6_ula}" ]; then
@ -156,14 +169,10 @@ gen_iface6_conf()
gen_dhcp6_conf() gen_dhcp6_conf()
{ {
echo -n "ifconfig_${dev}_ipv6=\"inet6" echo -n "ifconfig_${dev}_ipv6=\""
if [ -n "${mtu}" ]; then
echo -n " mtu ${mtu}"
fi
if [ "${method6}" = "dhcp" ] ; then if [ "${ip6_method}" = "dhcp" ] ; then
echo -n " DHCP" echo -n "DHCP "
# FreeBSD support for DHCP6 does not seem to be great: # FreeBSD support for DHCP6 does not seem to be great:
# https://forums.freebsd.org/threads/ipv6-dhcpv6-client-and-accept_rtadv-vs-rtsold.77421/ # https://forums.freebsd.org/threads/ipv6-dhcpv6-client-and-accept_rtadv-vs-rtsold.77421/
@ -175,7 +184,13 @@ gen_dhcp6_conf()
fi fi
fi fi
echo " accept_rtadv\"" echo -n "inet6 accept_rtadv"
if [ -n "${mtu}" ]; then
echo -n " mtu ${mtu}"
fi
echo "\""
# Enable Router Solicitation Deaemon # Enable Router Solicitation Deaemon
# NOTE: It's not enough to just enable the daemon during the current # NOTE: It's not enough to just enable the daemon during the current
@ -198,6 +213,12 @@ gen_alias6_conf()
echo -n " mtu ${mtu}" echo -n " mtu ${mtu}"
fi fi
# WARNING: On FreeBSD the interface metrics are used only
# by routing daemons (see man 8 ifconfig)
if [ -n "${ip6_metric}" ]; then
echo -n " metric ${ip6_metric}"
fi
echo " -accept_rtadv\"" echo " -accept_rtadv\""
fi fi
@ -210,7 +231,7 @@ gen_alias6_conf()
gen_network_configuration() gen_network_configuration()
{ {
# clean routing information # clean routing information
cat /dev/null > /etc/rc.conf.d/routing echo '# Generated by one-context' | tee /etc/rc.conf.d/routing
_context_interfaces=$(get_context_interfaces) _context_interfaces=$(get_context_interfaces)
@ -228,20 +249,20 @@ gen_network_configuration()
;; ;;
esac esac
case "${method6}" in case "${ip6_method}" in
''|static) ''|static)
[ -n "${ip6}" ] && gen_iface6_conf [ -n "${ip6}" ] && gen_iface6_conf
;; ;;
auto|dhcp) auto|dhcp)
gen_dhcp6_conf gen_dhcp6_conf
;; ;;
disabled) disable)
: :
;; ;;
esac esac
has_ip6="${ip6}" has_ip6="${ip6}"
_aliases=$(get_interface_alias) _aliases=$(get_interface_alias "$_iface")
alias_num=0 alias_num=0
for _nic_alias in $_aliases; do for _nic_alias in $_aliases; do

@ -38,12 +38,6 @@ configure_network()
{ {
gen_resolvconf gen_resolvconf
gen_network_configuration > /etc/network/interfaces gen_network_configuration > /etc/network/interfaces
case "${os_id}" in
debian|ubuntu|devuan)
echo "source /etc/network/interfaces.d/*.cfg" >> /etc/network/interfaces
;;
esac
} }
stop_network() stop_network()
@ -136,8 +130,9 @@ export mtu
export gateway export gateway
export gateway6 export gateway6
export method export method
export method6 export ip6_method
export metric export metric
export ip6_metric
export dns export dns
export search_domains export search_domains
export external export external
@ -154,10 +149,6 @@ iface ${dev} inet static
netmask ${mask} netmask ${mask}
EOT EOT
if [ -n "$mtu" ]; then
echo " mtu ${mtu}"
fi
if [ -n "$gateway" ]; then if [ -n "$gateway" ]; then
echo " gateway ${gateway}" echo " gateway ${gateway}"
@ -166,12 +157,30 @@ EOT
fi fi
fi fi
if [ -n "$mtu" ]; then
echo " mtu ${mtu}"
fi
echo "" echo ""
} }
gen_dhcp_conf() gen_dhcp_conf()
{ {
echo "iface ${dev} inet dhcp" echo "iface ${dev} inet dhcp"
if [ -n "$mtu" ]; then
case "${os_id}" in
alpine)
echo " mtu ${mtu}"
;;
debian|ubuntu|devuan)
echo " pre-up ip link set dev ${dev} mtu ${mtu}"
;;
*)
exit 1
;;
esac
fi
} }
gen_alias_conf() gen_alias_conf()
@ -209,12 +218,36 @@ EOT
;; ;;
esac esac
if [ -n "${mtu}" ]; then # On Alpine Linux when using IPv6 gateway/metric options,
echo " mtu ${mtu}" # they override the metric on IPv4 routes. We better configure
fi # default route via up script.
if [ "${os_id}" = 'alpine' ] && \
[ -n "${gateway6}" ] && [ -n "${ip6_metric}" ];
then
echo " up ip -6 route add default via ${gateway6} dev ${dev} metric ${ip6_metric}"
if [ -n "${gateway6}" ]; then elif [ -n "${gateway6}" ]; then
echo " gateway ${gateway6}" echo " gateway ${gateway6}"
if [ -n "${ip6_metric}" ]; then
echo " metric ${ip6_metric}"
fi
fi
if [ -n "${mtu}" ]; then
case "${os_id}" in
alpine)
echo " mtu ${mtu}"
;;
debian|ubuntu|devuan)
# Ignores "mtu x", IPv6-only interfaces would not be configured
echo " pre-up ip link set dev ${dev} mtu ${mtu}"
echo " pre-up echo ${mtu} > /proc/sys/net/ipv6/conf/${dev}/mtu"
;;
*)
exit 1
;;
esac
fi fi
if [ -n "${ip6_ula}" ]; then if [ -n "${ip6_ula}" ]; then
@ -231,11 +264,34 @@ EOT
gen_dhcp6_conf() gen_dhcp6_conf()
{ {
if [ "${method6}" = "auto" ] ; then if [ "${ip6_method}" = "auto" ] ; then
echo "iface ${dev} inet6 auto" echo "iface ${dev} inet6 auto"
else else
echo "iface ${dev} inet6 dhcp" echo "iface ${dev} inet6 dhcp"
fi fi
case "${os_id}" in
alpine)
if [ -n "${mtu}" ]; then
echo " mtu ${mtu}"
fi
echo " pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/use_tempaddr"
;;
debian|ubuntu|devuan)
echo " privext 0" # this might not be effective in "dhcp" mode
echo " pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/use_tempaddr"
if [ -n "${mtu}" ]; then
# Ignores "mtu x", IPv6-only interfaces would not be configured
echo " pre-up ip link set dev ${dev} mtu ${mtu}"
echo " pre-up echo ${mtu} > /proc/sys/net/ipv6/conf/${dev}/mtu"
fi
;;
*)
exit 1
;;
esac
} }
gen_alias6_conf() gen_alias6_conf()
@ -272,6 +328,7 @@ EOT
gen_network_configuration() gen_network_configuration()
{ {
cat <<EOT cat <<EOT
# Generated by one-context
auto lo auto lo
iface lo inet loopback iface lo inet loopback
@ -295,14 +352,14 @@ EOT
;; ;;
esac esac
case "${method6}" in case "${ip6_method}" in
''|static) ''|static)
[ -n "${ip6}" ] && gen_iface6_conf [ -n "${ip6}" ] && gen_iface6_conf
;; ;;
auto|dhcp) auto|dhcp)
gen_dhcp6_conf gen_dhcp6_conf
;; ;;
disabled) disable)
: :
;; ;;
esac esac
@ -322,4 +379,10 @@ EOT
fi fi
done done
done done
case "${os_id}" in
debian|ubuntu|devuan)
echo "source /etc/network/interfaces.d/*.cfg"
;;
esac
} }

@ -29,9 +29,21 @@ is_network_supported()
configure_network() configure_network()
{ {
init_netplan_renderer
gen_resolvconf gen_resolvconf
gen_network_configuration > /etc/netplan/00-opennebula-generated-network.yaml gen_network_configuration > /etc/netplan/50-one-context.yaml
netplan generate netplan generate
nm_symlink_run_connections
# On Debian 10 and Ubuntu 18.04 the initial netplan apply is needed to
# set some interface parameters (e.g., MTU). Unfortunately, this deadlocks
# booting of current systems, so we execute netplan apply on the background
case "${NETCFG_NETPLAN_RENDERER}" in
''|networkd)
nohup netplan apply &>/dev/null &
;;
esac
} }
stop_network() stop_network()
@ -41,14 +53,16 @@ stop_network()
start_network() start_network()
{ {
service networking start
netplan generate netplan generate
nm_symlink_run_connections
service networking start
netplan apply netplan apply
} }
reload_network() reload_network()
{ {
netplan generate netplan generate
nm_symlink_run_connections
netplan apply netplan apply
} }
@ -73,8 +87,9 @@ export mtu
export gateway export gateway
export gateway6 export gateway6
export method export method
export method6 export ip6_method
export metric export metric
export ip6_metric
export dns export dns
export search_domains export search_domains
export external export external
@ -90,7 +105,7 @@ gen_addresses()
;; ;;
esac esac
case "${method6}" in case "${ip6_method}" in
''|static) ''|static)
[ -n "${ip6}" ] && gen_addr6_conf [ -n "${ip6}" ] && gen_addr6_conf
;; ;;
@ -114,25 +129,35 @@ gen_addresses()
gen_routes() gen_routes()
{ {
if [ -n "${gateway}" ] ; then if [ -n "${gateway}" ] && { [ -z "${method}" ] || [ "${method}" = 'static' ]; }; then
cat <<EOT cat <<EOT
- to: "0.0.0.0/0" - to: "0.0.0.0/0"
via: ${gateway} via: ${gateway}
EOT EOT
# Force default Linux IPv4 metric (man 8 route) to override
# automatic metrics calculation done by NetworkManager and unify
# behavior among different renderers.
metric=${metric:-0}
if [ -n "${metric}" ] ; then if [ -n "${metric}" ] ; then
echo " metric: ${metric}" echo " metric: ${metric}"
fi fi
fi fi
if [ -n "${gateway6}" ] ; then if [ -n "${gateway6}" ] && { [ -z "${ip6_method}" ] || [ "${ip6_method}" = 'static' ]; }; then
cat <<EOT cat <<EOT
- to: "::/0" - to: "::/0"
via: ${gateway6} via: ${gateway6}
EOT EOT
if [ -n "${metric}" ] ; then # Force default Linux IPv6 metric (man 8 route) to override
echo " metric: ${metric}" # automatic metrics calculation done by NetworkManager and unify
# behavior among different renderers.
ip6_metric=${ip6_metric:-1}
if [ -n "${ip6_metric}" ] ; then
echo " metric: ${ip6_metric}"
fi fi
fi fi
} }
@ -160,8 +185,7 @@ gen_addr6_conf()
gen_dhcp6_conf() gen_dhcp6_conf()
{ {
# TODO: is this really correct? if [ "${ip6_method}" = "auto" ] ; then
if [ "${method6}" = "auto" ] ; then
cat <<EOT cat <<EOT
accept-ra: true accept-ra: true
dhcp6: false dhcp6: false
@ -172,17 +196,52 @@ EOT
dhcp6: true dhcp6: true
EOT EOT
fi fi
cat <<EOT
ipv6-privacy: false
EOT
} }
gen_ipv6_disable() gen_ipv6_disable()
{ {
# TODO: is this really correct? Won't it affect also IPv4 link-local?
cat <<EOT cat <<EOT
accept-ra: false accept-ra: false
link-local: [] link-local: []
EOT EOT
} }
# Old NM doesn't read from /run/NetworkManager/system-connections,
# so the generated Netplan configuration is not respected. As a workaround,
# we symlink the connection files into /etc
nm_symlink_run_connections()
{
if [ "${NETCFG_NETPLAN_RENDERER}" != 'NetworkManager' ] ||
! [ -d /run/NetworkManager/system-connections ];
then
return
fi
# cleanup any old symlinks
rm -f /etc/NetworkManager/system-connections/netplan-*
case "$(NetworkManager --version 2>/dev/null)" in
1.14.*) # Debian 10
echo "WARNING: Symlinking NM's ephemeral connections into /etc" >&2
;;
*)
return
;;
esac
# symlink Netplan connection files
for _src in /run/NetworkManager/system-connections/netplan-*; do
if [ -f "${_src}" ]; then
_dst="/etc/NetworkManager/system-connections/$(basename "${_src}")"
ln -s "${_src}" "${_dst}"
fi
done
}
init_netplan_renderer() init_netplan_renderer()
{ {
if [ -z "${NETCFG_NETPLAN_RENDERER}" ] ; then if [ -z "${NETCFG_NETPLAN_RENDERER}" ] ; then
@ -190,21 +249,40 @@ init_netplan_renderer()
NETCFG_NETPLAN_RENDERER='networkd' NETCFG_NETPLAN_RENDERER='networkd'
elif command -v nmcli >/dev/null ; then elif command -v nmcli >/dev/null ; then
NETCFG_NETPLAN_RENDERER='NetworkManager' NETCFG_NETPLAN_RENDERER='NetworkManager'
else
# fallback to networkd only not to leave the variable
# uninitialized, deployment most likely won't work!
NETCFG_NETPLAN_RENDERER='networkd'
fi fi
else
# support alternative names for some configuration renderers
_netcfg_netplan_renderer=$(echo "$NETCFG_NETPLAN_RENDERER" | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
tr '[:upper:]' '[:lower:]')
# normalize renderer names and support alternatives
case "${_netcfg_netplan_renderer}" in
systemd-networkd|systemd-network|systemd|networkd)
NETCFG_NETPLAN_RENDERER='networkd'
;;
networkmanager|nm)
NETCFG_NETPLAN_RENDERER='NetworkManager'
;;
esac
fi fi
} }
gen_network_configuration() gen_network_configuration()
{ {
init_netplan_renderer if [ "${NETCFG_NETPLAN_RENDERER}" = 'NetworkManager' ]; then
nm_enable
fi
# TODO: consider to change the default to more robust NetworkManager - the
# netplan's renderer default is networkd which may encounter issues with
# version 248
cat <<EOT cat <<EOT
# Generated by one-context
network: network:
version: 2 version: 2
renderer: ${NETCFG_NETPLAN_RENDERER:-networkd} renderer: ${NETCFG_NETPLAN_RENDERER}
EOT EOT
# ethernets key must have at least one interface # ethernets key must have at least one interface
@ -227,6 +305,11 @@ EOT
echo " mtu: ${mtu}" echo " mtu: ${mtu}"
fi fi
## Requires Netplan 0.98+
# if [ -n "${mtu}" ]; then
# echo " ip6-mtu: ${mtu}"
# fi
case "${method}" in case "${method}" in
''|static) ''|static)
: # in gen_addresses : # in gen_addresses
@ -236,14 +319,14 @@ EOT
;; ;;
esac esac
case "${method6}" in case "${ip6_method}" in
''|static) ''|static)
: # in gen_addresses : # in gen_addresses
;; ;;
auto|dhcp) auto|dhcp)
gen_dhcp6_conf gen_dhcp6_conf
;; ;;
disabled) disable)
gen_ipv6_disable gen_ipv6_disable
;; ;;
esac esac

@ -41,11 +41,20 @@ stop_network()
start_network() start_network()
{ {
systemctl start systemd-networkd.service systemctl start systemd-networkd.service
# Dummy query waits until networkd is running
networkctl list &>/dev/null || :
} }
reload_network() reload_network()
{ {
# TODO: for newer systemd-networkd use
# networkctl reload && networkctl reconfigure ethX
# and fallback to service restart only if needed
systemctl restart systemd-networkd.service systemctl restart systemd-networkd.service
# Dummy query waits until networkd is running
networkctl list &>/dev/null || :
} }
# #
@ -69,8 +78,9 @@ export mtu
export gateway export gateway
export gateway6 export gateway6
export method export method
export method6 export ip6_method
export metric export metric
export ip6_metric
export dns export dns
export search_domains export search_domains
export external export external
@ -157,6 +167,11 @@ EOT
;; ;;
esac esac
cat <<EOT
[Network]
IPv6PrivacyExtensions=no
EOT
echo "" echo ""
} }
@ -197,6 +212,10 @@ EOT
if [ -n "$gateway6" ]; then if [ -n "$gateway6" ]; then
echo "Gateway=${gateway6}" echo "Gateway=${gateway6}"
if [ -n "$ip6_metric" ]; then
echo "Metric=${ip6_metric}"
fi
fi fi
if [ -n "$ip6_ula" ]; then if [ -n "$ip6_ula" ]; then
@ -221,7 +240,6 @@ EOT
gen_ipv6_disable() gen_ipv6_disable()
{ {
# TODO: is this really correct? Won't it affect also IPv4 link-local?
cat <<EOT cat <<EOT
[Network] [Network]
LinkLocalAddressing=no LinkLocalAddressing=no
@ -268,9 +286,9 @@ gen_network_configuration()
# #
# This occurs at least with systemd/networkd version 248, which is on # This occurs at least with systemd/networkd version 248, which is on
# Cent OS 8 for example. # Cent OS 8 for example.
if networkd_iface_managed "${dev}" ; then if is_networkd_iface_managed "${dev}" ; then
# networkctl up/down is not on ubuntu <21.04 # networkctl up/down is not on ubuntu <21.04
networkctl down "$dev" || true networkctl down "$dev" 2>/dev/null || true
# this is still necessary to really unconfigure the interface # this is still necessary to really unconfigure the interface
ip addr flush "$dev" ip addr flush "$dev"
@ -278,6 +296,7 @@ gen_network_configuration()
{ {
cat <<EOT cat <<EOT
# Generated by one-context
[Match] [Match]
Name=${dev} Name=${dev}
EOT EOT
@ -286,6 +305,10 @@ EOT
cat <<EOT cat <<EOT
[Link] [Link]
MTUBytes=${mtu} MTUBytes=${mtu}
## Supported since Debian 10, Ubuntu 18.04, CentOS 8
# [Network]
# IPv6MTUBytes=${mtu}
EOT EOT
fi fi
@ -300,7 +323,7 @@ EOT
;; ;;
esac esac
case "${method6}" in case "${ip6_method}" in
''|static) ''|static)
[ -n "${ip6}" ] && gen_iface6_conf [ -n "${ip6}" ] && gen_iface6_conf
;; ;;
@ -318,7 +341,7 @@ EOT
dhcp_conf='ipv6' dhcp_conf='ipv6'
fi fi
;; ;;
disabled) disable)
gen_ipv6_disable gen_ipv6_disable
;; ;;
esac esac

@ -48,6 +48,8 @@ start_network()
reload_network() reload_network()
{ {
# VH-TODO: It only reloads configuration from a disk,
# but we don't directly generate configuration files
nmcli connection reload nmcli connection reload
} }
@ -72,8 +74,9 @@ export mtu
export gateway export gateway
export gateway6 export gateway6
export method export method
export method6 export ip6_method
export metric export metric
export ip6_metric
export dns export dns
export search_domains export search_domains
export external export external
@ -83,6 +86,8 @@ export all_search_domains
wait_for_nm() wait_for_nm()
{ {
nm_enable
_timeout=30 _timeout=30
while [ "$_timeout" -gt 0 ] ; do while [ "$_timeout" -gt 0 ] ; do
if _nm_networking=$(nmcli networking 2>/dev/null) ; then if _nm_networking=$(nmcli networking 2>/dev/null) ; then
@ -106,7 +111,7 @@ wait_for_nm()
gen_iface_conf() gen_iface_conf()
{ {
nmcli con mod "${dev}" ipv4.method manual ipv4.addr "${ip}/${cidr}" nmcli con mod "${dev}" ipv4.method manual ipv4.addresses "${ip}/${cidr}"
if [ -n "$gateway" ]; then if [ -n "$gateway" ]; then
nmcli con mod "${dev}" ipv4.gateway "${gateway}" nmcli con mod "${dev}" ipv4.gateway "${gateway}"
@ -117,16 +122,19 @@ gen_iface_conf()
if [ -n "$metric" ]; then if [ -n "$metric" ]; then
nmcli con mod "${dev}" ipv4.route-metric "${metric}" nmcli con mod "${dev}" ipv4.route-metric "${metric}"
else else
nmcli con mod "${dev}" ipv4.route-metric "" # Force default Linux IPv4 metric (man 8 route) to override
# automatic metrics calculation done by NetworkManager and unify
# behavior among different renderers.
nmcli con mod "${dev}" ipv4.route-metric "0"
fi fi
} }
reset_iface() reset_iface()
{ {
# the order is significant - ip.addr cannot be erased while gateway is set # the order is significant - ip.addresses cannot be erased while gateway is set
nmcli con mod "${dev}" ipv4.route-metric "" nmcli con mod "${dev}" ipv4.route-metric ""
nmcli con mod "${dev}" ipv4.gateway "" nmcli con mod "${dev}" ipv4.gateway ""
nmcli con mod "${dev}" ipv4.addr "" nmcli con mod "${dev}" ipv4.addresses ""
} }
gen_dhcp_conf() gen_dhcp_conf()
@ -139,16 +147,16 @@ gen_dhcp_conf()
gen_alias_conf() gen_alias_conf()
{ {
nmcli con mod "${dev}" +ipv4.addr "${ip}/${cidr}" nmcli con mod "${dev}" +ipv4.addresses "${ip}/${cidr}"
} }
gen_iface6_conf() gen_iface6_conf()
{ {
nmcli con mod "${dev}" ipv6.method manual \ nmcli con mod "${dev}" ipv6.method manual \
ipv6.addr "${ip6}/${ip6_prefix_length:-64}" ipv6.addresses "${ip6}/${ip6_prefix_length:-64}"
if [ -n "$ip6_ula" ]; then if [ -n "$ip6_ula" ]; then
nmcli con mod "${dev}" +ipv6.addr "${ip6_ula}/64" nmcli con mod "${dev}" +ipv6.addresses "${ip6_ula}/64"
fi fi
if [ -n "$gateway6" ]; then if [ -n "$gateway6" ]; then
@ -157,40 +165,53 @@ gen_iface6_conf()
nmcli con mod "${dev}" ipv6.gateway "" nmcli con mod "${dev}" ipv6.gateway ""
fi fi
if [ -n "$metric" ]; then if [ -n "$ip6_metric" ]; then
nmcli con mod "${dev}" ipv6.route-metric "${metric}" nmcli con mod "${dev}" ipv6.route-metric "${ip6_metric}"
else else
nmcli con mod "${dev}" ipv6.route-metric "" # Force default Linux IPv6 metric (man 8 route) to override
# automatic metrics calculation done by NetworkManager and unify
# behavior among different renderers.
nmcli con mod "${dev}" ipv6.route-metric "1"
fi fi
# We need this to ensure link-local address has expected form
nmcli con mod "${dev}" ipv6.addr-gen-mode eui64
} }
reset_iface6() reset_iface6()
{ {
# the order is significant - ip.addr cannot be erased while gateway is set # the order is significant - ipv6.addresses cannot be erased while gateway is set
nmcli con mod "${dev}" ipv6.route-metric "" nmcli con mod "${dev}" ipv6.route-metric ""
nmcli con mod "${dev}" ipv6.gateway "" nmcli con mod "${dev}" ipv6.gateway ""
nmcli con mod "${dev}" ipv6.addr "" nmcli con mod "${dev}" ipv6.addresses ""
} }
gen_alias6_conf() gen_alias6_conf()
{ {
nmcli con mod "${dev}" +ipv6.addr "${ip6}/${ip6_prefix_length:-64}" nmcli con mod "${dev}" +ipv6.addresses "${ip6}/${ip6_prefix_length:-64}"
if [ -n "$ip6_ula" ]; then if [ -n "$ip6_ula" ]; then
nmcli con mod "${dev}" +ipv6.addr "${ip6_ula}/64" nmcli con mod "${dev}" +ipv6.addresses "${ip6_ula}/64"
fi fi
} }
gen_dhcp6_conf() gen_dhcp6_conf()
{ {
if [ "${method6}" = "auto" ] ; then if [ "${ip6_method}" = "auto" ] ; then
# TODO: is this really correct? Shouldn't be auto? # Method "ignore" relies only on SLAAC configured by the kernel,
# while the "auto" might optionally trigger also DHCPv6 client!
# https://unix.stackexchange.com/questions/440076/disable-dhcpv6-while-not-disabling-slaac-in-network-manager
_dhcp=ignore _dhcp=ignore
else else
_dhcp=dhcp # Method "auto" optionally triggers DHCPv6 client if RA has relevant
# flags (also netplan+nm configures "auto")! Method "dhcp" could
# ignore RA.
_dhcp=auto
fi fi
nmcli con mod "${dev}" ipv6.method "${_dhcp}" nmcli con mod "${dev}" ipv6.method "${_dhcp}"
nmcli con mod "${dev}" ipv6.addr-gen-mode eui64
nmcli con mod "${dev}" ipv6.ip6-privacy 0
# cleanup any leftover from the static method # cleanup any leftover from the static method
reset_iface6 reset_iface6
@ -199,6 +220,8 @@ gen_dhcp6_conf()
# arg: <interface-connection> # arg: <interface-connection>
nm_connection_exist() nm_connection_exist()
( (
# VH-TODO: We should be better checking across all connections, if there
# isn't any with our device to avoid clashes and drop/rename that one
_iface=$(nmcli --field connection.interface-name con show "$1" | awk '{print $2}') _iface=$(nmcli --field connection.interface-name con show "$1" | awk '{print $2}')
if [ "${_iface}" = "$1" ] ; then if [ "${_iface}" = "$1" ] ; then
return 0 return 0
@ -216,8 +239,15 @@ gen_network_configuration()
skip_interface && continue skip_interface && continue
# We might need to disable IPv6 and privacy directly by sysctl
_disable_ipv6=''
_disable_ipv6_privacy=''
if ! nm_connection_exist "${dev}" ; then if ! nm_connection_exist "${dev}" ; then
nmcli con add type ethernet con-name "${dev}" ifname "${dev}" nmcli con add type ethernet \
con-name "${dev}" ifname "${dev}" \
ipv4.method disabled \
ipv6.method ignore
fi fi
nmcli con mod "${dev}" connection.autoconnect yes nmcli con mod "${dev}" connection.autoconnect yes
@ -237,15 +267,27 @@ gen_network_configuration()
;; ;;
esac esac
case "${method6}" in case "${ip6_method}" in
''|static) ''|static)
[ -n "${ip6}" ] && gen_iface6_conf [ -n "${ip6}" ] && gen_iface6_conf
;; ;;
auto|dhcp) auto)
gen_dhcp6_conf
# NOTE: Hot plugged NICs configured with IPv6 method ignore
# doesn't have to properly update the IPv6 privacy.
# We better enforce them via direct sysctl.
# VH-TODO: limit only for reconfigure action?
_disable_ipv6_privacy='yes'
;;
dhcp)
gen_dhcp6_conf gen_dhcp6_conf
;; ;;
disabled) disable)
nmcli con mod "${dev}" ipv6.method disabled # NOTE: Older NMs don't support ipv6.method disabled,
# in that case we rely on hard disablemenets via sysctl
nmcli con mod "${dev}" ipv6.method disabled ||
_disable_ipv6='yes'
;; ;;
esac esac
@ -266,5 +308,13 @@ gen_network_configuration()
# 'nmcli con reload' is not enough # 'nmcli con reload' is not enough
nmcli con up "${dev}" nmcli con up "${dev}"
if [ -n "${_disable_ipv6}" ]; then
disable_ipv6 "${dev}"
fi
if [ -n "${_disable_ipv6_privacy}" ]; then
disable_ipv6_privacy "${dev}"
fi
done done
} }

@ -22,12 +22,27 @@
is_network_supported() is_network_supported()
{ {
if [ -e /etc/sysconfig/network-scripts/ifup ] || \ # Red Hat family
[ -e /etc/sysconfig/network/ifup ] ; 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.
# For safety we check if network service is enabled
# and if not, we better choose different renderer.
if command -v systemctl &>/dev/null; then
systemctl is-enabled network &>/dev/null && return 0
# NOTE: Probably not necesary test on old systems
elif chkconfig network --level 3 &>/dev/null || \
chkconfig network --level 5 &>/dev/null;
then then
return 0 return 0
fi fi
# SUSE family
elif [ -d /etc/sysconfig/network/ ]; then
return 0
fi
return 1 return 1
} }
@ -73,8 +88,9 @@ export mtu
export gateway export gateway
export gateway6 export gateway6
export method export method
export method6 export ip6_method
export metric export metric
export ip6_metric
export dns export dns
export search_domains export search_domains
export external export external
@ -85,16 +101,24 @@ export all_search_domains
gen_iface_conf() gen_iface_conf()
{ {
cat <<EOT cat <<EOT
BOOTPROTO=none
NETMASK="${mask}" NETMASK="${mask}"
IPADDR="${ip}" IPADDR="${ip}"
EOT EOT
if [ -n "${gateway}" ]; then ### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; then if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo 'BOOTPROTO=static'
if [ -n "${gateway}" ]; then
echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" \ echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" \
>> "${config_path}/ifroute-${dev}" >> "${config_path}/ifroute-${dev}"
fi
### Red Hat family ###
else else
echo 'BOOTPROTO=none'
if [ -n "${gateway}" ]; then
echo "default via ${gateway} dev ${dev} ${metric:+metric ${metric}}" \ echo "default via ${gateway} dev ${dev} ${metric:+metric ${metric}}" \
>> "${config_path}/route-${dev}" >> "${config_path}/route-${dev}"
fi fi
@ -107,7 +131,25 @@ EOT
gen_dhcp_conf() gen_dhcp_conf()
{ {
echo "BOOTPROTO=dhcp" ### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; then
if [ "${ip6_method}" = 'dhcp' ]; then
echo 'BOOTPROTO=dhcp'
else
echo 'BOOTPROTO=dhcp4'
fi
### Red Hat family ###
else
cat <<EOT
BOOTPROTO=dhcp
PERSISTENT_DHCLIENT=1
EOT
fi
if [ -n "${mtu}" ]; then
echo "MTU=${mtu}"
fi
} }
gen_alias_conf() { gen_alias_conf() {
@ -119,6 +161,7 @@ EOT
gen_iface6_conf() gen_iface6_conf()
{ {
### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; then if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "IPADDR_6A=${ip6}/${ip6_prefix_length:-64}" echo "IPADDR_6A=${ip6}/${ip6_prefix_length:-64}"
@ -126,12 +169,29 @@ gen_iface6_conf()
net.ipv6.conf.\$SYSCTL_IF.autoconf = 0 net.ipv6.conf.\$SYSCTL_IF.autoconf = 0
net.ipv6.conf.\$SYSCTL_IF.accept_ra = 0 net.ipv6.conf.\$SYSCTL_IF.accept_ra = 0
EOT EOT
if [ -n "${mtu}" ]; then
# place only if not set via IPv4 parts
if [ -z "${_set_ipv4}" ]; then
echo "MTU=${mtu}"
fi
cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}"
net.ipv6.conf.\$SYSCTL_IF.mtu = ${mtu}
EOT
fi
### Red Hat family ###
else else
cat <<EOT cat <<EOT
IPV6INIT=yes IPV6INIT=yes
IPV6ADDR=${ip6}/${ip6_prefix_length:-64} IPV6ADDR=${ip6}/${ip6_prefix_length:-64}
IPV6_AUTOCONF=no IPV6_AUTOCONF=no
EOT EOT
if [ -n "${mtu}" ]; then
echo "IPV6_MTU=${mtu}"
fi
fi fi
if [ -n "${ip6_ula}" ]; then if [ -n "${ip6_ula}" ]; then
@ -144,20 +204,46 @@ EOT
if [ -n "${gateway6}" ]; then if [ -n "${gateway6}" ]; then
if [ "${config_path}" = "/etc/sysconfig/network" ]; then if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "default ${gateway6} - ${dev}" >> "/etc/sysconfig/network/ifroute-${dev}" echo "default ${gateway6} - ${dev} ${ip6_metric:+metric ${ip6_metric}}" \
>> "/etc/sysconfig/network/ifroute-${dev}"
else else
echo "IPV6_DEFAULTGW=${gateway6}" echo "default via ${gateway6} dev ${dev} ${ip6_metric:+metric ${ip6_metric}}" \
fi >> "${config_path}/route6-${dev}"
fi fi
if [ -n "${mtu}" ]; then
echo "IPV6_MTU=${mtu}"
fi fi
} }
gen_dhcp6_conf() gen_dhcp6_conf()
{ {
if [ "${method6}" = "auto" ] ; then ### SUSE family ###
if [ "${config_path}" = "/etc/sysconfig/network" ]; 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)
if [ "${ip6_method}" = 'dhcp' ] && [ "${method}" != 'dhcp' ]; then
echo 'BOOTPROTO=dhcp6'
fi
cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}"
net.ipv6.conf.\$SYSCTL_IF.autoconf = 1
net.ipv6.conf.\$SYSCTL_IF.accept_ra = 1
net.ipv6.conf.\$SYSCTL_IF.use_tempaddr = 0
EOT
if [ -n "${mtu}" ]; then
# place only if not set via IPv4 parts
if [ -z "${_set_ipv4}" ]; then
echo "MTU=${mtu}"
fi
cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}"
net.ipv6.conf.\$SYSCTL_IF.mtu = ${mtu}
EOT
fi
### Red Hat family ###
else
if [ "${ip6_method}" = "auto" ] ; then
cat <<EOT cat <<EOT
IPV6INIT=yes IPV6INIT=yes
IPV6_AUTOCONF=yes IPV6_AUTOCONF=yes
@ -169,6 +255,13 @@ IPV6_AUTOCONF=yes
DHCPV6C=yes DHCPV6C=yes
EOT EOT
fi fi
if [ -n "${mtu}" ]; then
echo "IPV6_MTU=${mtu}"
fi
echo 'IPV6_PRIVACY=no'
fi
} }
gen_alias6_conf() gen_alias6_conf()
@ -190,8 +283,19 @@ gen_alias6_conf()
gen_network_configuration() gen_network_configuration()
{ {
### Red Hat family ###
if [ -d /etc/sysconfig/network-scripts ]; then if [ -d /etc/sysconfig/network-scripts ]; then
config_path=/etc/sysconfig/network-scripts config_path=/etc/sysconfig/network-scripts
# if disabled, enable networking via network scripts
if [ -f /etc/sysconfig/network ] &&
! grep -qx 'NETWORKING=yes' /etc/sysconfig/network;
then
sed -i -e '/^NETWORKING=/d' /etc/sysconfig/network
echo 'NETWORKING=yes' >>/etc/sysconfig/network
fi
### SUSE family ###
elif [ -d /etc/sysconfig/network ]; then elif [ -d /etc/sysconfig/network ]; then
config_path=/etc/sysconfig/network config_path=/etc/sysconfig/network
fi fi
@ -203,19 +307,27 @@ gen_network_configuration()
skip_interface && continue skip_interface && continue
# in IPv6 sections we might need to know if
# any IPv4 configuration was already placed
_set_ipv4=
# cumulative variable # cumulative variable
ipv6addr_secondaries='' ipv6addr_secondaries=''
{ {
rm -f "/etc/sysconfig/network-scripts/route-${dev}" rm -f "/etc/sysconfig/network-scripts/route-${dev}"
rm -f "/etc/sysconfig/network-scripts/route6-${dev}"
rm -f "/etc/sysconfig/network/ifroute-${dev}" rm -f "/etc/sysconfig/network/ifroute-${dev}"
rm -f "/etc/sysconfig/network/ifsysctl-${dev}" rm -f "/etc/sysconfig/network/ifsysctl-${dev}"
cat <<EOT cat <<EOT
# Generated by one-context
DEVICE=${dev} DEVICE=${dev}
NM_CONTROLLED=no NM_CONTROLLED=no
TYPE=Ethernet TYPE=Ethernet
EOT EOT
# SUSE family
if [ "${config_path}" = "/etc/sysconfig/network" ]; then if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "STARTMODE=auto" echo "STARTMODE=auto"
else else
@ -224,21 +336,25 @@ EOT
case "${method}" in case "${method}" in
''|static) ''|static)
[ -n "${ip}" ] && gen_iface_conf if [ -n "${ip}" ]; then
gen_iface_conf
_set_ipv4=yes
fi
;; ;;
dhcp) dhcp)
gen_dhcp_conf gen_dhcp_conf
_set_ipv4=yes
;; ;;
esac esac
case "${method6}" in case "${ip6_method}" in
''|static) ''|static)
[ -n "${ip6}" ] && gen_iface6_conf [ -n "${ip6}" ] && gen_iface6_conf
;; ;;
auto|dhcp) auto|dhcp)
gen_dhcp6_conf gen_dhcp6_conf
;; ;;
disabled) disable)
: :
;; ;;
esac esac

@ -4,6 +4,7 @@ After=one-context.service
Requisite=one-context.service Requisite=one-context.service
ConditionPathExists=/var/run/one-context/context.sh.local ConditionPathExists=/var/run/one-context/context.sh.local
ConditionPathExists=/var/run/one-context/context.sh.network ConditionPathExists=/var/run/one-context/context.sh.network
StartLimitInterval=0
[Service] [Service]
Type=oneshot Type=oneshot

@ -1,11 +1,11 @@
[Unit] [Unit]
Description=OpenNebula early-networking contextualization Description=OpenNebula early-networking contextualization
Wants=one-context-local.service Requires=one-context-local.service
Wants=NetworkManager.service
After=one-context-local.service After=one-context-local.service
After=NetworkManager.service After=NetworkManager.service systemd-networkd.service
Before=network-online.target Wants=network.target
Before=NetworkManager-wait-online.service Before=network.target
Before=NetworkManager-wait-online.service systemd-networkd-wait-online.service
ConditionPathExists=!/var/run/one-context/context.sh.online ConditionPathExists=!/var/run/one-context/context.sh.online
[Service] [Service]
@ -14,4 +14,4 @@ RemainAfterExit=yes
ExecStart=/usr/sbin/one-contextd online ExecStart=/usr/sbin/one-contextd online
[Install] [Install]
WantedBy=network-online.target WantedBy=multi-user.target

@ -3,6 +3,7 @@ Description=OpenNebula delayed reconfiguration
After=one-context.service After=one-context.service
Requisite=one-context.service Requisite=one-context.service
ConditionPathExists=/var/run/one-context/context.sh.network ConditionPathExists=/var/run/one-context/context.sh.network
StartLimitInterval=0
[Service] [Service]
Type=forking Type=forking

@ -4,6 +4,7 @@ After=one-context.service
Requisite=one-context.service Requisite=one-context.service
Conflicts=one-context-reconfigure-delayed.service Conflicts=one-context-reconfigure-delayed.service
ConditionPathExists=/var/run/one-context/context.sh.network ConditionPathExists=/var/run/one-context/context.sh.network
StartLimitInterval=0
[Service] [Service]
Type=oneshot Type=oneshot

@ -1,7 +1,9 @@
[Unit] [Unit]
Description=OpenNebula contextualization Description=OpenNebula contextualization
Requires=one-context-local.service Requires=one-context-local.service one-context-online.service
After=multi-user.target one-context-local.service After=multi-user.target one-context-local.service one-context-online.service
Wants=network-online.target
After=network-online.target
ConditionPathExists=!/var/run/one-context/context.sh.network ConditionPathExists=!/var/run/one-context/context.sh.network
[Service] [Service]

@ -19,7 +19,7 @@
# Set PATH # Set PATH
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
TIMEOUT=${TIMEOUT:-60} TIMEOUT=${TIMEOUT:-30}
COMMAND=${1:-reconfigure} COMMAND=${1:-reconfigure}
CONTEXT_BASE=${CONTEXT_BASE:-/var/run/one-context/context.sh} CONTEXT_BASE=${CONTEXT_BASE:-/var/run/one-context/context.sh}

@ -99,6 +99,7 @@ function execute_scripts {
# choose # choose
case "${_type}" in case "${_type}" in
local|online) local|online)
# VH-TODO: separate online scripts? have onl- for online only with onl-10-network symlink pointing to loc-10-network?
local _scripts=$(find "${SCRIPTS_DIR}" \ local _scripts=$(find "${SCRIPTS_DIR}" \
-maxdepth 1 -mindepth 1 -type f \ -maxdepth 1 -mindepth 1 -type f \
-name 'loc-*' \ -name 'loc-*' \

Loading…
Cancel
Save