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

Commit bfba520

Browse files
ospalaxvholer
andauthored
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>
1 parent 70cf13f commit bfba520

24 files changed

+900
-193
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This enables sensible default for 'unmanaged-devices' on ubuntu:
2+
# https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1638842
3+
# https://askubuntu.com/questions/882806/ethernet-device-not-managed
4+
#
5+
# This file must exist prior start of NetworkManager to take an effect -
6+
# a simple reloading of the already running daemon will not work.
7+

src/etc/devd/context.conf##bsd

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# On NIC hotplug the delayed reconfiguration is triggered.
2+
3+
# NOTE: With hot-attached emulated NICs (e1000, ...) the interface
4+
# and kernel event may appear later, even after CD-ROM is refreshed.
5+
# Such interface doesn't configure, since new change in context
6+
# script is not detected anymore. We hack the state files so that the
7+
# recontextualization is forced to run.
8+
notify 21 {
9+
match "system" "ETHERNET";
10+
match "type" "IFATTACH";
11+
match "subsystem" "!vtnet[0-9]+";
12+
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'";
13+
};
14+
15+
notify 20 {
16+
match "system" "ETHERNET";
17+
match "type" "IFATTACH";
18+
action "service one-context-reconfigure-delayed onestart";
19+
};
20+
21+
notify 20 {
22+
match "system" "IFNET";
23+
match "type" "DETACH";
24+
action "service one-context-reconfigure-delayed onestart";
25+
};
26+
27+
# On CONTEXT CD-ROM change the immediate reconfiguration is triggered.
28+
notify 20 {
29+
match "system" "DEVFS";
30+
match "subsystem" "CDEV";
31+
match "type" "CREATE";
32+
match "cdev" "iso9660/CONTEXT";
33+
action "service one-context-reconfigure onestart";
34+
};
35+
36+
# Handle disk resize
37+
# NOTE: Event not generated on FreeBSD 12 and older
38+
notify 20 {
39+
match "system" "GEOM";
40+
match "subsystem" "DEV";
41+
match "type" "SIZECHANGE";
42+
match "cdev" "!(cd[0-9]+|.*/.*|.*p[0-9]+)"; # skip CD-ROM/context, filesystems and partitions
43+
action "service one-context-force onestart";
44+
};
45+
46+
# Handle swap hot-attach
47+
# NOTE: swap activation not supported on FreeBSD now

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,6 @@ if [ "${NETCFG_TYPE}" != 'none' ] ; then
7070
fi
7171
done
7272

73-
# this is a contextualization guard
74-
case "${required_context_type}" in
75-
''|local|online)
76-
if [ "${required_context_type:-local}" != "${context_type}" ] ; then
77-
# skip this netcfg at this stage
78-
exit 0
79-
fi
80-
;;
81-
*)
82-
echo "ERROR [!]: Unknown required context type: ${required_context_type}" >&2
83-
exit 1
84-
;;
85-
esac
86-
8773
if [ "${_found_valid_netcfg}" = 'no' ] ; then
8874
echo "ERROR [!]: None of the requested network types is supported on: ${os_id}" >&2
8975
exit 1
@@ -93,6 +79,38 @@ else
9379
action='none'
9480
fi
9581

82+
# regardless of the required_context_type we need cleanup in the 'local' stage
83+
#
84+
# TODO: currently we must skip cleanup during reconfigure action (check-out the
85+
# initialize_network function) otherwise we would wiped-out running config and
86+
# broke the system
87+
if [ "${context_type}" = 'local' ] ; then
88+
case "$action" in
89+
configure|reconfigure)
90+
initialize_network
91+
;;
92+
*)
93+
echo "ERROR [!]: Unknown ACTION: ${action}" >&2
94+
exit 1
95+
;;
96+
esac
97+
fi
98+
99+
# this is a contextualization guard
100+
# shellcheck disable=SC2154
101+
case "${required_context_type}" in
102+
''|local|online)
103+
if [ "${required_context_type:-local}" != "${context_type}" ] ; then
104+
# skip this netcfg at this stage
105+
exit 0
106+
fi
107+
;;
108+
*)
109+
echo "ERROR [!]: Unknown required context type: ${required_context_type}" >&2
110+
exit 1
111+
;;
112+
esac
113+
96114
case "$action" in
97115
none)
98116
echo "INFO: Network will not be configured" >&2

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

Lines changed: 134 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,67 @@ is_network_supported()
2929
false
3030
}
3131

