From 990e945ffd4b505e2cada4a65c22c858d0874b9d Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Wed, 4 Apr 2012 14:47:29 +0200 Subject: [PATCH] add mtu and macaddr to ip= --- dracut.cmdline.7.asc | 7 +++++-- modules.d/40network/ifup.sh | 10 +++++----- modules.d/40network/net-lib.sh | 27 +++++++++++++++++++++++++++ modules.d/40network/parse-ip-opts.sh | 4 ++-- modules.d/45ifcfg/write-ifcfg.sh | 3 +++ modules.d/99base/dracut-lib.sh | 26 -------------------------- 6 files changed, 42 insertions(+), 35 deletions(-) diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc index 59b3fb68..a1e06ddf 100644 --- a/dracut.cmdline.7.asc +++ b/dracut.cmdline.7.asc @@ -260,16 +260,19 @@ Network ibft::: iBFT autoconfiguration -**ip=**__:_{dhcp|on|any|dhcp6|auto6}_:: +**ip=**__:_{dhcp|on|any|dhcp6|auto6}_[:[__][:__]]:: This parameter can be specified multiple times. + dhcp|on|any|dhcp6::: get ip from dhcp server on a specific interface auto6::: do IPv6 autoconfiguration +::: optionally set on the -**ip=**__:__:__:__:__:__:_{none|off}_:: +**ip=**__:__:__:__:__:__:_{none|off|dhcp|on|any|dhcp6|auto6|ibft}_[:[__][:__]]:: explicit network configuration. If you want do define a IPv6 address, put it in brackets (e.g. [2001:DB8::1]). This parameter can be specified multiple times. ++ +::: optionally set on the **ifname=**__:__:: Assign network device name (ie eth0) to the NIC with MAC . diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh index ffae15c1..2111b412 100755 --- a/modules.d/40network/ifup.sh +++ b/modules.d/40network/ifup.sh @@ -10,9 +10,7 @@ PATH=/usr/sbin:/usr/bin:/sbin:/bin type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh -export PS4="ifup.$1.$$ + " -exec >>/run/initramfs/loginit.pipe 2>>/run/initramfs/loginit.pipe -type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh +type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh # Huh? No $1? [ -z "$1" ] && exit 1 @@ -107,6 +105,8 @@ do_static() { { echo ip link set $netif up echo wait_for_if_up $netif + [ -n "$macaddr" ] && echo ip link set address $macaddr + [ -n "$mtu" ] && echo ip link set mtu $mtu # do not flush addr for ipv6 strstr $ip '*:*:*' || \ echo ip addr flush dev $netif @@ -219,12 +219,12 @@ for p in $(getargs ip=); do ip_to_var $p # skip ibft [ "$autoconf" = "ibft" ] && continue - + # If this option isn't directed at our interface, skip it [ -n "$dev" ] && [ "$dev" != "$netif" ] && continue # Store config for later use - for i in ip srv gw mask hostname; do + for i in ip srv gw mask hostname macaddr; do eval '[ "$'$i'" ] && echo '$i'="$'$i'"' done > /tmp/net.$netif.override diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh index 4055ccf6..467c79f1 100644 --- a/modules.d/40network/net-lib.sh +++ b/modules.d/40network/net-lib.sh @@ -225,3 +225,30 @@ parse_iscsi_root() fi } +ip_to_var() { + local v=${1}: + local i + set -- + while [ -n "$v" ]; do + if [ "${v#\[*:*:*\]:}" != "$v" ]; then + # handle IPv6 address + i="${v%%\]:*}" + i="${i##\[}" + set -- "$@" "$i" + v=${v#\[$i\]:} + else + set -- "$@" "${v%%:*}" + v=${v#*:} + fi + done + + unset ip srv gw mask hostname dev autoconf macaddr mtu + case $# in + 0) autoconf="error" ;; + 1) autoconf=$1 ;; + 2) dev=$1; autoconf=$2 ;; + 3) dev=$1; autoconf=$2; mtu=$3 ;; + 4) dev=$1; autoconf=$2; mtu=$3; macaddr=$4 ;; + *) ip=$1; srv=$2; gw=$3; mask=$4; hostname=$5; dev=$6; autoconf=$7; mtu=$8; macaddr=$9 ;; + esac +} diff --git a/modules.d/40network/parse-ip-opts.sh b/modules.d/40network/parse-ip-opts.sh index 78513299..97702a27 100755 --- a/modules.d/40network/parse-ip-opts.sh +++ b/modules.d/40network/parse-ip-opts.sh @@ -5,9 +5,9 @@ # Format: # ip=[dhcp|on|any] # -# ip=:[dhcp|on|any] +# ip=:[dhcp|on|any][:[][:]] # -# ip=::::::[dhcp|on|any|none|off] +# ip=::::::{dhcp|on|any|none|off}[:[][:]] # # When supplying more than only ip= line, is mandatory and # bootdev= must contain the name of the primary interface to use for diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh index fe986df4..c072a138 100755 --- a/modules.d/45ifcfg/write-ifcfg.sh +++ b/modules.d/45ifcfg/write-ifcfg.sh @@ -38,6 +38,8 @@ for netif in $IFACES ; do echo "ONBOOT=yes" echo "NETBOOT=yes" echo "UUID=$uuid" + [ -n "$macaddr" ] && echo "MACADDR=$macaddr" + [ -n "$mtu" ] && echo "MTU=$mtu" if [ -f /tmp/net.$netif.lease ]; then strstr "$ip" '*:*:*' && echo "DHCPV6C=yes" @@ -60,6 +62,7 @@ for netif in $IFACES ; do echo "HWADDR=$(cat /sys/class/net/$netif/address)" echo "TYPE=Ethernet" echo "NAME=\"Boot Disk\"" + [ -n "$mtu" ] && echo "MTU=$mtu" } >> /tmp/ifcfg/ifcfg-$netif fi diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh index ad29451b..14ae6257 100755 --- a/modules.d/99base/dracut-lib.sh +++ b/modules.d/99base/dracut-lib.sh @@ -436,32 +436,6 @@ nfsroot_to_var() { fi } -ip_to_var() { - local v=${1}: - local i - set -- - while [ -n "$v" ]; do - if [ "${v#\[*:*:*\]:}" != "$v" ]; then - # handle IPv6 address - i="${v%%\]:*}" - i="${i##\[}" - set -- "$@" "$i" - v=${v#\[$i\]:} - else - set -- "$@" "${v%%:*}" - v=${v#*:} - fi - done - - unset ip srv gw mask hostname dev autoconf - case $# in - 0) autoconf="error" ;; - 1) autoconf=$1 ;; - 2) dev=$1; autoconf=$2 ;; - *) ip=$1; srv=$2; gw=$3; mask=$4; hostname=$5; dev=$6; autoconf=$7 ;; - esac -} - # Create udev rule match for a device with its device name, or the udev property # ID_FS_UUID or ID_FS_LABEL #