minix/etc/usr/rc
David van Moolenbroek 9ba65d2ea8 This patch switches the MINIX3 ethernet driver stack from a port-based
model to an instance-based model. Each ethernet driver instance is now
responsible for exactly one network interface card. The port field in
/etc/inet.conf now acts as an instance field instead.

This patch also updates the data link protocol. This update:
- eliminates the concept of ports entirely;
- eliminates DL_GETNAME entirely;
- standardizes on using m_source for IPC and DL_ENDPT for safecopies;
- removes error codes from TASK/STAT replies, as they were unused;
- removes a number of other old or unused fields;
- names and renames a few other fields.

All ethernet drivers have been changed to:
- conform to the new protocol, and exactly that;
- take on an instance number based on a given "instance" argument;
- skip that number of PCI devices in probe iterations;
- use config tables and environment variables based on that number;
- no longer be limited to a predefined maximum of cards in any way;
- get rid of any leftover non-safecopy support and other ancient junk;
- have a correct banner protocol figure, or none at all.

Other changes:
* Inet.conf is now taken to be line-based, and supports #-comments.
  No existing installations are expected to be affected by this.
* A new, select-based asynchio library replaces the old one.
  Kindly contributed by Kees J. Bot.
* Inet now supports use of select() on IP devices.
  Combined, the last two changes together speed up dhcpd
  considerably in the presence of multiple interfaces.
* A small bug has been fixed in nonamed.
2010-05-17 22:22:53 +00:00

209 lines
4.6 KiB
Text

# /usr/etc/rc - continued system initialization.
RANDOM_FILE=/usr/adm/random.dat
LOCAL_FILE=/usr/etc/rc.local
case "$#:$1" in
1:start|1:stop|1:down)
action=$1
;;
*) echo >&2 "Usage: $0 start|stop|down"
exit 1
esac
if [ -f "$LOCAL_FILE" ]
then . "$LOCAL_FILE" $1
fi
disabled()
{
ifs="$IFS"; IFS=,
for skip in `sysenv disable`
do
if [ "$skip" = "$1" ]
then
IFS="$ifs"; unset ifs
return 0
fi
done
IFS="$ifs"; unset ifs
return 1
}
daemonize()
{
# Function to start a daemon, if it exists.
local IFS=':'
local name="$1"
test "$1" = tcpd && name="$2"
for dir in $PATH
do
if [ -f "$dir/$1" ]
then
# check if this service is disabled at the boot monitor.
if disabled $name; then return; fi
echo -n " $name"
"$@" &
return
fi
done
}
up()
{
upopt " " "$@"
}
upopt()
{
opt=$1
shift
service=$1
shift
# Function to dynamically start a system service
# First check if this service is disabled at the boot monitor.
if disabled $service; then return; fi
# Service is not disabled. Try to bring it up.
echo -n " $service"
service $opt up /usr/sbin/$service "$@"
}
get_eth_labels() {
# Filter out the non-vlan ethernet entries from inet.conf.
# Produce as output a list of "drivername_instancenr"-formatted labels.
# The first sed is taken from /bin as older GNU sed versions don't know '\t'.
/bin/sed 's/\t/ /g' /etc/inet.conf | \
sed -n 's/^ *eth[0-9][0-9]* *\([^ ][^ ]*\) *\([0-9][0-9]*\).*$/\1_\2/p' | \
grep -v '^vlan_'
}
DAEMONS=/etc/rc.daemons
case $action in
start)
# Select console font.
test -f /etc/font && loadfont /etc/font </dev/console
# Cleanup.
rm -rf /tmp/. /usr/run/. /usr/spool/lpd/. /usr/spool/locks/.
# Start servers and drivers set at the boot monitor.
echo -n "Starting services:"
upopt -n random -dev /dev/random -devstyle STYLE_DEVA -period 3HZ
# load random number generator
if [ -f $RANDOM_FILE ]
then
cat < $RANDOM_FILE >/dev/random
# overwrite $RANDOM_FILE. We don't want to use this data again
dd if=/dev/random of=$RANDOM_FILE bs=1024 count=1 2> /dev/null
fi
# start network driver instances for all configured ethernet devices
for label in $(get_eth_labels); do
driver=$(echo $label | sed 's/\(.*\)_.*/\1/')
instance=$(echo $label | sed 's/.*_//')
eval arg=\$${label}_arg
if [ ! -z "$arg" ]; then arg=" $arg"; fi
arg="-args \"instance=$instance$arg\""
eval up $driver -label $label $arg -period 5HZ
done
up inet -script /etc/rs.inet -dev /dev/ip -devstyle STYLE_CLONE
upopt -n printer -dev /dev/lp -period 10HZ
upopt -n ipc
echo .
# Network initialization.
(: </dev/tcp) 2>/dev/null && net=t # Is there a TCP/IP server?
echo -n "Starting daemons:"
daemonize update
# Ugly error message when starting cron from CD.
# (and cron unnecessary then so..)
if [ ! -f /CD ]
then daemonize cron
else mkdir /tmp/log
rm -f /var/log || true
ln -s /tmp/log /var/log || true
. /etc/rc.cd
fi
# syslogd has not been started yet
rm -f /var/run/syslogd.pid
daemonize syslogd
echo .
if [ "$net" ]
then
if [ -f /etc/rc.net ]
then
# Let a customized TCP/IP initialization script figure it out.
. /etc/rc.net
else
# Standard network daemons.
echo -n "Starting networking:"
if grep -s 'psip0.*default' /etc/inet.conf
then ifconfig -h 10.0.0.1
else
daemonize dhcpd
fi
daemonize nonamed -L
if [ -f "$DAEMONS" ]
then . "$DAEMONS"
fi
# The last daemon has been started, so close the list:
echo .
fi
fi
if [ "$net" ]
then
# Get the nodename from the DNS and set it.
trap '' 2
intr -t 20 hostaddr -h
trap 2
fi
# Recover files being edited when the system crashed.
test -f /usr/bin/elvprsv && elvprsv /usr/tmp/elv*
# Run the daily cleanup on systems that are not on at night.
test -f /usr/etc/daily && sh /usr/etc/daily boot &
;;
stop|down)
# Save random data, if /usr is mounted rw.
if grep ' \/usr .*rw' /etc/mtab >/dev/null
then
if dd if=/dev/random of=$RANDOM_FILE.new bs=1024 count=1 2>/dev/null
then
mv $RANDOM_FILE.new $RANDOM_FILE
else
echo 'Failed to save random data.'
fi
fi
esac
d=/usr/local/etc/rc.d
# Let packages run their own scripts
if [ -d "$d" ]
then if cd $d
then
echo -n "Local packages ($action): "
for f in *
do
if [ -x "$f" ]
then echo -n "$f "
sh "$f" "$action"
fi
done
echo " done."
fi
fi