ifcfg/write-ifcfg: only write DEVICE for non-kernel names

Rename an interface to the kernel namespace is not allowed, so don't add
DEVICE="<iface>", if HWADDR is given.
This commit is contained in:
Harald Hoyer 2014-10-24 15:47:24 +02:00
parent 1c08ad507b
commit 3947f07d93
2 changed files with 84 additions and 21 deletions

View File

@ -551,7 +551,19 @@ find_iface_with_link() {
}
is_persistent_ethernet_name() {
case "$1" in
local _netif="$1"
local _name_assign_type="0"
[ -f "/sys/class/net/$_netif/name_assign_type" ] \
&& _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type")
# NET_NAME_ENUM 1
[ "$_name_assign_type" = "1" ] && return 1
# NET_NAME_PREDICTABLE 2
[ "$_name_assign_type" = "2" ] && return 0
case "$_netif" in
# udev persistent interface names
eno[0-9]|eno[0-9][0-9]|eno[0-9][0-9][0-9]*)
;;
@ -571,3 +583,35 @@ is_persistent_ethernet_name() {
esac
return 0
}
is_kernel_ethernet_name() {
local _netif="$1"
local _name_assign_type="1"
if [ -e "/sys/class/net/$_netif/name_assign_type" ]; then
_name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type")
case "$_name_assign_type" in
2|3|4)
# NET_NAME_PREDICTABLE 2
# NET_NAME_USER 3
# NET_NAME_RENAMED 4
return 1
;;
1|*)
# NET_NAME_ENUM 1
return 0
;;
esac
fi
# fallback to error prone manual name check
case "$_netif" in
eth[0-9]|eth[0-9][0-9]|eth[0-9][0-9][0-9]*)
return 0
;;
*)
return 1
esac
}

View File

@ -80,18 +80,41 @@ print_s390() {
return 0
}
hw_bind() {
local _netif="$1"
local _macaddr="$2"
[ -n "$_macaddr" ] \
&& echo "MACADDR=\"$_macaddr\""
print_s390 "$_netif" \
&& return 0
[ -n "$_macaddr" ] && return 0
is_persistent_ethernet_name "$_netif" && return 0
[ -f "/sys/class/net/$_netif/addr_assign_type" ] \
&& [ "$(cat "/sys/class/net/$_netif/addr_assign_type")" != "0" ] \
&& return 1
[ -f "/sys/class/net/$_netif/address" ] \
|| return 1
echo "HWADDR=\"$(cat /sys/class/net/$_netif/address)\""
}
interface_bind() {
local netif="$1"
local macaddr="$2"
if ! print_s390 $netif; then
if [ -z "$macaddr" ] && \
! is_persistent_ethernet_name "$netif" && \
[ -f /sys/class/net/$netif/addr_assign_type ] && \
[ "$(cat /sys/class/net/$netif/addr_assign_type)" = "0" ] && \
[ -f /sys/class/net/$netif/address ]; then
echo "HWADDR=\"$(cat /sys/class/net/$netif/address)\""
fi
local _netif="$1"
local _macaddr="$2"
# see, if we can bind it to some hw parms
if hw_bind "$_netif" "$_macaddr"; then
# only print out DEVICE, if it's user assigned
is_kernel_ethernet_name "$_netif" && return 0
fi
echo "DEVICE=\"$_netif\""
}
for netup in /tmp/net.*.did-setup ; do
@ -129,7 +152,8 @@ for netup in /tmp/net.*.did-setup ; do
{
echo "# Generated by dracut initrd"
echo "DEVICE=\"$netif\""
echo "NAME=\"$netif\""
interface_bind "$netif" "$macaddr"
echo "ONBOOT=yes"
echo "NETBOOT=yes"
echo "UUID=\"$uuid\""
@ -175,10 +199,7 @@ for netup in /tmp/net.*.did-setup ; do
if [ -z "$bridge" ] && [ -z "$bond" ] && [ -z "$vlan" ]; then
# standard interface
{
[ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
interface_bind "$netif" "$macaddr"
echo "TYPE=Ethernet"
echo "NAME=\"$netif\""
[ -n "$mtu" ] && echo "MTU=\"$mtu\""
} >> /tmp/ifcfg/ifcfg-$netif
fi
@ -205,16 +226,15 @@ for netup in /tmp/net.*.did-setup ; do
# write separate ifcfg file for the raw eth interface
(
echo "# Generated by dracut initrd"
echo "DEVICE=\"$slave\""
echo "NAME=\"$slave\""
echo "TYPE=Ethernet"
echo "ONBOOT=yes"
echo "NETBOOT=yes"
echo "SLAVE=yes"
echo "MASTER=\"$netif\""
echo "NAME=\"$slave\""
echo "UUID=\"$(cat /proc/sys/kernel/random/uuid)\""
unset macaddr
[ -e /tmp/net.$slave.override ] && . /tmp/net.$slave.override
[ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
interface_bind "$slave" "$macaddr"
) >> /tmp/ifcfg/ifcfg-$slave
done
@ -230,15 +250,14 @@ for netup in /tmp/net.*.did-setup ; do
# write separate ifcfg file for the raw eth interface
(
echo "# Generated by dracut initrd"
echo "DEVICE=\"$slave\""
echo "NAME=\"$slave\""
echo "TYPE=Ethernet"
echo "ONBOOT=yes"
echo "NETBOOT=yes"
echo "BRIDGE=\"$bridgename\""
echo "NAME=\"$slave\""
echo "UUID=\"$(cat /proc/sys/kernel/random/uuid)\""
unset macaddr
[ -e /tmp/net.$slave.override ] && . /tmp/net.$slave.override
[ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\""
interface_bind "$slave" "$macaddr"
) >> /tmp/ifcfg/ifcfg-$slave
done