2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
7 ip
=$
(ip
-o -f inet addr show
$iface)
12 iface_for_remote_addr
() {
13 set -- $
(ip
-o route get to
$1)
18 set -- $
(ip
-o addr show to
$1)
23 local interface
="" mac
="$(echo $1 | sed 'y/ABCDEF/abcdef/')"
24 for interface
in /sys
/class
/net
/*; do
25 if [ $
(cat $interface/address
) = "$mac" ]; then
31 # get the iface name for the given identifier - either a MAC, IP, or iface name
34 ??
:??
:??
:??
:??
:??|??
-??
-??
-??
-??
-??
) iface_for_mac
$1 ;;
35 *:*:*|
*.
*.
*.
*) iface_for_ip
$1 ;;
40 # list the configured interfaces
42 local IFACES
="" iface_id
="" rv
=1
43 [ -e "/tmp/net.ifaces" ] && read IFACES
< /tmp
/net.ifaces
44 if { pidof udevd || pidof systemd-udevd
; } > /dev
/null
; then
45 for iface_id
in $IFACES; do
46 echo $
(iface_name
$iface_id)
50 warn
"configured_ifaces called before udev is running"
52 [ -n "$IFACES" ] && rv
=0
58 local iface
="" IFACES
=""
59 [ -e "/tmp/net.ifaces" ] && read IFACES
< /tmp
/net.ifaces
60 for iface
in $IFACES; do
61 [ -e /tmp
/net.
$iface.up
] ||
return 1
66 local prefix
="" server
="" rest
=""
67 splitsep
"$1" ":" prefix server rest
69 [0-9]*\.
[0-9]*\.
[0-9]*\.
[0-9]*) echo "$server"; return 0 ;;
75 strstr
"$(ip route get $1 2>/dev/null)" " via "
80 # ip down/flush ensures that routing info goes away as well
81 ip link
set $netif down
82 ip addr flush dev
$netif
83 echo "#empty" > /etc
/resolv.conf
84 rm -f -- /tmp
/net.
$netif.did-setup
85 [ -e /sys
/class
/net
/$netif/address
] && \
86 rm -f -- /tmp
/net.$
(cat /sys
/class
/net
/$netif/address
).did-setup
87 # TODO: send "offline" uevent?
91 local netif
="$1" f
="" gw_ip
="" netroot_ip
="" iface
="" IFACES
=""
92 [ -e /tmp
/net.
$netif.did-setup
] && return
93 [ -e /sys
/class
/net
/$netif/address
] && \
94 [ -e /tmp
/net.$
(cat /sys
/class
/net
/$netif/address
).did-setup
] && return
95 [ -e "/tmp/net.ifaces" ] && read IFACES
< /tmp
/net.ifaces
96 [ -z "$IFACES" ] && IFACES
="$netif"
97 # run the scripts written by ifup
98 [ -e /tmp
/net.
$netif.gw
] && .
/tmp
/net.
$netif.gw
99 [ -e /tmp
/net.
$netif.hostname
] && .
/tmp
/net.
$netif.hostname
100 [ -e /tmp
/net.
$netif.override
] && .
/tmp
/net.
$netif.override
101 [ -e /tmp
/dhclient.
$netif.dhcpopts
] && .
/tmp
/dhclient.
$netif.dhcpopts
103 [ -e /tmp
/net.
$netif.resolv.conf
] && \
104 cp -f /tmp
/net.
$netif.resolv.conf
/etc
/resolv.conf
106 # Handle STP Timeout: arping the default gateway.
107 # (or the root server, if a) it's local or b) there's no gateway.)
108 # Note: This assumes that if no router is present the
109 # root server is on the same subnet.
111 # Get DHCP-provided router IP, or the cmdline-provided "gw=" argument
112 [ -n "$new_routers" ] && gw_ip
=${new_routers%%,*}
113 [ -n "$gw" ] && gw_ip
=$gw
115 # Get the "netroot" IP (if there's an IP address in there)
116 netroot_ip
=$
(get_netroot_ip
$netroot)
118 # try netroot if it's local (or there's no gateway)
119 if ip_is_local
$netroot_ip ||
[ -z "$gw_ip" ]; then
126 if [ -f /sys
/class
/net
/$netif/device
/layer2
]; then
127 read layer2
< /sys
/class
/net
/$netif/device
/layer2
130 if [ "$layer2" != "0" ] && [ -n "$dest" ] && ! strstr
"$dest" ":"; then
131 arping
-q -f -w 60 -I $netif $dest || info
"Resolving $dest via ARP on $netif failed"
135 > /tmp
/net.
$netif.did-setup
136 [ -e /sys
/class
/net
/$netif/address
] && \
137 > /tmp
/net.$
(cat /sys
/class
/net
/$netif/address
).did-setup
141 local netif
="$1" IFACES
="" f
="" i
=""
142 [ -e /tmp
/net.ifaces
] && read IFACES
< /tmp
/net.ifaces
143 # Add $netif to the front of IFACES (if it's not there already).
145 for i
in $IFACES; do [ "$i" != "$netif" ] && set -- "$@" "$i"; done
148 for f
in /tmp
/dhclient.
$i.
*; do
149 [ -f $f ] && cp -f $f /tmp
/net.
${f#/tmp/dhclient.}
152 echo $IFACES > /tmp
/.net.ifaces.new
153 mv /tmp
/.net.ifaces.new
/tmp
/net.ifaces
157 local name
="$1" mac
="$2" num
=-1 n
=""
158 # if it's already set, return the existing name
159 for n
in $
(getargs ifname
=); do
160 strstr
"$n" "$mac" && echo ${n%%:*} && return
162 # otherwise, pick a new name and use that
165 [ -e /sys
/class
/net
/$name$num ] && continue
166 for n
in $
(getargs ifname
=); do
167 [ "$name$num" = "${n%%:*}" ] && continue 2
171 echo "ifname=$name$num:$mac" >> /etc
/cmdline.d
/45-ifname.conf
175 # pxelinux provides macaddr '-' separated, but we need ':'
179 macaddr
=$
(for i
in ${macaddr} ; do echo -n $i:; done)
181 # strip hardware type field from pxelinux
182 [ -n "${macaddr%??:??:??:??:??:??}" ] && macaddr
=${macaddr#??:}
183 # return macaddr with lowercase alpha characters expected by udev
184 echo $macaddr |
sed 'y/ABCDEF/abcdef/'
189 modprobe
-q iscsi_ibft
191 for iface
in /sys
/firmware
/ibft
/ethernet
*; do
193 local dhcp
="" ip
="" gw
="" mask
="" hostname
=""
196 [ -e ${iface}/mac
] ||
continue
197 mac
=$
(read a
< ${iface}/mac
; echo $a)
198 [ -z "$mac" ] && continue
199 dev
=$
(set_ifname ibft
$mac)
201 [ -e /tmp
/net.
${dev}.has_ibft_config
] && continue
203 [ -e ${iface}/dhcp
] && dhcp
=$
(read a
< ${iface}/dhcp
; echo $a)
205 if [ -n "$dhcp" ]; then
207 elif [ -e ${iface}/ip-addr
]; then
208 [ -e ${iface}/ip-addr
] && ip
=$
(read a
< ${iface}/ip-addr
; echo $a)
209 # skip not assigned ip adresses
210 [ "$ip" = "0.0.0.0" ] && continue
211 [ -e ${iface}/gateway
] && gw
=$
(read a
< ${iface}/gateway
; echo $a)
212 [ -e ${iface}/subnet-mask
] && mask
=$
(read a
< ${iface}/subnet-mask
; echo $a)
213 [ -e ${iface}/primary-dns
] && dns1
=$
(read a
< ${iface}/primary-dns
; echo $a)
214 [ -e ${iface}/secondary-dns
] && dns2
=$
(read a
< ${iface}/secondary-dns
; echo $a)
215 [ -e ${iface}/hostname
] && hostname
=$
(read a
< ${iface}/hostname
; echo $a)
216 if [ -n "$ip" ] && [ -n "$mask" ]; then
217 echo "ip=$ip::$gw:$mask:$hostname:$dev:none${dns1:+:$dns1}${dns2:+:$dns2}"
219 warn
"${iface} does not contain a valid iBFT configuration"
222 warn
"subnet-mask=$mask"
223 warn
"hostname=$hostname"
226 info
"${iface} does not contain a valid iBFT configuration"
227 ls -l ${iface} | vinfo
230 if [ -e ${iface}/vlan
]; then
231 vlan
=$
(read a
< ${iface}/vlan
; echo $a)
232 if [ "$vlan" -ne "0" ]; then
235 echo "vlan=$dev.$vlan:$dev"
238 echo "vlan=$vlan:$dev"
244 echo $mac > /tmp
/net.
${dev}.has_ibft_config
246 ) >> /etc
/cmdline.d
/40-ibft.conf
254 # extract authentication info
259 # allow empty authinfo to allow having an @ in iscsi_target_name like this:
260 # netroot=iscsi:@192.168.1.100::3260::iqn.2009-01.com.example:testdi@sk
261 if [ -n "$authinfo" ]; then
266 if [ $# -gt 4 ]; then
267 warn
"Wrong authentication info in iscsi: parameter!"
272 if [ $# -gt 2 ]; then
283 iscsi_target_ip
=${v#[[]}
284 iscsi_target_ip
=${iscsi_target_ip%%[]]*}
285 v
=${v#[[]$iscsi_target_ip[]]:}
288 iscsi_target_ip
=${v%%[:]*}
289 v
=${v#$iscsi_target_ip:}
293 # extract target name
296 iscsi_target_name
=iqn.
${v##*:iqn.}
300 iscsi_target_name
=iqn.
${v##*:eui.}
304 iscsi_target_name
=iqn.
${v##*:naa.}
308 warn
"Invalid iscii target name, should begin with 'iqn.' or 'eui.' or 'naa.'"
319 iscsi_protocol
=$1; shift # ignored
320 iscsi_target_port
=$1; shift
321 if [ $# -eq 3 ]; then
322 iscsi_iface_name
=$1; shift
324 if [ $# -eq 2 ]; then
325 iscsi_netdev_name
=$1; shift
328 if [ $# -ne 0 ]; then
329 warn
"Invalid parameter in iscsi: parameter!"
338 while [ -n "$v" ]; do
339 if [ "${v#\[*:*:*\]:}" != "$v" ]; then
340 # handle IPv6 address
346 set -- "$@" "${v%%:*}"
351 unset ip srv gw mask hostname dev autoconf macaddr mtu dns1 dns2
353 0) autoconf
="error" ;;
355 2) [ -n "$1" ] && dev
=$1; [ -n "$2" ] && autoconf
=$2 ;;
356 3) [ -n "$1" ] && dev
=$1; [ -n "$2" ] && autoconf
=$2; [ -n "$3" ] && mtu
=$3 ;;
357 4) [ -n "$1" ] && dev
=$1; [ -n "$2" ] && autoconf
=$2; [ -n "$3" ] && mtu
=$3; [ -n "$4" ] && macaddr
=$4 ;;
358 *) [ -n "$1" ] && ip
=$1; [ -n "$2" ] && srv
=$2; [ -n "$3" ] && gw
=$3; [ -n "$4" ] && mask
=$4;
359 [ -n "$5" ] && hostname
=$5; [ -n "$6" ] && dev
=$6; [ -n "$7" ] && autoconf
=$7;
361 [0-9]*:*|
[0-9]*.
[0-9]*.
[0-9]*.
[0-9]*)
363 [ -n "$9" ] && dns2
="$9"
369 if [ -n "${9}" -a -n "${10}" -a -n "${11}" -a -n "${12}" -a -n "${13}" -a -n "${14}" ]; then
370 macaddr
="${9}:${10}:${11}:${12}:${13}:${14}"
377 # ip=<ipv4-address> means anaconda-style static config argument cluster:
378 # ip=<ip> gateway=<gw> netmask=<nm> hostname=<host> mtu=<mtu>
379 # ksdevice={link|bootif|ibft|<MAC>|<ifname>}
380 if strglob
"$autoconf" "*.*.*.*"; then
382 gw
=$
(getarg gateway
=)
383 mask
=$
(getarg netmask
=)
384 hostname
=$
(getarg hostname
=)
385 dev
=$
(getarg ksdevice
=)
389 # handle special values for ksdevice
391 bootif|BOOTIF
) dev
=$
(fix_bootif $
(getarg BOOTIF
=)) ;;
392 link
) dev
="" ;; # FIXME: do something useful with this
393 ibft
) dev
="" ;; # ignore - ibft is handled elsewhere
398 parse_ifname_opts
() {
405 # udev requires MAC addresses to be lower case
406 ifname_mac
=$
(echo $2:$3:$4:$5:$6:$7 |
sed 'y/ABCDEF/abcdef/')
409 die
"Invalid arguments for ifname="
414 eth
[0-9]|eth
[0-9][0-9]|eth
[0-9][0-9][0-9]|eth
[0-9][0-9][0-9][0-9])
415 warn
"ifname=$ifname_if uses the kernel name space for interfaces"
416 warn
"This can fail for multiple network interfaces and is discouraged!"
417 warn
"Please use a custom name like \"netboot\" or \"bluesocket\""
418 warn
"or use biosdevname and no ifname= at all."
424 # some network driver need long time to initialize, wait before it's ready.
428 while [ $cnt -lt 600 ]; do
429 li
=$
(ip
-o link show dev
$1 2>/dev
/null
)
430 [ -n "$li" ] && return 0
440 while [ $cnt -lt 200 ]; do
441 li
=$
(ip
-o link show up dev
$1)
442 [ -n "$li" ] && [ -z "${li##*state UP*}" ] && return 0
449 wait_for_route_ok
() {
451 while [ $cnt -lt 200 ]; do
453 [ -n "$li" ] && [ -z "${li##*$1*}" ] && return 0
460 wait_for_ipv6_dad
() {
463 while [ $cnt -lt 500 ]; do
464 li
=$
(ip
-6 addr show dev
$1)
465 strstr
"$li" "tentative" ||
return 0
472 wait_for_ipv6_auto
() {
475 while [ $cnt -lt 400 ]; do
476 li
=$
(ip
-6 addr show dev
$1)
477 if ! strstr
"$li" "tentative"; then
478 strstr
"$li" "dynamic" && return 0
487 wait_for_if_link
$1 2>/dev
/null\
488 && ip link
set $1 up
2>/dev
/null\
489 && wait_for_if_up
$1 2>/dev
/null
492 type hostname
>/dev
/null
2>&1 || \
494 cat /proc
/sys
/kernel
/hostname
498 local interface
="$1" flags
=""
499 [ -n "$interface" ] ||
return 2
500 interface
="/sys/class/net/$interface"
501 [ -d "$interface" ] ||
return 2
503 [ "$(cat $interface/carrier)" = 1 ] ||
return 1
504 # XXX Do we need to reset the flags here? anaconda never bothered..
507 find_iface_with_link
() {
508 local iface_path
="" iface
=""
509 for iface_path
in /sys
/class
/net
/*; do
510 iface
=${iface_path##*/}
511 str_starts
"$iface" "lo" && continue
512 if iface_has_link
$iface; then
520 is_persistent_ethernet_name
() {
522 # udev persistent interface names
523 eth
[0-9]|eth
[0-9][0-9]|eth
[0-9][0-9][0-9]*)
525 eno
[0-9]|eno
[0-9][0-9]|eno
[0-9][0-9][0-9]*)
527 ens
[0-9]|ens
[0-9][0-9]|ens
[0-9][0-9][0-9]*)
529 enp
[0-9]s
[0-9]*|enp
[0-9][0-9]s
[0-9]*|enp
[0-9][0-9][0-9]*s
[0-9]*)
531 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]*)
534 em
[0-9]|em
[0-9][0-9]|em
[0-9][0-9][0-9]*)
536 p
[0-9]p
[0-9]*|p
[0-9][0-9]p
[0-9]*|p
[0-9][0-9][0-9]*p
[0-9]*)