F #227: Refactor loc-10-network

* F #227: Update network context

- Rework support for DHCP and DHCP6
- Support new context ETH?_METHOD and ETH?_IP6_METHOD
- Add new loc-10-network netcfg interface: initialize_network
- Wipe out stale netcfg configs to avoid conflicts
- Add reference links for some workarounds
- Fix shellcheck

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* F #227: Let networkd to use default for IPv6

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* F #227: Improve cleanup in initialize_network

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* F #227: Fix Network Manager reconfiguration

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* M #-: Update systemd service descriptions

* F #227: Adapt FreeBSD, support live reconfiguration

* B #239: Use systemctl --no-block in udev on Debian-like

* F #227: Fix unmanaged-devices with NM on ubuntu

Instead of touching 10-globally-managed-devices.conf during netcfg-nm
script we are shipping the file as part of the package. The reason is
that this file must be in place *BEFORE* Network Manager daemon is
started and reload is not sufficiant (read: it does not work). Other
option would be to restarting NM instead of reloading but that would
ifup/down all interfaces which is not a desired behavior especially if
those are in use (recontextualization).

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* F #227: Improve cleanup for NM

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* F #227: Fix initialize_network usage and cleanup

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* F #227: Workaround FreeBSD emul. NIC attach, manage rtsold

* F #227: Fix is_true argument usage

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* F #227: Improve NM reconfigure

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* F #227: Fix NM and networkd reconfiguration

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* F #227: Fix netplan's issue with empty stanzas

Signed-off-by: Petr Ospalý <pospaly@opennebula.io>

* B #239: Use abs. path /bin/systemctl in Debian-like udev

Closes #239

Co-authored-by: Vlastimil Holer <vholer@opennebula.io>
pull/244/head
Petr Ospalý 3 years ago committed by GitHub
parent 70cf13f434
commit bfba520831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,7 @@
# This enables sensible default for 'unmanaged-devices' on ubuntu:
# https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
# https://askubuntu.com/questions/882806/ethernet-device-not-managed
#
# This file must exist prior start of NetworkManager to take an effect -
# a simple reloading of the already running daemon will not work.

@ -0,0 +1,47 @@
# On NIC hotplug the delayed reconfiguration is triggered.
# NOTE: With hot-attached emulated NICs (e1000, ...) the interface
# and kernel event may appear later, even after CD-ROM is refreshed.
# Such interface doesn't configure, since new change in context
# script is not detected anymore. We hack the state files so that the
# recontextualization is forced to run.
notify 21 {
match "system" "ETHERNET";
match "type" "IFATTACH";
match "subsystem" "!vtnet[0-9]+";
action "/bin/sh -c 'test -f /var/run/one-context/context.sh.local && echo >> /var/run/one-context/context.sh.local; test -f /var/run/one-context/context.sh.network && echo >> /var/run/one-context/context.sh.network; service one-context-reconfigure-delayed onestart'";
};
notify 20 {
match "system" "ETHERNET";
match "type" "IFATTACH";
action "service one-context-reconfigure-delayed onestart";
};
notify 20 {
match "system" "IFNET";
match "type" "DETACH";
action "service one-context-reconfigure-delayed onestart";
};
# On CONTEXT CD-ROM change the immediate reconfiguration is triggered.
notify 20 {
match "system" "DEVFS";
match "subsystem" "CDEV";
match "type" "CREATE";
match "cdev" "iso9660/CONTEXT";
action "service one-context-reconfigure onestart";
};
# Handle disk resize
# NOTE: Event not generated on FreeBSD 12 and older
notify 20 {
match "system" "GEOM";
match "subsystem" "DEV";
match "type" "SIZECHANGE";
match "cdev" "!(cd[0-9]+|.*/.*|.*p[0-9]+)"; # skip CD-ROM/context, filesystems and partitions
action "service one-context-force onestart";
};
# Handle swap hot-attach
# NOTE: swap activation not supported on FreeBSD now

@ -70,7 +70,34 @@ if [ "${NETCFG_TYPE}" != 'none' ] ; then
fi fi
done done
if [ "${_found_valid_netcfg}" = 'no' ] ; then
echo "ERROR [!]: None of the requested network types is supported on: ${os_id}" >&2
exit 1
fi
else
# any action is meaningless without functioning network type
action='none'
fi
# regardless of the required_context_type we need cleanup in the 'local' stage
#
# TODO: currently we must skip cleanup during reconfigure action (check-out the
# initialize_network function) otherwise we would wiped-out running config and
# broke the system
if [ "${context_type}" = 'local' ] ; then
case "$action" in
configure|reconfigure)
initialize_network
;;
*)
echo "ERROR [!]: Unknown ACTION: ${action}" >&2
exit 1
;;
esac
fi
# this is a contextualization guard # this is a contextualization guard
# shellcheck disable=SC2154
case "${required_context_type}" in case "${required_context_type}" in
''|local|online) ''|local|online)
if [ "${required_context_type:-local}" != "${context_type}" ] ; then if [ "${required_context_type:-local}" != "${context_type}" ] ; then
@ -84,15 +111,6 @@ if [ "${NETCFG_TYPE}" != 'none' ] ; then
;; ;;
esac esac
if [ "${_found_valid_netcfg}" = 'no' ] ; then
echo "ERROR [!]: None of the requested network types is supported on: ${os_id}" >&2
exit 1
fi
else
# any action is meaningless without functioning network type
action='none'
fi
case "$action" in case "$action" in
none) none)
echo "INFO: Network will not be configured" >&2 echo "INFO: Network will not be configured" >&2

