xref: /minix/etc/rs.lwip (revision 9f81acbc)
1#!/bin/sh
2
3# Recovery script for LWIP.  Aside from restarting the LWIP service itself, the
4# script aims to restart all of networking.  This includes in particular any
5# network daemons: these daemons typically have open (listening) sockets that
6# will now have become invalid, and the daemons typically do not know how to
7# deal with that.  Unfortunately, there is no reliable way to determine the
8# list of rc scripts that concern network daemons, so for now we hardcode a
9# list of known ones here: this is the list of network-related rc.d scripts.
10# FIXME: since we are not yet done importing etc/rc.d from NetBSD, this list is
11# still incomplete and should be extended as more scripts are imported!
12RC_SCRIPTS="dhclient dhcpcd dhcpd dhcrelay ftpd inetd named network rtadvd \
13    sshd staticroute syslogd"
14
15exec < /dev/console
16exec > /dev/console
17exec 2> /dev/console
18
19export HOME=/
20export PATH=/sbin:/usr/sbin:/bin:/usr/bin
21
22. /etc/rc.subr
23. /etc/rc.conf
24
25# Restart the LWIP service.
26
27# There is no need to shut down daemons before bringing back up the service.
28# Note that "minix-service restart" does not do the same as these steps, and in
29# fact breaks a proper LWIP restart.
30restarts=$(grep restarts /proc/service/$1 | cut -d: -f2)
31minix-service down "$1"
32minix-service up /service/lwip -dev /dev/bpf -script /etc/rs.lwip \
33    -restarts $(($restarts + 1))
34
35# Reload TCP ISN, or make a new one if there is none.  Do not save anything.
36TCPISN_FILE=/usr/adm/tcpisn.dat
37TCPISN_LEN=$(sysctl -n net.inet.tcp.isn_secret | awk '{print length/2}')
38if [ ! -f $TCPISN_FILE ]; then TCPISN_FILE=/dev/random; fi
39sysctl -qw net.inet.tcp.isn_secret=`dd if=$TCPISN_FILE bs=$TCPISN_LEN \
40    count=1 2>/dev/null | hexdump -v -e '/1 "%02x"'` 2>/dev/null
41
42# Let LWIP find all network drivers before performing initialization.
43sleep 1
44
45# Restart all network daemons.
46
47# Start with dhcpcd, which may be launched directly from ifconfig.if(5) scripts
48# and therefore may not be enabled in, and thus stopped by, rc.d scripts below.
49service dhcpcd onestop >/dev/null 2>&1
50
51# Then stop and start all known network daemons using their rc.d scripts.
52regex='/('"$(echo $RC_SCRIPTS | tr ' ' '|')"')$'
53scripts=$(for rcd in ${rc_directories:-/etc/rc.d}; do
54	test -d ${rcd} && echo ${rcd}/*; done)
55files=$(rcorder ${scripts} | grep -E "$regex")
56
57for _rc_elem in $(reverse_list $files); do
58	# We have already stopped dhcpcd if it was running, so skip it here.
59	[ $_rc_elem != /etc/rc.d/dhcpcd ] && run_rc_script $_rc_elem stop
60done
61
62for _rc_elem in $files; do
63	run_rc_script $_rc_elem start
64done
65