ifcfg-eth99 4.78 KB
Newer Older
1
2
3
#/bin/sh -
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2004, 2005 University of Utah and the Flux Group.
5
6
7
8
9
# All rights reserved.
#

#
# HACK: run dhclient on all interfaces, and do nothing else
10
# (well, now also bring up a widearea node control net statically if asked)
11
12
13
14
15
16
17
18
19
20
21
22
#
# Note that this file's name (eth99) cannot overlap with an actual
# existing interface or dhclient will loop.  dhclient-script invokes
# the source-config function which sources the ifcfg-ethN file.  Thus
# if this script were called "ifcfg-eth0" and eth0 was the DHCPable
# interface, we would wind up recursively invoking dhclient (trust me,
# I tried it :-)
#

. /etc/emulab/paths.sh

DEVICE="eth99"
23
IFACETYPES="3c59x e100 e1000 tulip e1000e tg3"
24
25
26
27
28
29

#
# First, probe for all our supported ethernet types
#
modprobe -qa $IFACETYPES

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#
# Check: are we a remote node?  If so, possibly try static config in pref
# to dhcp.
#
if [ -e /etc/emulab/isrem -a -e /etc/emulab/waconfig ]; then
    . /etc/emulab/waconfig
    echo "Found Emulab widearea config info..."

    _ifs=`ifconfig -s -a | awk '{ print $1 }' | grep -v 'Iface' | grep -v '^lo$'`
    if [ "$WA_BOOTMETHOD" = "static" -a "$WA_MAC" != "" ]; then 
	# try to find an iface matching WA_MAC
	cnetif=""
	for _if in $_ifs; do
	    ifconfig $_if | grep HWaddr | sed -e 's/.*HWaddr\s*\(.*\)/\1/' \
		| grep -q -i "$WA_MAC"
	    if [ "$?" = "0" ]; then
		cnetif="$_if"
		break
	    fi
	done

	if [ "$cnetif" = "" ]; then
	    echo "Could not find iface with MAC $WA_MAC; trying DHCP!"
	    WA_BOOTMETHOD="dhcp"
	elif [ "$WA_HOSTNAME" = "" \
	       -o "$WA_DOMAIN" = "" \
	       -o "$WA_IP_ADDR" = "" \
	       -o "$WA_IP_NETMASK" = "" \
	       -o "$WA_IP_GATEWAY" = "" \
	       -o "$WA_IP_DNS1" = ""  ]; then
	    echo "Missing static IP config vars; trying DHCP!"
	    WA_BOOTMETHOD="dhcp"
	fi
    fi
fi

#
# Try static config if all its constraints above are met...
#
if [ "$WA_BOOTMETHOD" = "static" ]; then
    echo "Statically configuring control net on $cnetif ..."
    ifconfig "$cnetif" inet "$WA_IP_ADDR" netmask "$WA_IP_NETMASK" up
    route add default gateway "$WA_IP_GATEWAY"

    # bring up lo too just to make sure it's up
    ifconfig lo inet 127.0.0.1 up
    route add -net 127.0.0.0/8 dev lo

    # setup resolv.conf
    echo "search $WA_DOMAIN" > /etc/resolv.conf
    echo "nameserver $WA_IP_DNS1" >> /etc/resolv.conf
    if [ x"$WA_IP_DNS2" != x ]; then
	echo "nameserver $WA_IP_DNS2" >> /etc/resolv.conf
    fi

    # set hostname
    hosts_str="$WA_HOSTNAME"
    echo "$WA_HOSTNAME" | grep -q \\.
    if [ $? = 0 ]; then
	hostname "$WA_HOSTNAME"
    else
	hostname "${WA_HOSTNAME}.${WA_DOMAIN}"
	hosts_str="${WA_HOSTNAME}.${WA_DOMAIN} ${hosts_str}"
    fi

    # setup hosts file
    echo "$WA_IP_ADDR ${hosts_str}" >> /etc/hosts

    # setup a few necessary emulab files...
    echo "$cnetif" > $BOOTDIR/controlif
    if [ -e "/etc/emulab/bossnode" ]; then
        bossnode=`cat /etc/emulab/bossnode`
	bossip=`host -t A "$bossnode"`
	retval="$?"
	i=0
	while [ "$retval" != "0" -a $i -lt 6 ]; do
	    bossip=`host -t A "$bossnode"`
	    retval="$?"
	    i=`expr $i + 1`
	    sleep 5
	done
	echo `echo "$bossip" | sed -n -e 's/.*has address\s*\(.*\)/\1/p'` \
	    > $BOOTDIR/bossip
    fi
    echo "$WA_HOSTNAME" > $BOOTDIR/realname
    echo "$WA_IP_GATEWAY" > $BOOTDIR/routerip
    echo "$WA_IP_ADDR" > $BOOTDIR/myip
    echo "$WA_IP_NETMASK" > $BOOTDIR/mynetmask

    exit 0
fi

#
# else default to dhclient...
#
125
interfaces=`ifconfig -a -s | sed '1d;/^lo /d;s/ .*$//'`
126

127
128
129
130
131
132
133
#
# If dhclient returns success, then it has configured the first interface
# and gone into background mode.  At that point we don't care about it any
# more and just kill it.  We also shutdown all the other interfaces (which
# dhclient will leave "up") and set ONBOOT=no to prevent ifup (our caller)
# from doing any further configuration on this fake interface.
#
134
echo "Discovering control net via dhcp ..."
135
if [ -x /sbin/dhclient ] && /sbin/dhclient -q $interfaces; then
136
137
138
139
140
141
142
143
144
145
146
147
    killall dhclient

    if [ -e $BOOTDIR/controlif ]; then
	interface=`cat $BOOTDIR/controlif`
	for _if in `ifconfig -s | awk '{ print $1 }' | grep -v Iface`
	do
	    if [ $_if != "lo" -a x$_if != x$interface ]
	    then
		echo "taking $_if down"
	        ifconfig $_if down
	    fi >>$LOGDIR/dhclient.log 2>&1
	done
148
149
150
151
152
153
154
155
156
157
158
159

        #
        # Now probe for wifi interfaces.  We don't want to
        # do this before dhcp'ing on the wired interfaces since
        # there is a possibility that the wifi interface will
        # grab an address and become the control net!
        #
        # This expects to load the madwifi-ng driver; the param states
        # that no "virtual AP" device is to be created on module load.
        # This is deferred until Emulab interface configuration time.
        #
        modprobe -q ath_pci autocreate=none
160
161
162
163
164
165
    fi
    ONBOOT="no"
else
    # eat flaming death
    exit 1
fi