5 ip=$(ip -o -f inet addr show $iface)
10 iface_for_remote_addr() {
11 set -- $(ip -o route get to $1)
16 local interface="" mac="$(echo $1 | tr '[:upper:]' '[:lower:]')"
17 for interface in /sys/class/net/*; do
18 if [ $(cat $interface/address) = "$mac" ]; then
25 local interface="$1" flags=""
26 [ -n "$interface" ] || return 2
27 interface="/sys/class/net/$interface"
28 [ -d "$interface" ] || return 2
29 flags=$(cat $interface/flags)
30 echo $(($flags|0x41)) > $interface/flags # 0x41: IFF_UP|IFF_RUNNING
31 [ "$(cat $interface/carrier)" = 1 ] || return 1
32 # XXX Do we need to reset the flags here? anaconda never bothered..
36 local iface="" IFACES=""
37 [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces
38 for iface in $IFACES; do
39 [ -e /tmp/net.$iface.up ] || return 1
44 local prefix="" server="" rest=""
45 splitsep "$1" ":" prefix server rest
47 [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) echo "$server"; return 0 ;;
53 strstr "$(ip route get $1 2>/dev/null)" " via "
58 # ip down/flush ensures that routing info goes away as well
59 ip link set $netif down
60 ip addr flush dev $netif
61 echo "#empty" > /etc/resolv.conf
62 rm -f /tmp/net.$netif.did-setup
63 # TODO: send "offline" uevent?
67 local netif="$1" f="" gw_ip="" netroot_ip="" iface="" IFACES=""
68 [ -e /tmp/net.$netif.did-setup ] && return
69 [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces
70 [ -z "$IFACES" ] && IFACES="$netif"
71 # run the scripts written by ifup
72 [ -e /tmp/net.$netif.gw ] && . /tmp/net.$netif.gw
73 [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname
74 [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
75 [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
77 [ -e /tmp/net.$netif.resolv.conf ] && \
78 cp -f /tmp/net.$netif.resolv.conf /etc/resolv.conf
80 # Handle STP Timeout: arping the default gateway.
81 # (or the root server, if a) it's local or b) there's no gateway.)
82 # Note: This assumes that if no router is present the
83 # root server is on the same subnet.
85 # Get DHCP-provided router IP, or the cmdline-provided "gw=" argument
86 [ -n "$new_routers" ] && gw_ip=${new_routers%%,*}
87 [ -n "$gw" ] && gw_ip=$gw
89 # Get the "netroot" IP (if there's an IP address in there)
90 netroot_ip=$(get_netroot_ip $netroot)
92 # try netroot if it's local (or there's no gateway)
93 if ip_is_local $netroot_ip || [ -z "$gw_ip" ]; then
98 if [ -n "$dest" ] && ! arping -q -f -w 60 -I $netif $dest ; then
99 info "Resolving $dest via ARP on $netif failed"
101 > /tmp/net.$netif.did-setup
105 local netif="$1" IFACES="" f="" i=""
106 [ -e /tmp/net.ifaces ] && read IFACES < /tmp/net.ifaces
107 # Add $netif to the front of IFACES (if it's not there already).
109 for i in $IFACES; do [ "$i" != "$netif" ] && set -- "$@" "$i"; done
112 for f in /tmp/dhclient.$i.*; do
113 [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhclient.}
116 echo $IFACES > /tmp/.net.ifaces.new
117 mv /tmp/.net.ifaces.new /tmp/net.ifaces
121 local name="$1" mac="$2" num=0 n=""
122 # if it's already set, return the existing name
123 for n in $(getargs ifname=); do
124 strstr "$n" "$mac" && echo ${n%%:*} && return
126 # otherwise, pick a new name and use that
127 while [ -e /sys/class/$name$num ]; do num=$(($num+1)); done
128 echo "ifname=$name$num:$mac" >> /etc/cmdline.d/45-ifname.conf
133 local iface="" mac="" dev=""
134 local dhcp="" ip="" gw="" mask="" hostname=""
135 modprobe -q iscsi_ibft
137 for iface in /sys/firmware/ibft/ethernet*; do
138 [ -e ${iface}/mac ] || continue
139 mac=$(read a < ${iface}/mac; echo $a)
140 [ -z "$ifname_mac" ] && continue
141 dev=$(set_ifname ibft $ifname_mac)
142 dhcp=$(read a < ${iface}/dhcp; echo $a)
143 if [ -n "$dhcp" ]; then
146 ip=$(read a < ${iface}/ip-addr; echo $a)
147 gw=$(read a < ${iface}/gateway; echo $a)
148 mask=$(read a < ${iface}/subnet-mask; echo $a)
149 hostname=$(read a < ${iface}/hostname; echo $a)
150 echo "ip=$ip::$gw:$mask:$hostname:$dev:none"
153 ) >> /etc/cmdline.d/40-ibft.conf
163 # extract authentication info
168 # allow empty authinfo to allow having an @ in iscsi_target_name like this:
169 # netroot=iscsi:@192.168.1.100::3260::iqn.2009-01.com.example:testdi@sk
170 if [ -n "$authinfo" ]; then
175 if [ $# -gt 4 ]; then
176 warn "Wrong authentication info in iscsi: parameter!"
181 if [ $# -gt 2 ]; then
192 iscsi_target_ip=${v#[[]}
193 iscsi_target_ip=${iscsi_target_ip%%[]]*}
194 v=${v#[[]$iscsi_target_ip[]]:}
197 iscsi_target_ip=${v%%[:]*}
198 v=${v#$iscsi_target_ip:}
202 # extract target name
205 iscsi_target_name=iqn.${v##*:iqn.}
209 iscsi_target_name=iqn.${v##*:eui.}
213 iscsi_target_name=iqn.${v##*:naa.}
217 warn "Invalid iscii target name, should begin with 'iqn.' or 'eui.' or 'naa.'"
228 iscsi_protocol=$1; shift # ignored
229 iscsi_target_port=$1; shift
230 if [ $# -eq 3 ]; then
231 iscsi_iface_name=$1; shift
233 if [ $# -eq 2 ]; then
234 iscsi_netdev_name=$1; shift
237 if [ $# -ne 0 ]; then
238 warn "Invalid parameter in iscsi: parameter!"
247 while [ -n "$v" ]; do
248 if [ "${v#\[*:*:*\]:}" != "$v" ]; then
249 # handle IPv6 address
255 set -- "$@" "${v%%:*}"
260 unset ip srv gw mask hostname dev autoconf macaddr mtu
262 0) autoconf="error" ;;
264 2) dev=$1; autoconf=$2 ;;
265 3) dev=$1; autoconf=$2; mtu=$3 ;;
266 4) dev=$1; autoconf=$2; mtu=$3; macaddr=$4 ;;
267 *) ip=$1; srv=$2; gw=$3; mask=$4; hostname=$5; dev=$6; autoconf=$7; mtu=$8; macaddr=$9 ;;