5 ip
=$
(ip
-o -f inet addr show
$iface)
10 iface_for_remote_addr
() {
11 set -- $
(ip
-o route get to
$1)
16 set -- $
(ip
-o addr show to
$1)
21 local interface
="" mac
="$(echo $1 | sed 'y/ABCDEF/abcdef/')"
22 for interface
in /sys
/class
/net
/*; do
23 if [ $
(cat $interface/address
) = "$mac" ]; then
29 # get the iface name for the given identifier - either a MAC, IP, or iface name
32 ??
:??
:??
:??
:??
:??|??
-??
-??
-??
-??
-??
) iface_for_mac
$1 ;;
33 *:*:*|
*.
*.
*.
*) iface_for_ip
$1 ;;
38 # list the configured interfaces
40 local IFACES
="" iface_id
="" rv
=1
41 [ -e "/tmp/net.ifaces" ] && read IFACES
< /tmp
/net.ifaces
42 if { pidof udevd || pidof systemd-udevd
; } > /dev
/null
; then
43 for iface_id
in $IFACES; do
44 echo $
(iface_name
$iface_id)
48 warn
"configured_ifaces called before udev is running"
50 [ -n "$IFACES" ] && rv
=0
56 local iface
="" IFACES
=""
57 [ -e "/tmp/net.ifaces" ] && read IFACES
< /tmp
/net.ifaces
58 for iface
in $IFACES; do
59 [ -e /tmp
/net.
$iface.up
] ||
return 1
64 local prefix
="" server
="" rest
=""
65 splitsep
"$1" ":" prefix server rest
67 [0-9]*\.
[0-9]*\.
[0-9]*\.
[0-9]*) echo "$server"; return 0 ;;
73 strstr
"$(ip route get $1 2>/dev/null)" " via "
78 # ip down/flush ensures that routing info goes away as well
79 ip link
set $netif down
80 ip addr flush dev
$netif
81 echo "#empty" > /etc
/resolv.conf
82 rm -f -- /tmp
/net.
$netif.did-setup
83 [ -e /sys
/class
/net
/$netif/address
] && \
84 rm -f -- /tmp
/net.$
(cat /sys
/class
/net
/$netif/address
).did-setup
85 # TODO: send "offline" uevent?
89 local netif
="$1" f
="" gw_ip
="" netroot_ip
="" iface
="" IFACES
=""
91 [ -e /tmp
/net.
$netif.did-setup
] && return
92 [ -e /sys
/class
/net
/$netif/address
] && \
93 [ -e /tmp
/net.$
(cat /sys
/class
/net
/$netif/address
).did-setup
] && return
94 [ -e "/tmp/net.ifaces" ] && read IFACES
< /tmp
/net.ifaces
95 [ -z "$IFACES" ] && IFACES
="$netif"
96 # run the scripts written by ifup
97 [ -e /tmp
/net.
$netif.hostname
] && .
/tmp
/net.
$netif.hostname
98 [ -e /tmp
/net.
$netif.override
] && .
/tmp
/net.
$netif.override
99 [ -e /tmp
/dhclient.
$netif.dhcpopts
] && .
/tmp
/dhclient.
$netif.dhcpopts
101 [ -e /tmp
/net.
$netif.resolv.conf
] && \
102 cp -f /tmp
/net.
$netif.resolv.conf
/etc
/resolv.conf
103 [ -e /tmp
/net.
$netif.gw
] && .
/tmp
/net.
$netif.gw
106 for _p
in $
(getargs rd.route
); do
107 route_to_var
"$_p" ||
continue
108 [ -n "$route_dev" ] && [ "$route_dev" != "$netif" ] && continue
109 ip route add
"$route_mask" ${route_gw:+via "$route_gw"} ${route_dev:+dev "$route_dev"}
110 if strstr
":" "$route_mask"; then
111 printf -- "%s\n" "$route_mask ${route_gw:+via $route_gw} ${route_dev:+dev $route_dev}" \
112 > /tmp
/net.route6.
"$netif"
114 printf -- "%s\n" "$route_mask ${route_gw:+via $route_gw} ${route_dev:+dev $route_dev}" \
115 > /tmp
/net.route.
"$netif"
119 # Handle STP Timeout: arping the default gateway.
120 # (or the root server, if a) it's local or b) there's no gateway.)
121 # Note: This assumes that if no router is present the
122 # root server is on the same subnet.
124 # Get DHCP-provided router IP, or the cmdline-provided "gw=" argument
125 [ -n "$new_routers" ] && gw_ip
=${new_routers%%,*}
126 [ -n "$gw" ] && gw_ip
=$gw
128 # Get the "netroot" IP (if there's an IP address in there)
129 netroot_ip
=$
(get_netroot_ip
$netroot)
131 # try netroot if it's local (or there's no gateway)
132 if ip_is_local
$netroot_ip ||
[ -z "$gw_ip" ]; then
139 if [ -f /sys
/class
/net
/$netif/device
/layer2
]; then
140 read layer2
< /sys
/class
/net
/$netif/device
/layer2
143 if [ "$layer2" != "0" ] && [ -n "$dest" ] && ! strstr
"$dest" ":"; then
144 arping
-q -f -w 60 -I $netif $dest || info
"Resolving $dest via ARP on $netif failed"
148 > /tmp
/net.
$netif.did-setup
149 [ -e /sys
/class
/net
/$netif/address
] && \
150 > /tmp
/net.$
(cat /sys
/class
/net
/$netif/address
).did-setup
154 local netif
="$1" IFACES
="" f
="" i
=""
155 [ -e /tmp
/net.ifaces
] && read IFACES
< /tmp
/net.ifaces
156 # Add $netif to the front of IFACES (if it's not there already).
158 for i
in $IFACES; do [ "$i" != "$netif" ] && set -- "$@" "$i"; done
161 for f
in /tmp
/dhclient.
$i.
*; do
162 [ -f $f ] && cp -f $f /tmp
/net.
${f#/tmp/dhclient.}
165 echo $IFACES > /tmp
/.net.ifaces.new
166 mv /tmp
/.net.ifaces.new
/tmp
/net.ifaces
170 local name
="$1" mac
="$2" num
=-1 n
=""
171 # if it's already set, return the existing name
172 for n
in $
(getargs ifname
=); do
173 strstr
"$n" "$mac" && echo ${n%%:*} && return
175 # otherwise, pick a new name and use that
178 [ -e /sys
/class
/net
/$name$num ] && continue
179 for n
in $
(getargs ifname
=); do
180 [ "$name$num" = "${n%%:*}" ] && continue 2
184 echo "ifname=$name$num:$mac" >> /etc
/cmdline.d
/45-ifname.conf
188 # pxelinux provides macaddr '-' separated, but we need ':'
192 macaddr
=$
(printf '%s:' ${macaddr})
194 # strip hardware type field from pxelinux
195 [ -n "${macaddr%??:??:??:??:??:??}" ] && macaddr
=${macaddr#??:}
196 # return macaddr with lowercase alpha characters expected by udev
197 echo $macaddr |
sed 'y/ABCDEF/abcdef/'
202 modprobe
-q iscsi_ibft
204 for iface
in /sys
/firmware
/ibft
/ethernet
*; do
206 local dhcp
="" ip
="" gw
="" mask
="" hostname
=""
209 [ -e ${iface}/mac
] ||
continue
210 mac
=$
(read a
< ${iface}/mac
; echo $a)
211 [ -z "$mac" ] && continue
212 dev
=$
(set_ifname ibft
$mac)
214 [ -e /tmp
/net.
${dev}.has_ibft_config
] && continue
216 [ -e ${iface}/dhcp
] && dhcp
=$
(read a
< ${iface}/dhcp
; echo $a)
218 if [ -n "$dhcp" ]; then
220 elif [ -e ${iface}/ip-addr
]; then
221 [ -e ${iface}/ip-addr
] && ip
=$
(read a
< ${iface}/ip-addr
; echo $a)
222 # skip not assigned ip adresses
223 [ "$ip" = "0.0.0.0" ] && continue
224 [ -e ${iface}/gateway
] && gw
=$
(read a
< ${iface}/gateway
; echo $a)
225 [ -e ${iface}/subnet-mask
] && mask
=$
(read a
< ${iface}/subnet-mask
; echo $a)
226 [ -e ${iface}/primary-dns
] && dns1
=$
(read a
< ${iface}/primary-dns
; echo $a)
227 [ -e ${iface}/secondary-dns
] && dns2
=$
(read a
< ${iface}/secondary-dns
; echo $a)
228 [ -e ${iface}/hostname
] && hostname
=$
(read a
< ${iface}/hostname
; echo $a)
229 if [ -n "$ip" ] && [ -n "$mask" ]; then
230 echo "ip=$ip::$gw:$mask:$hostname:$dev:none${dns1:+:$dns1}${dns2:+:$dns2}"
232 warn
"${iface} does not contain a valid iBFT configuration"
235 warn
"subnet-mask=$mask"
236 warn
"hostname=$hostname"
239 info
"${iface} does not contain a valid iBFT configuration"
240 ls -l ${iface} | vinfo
243 if [ -e ${iface}/vlan
]; then
244 vlan
=$
(read a
< ${iface}/vlan
; echo $a)
245 if [ "$vlan" -ne "0" ]; then
248 echo "vlan=$dev.$vlan:$dev"
249 echo $mac > /tmp
/net.
${dev}.
${vlan}.has_ibft_config
252 echo "vlan=$vlan:$dev"
253 echo $mac > /tmp
/net.
${vlan}.has_ibft_config
257 echo $mac > /tmp
/net.
${dev}.has_ibft_config
260 echo $mac > /tmp
/net.
${dev}.has_ibft_config
264 ) >> /etc
/cmdline.d
/40-ibft.conf
272 # extract authentication info
277 # allow empty authinfo to allow having an @ in iscsi_target_name like this:
278 # netroot=iscsi:@192.168.1.100::3260::iqn.2009-01.com.example:testdi@sk
279 if [ -n "$authinfo" ]; then
284 if [ $# -gt 4 ]; then
285 warn
"Wrong authentication info in iscsi: parameter!"
290 if [ $# -gt 2 ]; then
301 iscsi_target_ip
=${v#[[]}
302 iscsi_target_ip
=${iscsi_target_ip%%[]]*}
303 v
=${v#[[]$iscsi_target_ip[]]:}
306 iscsi_target_ip
=${v%%[:]*}
307 v
=${v#$iscsi_target_ip:}
311 unset iscsi_target_name
312 # extract target name
315 iscsi_target_name
=iqn.
${v##*:iqn.}
319 iscsi_target_name
=eui.
${v##*:eui.}
323 iscsi_target_name
=naa.
${v##*:naa.}
334 iscsi_protocol
=$1; shift # ignored
335 iscsi_target_port
=$1; shift
337 if [ -n "$iscsi_target_name" ]; then
338 if [ $# -eq 3 ]; then
339 iscsi_iface_name
=$1; shift
341 if [ $# -eq 2 ]; then
342 iscsi_netdev_name
=$1; shift
345 if [ $# -ne 0 ]; then
346 warn
"Invalid parameter in iscsi: parameter!"
353 if [ $# -gt 3 ] && [ -n "$1$2" ]; then
354 if [ -z "$3" ] ||
[ "$3" -ge 0 ] 2>/dev
/null
; then
355 iscsi_iface_name
=$1; shift
356 iscsi_netdev_name
=$1; shift
362 iscsi_target_name
=$
(printf "%s:" "$@")
363 iscsi_target_name
=${iscsi_target_name%:}
370 while [ -n "$v" ]; do
371 if [ "${v#\[*:*:*\]:}" != "$v" ]; then
372 # handle IPv6 address
378 set -- "$@" "${v%%:*}"
383 unset ip srv gw mask hostname dev autoconf macaddr mtu dns1 dns2
385 0) autoconf
="error" ;;
387 2) [ -n "$1" ] && dev
=$1; [ -n "$2" ] && autoconf
=$2 ;;
388 3) [ -n "$1" ] && dev
=$1; [ -n "$2" ] && autoconf
=$2; [ -n "$3" ] && mtu
=$3 ;;
389 4) [ -n "$1" ] && dev
=$1; [ -n "$2" ] && autoconf
=$2; [ -n "$3" ] && mtu
=$3; [ -n "$4" ] && macaddr
=$4 ;;
390 *) [ -n "$1" ] && ip
=$1; [ -n "$2" ] && srv
=$2; [ -n "$3" ] && gw
=$3; [ -n "$4" ] && mask
=$4;
391 [ -n "$5" ] && hostname
=$5; [ -n "$6" ] && dev
=$6; [ -n "$7" ] && autoconf
=$7;
393 [0-9]*:*|
[0-9]*.
[0-9]*.
[0-9]*.
[0-9]*)
395 [ -n "$9" ] && dns2
="$9"
401 if [ -n "${9}" -a -n "${10}" -a -n "${11}" -a -n "${12}" -a -n "${13}" -a -n "${14}" ]; then
402 macaddr
="${9}:${10}:${11}:${12}:${13}:${14}"
409 # ip=<ipv4-address> means anaconda-style static config argument cluster:
410 # ip=<ip> gateway=<gw> netmask=<nm> hostname=<host> mtu=<mtu>
411 # ksdevice={link|bootif|ibft|<MAC>|<ifname>}
412 if strglob
"$autoconf" "*.*.*.*"; then
414 gw
=$
(getarg gateway
=)
415 mask
=$
(getarg netmask
=)
416 hostname
=$
(getarg hostname
=)
417 dev
=$
(getarg ksdevice
=)
421 # handle special values for ksdevice
423 bootif|BOOTIF
) dev
=$
(fix_bootif $
(getarg BOOTIF
=)) ;;
424 link
) dev
="" ;; # FIXME: do something useful with this
425 ibft
) dev
="" ;; # ignore - ibft is handled elsewhere
434 while [ -n "$v" ]; do
435 if [ "${v#\[*:*:*\]:}" != "$v" ]; then
436 # handle IPv6 address
442 set -- "$@" "${v%%:*}"
447 unset route_mask route_gw route_dev
449 2) [ -n "$1" ] && route_mask
="$1"; [ -n "$2" ] && route_gw
="$2"
451 3) [ -n "$1" ] && route_mask
="$1"; [ -n "$2" ] && route_gw
="$2"; [ -n "$3" ] && route_dev
="$3"
457 parse_ifname_opts
() {
464 # udev requires MAC addresses to be lower case
465 ifname_mac
=$
(echo $2:$3:$4:$5:$6:$7 |
sed 'y/ABCDEF/abcdef/')
468 die
"Invalid arguments for ifname="
473 eth
[0-9]|eth
[0-9][0-9]|eth
[0-9][0-9][0-9]|eth
[0-9][0-9][0-9][0-9])
474 warn
"ifname=$ifname_if uses the kernel name space for interfaces"
475 warn
"This can fail for multiple network interfaces and is discouraged!"
476 warn
"Please use a custom name like \"netboot\" or \"bluesocket\""
477 warn
"or use biosdevname and no ifname= at all."
483 # some network driver need long time to initialize, wait before it's ready.
487 while [ $cnt -lt 600 ]; do
488 li
=$
(ip
-o link show dev
$1 2>/dev
/null
)
489 [ -n "$li" ] && return 0
499 while [ $cnt -lt 200 ]; do
500 li
=$
(ip
-o link show up dev
$1)
501 [ -n "$li" ] && [ -z "${li##*state UP*}" ] && return 0
508 wait_for_route_ok
() {
510 while [ $cnt -lt 200 ]; do
512 [ -n "$li" ] && [ -z "${li##*$1*}" ] && return 0
519 wait_for_ipv6_dad
() {
522 while [ $cnt -lt 500 ]; do
523 li
=$
(ip
-6 addr show dev
$1 scope link
)
524 strstr
"$li" "tentative" ||
return 0
531 wait_for_ipv6_auto
() {
534 while [ $cnt -lt 400 ]; do
535 li
=$
(ip
-6 addr show dev
$1)
536 if ! strstr
"$li" "tentative"; then
537 strstr
"$li" "dynamic" && return 0
546 wait_for_if_link
$1 2>/dev
/null\
547 && ip link
set $1 up
2>/dev
/null\
548 && wait_for_if_up
$1 2>/dev
/null
551 type hostname
>/dev
/null
2>&1 || \
553 cat /proc
/sys
/kernel
/hostname
558 local interface
="$1" flags
=""
559 [ -n "$interface" ] ||
return 2
560 interface
="/sys/class/net/$interface"
561 [ -d "$interface" ] ||
return 2
563 while [ $cnt -lt 50 ]; do
564 [ "$(cat $interface/carrier)" = 1 ] && return 0
571 find_iface_with_link
() {
572 local iface_path
="" iface
=""
573 for iface_path
in /sys
/class
/net
/*; do
574 iface
=${iface_path##*/}
575 str_starts
"$iface" "lo" && continue
576 if iface_has_link
$iface; then
584 is_persistent_ethernet_name
() {
586 local _name_assign_type
="0"
588 [ -f "/sys/class/net/$_netif/name_assign_type" ] \
589 && _name_assign_type
=$
(cat "/sys/class/net/$_netif/name_assign_type")
592 [ "$_name_assign_type" = "1" ] && return 1
594 # NET_NAME_PREDICTABLE 2
595 [ "$_name_assign_type" = "2" ] && return 0
598 # udev persistent interface names
599 eno
[0-9]|eno
[0-9][0-9]|eno
[0-9][0-9][0-9]*)
601 ens
[0-9]|ens
[0-9][0-9]|ens
[0-9][0-9][0-9]*)
603 enp
[0-9]s
[0-9]*|enp
[0-9][0-9]s
[0-9]*|enp
[0-9][0-9][0-9]*s
[0-9]*)
605 enP
*p
[0-9]s
[0-9]*|enP
*p
[0-9][0-9]s
[0-9]*|enP
*p
[0-9][0-9][0-9]*s
[0-9]*)
608 em
[0-9]|em
[0-9][0-9]|em
[0-9][0-9][0-9]*)
610 p
[0-9]p
[0-9]*|p
[0-9][0-9]p
[0-9]*|p
[0-9][0-9][0-9]*p
[0-9]*)
618 is_kernel_ethernet_name
() {
620 local _name_assign_type
="1"
622 if [ -e "/sys/class/net/$_netif/name_assign_type" ]; then
623 _name_assign_type
=$
(cat "/sys/class/net/$_netif/name_assign_type")
625 case "$_name_assign_type" in
627 # NET_NAME_PREDICTABLE 2
639 # fallback to error prone manual name check
641 eth
[0-9]|eth
[0-9][0-9]|eth
[0-9][0-9][0-9]*)