3 # the name of the floppy based network configuration
4 # files (checked first). the name planet.cnf is kept
5 # for backward compatibility with old nodes
6 FLOPPY_NET_CONF=planet.cnf
8 # location of cd-based network configuration file
9 # (checked if floppy conf file missing)
10 USER_NET_CONF=/usr/boot/user-net.cnf
12 # if all other network configuration file sources
13 # don't exist, fall back to this one (always on the cd)
14 FALLBACK_NET_CONF=/usr/boot/default-net.cnf
16 # once a configuration file is found, save it in /tmp
17 # (may be used later by boot scripts)
18 USED_NET_CONF=/tmp/planet.cnf
20 # default device to use for contacting PLC
23 # where to store the temporary dhclient conf file
24 DHCLIENT_CONF_FILE=/tmp/dhclient.conf
26 # which fs types we support floppy disks in
27 FLOPPY_FS_TYPES="msdos,ext2"
29 FLOPPY_MOUNT_POINT=/mnt/floppy
30 /bin/mkdir -p $FLOPPY_MOUNT_POINT
36 echo "pl_netinit: network initialization failed,"
37 echo "pl_netinit: shutting down machine in two hours"
43 # Function for checking the IP address to see if its sensible.
47 "" | *[!0-9.]* | *[!0-9]) return 1 ;;
52 [ ${1:-666} -le 255 ] && [ ${2:-666} -le 255 ] &&
53 [ ${3:-666} -le 255 ] && [ ${4:-666} -le 255 ]
56 echo "pl_netinit: bringing loopback network device up"
57 /sbin/ifconfig lo 127.0.0.1 up
63 echo "pl_netinit: looking for network configuration on floppy"
64 /bin/mount -o ro -t $FLOPPY_FS_TYPES /dev/fd0 $FLOPPY_MOUNT_POINT 2>&1 > /dev/null
65 if [[ $? -eq 0 ]]; then
66 floppy_conf_file="$FLOPPY_MOUNT_POINT/$FLOPPY_NET_CONF"
67 if [ -r "$floppy_conf_file" ]; then
69 echo "pl_netinit: found floppy configuration file, using"
70 /etc/init.d/pl_validateconf < $floppy_conf_file > $USED_NET_CONF
73 echo "pl_netinit: floppy mounted, but no configuration file."
75 /bin/umount $FLOPPY_MOUNT_POINT
77 echo "pl_netinit: no floppy found"
81 if [[ $FOUND_NET_CONF -eq 0 ]]; then
82 echo "pl_netinit: looking for network configuration on cd"
83 if [ -r "$USER_NET_CONF" ]; then
85 echo "pl_netinit: found cd configuration file, using"
86 /etc/init.d/pl_validateconf < $USER_NET_CONF > $USED_NET_CONF
91 if [[ $FOUND_NET_CONF -eq 0 ]]; then
92 echo "pl_netinit: using default network configuration"
93 if [ -r "$FALLBACK_NET_CONF" ]; then
95 echo "pl_netinit: found cd default configuration file, using"
96 /etc/init.d/pl_validateconf < $FALLBACK_NET_CONF > $USED_NET_CONF
103 if [[ $FOUND_NET_CONF -eq 0 ]]; then
104 # no network configuration file found. this should not happen as the
105 # default cd image has a backup one. halt.
106 echo "pl_netinit: unable to find even a default network configuration"
107 echo "pl_netinit: file, this cd may be corrupt."
111 # load the configuration file. if it was a default one (not user specified),
112 # then remove the saved copy from /tmp, but continue on. since a network
113 # configuration file is required and boot scripts only know about this location
114 # they will fail (as they should) - but the network will be up if dhcp is
117 echo "pl_netinit: loading network configuration"
120 if [[ $DEFAULT_NET_CONF -eq 1 ]]; then
121 /bin/rm -f $USED_NET_CONF
124 # now, we need to find which device to use (ie, eth0 or eth1). start out
125 # by defaulting to eth0, then see if the network configuration file specified
126 # either a mac address (in which case we will need to find the device), or
129 if [[ -n "$PRIMARY_MAC" ]]; then
130 # the user specified a mac address we should use. find the network
132 echo "pl_netinit: looking for a device with mac address $PRIMARY_MAC"
137 dev_address=`cat $device/address`
138 if [[ "$dev_address" == "$PRIMARY_MAC" ]]; then
140 echo "pl_netinit: found device $ETH_DEVICE"
146 elif [[ -n "$PRIMARY_DEV" ]]; then
147 # the user specified a virtual ethernet device to use.
148 ETH_DEVICE=$PRIMARY_DEV
149 echo "pl_netinit: using user specified device $ETH_DEVICE"
152 ETH_DEVICE=$DEFAULT_NET_DEV
153 echo "pl_netinit: using default device $ETH_DEVICE"
158 # if we couldn't find a device (would happen if PRIMARY_MAC was specified
159 # but we couldn't find a device for that addresS), then abort the rest
162 if [[ -z "$ETH_DEVICE" ]]; then
163 echo "pl_netinit: unable to find a usable device, check to make sure"
164 echo "pl_netinit: the PRIMARY_MAC field in the configuration file"
165 echo "pl_netinit: cooresponds with a network adapter on this system"
170 # actually check to make sure ifconfig <device> succeeds
171 /sbin/ifconfig $ETH_DEVICE up 2>&1 > /dev/null
172 if [[ $? -ne 0 ]]; then
173 echo "pl_netinit: device $ETH_DEVICE does not exist,"
174 echo "pl_netinit: this is due to either the device not existing,"
175 echo "pl_netinit: or its device drivers not being loaded"
179 if [[ "$IP_METHOD" == "dhcp" ]]; then
180 echo "pl_netinit: attempting to bring up device with dhcp"
182 # setup a dhclient conf file for this device (used to send
183 # our hostname to the dhcp server)
184 echo "interface \"$ETH_DEVICE\" {" > $DHCLIENT_CONF_FILE
185 echo "send host-name \"$HOST_NAME.$DOMAIN_NAME\";" >> $DHCLIENT_CONF_FILE
186 echo "}" >> $DHCLIENT_CONF_FILE
188 # touch the redhat net device configuration file so
189 # dhclient doesn't complain
190 /bin/touch /etc/sysconfig/network-scripts/ifcfg-$ETH_DEVICE
193 while [[ $configured -eq 0 ]]; do
194 /sbin/dhclient -1 -cf $DHCLIENT_CONF_FILE $ETH_DEVICE
195 if [[ $? -ne 0 ]]; then
196 echo "pl_netinit: dhcp failed, retrying in 2 minutes"
199 echo "pl_netinit: dhcp succeeded"
205 echo "pl_netinit: configuring device statically"
207 /sbin/ifconfig $ETH_DEVICE $IP_ADDRESS broadcast $IP_BROADCASTADDR \
209 /sbin/route add default gw $IP_GATEWAY dev $ETH_DEVICE
211 if [[ -z "$IP_DNS1" ]]; then
212 echo "pl_netinit: no dns server specified, cannot continue."
216 echo "nameserver $IP_DNS1" > /etc/resolv.conf
217 if [[ -n "$IP_DNS2" ]]; then
218 echo "nameserver $IP_DNS2" >> /etc/resolv.conf
222 echo "pl_netinit: network online"