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 local interface="" mac="$(echo $1 | sed 'y/ABCDEF/abcdef/')"
19 for interface in /sys/class/net/*; do
20 if [ $(cat $interface/address) = "$mac" ]; then
27 local interface="$1" flags=""
28 [ -n "$interface" ] || return 2
29 interface="/sys/class/net/$interface"
30 [ -d "$interface" ] || return 2
31 flags=$(cat $interface/flags)
32 echo $(($flags|0x41)) > $interface/flags # 0x41: IFF_UP|IFF_RUNNING
33 [ "$(cat $interface/carrier)" = 1 ] || return 1
34 # XXX Do we need to reset the flags here? anaconda never bothered..
38 local iface="" IFACES=""
39 [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces
40 for iface in $IFACES; do
41 [ -e /tmp/net.$iface.up ] || return 1
46 local prefix="" server="" rest=""
47 splitsep "$1" ":" prefix server rest
49 [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) echo "$server"; return 0 ;;
55 strstr "$(ip route get $1 2>/dev/null)" " via "
60 # ip down/flush ensures that routing info goes away as well
61 ip link set $netif down
62 ip addr flush dev $netif
63 echo "#empty" > /etc/resolv.conf
64 rm -f /tmp/net.$netif.did-setup
65 # TODO: send "offline" uevent?
69 local netif="$1" f="" gw_ip="" netroot_ip="" iface="" IFACES=""
70 [ -e /tmp/net.$netif.did-setup ] && return
71 [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces
72 [ -z "$IFACES" ] && IFACES="$netif"
73 # run the scripts written by ifup
74 [ -e /tmp/net.$netif.gw ] && . /tmp/net.$netif.gw
75 [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname
76 [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
77 [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
79 [ -e /tmp/net.$netif.resolv.conf ] && \
80 cp -f /tmp/net.$netif.resolv.conf /etc/resolv.conf
82 # Handle STP Timeout: arping the default gateway.
83 # (or the root server, if a) it's local or b) there's no gateway.)
84 # Note: This assumes that if no router is present the
85 # root server is on the same subnet.
87 # Get DHCP-provided router IP, or the cmdline-provided "gw=" argument
88 [ -n "$new_routers" ] && gw_ip=${new_routers%%,*}
89 [ -n "$gw" ] && gw_ip=$gw
91 # Get the "netroot" IP (if there's an IP address in there)
92 netroot_ip=$(get_netroot_ip $netroot)
94 # try netroot if it's local (or there's no gateway)
95 if ip_is_local $netroot_ip || [ -z "$gw_ip" ]; then
102 if [ -f /sys/class/net/$netif/device/layer2 ]; then
103 read layer2 < /sys/class/net/$netif/device/layer2
106 if [ "$layer2" != "0" ] && [ -n "$dest" ] && ! arping -q -f -w 60 -I $netif $dest ; then
107 info "Resolving $dest via ARP on $netif failed"
111 > /tmp/net.$netif.did-setup
115 local netif="$1" IFACES="" f="" i=""
116 [ -e /tmp/net.ifaces ] && read IFACES < /tmp/net.ifaces
117 # Add $netif to the front of IFACES (if it's not there already).
119 for i in $IFACES; do [ "$i" != "$netif" ] && set -- "$@" "$i"; done
122 for f in /tmp/dhclient.$i.*; do
123 [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhclient.}
126 echo $IFACES > /tmp/.net.ifaces.new
127 mv /tmp/.net.ifaces.new /tmp/net.ifaces
131 local name="$1" mac="$2" num=0 n=""
132 # if it's already set, return the existing name
133 for n in $(getargs ifname=); do
134 strstr "$n" "$mac" && echo ${n%%:*} && return
136 # otherwise, pick a new name and use that
137 while [ -e /sys/class/$name$num ]; do num=$(($num+1)); done
138 echo "ifname=$name$num:$mac" >> /etc/cmdline.d/45-ifname.conf
143 local iface="" mac="" dev=""
144 local dhcp="" ip="" gw="" mask="" hostname=""
145 modprobe -q iscsi_ibft
147 for iface in /sys/firmware/ibft/ethernet*; do
148 [ -e ${iface}/mac ] || continue
149 mac=$(read a < ${iface}/mac; echo $a)
150 [ -z "$mac" ] && continue
151 dev=$(set_ifname ibft $mac)
152 dhcp=$(read a < ${iface}/dhcp; echo $a)
153 if [ -n "$dhcp" ]; then
156 ip=$(read a < ${iface}/ip-addr; echo $a)
157 gw=$(read a < ${iface}/gateway; echo $a)
158 mask=$(read a < ${iface}/subnet-mask; echo $a)
159 hostname=$(read a < ${iface}/hostname; echo $a)
160 echo "ip=$ip::$gw:$mask:$hostname:$dev:none"
162 echo $mac > /tmp/net.${dev}.has_ibft_config
164 ) >> /etc/cmdline.d/40-ibft.conf
174 # extract authentication info
179 # allow empty authinfo to allow having an @ in iscsi_target_name like this:
180 # netroot=iscsi:@192.168.1.100::3260::iqn.2009-01.com.example:testdi@sk
181 if [ -n "$authinfo" ]; then
186 if [ $# -gt 4 ]; then
187 warn "Wrong authentication info in iscsi: parameter!"
192 if [ $# -gt 2 ]; then
203 iscsi_target_ip=${v#[[]}
204 iscsi_target_ip=${iscsi_target_ip%%[]]*}
205 v=${v#[[]$iscsi_target_ip[]]:}
208 iscsi_target_ip=${v%%[:]*}
209 v=${v#$iscsi_target_ip:}
213 # extract target name
216 iscsi_target_name=iqn.${v##*:iqn.}
220 iscsi_target_name=iqn.${v##*:eui.}
224 iscsi_target_name=iqn.${v##*:naa.}
228 warn "Invalid iscii target name, should begin with 'iqn.' or 'eui.' or 'naa.'"
239 iscsi_protocol=$1; shift # ignored
240 iscsi_target_port=$1; shift
241 if [ $# -eq 3 ]; then
242 iscsi_iface_name=$1; shift
244 if [ $# -eq 2 ]; then
245 iscsi_netdev_name=$1; shift
248 if [ $# -ne 0 ]; then
249 warn "Invalid parameter in iscsi: parameter!"
258 while [ -n "$v" ]; do
259 if [ "${v#\[*:*:*\]:}" != "$v" ]; then
260 # handle IPv6 address
266 set -- "$@" "${v%%:*}"
271 unset ip srv gw mask hostname dev autoconf macaddr mtu
273 0) autoconf="error" ;;
275 2) [ -n "$1" ] && dev=$1; [ -n "$2" ] && autoconf=$2 ;;
276 3) [ -n "$1" ] && dev=$1; [ -n "$2" ] && autoconf=$2; [ -n "$3" ] && mtu=$3 ;;
277 4) [ -n "$1" ] && dev=$1; [ -n "$2" ] && autoconf=$2; [ -n "$3" ] && mtu=$3; [ -n "$4" ] && macaddr=$4 ;;
278 *) [ -n "$1" ] && ip=$1; [ -n "$2" ] && srv=$2; [ -n "$3" ] && gw=$3; [ -n "$4" ] && mask=$4;
279 [ -n "$5" ] && hostname=$5; [ -n "$6" ] && dev=$6; [ -n "$7" ] && autoconf=$7; [ -n "$8" ] && mtu=$8;
280 if [ -n "${9}" -a -n "${10}" -a -n "${11}" -a -n "${12}" -a -n "${13}" -a -n "${14}" ]; then
281 macaddr="${9}:${10}:${11}:${12}:${13}:${14}"
285 # anaconda-style argument cluster
286 if strstr "$autoconf" "*.*.*.*"; then
288 gw=$(getarg gateway=)
289 mask=$(getarg netmask=)
290 hostname=$(getarg hostname=)
291 dev=$(getarg ksdevice=)
295 # ignore fancy values for ksdevice=XXX
296 link|bootif|BOOTIF|ibft|*:*:*:*:*:*) dev="" ;;
301 parse_ifname_opts() {
308 # udev requires MAC addresses to be lower case
309 ifname_mac=$(echo $2:$3:$4:$5:$6:$7 | sed 'y/ABCDEF/abcdef/')
312 die "Invalid arguments for ifname="
317 eth[0-9]|eth[0-9][0-9]|eth[0-9][0-9][0-9]|eth[0-9][0-9][0-9][0-9])
318 warn "ifname=$ifname_if uses the kernel name space for interfaces"
319 warn "This can fail for multiple network interfaces and is discouraged!"
320 warn "Please use a custom name like \"netboot\" or \"bluesocket\""
321 warn "or use biosdevname and no ifname= at all."
327 # some network driver need long time to initialize, wait before it's ready.
331 while [ $cnt -lt 600 ]; do
332 li=$(ip -o link show dev $1 2>/dev/null)
333 [ -n "$li" ] && return 0
343 while [ $cnt -lt 200 ]; do
344 li=$(ip -o link show up dev $1)
345 [ -n "$li" ] && return 0
352 wait_for_route_ok() {
354 while [ $cnt -lt 200 ]; do
356 [ -n "$li" ] && [ -z "${li##*$1*}" ] && return 0
363 wait_for_ipv6_auto() {
366 while [ $cnt -lt 400 ]; do
367 li=$(ip -6 addr show dev $1)
368 strstr "$li" "dynamic" && return 0
376 wait_for_if_link $1 2>/dev/null\
377 && ip link set $1 up 2>/dev/null\
378 && wait_for_if_up $1 2>/dev/null
381 type hostname >/dev/null 2>&1 || \
383 cat /proc/sys/kernel/hostname