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
32 # for some backwards compatibility, save the ifconfig <device>
34 IFCONFIG_OUTPUT=/tmp/ifconfig
40 echo "pl_netinit: network initialization failed,"
41 echo "pl_netinit: shutting down machine in two hours"
47 # Function for checking the IP address to see if its sensible.
51 "" | *[!0-9.]* | *[!0-9]) return 1 ;;
56 [ ${1:-666} -le 255 ] && [ ${2:-666} -le 255 ] &&
57 [ ${3:-666} -le 255 ] && [ ${4:-666} -le 255 ]
60 echo "pl_netinit: bringing loopback network device up"
61 /sbin/ifconfig lo 127.0.0.1 up
67 echo "pl_netinit: looking for network configuration on floppy"
68 /bin/mount -o ro -t $FLOPPY_FS_TYPES /dev/fd0 $FLOPPY_MOUNT_POINT 2>&1 > /dev/null
69 if [[ $? -eq 0 ]]; then
70 floppy_conf_file="$FLOPPY_MOUNT_POINT/$FLOPPY_NET_CONF"
71 if [ -r "$floppy_conf_file" ]; then
73 echo "pl_netinit: found floppy configuration file, using"
74 /etc/init.d/pl_validateconf < $floppy_conf_file > $USED_NET_CONF
77 echo "pl_netinit: floppy mounted, but no configuration file."
79 /bin/umount $FLOPPY_MOUNT_POINT
81 echo "pl_netinit: no floppy found"
85 if [[ $FOUND_NET_CONF -eq 0 ]]; then
86 echo "pl_netinit: looking for network configuration on cd"
87 if [ -r "$USER_NET_CONF" ]; then
89 echo "pl_netinit: found cd configuration file, using"
90 /etc/init.d/pl_validateconf < $USER_NET_CONF > $USED_NET_CONF
95 if [[ $FOUND_NET_CONF -eq 0 ]]; then
96 echo "pl_netinit: using default network configuration"
97 if [ -r "$FALLBACK_NET_CONF" ]; then
99 echo "pl_netinit: found cd default configuration file, using"
100 /etc/init.d/pl_validateconf < $FALLBACK_NET_CONF > $USED_NET_CONF
107 if [[ $FOUND_NET_CONF -eq 0 ]]; then
108 # no network configuration file found. this should not happen as the
109 # default cd image has a backup one. halt.
110 echo "pl_netinit: unable to find even a default network configuration"
111 echo "pl_netinit: file, this cd may be corrupt."
115 # load the configuration file. if it was a default one (not user specified),
116 # then remove the saved copy from /tmp, but continue on. since a network
117 # configuration file is required and boot scripts only know about this location
118 # they will fail (as they should) - but the network will be up if dhcp is
121 echo "pl_netinit: loading network configuration"
124 if [[ $DEFAULT_NET_CONF -eq 1 ]]; then
125 /bin/rm -f $USED_NET_CONF
128 # now, we need to find which device to use (ie, eth0 or eth1). start out
129 # by defaulting to eth0, then see if the network configuration file specified
130 # either a mac address (in which case we will need to find the device), or
133 if [[ -n "$PRIMARY_MAC" ]]; then
134 # the user specified a mac address we should use. find the network
136 echo "pl_netinit: looking for a device with mac address $PRIMARY_MAC"
141 dev_address=`cat $device/address`
142 if [[ "$dev_address" == "$PRIMARY_MAC" ]]; then
144 echo "pl_netinit: found device $ETH_DEVICE"
150 elif [[ -n "$PRIMARY_DEV" ]]; then
151 # the user specified a virtual ethernet device to use.
152 ETH_DEVICE=$PRIMARY_DEV
153 echo "pl_netinit: using user specified device $ETH_DEVICE"
156 ETH_DEVICE=$DEFAULT_NET_DEV
157 echo "pl_netinit: using default device $ETH_DEVICE"
162 # if we couldn't find a device (would happen if PRIMARY_MAC was specified
163 # but we couldn't find a device for that addresS), then abort the rest
166 if [[ -z "$ETH_DEVICE" ]]; then
167 echo "pl_netinit: unable to find a usable device, check to make sure"
168 echo "pl_netinit: the PRIMARY_MAC field in the configuration file"
169 echo "pl_netinit: cooresponds with a network adapter on this system"
174 # actually check to make sure ifconfig <device> succeeds
175 /sbin/ifconfig $ETH_DEVICE up 2>&1 > /dev/null
176 if [[ $? -ne 0 ]]; then
177 echo "pl_netinit: device $ETH_DEVICE does not exist,"
178 echo "pl_netinit: this is due to either the device not existing,"
179 echo "pl_netinit: or its device drivers not being loaded"
183 if [[ "$IP_METHOD" == "dhcp" ]]; then
184 echo "pl_netinit: attempting to bring up device with dhcp"
186 # setup a dhclient conf file for this device (used to send
187 # our hostname to the dhcp server)
188 echo "interface \"$ETH_DEVICE\" {" > $DHCLIENT_CONF_FILE
189 echo "send host-name \"$HOST_NAME.$DOMAIN_NAME\";" >> $DHCLIENT_CONF_FILE
190 echo "}" >> $DHCLIENT_CONF_FILE
192 # touch the redhat net device configuration file so
193 # dhclient doesn't complain
194 /bin/touch /etc/sysconfig/network-scripts/ifcfg-$ETH_DEVICE
197 while [[ $configured -eq 0 ]]; do
198 /sbin/dhclient -1 -cf $DHCLIENT_CONF_FILE $ETH_DEVICE
199 if [[ $? -ne 0 ]]; then
200 echo "pl_netinit: dhcp failed, retrying in 2 minutes"
203 echo "pl_netinit: dhcp succeeded"
209 echo "pl_netinit: configuring device statically"
211 /sbin/ifconfig $ETH_DEVICE $IP_ADDRESS broadcast $IP_BROADCASTADDR \
213 /sbin/route add default gw $IP_GATEWAY dev $ETH_DEVICE
215 if [[ -z "$IP_DNS1" ]]; then
216 echo "pl_netinit: no dns server specified, cannot continue."
220 echo "nameserver $IP_DNS1" > /etc/resolv.conf
221 if [[ -n "$IP_DNS2" ]]; then
222 echo "nameserver $IP_DNS2" >> /etc/resolv.conf
226 # for backwards compatibility
227 /sbin/ifconfig $ETH_DEVICE > $IFCONFIG_OUTPUT
229 echo "pl_netinit: network online"