3 # We don't need to check for ip= errors here, that is handled by the
4 # cmdline parser script
6 # without $2 means this is for real netroot case
7 # or it is for manually bring up network ie. for kdump scp vmcore
8 PATH
=/usr
/sbin
:/usr
/bin
:/sbin
:/bin
10 type getarg
>/dev
/null
2>&1 || .
/lib
/dracut-lib.sh
11 type ip_to_var
>/dev
/null
2>&1 || .
/lib
/net-lib.sh
16 # $netif reads easier than $1
19 # loopback is always handled the same way
20 if [ "$netif" = "lo" ] ; then
22 ip addr add
127.0.0.1/8 dev lo
28 # dhclient-script will mark the netif up and generate the online
30 # XXX add -V vendor class and option parsing per kernel
33 local _timeout
=$
(getargs rd.net.timeout.dhcp
=)
34 local _DHCPRETRY
=$
(getargs rd.net.dhcp.retry
=)
35 _DHCPRETRY
=${_DHCPRETRY:-1}
37 [ -e /tmp
/dhclient.
$netif.pid
] && return 0
39 if ! iface_has_carrier
$netif; then
40 warn
"No carrier detected on interface $netif"
44 if [ ! -e /run
/NetworkManager
/conf.d
/10-dracut-dhclient.conf
]; then
45 mkdir
-p /run
/NetworkManager
/conf.d
46 echo '[main]' > /run
/NetworkManager
/conf.d
/10-dracut-dhclient.conf
47 echo 'dhcp=dhclient' >>/run
/NetworkManager
/conf.d
/10-dracut-dhclient.conf
50 while [ $_COUNT -lt $_DHCPRETRY ]; do
51 info
"Starting dhcp for interface $netif"
53 ${_timeout:+-timeout $_timeout} \
55 -cf /etc
/dhclient.conf \
56 -pf /tmp
/dhclient.
$netif.pid \
57 -lf /tmp
/dhclient.
$netif.lease \
61 [ $_COUNT -lt $_DHCPRETRY ] && sleep 1
63 warn
"dhcp for interface $netif failed"
68 [ -d /proc
/sys
/net
/ipv6
] && return
71 while [ ! -d /proc
/sys
/net
/ipv6
]; do
73 [ $i -gt 10 ] && break
81 echo 0 > /proc
/sys
/net
/ipv
6/conf
/$netif/forwarding
82 echo 1 > /proc
/sys
/net
/ipv
6/conf
/$netif/accept_ra
83 echo 1 > /proc
/sys
/net
/ipv
6/conf
/$netif/accept_redirects
85 wait_for_ipv6_auto
$netif
88 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp
/net.
$netif.hostname
93 # Handle static ip configuration
95 strglobin
$ip '*:*:*' && load_ipv6
97 if ! iface_has_carrier
"$netif"; then
98 warn
"No carrier detected on interface $netif"
100 elif ! linkup
"$netif"; then
101 warn
"Could not bring interface $netif up!"
105 ip route get
"$ip" |
{
107 if [ "$a" = "local" ]; then
108 warn
"Not assigning $ip to interface $netif, cause it is already assigned!"
114 [ -n "$macaddr" ] && ip link
set address
$macaddr dev
$netif
115 [ -n "$mtu" ] && ip link
set mtu
$mtu dev
$netif
116 if strglobin
$ip '*:*:*'; then
117 # note no ip addr flush for ipv6
118 ip addr add
$ip/$mask ${srv:+peer $srv} dev
$netif
119 echo 0 > /proc
/sys
/net
/ipv
6/conf
/$netif/forwarding
120 echo 1 > /proc
/sys
/net
/ipv
6/conf
/$netif/accept_ra
121 echo 1 > /proc
/sys
/net
/ipv
6/conf
/$netif/accept_redirects
122 wait_for_ipv6_dad
$netif
124 if [ -z "$srv" ]; then
125 if command -v arping2
>/dev
/null
; then
126 if arping2
-q -C 1 -c 2 -I $netif -0 $ip ; then
127 warn
"Duplicate address detected for $ip for interface $netif."
131 if ! arping
-f -q -D -c 2 -I $netif $ip ; then
132 warn
"Duplicate address detected for $ip for interface $netif."
137 ip addr flush dev
$netif
138 ip addr add
$ip/$mask ${srv:+peer $srv} brd
+ dev
$netif
141 [ -n "$gw" ] && echo ip route replace default via
$gw dev
$netif > /tmp
/net.
$netif.gw
142 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp
/net.
$netif.hostname
158 # check, if we need VLAN's for this interface
159 if [ -z "$DO_VLAN_PHY" ] && [ -e /tmp
/vlan.
${netif}.phy
]; then
161 NO_AUTO_DHCP
=yes DO_VLAN_PHY
=yes ifup
"$netif"
164 for i
in /tmp
/vlan.
*.
${netif}; do
165 [ -e "$i" ] ||
continue
169 if [ -n "$vlanname" ]; then
171 ip link add dev
"$vlanname" link
"$phydevice" type vlan id
"$(get_vid $vlanname)"
178 # Check, if interface is VLAN interface
179 if ! [ -e /tmp
/vlan.
${netif}.phy
]; then
180 for i
in /tmp
/vlan.
${netif}.
*; do
181 [ -e "$i" ] ||
continue
188 # bridge this interface?
189 if [ -z "$NO_BRIDGE_MASTER" ]; then
190 for i
in /tmp
/bridge.
*.info
; do
191 [ -e "$i" ] ||
continue
195 for ethname
in $bridgeslaves ; do
196 [ "$netif" != "$ethname" ] && continue
198 NO_BRIDGE_MASTER
=yes NO_AUTO_DHCP
=yes ifup
$ethname
200 if [ ! -e /tmp
/bridge.
$bridgename.up
]; then
201 ip link add name
$bridgename type bridge
202 echo 0 > /sys
/devices
/virtual
/net
/$bridgename/bridge
/forward_delay
203 > /tmp
/bridge.
$bridgename.up
205 ip link
set dev
$ethname master
$bridgename
212 # enslave this interface to bond?
213 if [ -z "$NO_BOND_MASTER" ]; then
214 for i
in /tmp
/bond.
*.info
; do
215 [ -e "$i" ] ||
continue
219 for slave
in $bondslaves ; do
220 [ "$netif" != "$slave" ] && continue
223 [ -e /tmp
/bond.
$bondname.up
] && exit 0
225 # wait for all slaves to show up
226 for slave
in $bondslaves ; do
227 # try to create the slave (maybe vlan or bridge)
228 NO_BOND_MASTER
=yes NO_AUTO_DHCP
=yes ifup
$slave
230 if ! ip link show dev
$slave >/dev
/null
2>&1; then
231 # wait for the last slave to show up
236 modprobe
-q -b bonding
237 echo "+$bondname" > /sys
/class
/net
/bonding_masters
2>/dev
/null
238 ip link
set $bondname down
240 # Stolen from ifup-eth
241 # add the bits to setup driver parameters here
242 for arg
in $bondoptions ; do
245 # %{value:0:1} is replaced with non-bash specific construct
246 if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then
249 for arp_ip
in $value; do
250 echo +$arp_ip > /sys
/class
/net
/${bondname}/bonding
/$key
254 echo $value > /sys
/class
/net
/${bondname}/bonding
/$key
260 for slave
in $bondslaves ; do
261 cat /sys
/class
/net
/$slave/address
> /tmp
/net.
${bondname}.
${slave}.hwaddr
262 ip link
set $slave down
263 echo "+$slave" > /sys
/class
/net
/$bondname/bonding
/slaves
267 # Set mtu on bond master
268 [ -n "$bondmtu" ] && ip link
set mtu
$bondmtu dev
$bondname
270 # add the bits to setup the needed post enslavement parameters
271 for arg
in $bondoptions ; do
274 if [ "${key}" = "primary" ]; then
275 echo $value > /sys
/class
/net
/${bondname}/bonding
/$key
279 > /tmp
/bond.
$bondname.up
281 NO_BOND_MASTER
=yes ifup
$bondname
287 if [ -z "$NO_TEAM_MASTER" ]; then
288 for i
in /tmp
/team.
*.info
; do
289 [ -e "$i" ] ||
continue
293 for slave
in $teamslaves ; do
294 [ "$netif" != "$slave" ] && continue
296 [ -e /tmp
/team.
$teammaster.up
] && exit 0
298 # wait for all slaves to show up
299 for slave
in $teamslaves ; do
300 # try to create the slave (maybe vlan or bridge)
301 NO_TEAM_MASTER
=yes NO_AUTO_DHCP
=yes ifup
$slave
303 if ! ip link show dev
$slave >/dev
/null
2>&1; then
304 # wait for the last slave to show up
309 if [ ! -e /tmp
/team.
$teammaster.up
] ; then
310 # We shall only bring up those _can_ come up
311 # in case of some slave is gone in active-backup mode
313 for slave
in $teamslaves ; do
314 teamdctl
${teammaster} port present
${slave} 2>/dev
/null \
316 ip link
set dev
$slave up
2>/dev
/null
317 if wait_for_if_up
$slave; then
318 working_slaves
="$working_slaves$slave "
321 # Do not add slaves now
322 teamd
-d -U -n -N -t $teammaster -f /etc
/teamd
/${teammaster}.conf
323 for slave
in $working_slaves; do
324 # team requires the slaves to be down before joining team
325 ip link
set dev
$slave down
327 unset TEAM_PORT_CONFIG
328 _hwaddr
=$
(cat /sys
/class
/net
/$slave/address
)
329 _subchannels
=$
(iface_get_subchannels
"$slave")
330 if [ -n "$_hwaddr" ] && [ -e "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf" ]; then
331 .
"/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf"
332 elif [ -n "$_subchannels" ] && [ -e "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf" ]; then
333 .
"/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf"
334 elif [ -e "/etc/sysconfig/network-scripts/ifcfg-${slave}" ]; then
335 .
"/etc/sysconfig/network-scripts/ifcfg-${slave}"
338 if [ -n "${TEAM_PORT_CONFIG}" ]; then
339 /usr
/bin
/teamdctl
${teammaster} port config update ${slave} "${TEAM_PORT_CONFIG}"
342 teamdctl $teammaster port add $slave
345 ip link set dev $teammaster up
347 > /tmp/team.$teammaster.up
348 NO_TEAM_MASTER=yes ifup $teammaster
355 # all synthetic interfaces done.. now check if the interface is available
356 if ! ip link show dev $netif >/dev/null 2>&1; then
360 # disable manual ifup while netroot is set for simplifying our logic
361 # in netroot case we prefer netroot to bringup $netif automaticlly
362 [ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"
364 if [ -n "$manualup" ]; then
365 >/tmp/net.$netif.manualup
366 rm -f /tmp/net.${netif}.did-setup
368 [ -e /tmp/net.${netif}.did-setup ] && exit 0
369 [ -z "$DO_VLAN" ] && \
370 [ -e /sys/class/net/$netif/address ] && \
371 [ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && exit 0
375 # No ip lines default to dhcp
378 if [ -z "$NO_AUTO_DHCP" ] && [ -z "$ip" ]; then
379 if [ "$netroot" = "dhcp6
" ]; then
385 for s in $(getargs nameserver); do
386 [ -n "$s" ] || continue
387 echo nameserver $s >> /tmp/net.$netif.resolv.conf
392 # Specific configuration, spin through the kernel command line
393 # looking for ip= lines
394 for p in $(getargs ip=); do
397 [ "$autoconf" = "ibft
" ] && continue
400 ??:??:??:??:??:??) # MAC address
401 _dev=$(iface_for_mac $dev)
402 [ -n "$_dev" ] && dev="$_dev"
404 ??-??-??-??-??-??) # MAC address in BOOTIF form
405 _dev=$(iface_for_mac $(fix_bootif $dev))
406 [ -n "$_dev" ] && dev="$_dev"
410 # If this option isn't directed at our interface, skip it
411 [ -n "$dev" ] && [ "$dev" != "$netif" ] && continue
413 # Store config for later use
414 for i in ip srv gw mask hostname macaddr mtu dns1 dns2; do
415 eval '[ "$
'$i'" ] && echo '$i'="$
'$i'"'
416 done > /tmp/net.$netif.override
418 for autoopt in $(str_replace "$autoconf" "," " "); do
428 do_ipv6auto || do_dhcp -6 ;;
436 for s in "$dns1" "$dns2" $(getargs nameserver); do
437 [ -n "$s" ] || continue
438 echo nameserver $s >> /tmp/net.$netif.resolv.conf
441 if [ $ret -eq 0 ]; then
442 > /tmp/net.${netif}.up
444 if [ -z "$DO_VLAN" ] && [ -e /sys/class/net/${netif}/address ]; then
445 > /tmp/net.$(cat /sys/class/net/${netif}/address).up
452 if [ $ret -eq 0 ]; then
454 source_hook initqueue/online $netif
455 if [ -z "$manualup" ]; then
465 # no ip option directed at our interface?
466 if [ -z "$NO_AUTO_DHCP" ] && [ ! -e /tmp/net.${netif}.up ]; then
467 if [ -e /tmp/net.bootdev ]; then
468 BOOTDEV=$(cat /tmp/net.bootdev)
469 if [ "$netif" = "$BOOTDEV" ] || [ "$BOOTDEV" = "$
(cat /sys
/class
/net
/${netif}/address
)" ]; then
474 if getargs 'ip=dhcp6'; then
478 if getargs 'ip=dhcp'; then