32+
initialize_network()
33+
{
34+
# shellcheck disable=SC2154
35+
case "${os_id}" in
36+
freebsd)
37+
:
38+
;;
39+
*)
40+
mkdir -p /etc/sysctl.d/
41+
rm -f /etc/sysctl.d/00-opennebula-netcfg.conf
42+
sysctl -p
43+
;;
44+
esac
45+
46+
#
47+
# remove all stale configs from any of the previous runs
48+
#
49+
50+
# TODO: improve this and support proper network unconfigure and cleanup
51+
# on action=reconfigure too - this becomes problematic when NETCFG_TYPE is
52+
# changed while VM is running (deleting configs will break ifdown etc.)
53+
#
54+
# shellcheck disable=SC2154
55+
[ "${action}" = 'configure' ] || return 0
56+
57+
_context_interfaces=$(get_context_interfaces)
58+
_iface_mac=$(get_interface_mac)
59+
60+
for _iface in $_context_interfaces; do
61+
_mac=$(get_iface_var "${_iface}" "MAC")
62+
_dev=$(get_dev "${_iface_mac}" "${_mac}")
63+
64+
# network-scripts
65+
rm -f \
66+
"/etc/sysconfig/network-scripts/route-${dev}" \
67+
"/etc/sysconfig/network/ifroute-${dev}" \
68+
"/etc/sysconfig/network/ifsysctl-${dev}" \
69+
"/etc/sysconfig/network-scripts/ifcfg-${dev}" \
70+
"/etc/sysconfig/network/ifcfg-${dev}" \
71+
;
72+
73+
# networkd
74+
rm -f "/etc/systemd/network/${dev}.network"
75+
76+
# nm (on RH systems it was deleted with ifcfg-*)
77+
for _nm_con in /etc/NetworkManager/system-connections/* ; do
78+
if [ -e "${_nm_con}" ] && grep -q "^interface-name=${_dev}$" "${_nm_con}" ; then
79+
rm -f "${_nm_con}"
80+
fi
81+
done
82+
done
83+
84+
# interfaces
85+
if [ -e /etc/network/interfaces ] ; then
86+
cat /dev/null > /etc/network/interfaces
87+
fi
88+
89+
# netplan
90+
rm -f /etc/netplan/00-opennebula-generated-network.yaml
91+
}
92+
3293
configure_network()
3394
{
3495
echo "ERROR [!]: No 'configure_network' implementation for the network type: ${NETCFG_TYPE}" >&2
@@ -57,9 +118,10 @@ reload_network()
57118
# generic shared functions
58119
#
59120

121+
# arg: <true|yes|false|no>
60122
is_true()
61123
(
62-
_value=$(eval echo "\$${1}" | \
124+
_value=$(echo "$1" | \
63125
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
64126
tr '[:upper:]' '[:lower:]')
65127
case "$_value" in
@@ -84,14 +146,79 @@ detect_os()
84146
fi
85147
)
86148

149+
# arg: <iface>
150+
disable_ipv6()
151+
(
152+
# shellcheck disable=SC2154
153+
case "${os_id}" in
154+
freebsd)
155+
# TODO: these are the relevant options in /etc/rc.conf:
156+
# ip6addrctl_enable="NO"
157+
# ip6addrctl_policy="ipv4_prefer"
158+
# ipv6_activate_all_interfaces="NO"
159+
# ipv6_network_interfaces="none"
160+
echo "ERROR [!]: Disabling of IPv6 on '${os_id}' is not supported" >&2
161+
;;
162+
*)
163+
echo "net.ipv6.conf.${1}.disable_ipv6 = 1" >> /etc/sysctl.d/00-opennebula-netcfg.conf
164+
sysctl -w "net.ipv6.conf.${1}.disable_ipv6=1"
165+
;;
166+
esac
167+
)
168+
87169
skip_interface()
88170
{
89171
[ -z "${dev}" ] && return 0
90172

91-
is_true "${dhcp}" && return 1
92-
is_true "${dhcp6}" && return 1
173+
_skip4=
174+
case "${method}" in
175+
''|static)
176+
if [ -z "${ip}" ] ; then
177+
_skip4=yes
178+
else
179+
_skip4=no
180+
fi
181+
;;
182+
skip)
183+
_skip4=yes
184+
;;
185+
dhcp)
186+
_skip4=no
187+
;;
188+
*)
189+
echo "ERROR [!]: Unknown IPv4 method: ${method}" >&2
190+
exit 1
191+
;;
192+
esac
193+
194+
_skip6=
195+
case "${method6}" in
196+
''|static)
197+
if [ -z "${ip6}" ] ; then
198+
_skip6=yes
199+
else
200+
_skip6=no
201+
fi
202+
;;
203+
skip)
204+
_skip6=yes
205+
;;
206+
disabled)
207+
disable_ipv6 "${dev}"
208+
_skip6=yes
209+
;;
210+
auto|dhcp)
211+
_skip6=no
212+
;;
213+
*)
214+
echo "ERROR [!]: Unknown IPv4 method: ${method6}" >&2
215+
exit 1
216+
;;
217+
esac
93218

94-
[ -z "${ip}${ip6}" ] && return 0
219+
if is_true "${_skip4}" && is_true "${_skip6}" ; then
220+
return 0
221+
fi
95222

96223
return 1
97224
}
@@ -244,7 +371,6 @@ setup_ipadr_vars()
244371
export network=$(get_network "$1")
245372
export mask=$(get_mask "$1")
246373
export cidr=$(mask2cidr "$mask")
247-
export dhcp=$(get_iface_var "$1" "DHCP")
248374
}
249375

250376
# arg: <interface/alias>
@@ -253,7 +379,6 @@ setup_ip6adr_vars()
253379
export ip6=$(get_iface_var "$1" "IP6")
254380
export ip6_prefix_length=$(get_iface_var "$1" "IP6_PREFIX_LENGTH")
255381
export ip6_ula=$(get_iface_var "$1" "IP6_ULA")
256-
export dhcp6=$(get_iface_var "$1" "DHCP6")
257382

258383
[ -z "$ip6" ] && ip6=$(get_iface_var "$1" "IPV6")
259384
[ -z "$ip6_prefix_length" ] && ip6_prefix_length=64
@@ -268,10 +393,12 @@ setup_iface_vars()
268393
export dev=$(get_dev "$_iface_mac" "$mac")
269394
export mtu=$(get_mtu "$1")
270395
export gateway=$(get_gateway "$1")
396+
export gateway6=$(get_gateway6 "$1")
271397
export metric=$(get_iface_var "$1" "METRIC")
272398
export dns=$(get_dns "$1")
273399
export search_domains=$(get_search_domain "$1")
274-
export gateway6=$(get_gateway6 "$1")
400+
export method=$(get_iface_var "$1" "METHOD")
401+
export method6=$(get_iface_var "$1" "IP6_METHOD")
275402

276403
setup_ipadr_vars "$1"
277404
setup_ip6adr_vars "$1"

0 commit comments

Comments
 (0)