Add systemd-networkd control mode
This commit is contained in:
parent
187aa4a067
commit
229c7177e0
@ -11,7 +11,7 @@ Requires: alterator >= 5.0 libshell >= 0.1.3
|
||||
Requires: alterator-l10n >= 2.1-alt9
|
||||
Requires: alterator-sh-functions >= 0.12-alt1
|
||||
Requires: alterator-hw-functions >= 0.7-alt2
|
||||
Requires: alterator-net-functions >= 2.0.0
|
||||
Requires: alterator-net-functions >= 2.1.0
|
||||
Requires: etcnet openresolv avahi-autoipd
|
||||
# For use in netdev_is_wireless() from alterator-hw-functions.
|
||||
Requires: iw
|
||||
|
@ -13,6 +13,9 @@ NETWORKMANAGER=/usr/sbin/NetworkManager
|
||||
NMCLI=/usr/bin/nmcli
|
||||
IPA_CONFIGURED=/usr/sbin/ipa_configured
|
||||
|
||||
SYSTEMD_NETWORKD=/lib/systemd/systemd-networkd
|
||||
NETWORKCTL=/bin/networkctl
|
||||
|
||||
max_hostname_length=64
|
||||
|
||||
alterator_api_version=1
|
||||
@ -110,6 +113,7 @@ init_cache()
|
||||
if [ ! -d "$dstdir" ] ;then
|
||||
[ -d "$ifacedir" ] && cp -a "$ifacedir" "$cachedir"
|
||||
mkdir -p -- "$dstdir"
|
||||
init_systemd_networkd "$dstdir" "$name"
|
||||
fi
|
||||
|
||||
[ ! -f /etc/sysconfig/network -o -f "$cachedir/network" ] || cp -p /etc/sysconfig/network "$cachedir/network"
|
||||
@ -174,6 +178,7 @@ list_ifaces_for_restart()
|
||||
commit_cache()
|
||||
{
|
||||
local need_reload_nm=
|
||||
local need_reload_networkctl=
|
||||
|
||||
#little run-parts: check configuration before apply it
|
||||
set_locale
|
||||
@ -212,6 +217,12 @@ commit_cache()
|
||||
need_reload_nm=1
|
||||
fi
|
||||
|
||||
if [ -f "$NETWORKCTL" -a -z "$DURING_INSTALL" ] && \
|
||||
[ "$new_controlled" = "systemd-networkd" -o \
|
||||
"$old_controlled" = "systemd-networkd" ]; then
|
||||
need_reload_networkctl=1
|
||||
fi
|
||||
|
||||
if [ -z "$restart_only" ]; then
|
||||
# IPv4 configuration
|
||||
local old_config_ipv4="$(read_config_ipv "$old_ifacedir" 4)"
|
||||
@ -240,6 +251,7 @@ commit_cache()
|
||||
fi
|
||||
|
||||
mv -f -- "$new_ifacedir" "$old_ifacedir"
|
||||
commit_systemd_networkd "$old_ifacedir" "$ifname"
|
||||
fi
|
||||
|
||||
#try to restart
|
||||
@ -279,6 +291,10 @@ commit_cache()
|
||||
"$NMCLI" connection reload 2>/dev/null ||:
|
||||
fi
|
||||
|
||||
if [ -n "$need_reload_networkctl" ]; then
|
||||
"$NETWORKCTL" reload 2>/dev/null ||:
|
||||
fi
|
||||
|
||||
clear_cache
|
||||
/sbin/update_chrooted conf >&2 || :
|
||||
}
|
||||
@ -419,6 +435,9 @@ list_controlled()
|
||||
write_enum_item "NetworkManager" "NetworkManager (etcnet)"
|
||||
write_enum_item "NetworkManagerNative" "NetworkManager (native)"
|
||||
fi
|
||||
if [ -f "$SYSTEMD_NETWORKD" ] && ! is_bond "$name" && ! is_bridge "$name" && ! is_vlan "$name"; then
|
||||
write_enum_item "systemd-networkd" "systemd-networkd"
|
||||
fi
|
||||
write_enum_item "nothing" "`_ "not under control"`"
|
||||
}
|
||||
|
||||
@ -481,6 +500,7 @@ read_info()
|
||||
read_controlled()
|
||||
{
|
||||
local nm_controlled="$(read_iface_option "$1" NM_CONTROLLED)"
|
||||
local systemd_controlled="$(read_iface_option "$1" SYSTEMD_CONTROLLED)"
|
||||
local disabled="$(read_iface_option "$1" DISABLED)"
|
||||
local bootproto="$(read_iface_option "$1" BOOTPROTO)"
|
||||
|
||||
@ -488,6 +508,10 @@ read_controlled()
|
||||
if [ -f "$NETWORKMANAGER" -a ! -d "$1" ]; then
|
||||
nm_controlled="yes"
|
||||
bootproto="static"
|
||||
# Set systemd-networkd as default if NetworkManager not exists
|
||||
elif [ -f "$SYSTEMD_NETWORKD" -a ! -d "$1" ]; then
|
||||
systemd_controlled="yes"
|
||||
nm_controlled="no"
|
||||
fi
|
||||
|
||||
if [ $(write_bool "$nm_controlled") = "#t" ];then
|
||||
@ -496,6 +520,8 @@ read_controlled()
|
||||
else
|
||||
echo 'NetworkManager'
|
||||
fi
|
||||
elif [ $(write_bool "$systemd_controlled") = "#t" ];then
|
||||
echo 'systemd-networkd'
|
||||
elif [ $(write_bool "$disabled") = "#f" ];then
|
||||
echo 'etcnet'
|
||||
else
|
||||
@ -621,24 +647,33 @@ write_controlled()
|
||||
local controlled="$1";shift
|
||||
|
||||
case "$controlled" in
|
||||
systemd-networkd)
|
||||
write_iface_option "$ifacedir" DISABLED yes
|
||||
write_iface_option "$ifacedir" NM_CONTROLLED no
|
||||
write_iface_option "$ifacedir" SYSTEMD_CONTROLLED yes
|
||||
;;
|
||||
NetworkManagerNative)
|
||||
write_iface_option "$ifacedir" DISABLED yes
|
||||
write_iface_option "$ifacedir" NM_CONTROLLED yes
|
||||
write_iface_option "$ifacedir" SYSTEMD_CONTROLLED no
|
||||
write_iface_option "$ifacedir" BOOTPROTO "static"
|
||||
rm -f -- "$ifacedir/ipv4address"
|
||||
;;
|
||||
NetworkManager)
|
||||
write_iface_option "$ifacedir" DISABLED yes
|
||||
write_iface_option "$ifacedir" NM_CONTROLLED yes
|
||||
write_iface_option "$ifacedir" SYSTEMD_CONTROLLED no
|
||||
touch "$ifacedir/ipv4address"
|
||||
;;
|
||||
etcnet)
|
||||
write_iface_option "$ifacedir" DISABLED no
|
||||
write_iface_option "$ifacedir" NM_CONTROLLED no
|
||||
write_iface_option "$ifacedir" SYSTEMD_CONTROLLED no
|
||||
;;
|
||||
nothing)
|
||||
write_iface_option "$ifacedir" DISABLED yes
|
||||
write_iface_option "$ifacedir" NM_CONTROLLED no
|
||||
write_iface_option "$ifacedir" SYSTEMD_CONTROLLED no
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@ -689,12 +724,72 @@ get_etcnet_bootproto()
|
||||
echo "$bootproto"
|
||||
}
|
||||
|
||||
# Try to determine BOOTPROTO according with
|
||||
# that brain-damaged logic in etcnet for systemd-networkd
|
||||
get_systemd_networkd_bootproto()
|
||||
{
|
||||
local ipv4config="$1"; shift
|
||||
local ipv6config="$1"; shift
|
||||
local bootproto=
|
||||
|
||||
if [ -z "$ipv4config" ]; then
|
||||
case "$ipv6config" in
|
||||
dhcp) bootproto=dhcp6 ;;
|
||||
ra) bootproto=ipv6ll ;;
|
||||
*) bootproto=static ;;
|
||||
esac
|
||||
elif [ -z "$ipv6config" ]; then
|
||||
bootproto="$ipv4config"
|
||||
fi
|
||||
|
||||
case "$bootproto" in
|
||||
static)
|
||||
if [ "$ipv6config" = dhcp ]; then
|
||||
bootproto=dhcp6
|
||||
elif [ "$ipv6config" = ra ]; then
|
||||
bootproto=ipv6ll
|
||||
else
|
||||
bootproto=static
|
||||
fi
|
||||
;;
|
||||
ipv4ll)
|
||||
if [ "$ipv6config" = dhcp ]; then
|
||||
bootproto=ipv4ll
|
||||
else # static | ra
|
||||
bootproto=ip4ll
|
||||
fi
|
||||
;;
|
||||
dhcp)
|
||||
if [ "$ipv6config" = dhcp ]; then
|
||||
bootproto=dhcp
|
||||
else # static | ra
|
||||
bootproto=dhcp4
|
||||
fi
|
||||
;;
|
||||
dhcp6|ipv6ll)
|
||||
bootproto="$bootproto"
|
||||
;;
|
||||
*)
|
||||
if [ "$ipv6config" = dhcp ]; then
|
||||
bootproto=dhcp6
|
||||
elif [ "$ipv6config" = ra ]; then
|
||||
bootproto=dhcp
|
||||
else
|
||||
bootproto=static
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "$bootproto"
|
||||
}
|
||||
|
||||
write_configuration()
|
||||
{
|
||||
local ifacedir="$1";shift
|
||||
local configuration="$1";shift
|
||||
local ipv="$1"; shift
|
||||
local bootproto=
|
||||
local systemd_bootproto=
|
||||
local ipv4config= ipv6config=
|
||||
|
||||
if [ "$ipv" = 4 ]; then
|
||||
@ -708,9 +803,11 @@ write_configuration()
|
||||
fi
|
||||
|
||||
bootproto="$(get_etcnet_bootproto "$ipv4config" "$ipv6config")"
|
||||
systemd_bootproto="$(get_systemd_networkd_bootproto "$ipv4config" "$ipv6config")"
|
||||
|
||||
if [ -n "$bootproto" ]; then
|
||||
write_iface_option "$ifacedir" BOOTPROTO "$bootproto"
|
||||
write_iface_option "$ifacedir" SYSTEMD_BOOTPROTO "$systemd_bootproto"
|
||||
if [ "$ipv" = 6 -a "$ipv6config" = ra ]; then
|
||||
# Actually RA-only it is static without configuration.
|
||||
# So remove ipv6* config files.
|
||||
@ -764,6 +861,7 @@ write_iface()
|
||||
local name="$1"; shift
|
||||
local ifacedir="$cachedir/$name"
|
||||
local is_wireless=
|
||||
local systemd_bootproto=
|
||||
|
||||
# check bond settings
|
||||
if is_bond "$name" && ! check_bond "$name"; then
|
||||
@ -812,8 +910,15 @@ write_iface()
|
||||
write_iface_search "$ifacedir" "$in_search"
|
||||
fi
|
||||
|
||||
[ -n "$in_controlled" ] &&
|
||||
write_controlled "$ifacedir" "$in_controlled"
|
||||
if [ -n "$in_controlled" ]; then
|
||||
write_controlled "$ifacedir" "$in_controlled"
|
||||
systemd_bootproto="$(read_iface_option "$ifacedir" SYSTEMD_BOOTPROTO)"
|
||||
if [ "$in_controlled" = "systemd-networkd" -a -n "$systemd_bootproto" ]; then
|
||||
write_systemd_networkd "$ifacedir" "$name" "$systemd_bootproto"
|
||||
else
|
||||
del_systemd_networkd "$ifacedir" "$name"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
check_ip()
|
||||
|
Loading…
x
Reference in New Issue
Block a user