@ -29,6 +29,67 @@ is_network_supported()
false false
} }
initialize_network()
{
# shellcheck disable=SC2154
case "${os_id}" in
freebsd)
:
;;
*)
mkdir -p /etc/sysctl.d/
rm -f /etc/sysctl.d/00-opennebula-netcfg.conf
sysctl -p
;;
esac
#
# remove all stale configs from any of the previous runs
#
# TODO: improve this and support proper network unconfigure and cleanup
# on action=reconfigure too - this becomes problematic when NETCFG_TYPE is
# changed while VM is running (deleting configs will break ifdown etc.)
#
# shellcheck disable=SC2154
[ "${action}" = 'configure' ] || return 0
_context_interfaces=$(get_context_interfaces)
_iface_mac=$(get_interface_mac)
for _iface in $_context_interfaces; do
_mac=$(get_iface_var "${_iface}" "MAC")
_dev=$(get_dev "${_iface_mac}" "${_mac}")
# network-scripts
rm -f \
"/etc/sysconfig/network-scripts/route-${dev}" \
"/etc/sysconfig/network/ifroute-${dev}" \
"/etc/sysconfig/network/ifsysctl-${dev}" \
"/etc/sysconfig/network-scripts/ifcfg-${dev}" \
"/etc/sysconfig/network/ifcfg-${dev}" \
;
# networkd
rm -f "/etc/systemd/network/${dev}.network"
# nm (on RH systems it was deleted with ifcfg-*)
for _nm_con in /etc/NetworkManager/system-connections/* ; do
if [ -e "${_nm_con}" ] && grep -q "^interface-name=${_dev}$" "${_nm_con}" ; then
rm -f "${_nm_con}"
fi
done
done
# interfaces
if [ -e /etc/network/interfaces ] ; then
cat /dev/null > /etc/network/interfaces
fi
# netplan
rm -f /etc/netplan/00-opennebula-generated-network.yaml
}
configure_network() configure_network()
{ {
echo "ERROR [!]: No 'configure_network' implementation for the network type: ${NETCFG_TYPE}" >&2 echo "ERROR [!]: No 'configure_network' implementation for the network type: ${NETCFG_TYPE}" >&2
@ -57,9 +118,10 @@ reload_network()
# generic shared functions # generic shared functions
# #
# arg: <true|yes|false|no>
is_true() is_true()
( (
_value=$(eval echo "\$${1}" | \ _value=$(echo "$1" | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \ sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
tr '[:upper:]' '[:lower:]') tr '[:upper:]' '[:lower:]')
case "$_value" in case "$_value" in
@ -84,14 +146,79 @@ detect_os()
fi fi
) )
# arg: <iface>
disable_ipv6()
(
# shellcheck disable=SC2154
case "${os_id}" in
freebsd)
# TODO: these are the relevant options in /etc/rc.conf:
# ip6addrctl_enable="NO"
# ip6addrctl_policy="ipv4_prefer"
# ipv6_activate_all_interfaces="NO"
# ipv6_network_interfaces="none"
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
sysctl -w "net.ipv6.conf.${1}.disable_ipv6=1"
;;
esac
)
skip_interface() skip_interface()
{ {
[ -z "${dev}" ] && return 0 [ -z "${dev}" ] && return 0
is_true "${dhcp}" && return 1 _skip4=
is_true "${dhcp6}" && return 1 case "${method}" in
''|static)
if [ -z "${ip}" ] ; then
_skip4=yes
else
_skip4=no
fi
;;
skip)
_skip4=yes
;;
dhcp)
_skip4=no
;;
*)
echo "ERROR [!]: Unknown IPv4 method: ${method}" >&2
exit 1
;;
esac
_skip6=
case "${method6}" in
''|static)
if [ -z "${ip6}" ] ; then
_skip6=yes
else
_skip6=no
fi
;;
skip)
_skip6=yes
;;
disabled)
disable_ipv6 "${dev}"
_skip6=yes
;;
auto|dhcp)
_skip6=no
;;
*)
echo "ERROR [!]: Unknown IPv4 method: ${method6}" >&2
exit 1
;;
esac
[ -z "${ip}${ip6}" ] && return 0 if is_true "${_skip4}" && is_true "${_skip6}" ; then
return 0
fi
return 1 return 1
} }
@ -244,7 +371,6 @@ setup_ipadr_vars()
export network=$(get_network "$1") export network=$(get_network "$1")
export mask=$(get_mask "$1") export mask=$(get_mask "$1")
export cidr=$(mask2cidr "$mask") export cidr=$(mask2cidr "$mask")
export dhcp=$(get_iface_var "$1" "DHCP")
} }
# arg: <interface/alias> # arg: <interface/alias>
@ -253,7 +379,6 @@ setup_ip6adr_vars()
export ip6=$(get_iface_var "$1" "IP6") export ip6=$(get_iface_var "$1" "IP6")
export ip6_prefix_length=$(get_iface_var "$1" "IP6_PREFIX_LENGTH") export ip6_prefix_length=$(get_iface_var "$1" "IP6_PREFIX_LENGTH")
export ip6_ula=$(get_iface_var "$1" "IP6_ULA") export ip6_ula=$(get_iface_var "$1" "IP6_ULA")
export dhcp6=$(get_iface_var "$1" "DHCP6")
[ -z "$ip6" ] && ip6=$(get_iface_var "$1" "IPV6") [ -z "$ip6" ] && ip6=$(get_iface_var "$1" "IPV6")
[ -z "$ip6_prefix_length" ] && ip6_prefix_length=64 [ -z "$ip6_prefix_length" ] && ip6_prefix_length=64
@ -268,10 +393,12 @@ setup_iface_vars()
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 gateway=$(get_gateway "$1") export gateway=$(get_gateway "$1")
export gateway6=$(get_gateway6 "$1")
export metric=$(get_iface_var "$1" "METRIC") export metric=$(get_iface_var "$1" "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 gateway6=$(get_gateway6 "$1") export method=$(get_iface_var "$1" "METHOD")
export method6=$(get_iface_var "$1" "IP6_METHOD")
setup_ipadr_vars "$1" setup_ipadr_vars "$1"
setup_ip6adr_vars "$1" setup_ip6adr_vars "$1"

@ -41,18 +41,21 @@ stop_network()
{ {
service netif stop >/dev/null service netif stop >/dev/null
service routing stop >/dev/null service routing stop >/dev/null
service rtsold stop >/dev/null
} }
start_network() start_network()
{ {
service netif start >/dev/null service netif start >/dev/null
service routing start >/dev/null service routing start >/dev/null
service rtsold start >/dev/null
} }
reload_network() reload_network()
{ {
service netif restart >/dev/null service netif restart >/dev/null
service routing restart >/dev/null service routing restart >/dev/null
service rtsold restart >/dev/null
} }
# #
@ -67,19 +70,19 @@ export ip
export network export network
export mask export mask
export cidr export cidr
export dhcp
export ip6 export ip6
export ip6_prefix_length export ip6_prefix_length
export ip6_ula export ip6_ula
export dhcp6
export mac export mac
export dev export dev
export mtu export mtu
export gateway export gateway
export gateway6
export method
export method6
export metric export metric
export dns export dns
export search_domains export search_domains
export gateway6
export external export external
export detach export detach
export all_nameservers export all_nameservers
@ -114,7 +117,13 @@ gen_iface_conf()
gen_dhcp_conf() gen_dhcp_conf()
{ {
echo "ifconfig_${dev}=\"DHCP\"" echo -n "ifconfig_${dev}=\"DHCP"
if [ -n "${mtu}" ]; then
echo -n " mtu ${mtu}"
fi
echo "\""
} }
gen_alias_conf() gen_alias_conf()
@ -147,11 +156,33 @@ gen_iface6_conf()
gen_dhcp6_conf() gen_dhcp6_conf()
{ {
# TODO: FreeBSD support for DHCP6 does not seem to be great: echo -n "ifconfig_${dev}_ipv6=\"inet6"
if [ -n "${mtu}" ]; then
echo -n " mtu ${mtu}"
fi
if [ "${method6}" = "dhcp" ] ; then
echo -n " DHCP"
# 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/
# https://forums.freebsd.org/threads/is-there-a-working-dhcpv6-client-for-freebsd.60168/ # https://forums.freebsd.org/threads/is-there-a-working-dhcpv6-client-for-freebsd.60168/
echo "ERROR [!]: DHCP6 on '${os_id}' is not supported" >&2 # https://subatomicsolutions.org/8-freebsd/13-ipv4-ipv6-client-addresses-via-dhcp
return 1 _dhclient_program=$(sysrc -n dhclient_program 2>/dev/null)
if [ -z "${_dhclient_program}" ] || [ "${_dhclient_program}" = '/sbin/dhclient' ]; then
echo "WARNING [!]: DHCPv6 on '${os_id}' is poorly supported, you need a different DHCP client! You can install net/isc-dhcp44-client and put into /etc/rc.conf: dhclient_program=\"/usr/sbin/one-dual-dhclient\"" >&2
fi
fi
echo " accept_rtadv\""
# Enable Router Solicitation Deaemon
# NOTE: It's not enough to just enable the daemon during the current
# boot process, since the services to run are already evaluated. We also
# explicitly start the service on our own (but doesn't have to be correct!)
sysrc rtsold_enable="YES" >/dev/null
service rtsold start >/dev/null
} }
gen_alias6_conf() gen_alias6_conf()
@ -188,17 +219,26 @@ gen_network_configuration()
skip_interface && continue skip_interface && continue
if is_true "${dhcp}" ; then case "${method}" in
''|static)
[ -n "${ip}" ] && gen_iface_conf
;;
dhcp)
gen_dhcp_conf gen_dhcp_conf
elif [ -n "${ip}" ] ; then ;;
gen_iface_conf esac
fi
if is_true "${dhcp6}" ; then case "${method6}" in
''|static)
[ -n "${ip6}" ] && gen_iface6_conf
;;
auto|dhcp)
gen_dhcp6_conf gen_dhcp6_conf
elif [ -n "${ip6}" ] ; then ;;
gen_iface6_conf disabled)
fi :
;;
esac
has_ip6="${ip6}" has_ip6="${ip6}"
_aliases=$(get_interface_alias) _aliases=$(get_interface_alias)

@ -127,19 +127,19 @@ export ip
export network export network
export mask export mask
export cidr export cidr
export dhcp
export ip6 export ip6
export ip6_prefix_length export ip6_prefix_length
export ip6_ula export ip6_ula
export dhcp6
export mac export mac
export dev export dev
export mtu export mtu
export gateway export gateway
export gateway6
export method
export method6
export metric export metric
export dns export dns
export search_domains export search_domains
export gateway6
export external export external
export detach export detach
export all_nameservers export all_nameservers
@ -209,7 +209,7 @@ EOT
;; ;;
esac esac
if [ -n "$mtu" ]; then if [ -n "${mtu}" ]; then
echo " mtu ${mtu}" echo " mtu ${mtu}"
fi fi
@ -224,19 +224,6 @@ iface ${dev} inet6 static
address ${ip6_ula} address ${ip6_ula}
netmask 64 netmask 64
EOT EOT
case "${os_id}" in
debian|ubuntu|devuan)
cat <<EOT
autoconf 0
accept_ra 0
EOT
;;
esac
if [ -n "$mtu" ]; then
echo " mtu ${mtu}"
fi
fi fi
echo "" echo ""
@ -244,7 +231,11 @@ EOT
gen_dhcp6_conf() gen_dhcp6_conf()
{ {
if [ "${method6}" = "auto" ] ; then
echo "iface ${dev} inet6 auto"
else
echo "iface ${dev} inet6 dhcp" echo "iface ${dev} inet6 dhcp"
fi
} }
gen_alias6_conf() gen_alias6_conf()
@ -255,8 +246,6 @@ gen_alias6_conf()
iface ${dev} inet6 static iface ${dev} inet6 static
address ${ip6} address ${ip6}
netmask ${ip6_prefix_length:-64} netmask ${ip6_prefix_length:-64}
pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/autoconf
pre-up echo 0 > /proc/sys/net/ipv6/conf/${dev}/accept_ra
EOT EOT
;; ;;
debian|ubuntu|devuan) debian|ubuntu|devuan)
@ -264,8 +253,6 @@ EOT
iface ${dev} inet6 static iface ${dev} inet6 static
address ${ip6} address ${ip6}
netmask ${ip6_prefix_length:-64} netmask ${ip6_prefix_length:-64}
autoconf 0
accept_ra 0
EOT EOT
;; ;;
esac esac
@ -299,17 +286,26 @@ EOT
echo "auto ${dev}" echo "auto ${dev}"
if is_true "${dhcp}" ; then case "${method}" in
''|static)
[ -n "${ip}" ] && gen_iface_conf
;;
dhcp)
gen_dhcp_conf gen_dhcp_conf
elif [ -n "${ip}" ] ; then ;;
gen_iface_conf esac
fi
if is_true "${dhcp6}" ; then case "${method6}" in
''|static)
[ -n "${ip6}" ] && gen_iface6_conf
;;
auto|dhcp)
gen_dhcp6_conf gen_dhcp6_conf
elif [ -n "${ip6}" ] ; then ;;
gen_iface6_conf disabled)
fi :
;;
esac
_aliases=$(get_interface_alias "$_iface") _aliases=$(get_interface_alias "$_iface")

@ -64,19 +64,19 @@ export ip
export network export network
export mask export mask
export cidr export cidr
export dhcp
export ip6 export ip6
export ip6_prefix_length export ip6_prefix_length
export ip6_ula export ip6_ula
export dhcp6
export mac export mac
export dev export dev
export mtu export mtu
export gateway export gateway
export gateway6
export method
export method6
export metric export metric
export dns export dns
export search_domains export search_domains
export gateway6
export external export external
export detach export detach
export all_nameservers export all_nameservers
@ -84,15 +84,17 @@ export all_search_domains
gen_addresses() gen_addresses()
{ {
echo " addresses:" case "${method}" in
''|static)
if [ -n "${ip}" ] ; then [ -n "${ip}" ] && gen_addr_conf
gen_addr_conf ;;
fi esac
if [ -n "${ip6}" ] ; then case "${method6}" in
gen_addr6_conf ''|static)
fi [ -n "${ip6}" ] && gen_addr6_conf
;;
esac
_aliases=$(get_interface_alias "$_iface") _aliases=$(get_interface_alias "$_iface")
@ -112,8 +114,6 @@ gen_addresses()
gen_routes() gen_routes()
{ {
echo " routes:"
if [ -n "${gateway}" ] ; then if [ -n "${gateway}" ] ; then
cat <<EOT cat <<EOT
- to: "0.0.0.0/0" - to: "0.0.0.0/0"
@ -160,8 +160,26 @@ gen_addr6_conf()
gen_dhcp6_conf() gen_dhcp6_conf()
{ {
# TODO: is this really correct?
if [ "${method6}" = "auto" ] ; then
cat <<EOT
accept-ra: true
dhcp6: false
EOT
else
cat <<EOT cat <<EOT
accept-ra: true
dhcp6: true dhcp6: true
EOT
fi
}
gen_ipv6_disable()
{
# TODO: is this really correct? Won't it affect also IPv4 link-local?
cat <<EOT
accept-ra: false
link-local: []
EOT EOT
} }
@ -180,6 +198,9 @@ gen_network_configuration()
{ {
init_netplan_renderer init_netplan_renderer
# 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
network: network:
version: 2 version: 2
@ -202,19 +223,41 @@ EOT
fi fi
echo " ${dev}:" echo " ${dev}:"
if [ -n "$mtu" ]; then if [ -n "${mtu}" ]; then
echo " mtu: ${mtu}" echo " mtu: ${mtu}"
fi fi
if is_true "${dhcp}" ; then case "${method}" in
''|static)
: # in gen_addresses
;;
dhcp)
gen_dhcp_conf gen_dhcp_conf
fi ;;
esac
if is_true "${dhcp6}" ; then
case "${method6}" in
''|static)
: # in gen_addresses
;;
auto|dhcp)
gen_dhcp6_conf gen_dhcp6_conf
;;
disabled)
gen_ipv6_disable
;;
esac
_addresses=$(gen_addresses)
if [ -n "${_addresses}" ] ; then
echo " addresses:"
echo "${_addresses}"
fi fi
gen_addresses _routes=$(gen_routes)
gen_routes if [ -n "${_routes}" ] ; then
echo " routes:"
echo "${_routes}"
fi
done done
} }

@ -60,19 +60,19 @@ export ip
export network export network
export mask export mask
export cidr export cidr
export dhcp
export ip6 export ip6
export ip6_prefix_length export ip6_prefix_length
export ip6_ula export ip6_ula
export dhcp6
export mac export mac
export dev export dev
export mtu export mtu
export gateway export gateway
export gateway6
export method
export method6
export metric export metric
export dns export dns
export search_domains export search_domains
export gateway6
export external export external
export detach export detach
export all_nameservers export all_nameservers
@ -114,10 +114,50 @@ EOT
gen_dhcp_conf() gen_dhcp_conf()
{ {
case "${dhcp_conf}" in
ipv4)
cat <<EOT
[Network]
DHCP=ipv4
EOT
;;
ipv4+auto)
cat <<EOT cat <<EOT
[Network] [Network]
DHCP=ipv4 DHCP=ipv4
IPv6AcceptRA=yes
[IPv6AcceptRA]
DHCPv6Client=no
EOT
;;
ipv6)
cat <<EOT
[Network]
DHCP=ipv6
IPv6AcceptRA=yes
EOT EOT
;;
both)
cat <<EOT
[Network]
DHCP=yes
IPv6AcceptRA=yes
EOT
;;
auto)
cat <<EOT
[Network]
DHCP=no
IPv6AcceptRA=yes
[IPv6AcceptRA]
DHCPv6Client=no
EOT
;;
esac
echo ""
} }
gen_alias_conf() gen_alias_conf()
@ -126,6 +166,8 @@ gen_alias_conf()
[Address] [Address]
Address=${ip}/${cidr} Address=${ip}/${cidr}
EOT EOT
echo ""
} }
gen_iface6_conf() gen_iface6_conf()
@ -167,23 +209,44 @@ EOT
echo "" echo ""
} }
gen_dhcp6_conf() gen_alias6_conf()
{ {
cat <<EOT cat <<EOT
[Network] [Address]
DHCP=ipv6 Address=${ip6}/${ip6_prefix_length:-64}
IPv6AcceptRA=true
EOT EOT
echo ""
} }
gen_alias6_conf() gen_ipv6_disable()
{ {
# TODO: is this really correct? Won't it affect also IPv4 link-local?
cat <<EOT cat <<EOT
[Address] [Network]
Address=${ip6}/${ip6_prefix_length:-64} LinkLocalAddressing=no
IPv6AcceptRA=no
EOT EOT
echo ""
} }
# arg: <interface>
is_networkd_iface_managed()
(
_managed=$(LANG=C networkctl list -al --no-pager --no-legend | \
awk -v dev="$1" '{if ($2 == dev) print $NF;}' | \
tr '[:upper:]' '[:lower:]')
case "${_managed}" in
''|unmanaged)
return 1
;;
esac
return 0
)
gen_network_configuration() gen_network_configuration()
{ {
_context_interfaces=$(get_context_interfaces) _context_interfaces=$(get_context_interfaces)
@ -193,30 +256,74 @@ gen_network_configuration()
skip_interface && continue skip_interface && continue
# NOTE: This is needed to workaround issue with the networkd metrics.
#
# When attaching new NIC from the same vnet on a running system then
# the networkd will assign some metric to the prefix route of the first
# NIC but leave out metric for the same prefix route of the new NIC.
#
# What happens is that outgoing packets on this subnet will now always
# use the second NIC even while the incoming packets were targeted for
# the IP on the first NIC - the result is a broken connection.
#
# This occurs at least with systemd/networkd version 248, which is on
# Cent OS 8 for example.
if networkd_iface_managed "${dev}" ; then
# networkctl up/down is not on ubuntu <21.04
networkctl down "$dev" || true
# this is still necessary to really unconfigure the interface
ip addr flush "$dev"
fi
{ {
cat <<EOT cat <<EOT
[Match] [Match]
Name=${dev} Name=${dev}
EOT EOT
if [ -n "$mtu" ]; then if [ -n "${mtu}" ]; then
cat <<EOT cat <<EOT
[Link] [Link]
MTUBytes=${mtu} MTUBytes=${mtu}
EOT EOT
fi fi
if is_true "${dhcp}" ; then dhcp_conf=''
gen_dhcp_conf
elif [ -n "${ip}" ] ; then case "${method}" in
gen_iface_conf ''|static)
[ -n "${ip}" ] && gen_iface_conf
;;
dhcp)
dhcp_conf='ipv4'
;;
esac
case "${method6}" in
''|static)
[ -n "${ip6}" ] && gen_iface6_conf
;;
auto)
if [ -n "${dhcp_conf}" ] ; then
dhcp_conf='ipv4+auto'
else
dhcp_conf='auto'
fi fi
;;
if is_true "${dhcp6}" ; then dhcp)
gen_dhcp6_conf if [ -n "${dhcp_conf}" ] ; then
elif [ -n "${ip6}" ] ; then dhcp_conf='both'
gen_iface6_conf else
dhcp_conf='ipv6'
fi fi
;;
disabled)
gen_ipv6_disable
;;
esac
[ -n "${dhcp_conf}" ] && gen_dhcp_conf
_aliases=$(get_interface_alias "$_iface") _aliases=$(get_interface_alias "$_iface")

@ -34,10 +34,6 @@ configure_network()
wait_for_nm wait_for_nm
gen_resolvconf gen_resolvconf
gen_network_configuration gen_network_configuration
# this enables sensible default for 'unmanaged-devices'
mkdir -p /etc/NetworkManager/conf.d
touch /etc/NetworkManager/conf.d/10-globally-managed-devices.conf
} }
stop_network() stop_network()
@ -67,19 +63,19 @@ export ip
export network export network
export mask export mask
export cidr export cidr
export dhcp
export ip6 export ip6
export ip6_prefix_length export ip6_prefix_length
export ip6_ula export ip6_ula
export dhcp6
export mac export mac
export dev export dev
export mtu export mtu
export gateway export gateway
export gateway6
export method
export method6
export metric export metric
export dns export dns
export search_domains export search_domains
export gateway6
export external export external
export detach export detach
export all_nameservers export all_nameservers
@ -114,16 +110,31 @@ gen_iface_conf()
if [ -n "$gateway" ]; then if [ -n "$gateway" ]; then
nmcli con mod "${dev}" ipv4.gateway "${gateway}" nmcli con mod "${dev}" ipv4.gateway "${gateway}"
else
nmcli con mod "${dev}" ipv4.gateway ""
fi fi
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
nmcli con mod "${dev}" ipv4.route-metric ""
fi fi
} }
reset_iface()
{
# the order is significant - ip.addr cannot be erased while gateway is set
nmcli con mod "${dev}" ipv4.route-metric ""
nmcli con mod "${dev}" ipv4.gateway ""
nmcli con mod "${dev}" ipv4.addr ""
}
gen_dhcp_conf() gen_dhcp_conf()
{ {
nmcli con mod "${dev}" ipv4.method auto nmcli con mod "${dev}" ipv4.method auto
# cleanup any leftover from the static method
reset_iface
} }
gen_alias_conf() gen_alias_conf()
@ -142,13 +153,25 @@ gen_iface6_conf()
if [ -n "$gateway6" ]; then if [ -n "$gateway6" ]; then
nmcli con mod "${dev}" ipv6.gateway "${gateway6}" nmcli con mod "${dev}" ipv6.gateway "${gateway6}"
else
nmcli con mod "${dev}" ipv6.gateway ""
fi fi
if [ -n "$metric" ]; then if [ -n "$metric" ]; then
nmcli con mod "${dev}" ipv6.route-metric "${metric}" nmcli con mod "${dev}" ipv6.route-metric "${metric}"
else
nmcli con mod "${dev}" ipv6.route-metric ""
fi fi
} }
reset_iface6()
{
# the order is significant - ip.addr cannot be erased while gateway is set
nmcli con mod "${dev}" ipv6.route-metric ""
nmcli con mod "${dev}" ipv6.gateway ""
nmcli con mod "${dev}" ipv6.addr ""
}
gen_alias6_conf() gen_alias6_conf()
{ {
nmcli con mod "${dev}" +ipv6.addr "${ip6}/${ip6_prefix_length:-64}" nmcli con mod "${dev}" +ipv6.addr "${ip6}/${ip6_prefix_length:-64}"
@ -160,7 +183,17 @@ gen_alias6_conf()
gen_dhcp6_conf() gen_dhcp6_conf()
{ {
nmcli con mod "${dev}" ipv6.method dhcp if [ "${method6}" = "auto" ] ; then
# TODO: is this really correct? Shouldn't be auto?
_dhcp=ignore
else
_dhcp=dhcp
fi
nmcli con mod "${dev}" ipv6.method "${_dhcp}"
# cleanup any leftover from the static method
reset_iface6
} }
# arg: <interface-connection> # arg: <interface-connection>
@ -189,21 +222,32 @@ gen_network_configuration()
nmcli con mod "${dev}" connection.autoconnect yes nmcli con mod "${dev}" connection.autoconnect yes
if [ -n "$mtu" ]; then if [ -n "${mtu}" ]; then
nmcli con mod "${dev}" ethernet.mtu "${mtu}" nmcli con mod "${dev}" ethernet.mtu "${mtu}"
else
nmcli con mod "${dev}" ethernet.mtu ""
fi fi
if is_true "${dhcp}" ; then case "${method}" in
''|static)
[ -n "${ip}" ] && gen_iface_conf
;;
dhcp)
gen_dhcp_conf gen_dhcp_conf
elif [ -n "${ip}" ] ; then ;;
gen_iface_conf esac
fi
case "${method6}" in
if is_true "${dhcp6}" ; then ''|static)
[ -n "${ip6}" ] && gen_iface6_conf
;;
auto|dhcp)
gen_dhcp6_conf gen_dhcp6_conf
elif [ -n "${ip6}" ] ; then ;;
gen_iface6_conf disabled)
fi nmcli con mod "${dev}" ipv6.method disabled
;;
esac
_aliases=$(get_interface_alias "$_iface") _aliases=$(get_interface_alias "$_iface")
@ -219,5 +263,8 @@ gen_network_configuration()
fi fi
fi fi
done done
# 'nmcli con reload' is not enough
nmcli con up "${dev}"
done done
} }

@ -64,19 +64,19 @@ export ip
export network export network
export mask export mask
export cidr export cidr
export dhcp
export ip6 export ip6
export ip6_prefix_length export ip6_prefix_length
export ip6_ula export ip6_ula
export dhcp6
export mac export mac
export dev export dev
export mtu export mtu
export gateway export gateway
export gateway6
export method
export method6
export metric export metric
export dns export dns
export search_domains export search_domains
export gateway6
export external export external
export detach export detach
export all_nameservers export all_nameservers
@ -90,8 +90,8 @@ NETMASK="${mask}"
IPADDR="${ip}" IPADDR="${ip}"
EOT EOT
if [ -n "$gateway" ]; then if [ -n "${gateway}" ]; then
if [ "$config_path" = "/etc/sysconfig/network" ]; then if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" \ echo "default ${gateway} - ${dev} ${metric:+metric ${metric}}" \
>> "${config_path}/ifroute-${dev}" >> "${config_path}/ifroute-${dev}"
else else
@ -100,7 +100,7 @@ EOT
fi fi
fi fi
if [ -n "$mtu" ]; then if [ -n "${mtu}" ]; then
echo "MTU=${mtu}" echo "MTU=${mtu}"
fi fi
} }
@ -119,7 +119,7 @@ EOT
gen_iface6_conf() gen_iface6_conf()
{ {
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}"
cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}" cat <<EOT >> "/etc/sysconfig/network/ifsysctl-${dev}"
@ -134,16 +134,16 @@ IPV6_AUTOCONF=no
EOT EOT
fi fi
if [ -n "$ip6_ula" ]; then if [ -n "${ip6_ula}" ]; then
if [ "$config_path" = "/etc/sysconfig/network" ]; then if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "IPADDR_6B=${ip6_ula}/64" echo "IPADDR_6B=${ip6_ula}/64"
else else
ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6_ula}/64" ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6_ula}/64"
fi fi
fi fi
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}" >> "/etc/sysconfig/network/ifroute-${dev}"
else else
echo "IPV6_DEFAULTGW=${gateway6}" echo "IPV6_DEFAULTGW=${gateway6}"
@ -157,23 +157,30 @@ EOT
gen_dhcp6_conf() gen_dhcp6_conf()
{ {
if [ "${method6}" = "auto" ] ; then
cat <<EOT cat <<EOT
IPV6INIT=yes IPV6INIT=yes
IPV6_AUTOCONF=no IPV6_AUTOCONF=yes
EOT
else
cat <<EOT
IPV6INIT=yes
IPV6_AUTOCONF=yes
DHCPV6C=yes DHCPV6C=yes
EOT EOT
fi
} }
gen_alias6_conf() gen_alias6_conf()
{ {
if [ "$config_path" = "/etc/sysconfig/network" ]; then if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "IPADDR_A6A${alias_num}=${ip6}/${ip6_prefix_length:-64}" echo "IPADDR_A6A${alias_num}=${ip6}/${ip6_prefix_length:-64}"
else else
ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6}/${ip6_prefix_length:-64}" ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6}/${ip6_prefix_length:-64}"
fi fi
if [ -n "$ip6_ula" ]; then if [ -n "${ip6_ula}" ]; then
if [ "$config_path" = "/etc/sysconfig/network" ]; then if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "IPADDR_A6B${alias_num}=${ip6_ula}/64" echo "IPADDR_A6B${alias_num}=${ip6_ula}/64"
else else
ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6_ula}/64" ipv6addr_secondaries="${ipv6addr_secondaries} ${ip6_ula}/64"
@ -209,23 +216,32 @@ DEVICE=${dev}
NM_CONTROLLED=no NM_CONTROLLED=no
TYPE=Ethernet TYPE=Ethernet
EOT EOT
if [ "$config_path" = "/etc/sysconfig/network" ]; then if [ "${config_path}" = "/etc/sysconfig/network" ]; then
echo "STARTMODE=auto" echo "STARTMODE=auto"
else else
echo "ONBOOT=yes" echo "ONBOOT=yes"
fi fi
if is_true "${dhcp}" ; then case "${method}" in
''|static)
[ -n "${ip}" ] && gen_iface_conf
;;
dhcp)
gen_dhcp_conf gen_dhcp_conf
elif [ -n "${ip}" ] ; then ;;
gen_iface_conf esac
fi
case "${method6}" in
if is_true "${dhcp6}" ; then ''|static)
[ -n "${ip6}" ] && gen_iface6_conf
;;
auto|dhcp)
gen_dhcp6_conf gen_dhcp6_conf
elif [ -n "${ip6}" ] ; then ;;
gen_iface6_conf disabled)
fi :
;;
esac
_aliases=$(get_interface_alias "$_iface") _aliases=$(get_interface_alias "$_iface")
alias_num=0 alias_num=0

@ -18,7 +18,7 @@
### BEGIN INIT INFO ### BEGIN INIT INFO
# PROVIDE: one-context # PROVIDE: one-context
# REQUIRE: LOGIN NETWORKING # REQUIRE: LOGIN NETWORKING one-context-local
### END INIT INFO ### END INIT INFO
. /etc/rc.subr . /etc/rc.subr
@ -26,12 +26,42 @@
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
name="one_context" name="one_context"
desc="OpenNebula's context scripts" desc="OpenNebula contextualization"
rcvar="${name}_enable" rcvar="${name}_enable"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
command="/usr/sbin/one-contextd" command="/usr/sbin/one-contextd"
command_args="network" command_args="network"
one_context_get_pids()
{
# get main process PID and direct children processes
for _pid in $(pgrep -f "${command} ${command_args}$"); do
echo "${_pid}"
pgrep -P "${_pid}"
done
}
one_context_prestart()
{
if [ -f /var/run/one-context/context.sh.network ]; then
warn "Service started once already."
return 1
fi
}
one_context_stop()
{
echo -n "Stopping ${name}"
_pids=$(one_context_get_pids)
for _pid in $_pids; do
kill -- "${_pid}" >/dev/null 2>&1
done
echo '.'
}
load_rc_config $name load_rc_config $name
: ${one_context_enable:="yes"} : ${one_context_enable:="yes"}
run_rc_command "$1" run_rc_command "$1"

@ -17,9 +17,8 @@
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
### BEGIN INIT INFO ### BEGIN INIT INFO
# REQUIRE: one-context-local one-context
# PROVIDE: one-context-force # PROVIDE: one-context-force
# Short-Description: OpenNebula forced reconfiguration # REQUIRE: one-context-local one-context
### END INIT INFO ### END INIT INFO
. /etc/rc.subr . /etc/rc.subr
@ -29,10 +28,67 @@ export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/b
name="one_context_force" name="one_context_force"
desc="OpenNebula forced reconfiguration" desc="OpenNebula forced reconfiguration"
rcvar="${name}_enable" rcvar="${name}_enable"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
command="/usr/sbin/one-context-run" command="/usr/sbin/one-context-run"
command_args="force" command_args="force"
one_context_get_pids()
{
# get main process PID and direct children processes
for _pid in $(pgrep -f "${command} ${command_args}$"); do
echo "${_pid}"
pgrep -P "${_pid}"
done
}
one_context_force_status()
{
_pids=$(one_context_get_pids)
if [ -z "${_pids}" ]; then
echo "${name} is not running."
return 1
else
echo "${name} is running as pids ${_pids}."
return 0
fi
}
one_context_force_prestart()
{
if ! [ -f /var/run/one-context/context.sh.local ]; then
warn "Service one-context-local must run first."
return 1
fi
if ! [ -f /var/run/one-context/context.sh.network ]; then
warn "Service one-context must run first."
return 1
fi
_pids=$(one_context_get_pids)
if [ -n "${_pids}" ]; then
warn "${name} already running? (pids=${_pids})"
return 1
fi
return 0
}
one_context_force_stop()
{
echo -n "Stopping ${name}"
_pids=$(one_context_get_pids)
for _pid in $_pids; do
kill -- "${_pid}" >/dev/null 2>&1
done
echo '.'
}
# run without any delay # run without any delay
export TIMEOUT=0 export TIMEOUT=0

@ -18,7 +18,7 @@
### BEGIN INIT INFO ### BEGIN INIT INFO
# PROVIDE: one-context-local # PROVIDE: one-context-local
# REQUIRE: FILESYSTEMS # REQUIRE: FILESYSTEMS ldconfig
# BEFORE: NETWORKING hostname # BEFORE: NETWORKING hostname
### END INIT INFO ### END INIT INFO
@ -29,10 +29,40 @@ export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/b
name="one_context_local" name="one_context_local"
desc="OpenNebula pre-networking contextualization" desc="OpenNebula pre-networking contextualization"
rcvar="${name}_enable" rcvar="${name}_enable"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
command="/usr/sbin/one-contextd" command="/usr/sbin/one-contextd"
command_args="local" command_args="local"
one_context_get_pids()
{
# get main process PID and direct children processes
for _pid in $(pgrep -f "${command} ${command_args}$"); do
echo "${_pid}"
pgrep -P "${_pid}"
done
}
one_context_local_prestart()
{
if [ -f /var/run/one-context/context.sh.local ]; then
warn "Service started once already."
return 1
fi
}
one_context_local_stop()
{
echo -n "Stopping ${name}"
_pids=$(one_context_get_pids)
for _pid in $_pids; do
kill -- "${_pid}" >/dev/null 2>&1
done
echo '.'
}
load_rc_config $name load_rc_config $name
: ${one_context_local_enable:="yes"} : ${one_context_local_enable:="yes"}
run_rc_command "$1" run_rc_command "$1"

@ -17,8 +17,8 @@
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
### BEGIN INIT INFO ### BEGIN INIT INFO
# REQUIRE: one-context-local one-context
# PROVIDE: one-context-reconfigure # PROVIDE: one-context-reconfigure
# REQUIRE: one-context-local one-context
### END INIT INFO ### END INIT INFO
. /etc/rc.subr . /etc/rc.subr
@ -28,9 +28,69 @@ export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/b
name="one_context_reconfigure" name="one_context_reconfigure"
desc="OpenNebula reconfiguration" desc="OpenNebula reconfiguration"
rcvar="${name}_enable" rcvar="${name}_enable"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
command="/usr/sbin/one-context-run" command="/usr/sbin/one-context-run"
one_context_get_pids()
{
# get main process PID and direct children processes
for _pid in $(pgrep -f "${command}$"); do
echo "${_pid}"
pgrep -P "${_pid}"
done
}
one_context_reconfigure_status()
{
_pids=$(one_context_get_pids)
if [ -z "${_pids}" ]; then
echo "${name} is not running."
return 1
else
echo "${name} is running as pids ${_pids}."
return 0
fi
}
one_context_reconfigure_prestart()
{
if ! [ -f /var/run/one-context/context.sh.local ]; then
warn "Service one-context-local must run first."
return 1
fi
if ! [ -f /var/run/one-context/context.sh.network ]; then
warn "Service one-context must run first."
return 1
fi
# immediate reconfiguration terminates delayed reconfiguration
service one-context-reconfigure-delayed onestop >/dev/null 2>&1
_pids=$(one_context_get_pids)
if [ -n "${_pids}" ]; then
warn "${name} already running? (pids=${_pids})"
return 1
fi
return 0
}
one_context_reconfigure_stop()
{
echo -n "Stopping ${name}"
_pids=$(one_context_get_pids)
for _pid in $_pids; do
kill -- "${_pid}" >/dev/null 2>&1
done
echo '.'
}
# run without any delay # run without any delay
export TIMEOUT=0 export TIMEOUT=0

@ -17,8 +17,8 @@
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
### BEGIN INIT INFO ### BEGIN INIT INFO
# REQUIRE: one-context-local one-context
# PROVIDE: one-context-reconfigure-delayed # PROVIDE: one-context-reconfigure-delayed
# REQUIRE: one-context-local one-context
### END INIT INFO ### END INIT INFO
. /etc/rc.subr . /etc/rc.subr
@ -28,9 +28,66 @@ export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/b
name="one_context_reconfigure_delayed" name="one_context_reconfigure_delayed"
desc="OpenNebula delayed reconfiguration" desc="OpenNebula delayed reconfiguration"
rcvar="${name}_enable" rcvar="${name}_enable"
start_precmd="${name}_prestart"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
command="/usr/sbin/one-context-run" command="/usr/sbin/one-context-run"
one_context_get_pids()
{
# get main process PID and direct children processes
for _pid in $(pgrep -f "${command}$"); do
echo "${_pid}"
pgrep -P "${_pid}"
done
}
one_context_reconfigure_delayed_status()
{
_pids=$(one_context_get_pids)
if [ -z "${_pids}" ]; then
echo "${name} is not running."
return 1
else
echo "${name} is running as pids ${_pids}."
return 0
fi
}
one_context_reconfigure_delayed_prestart()
{
if ! [ -f /var/run/one-context/context.sh.local ]; then
warn "Service one-context-local must run first."
return 1
fi
if ! [ -f /var/run/one-context/context.sh.network ]; then
warn "Service one-context must run first."
return 1
fi
_pids=$(one_context_get_pids)
if [ -n "${_pids}" ]; then
warn "${name} already running? (pids=${_pids})"
return 1
fi
return 0
}
one_context_reconfigure_delayed_stop()
{
echo -n "Stopping ${name}"
_pids=$(one_context_get_pids)
for _pid in $_pids; do
kill -- "${_pid}" >/dev/null 2>&1
done
echo '.'
}
load_rc_config $name load_rc_config $name
: ${one_context_reconfigure_delayed_enable:="no"} : ${one_context_reconfigure_delayed_enable:="no"}
run_rc_command "$1" run_rc_command "$1"

@ -7,12 +7,10 @@ SUBSYSTEM=="net", ACTION=="remove", \
# On NIC hotplug the delayed reconfiguration is triggered. # On NIC hotplug the delayed reconfiguration is triggered.
SUBSYSTEM=="net", ACTION=="add", \ SUBSYSTEM=="net", ACTION=="add", \
TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service", \ RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-reconfigure-delayed.service || /usr/sbin/service one-context-reconfigure-delayed start'"
RUN+="/usr/bin/timeout 5 /usr/sbin/service one-context-reconfigure-delayed start"
SUBSYSTEM=="net", ACTION=="remove", \ SUBSYSTEM=="net", ACTION=="remove", \
TAG+="systemd", ENV{SYSTEMD_WANTS}+="one-context-reconfigure-delayed.service", \ RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-reconfigure-delayed.service || /usr/sbin/service one-context-reconfigure-delayed start'"
RUN+="/usr/bin/timeout 5 /usr/sbin/service one-context-reconfigure-delayed start"
# When CONTEXT CD-ROM is changed, it generates 2 events. This rule takes # When CONTEXT CD-ROM is changed, it generates 2 events. This rule takes
# every second event and triggers systemd service one-context-reconfigure. # every second event and triggers systemd service one-context-reconfigure.
@ -21,19 +19,19 @@ SUBSYSTEM=="block", ACTION=="change", \
ENV{ID_CDROM}=="1", \ ENV{ID_CDROM}=="1", \
ENV{ID_FS_TYPE}=="iso9660" ENV{ID_FS_LABEL_ENC}=="CONTEXT", \ ENV{ID_FS_TYPE}=="iso9660" ENV{ID_FS_LABEL_ENC}=="CONTEXT", \
ENV{SEQNUM}=="*[02468]", \ ENV{SEQNUM}=="*[02468]", \
RUN+="/usr/sbin/service one-context-reconfigure start" RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-reconfigure.service || /usr/sbin/service one-context-reconfigure start'"
# Handle disk resize # Handle disk resize
SUBSYSTEM=="block", ACTION=="change", \ SUBSYSTEM=="block", ACTION=="change", \
ENV{RESIZE}=="1", \ ENV{RESIZE}=="1", \
RUN+="/usr/sbin/service one-context-force start" RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-force.service || /usr/sbin/service one-context-force start'"
SUBSYSTEM=="scsi", ACTION=="change", \ SUBSYSTEM=="scsi", ACTION=="change", \
ENV{SDEV_UA}=="CAPACITY_DATA_HAS_CHANGED", \ ENV{SDEV_UA}=="CAPACITY_DATA_HAS_CHANGED", \
RUN+="/usr/sbin/service one-context-force start" RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-force.service || /usr/sbin/service one-context-force start'"
# Handle swap hot-attach # Handle swap hot-attach
SUBSYSTEM=="block", ACTION=="add", \ SUBSYSTEM=="block", ACTION=="add", \
ENV{ID_FS_TYPE}=="swap", \ ENV{ID_FS_TYPE}=="swap", \
ENV{DM_ACTIVATION}!="1", \ ENV{DM_ACTIVATION}!="1", \
RUN+="/usr/sbin/service one-context-force start" RUN+="/bin/sh -c '/bin/systemctl --no-block start one-context-force.service || /usr/sbin/service one-context-force start'"

@ -1,5 +1,5 @@
[Unit] [Unit]
Description=OpenNebula pre-networking contextualization script Description=OpenNebula pre-networking contextualization
DefaultDependencies=no DefaultDependencies=no
Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target
Before=network-pre.target Before=network-pre.target

@ -1,5 +1,5 @@
[Unit] [Unit]
Description=OpenNebula pre-networking contextualization script Description=OpenNebula pre-networking contextualization
Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target Wants=network-pre.target local-fs.target systemd-udev-settle.service syslog.target
Before=network-pre.target Before=network-pre.target
After=local-fs.target systemd-udev-settle.service syslog.target After=local-fs.target systemd-udev-settle.service syslog.target

@ -1,5 +1,5 @@
[Unit] [Unit]
Description=OpenNebula early-networking contextualization script Description=OpenNebula early-networking contextualization
Wants=one-context-local.service Wants=one-context-local.service
Wants=NetworkManager.service Wants=NetworkManager.service
After=one-context-local.service After=one-context-local.service

@ -1,5 +1,5 @@
[Unit] [Unit]
Description=OpenNebula delayed reconfiguration script 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

@ -1,5 +1,5 @@
[Unit] [Unit]
Description=OpenNebula reconfiguration script Description=OpenNebula reconfiguration
After=one-context.service After=one-context.service
Requisite=one-context.service Requisite=one-context.service
Conflicts=one-context-reconfigure-delayed.service Conflicts=one-context-reconfigure-delayed.service

@ -1,5 +1,5 @@
[Unit] [Unit]
Description=OpenNebula contextualization script Description=OpenNebula contextualization
Requires=network.target Requires=network.target
After=multi-user.target After=multi-user.target
ConditionPathExists=!/var/run/one-context/context.sh.local ConditionPathExists=!/var/run/one-context/context.sh.local

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

@ -0,0 +1,28 @@
#!/bin/sh
# Public domain
### For FreeBSD only:
# Modified dual-dhclient script from package net/dual-dhclient
# which conditionally triggers only a specific DHCP client
# if it's enabled in interface configuration. This script needs to
# 1. have dhclient from package net/isc-dhcp44-client installed
# 2. be explicitly configured in /etc/rc.conf via
# dhclient_program="/usr/sbin/one-dual-dhclient"
# trigger DHCPv4 client only if DHCP tag is in interface configuration
if sysrc -f /etc/rc.conf.d/network -f /etc/rc.conf -n "ifconfig_$@" | grep -q -i DHCP; then
/sbin/dhclient "$@"
fi
# trigger DHCPv6 client only if DHCP tag is in interface configuration
if sysrc -f /etc/rc.conf.d/network -f /etc/rc.conf -n "ifconfig_$@_ipv6" | grep -q -i DHCP; then
DHCLIENT6='/usr/local/sbin/dhclient'
if ! [ -x "${DHCLIENT6}" ]; then
echo "ERROR: Suitable DHCPv6 client ${DHCLIENT6} not found. Install net/isc-dhcp44-client!" >&2
exit 1
fi
"${DHCLIENT6}" -6 -nw -cf /dev/null "$@"
fi
Loading…
Cancel
Save