summaryrefslogtreecommitdiff
path: root/etc/netstart
blob: 02cdfa1b51c242e952d8ae2c1d9b46575578e777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/sh -
#
#	$NetBSD: netstart,v 1.67 1999/12/20 15:51:14 itojun Exp $
#	from: @(#)netstart	8.1 (Berkeley) 7/23/93

if [ -f /etc/rc.subr ]; then
	. /etc/rc.subr
else
	echo "Can't read /etc/rc.subr; aborting."
	exit 1;
fi

if [ -f /etc/rc.conf ]; then
	. /etc/rc.conf
fi

# If $hostname is set, use it for my Internet name, otherwise use /etc/myname
if [ -z "$hostname" -a -f /etc/myname ]; then
	hostname=`cat /etc/myname`
fi
if [ -n "$hostname" ]; then
	echo "hostname: $hostname"
	hostname $hostname
fi

# Check $domainname first, then /etc/defaultdomain, for NIS/YP domain name
if [ -z "$domainname" -a -f /etc/defaultdomain ]; then
	domainname=`cat /etc/defaultdomain`
fi
if [ -n "$domainname" ]; then
	echo "domainname: $domainname"
	domainname $domainname
fi

# Flush all routes just to make sure it is clean
if checkyesno flushroutes; then
	route flush
fi

# Enable, flush and install packet filter rules before configuring interfaces.
if checkyesno ipfilter; then
	if [ -f /etc/ipf.conf ]; then
		echo 'installing packet filter rules ... '
		ipf -E -Fa -f /etc/ipf.conf
	else
		echo
		echo "WARNING: /etc/ipf.conf not readable " \
		    "ipfilter not started."
		# abort the boot rather than risk a security problem
		exit 1;
	fi
fi

# Set the address for the first loopback interface, so that the auto-route
# from a newly configured interface's address to lo0 works correctly.
#
# NOTE: obscure networking problems may occur if lo0 isn't configured...
#
ifconfig lo0 inet 127.0.0.1

# Configure all of the network interfaces listed in $net_interfaces;
# if $auto_ifconfig is YES, grab all interfaces from ifconfig.
# In the following, "xxN" stands in for interface names, like "le0".
# For any interfaces that has an $ifconfig_xxN variable associated,
# we do "ifconfig xxN $ifconfig_xxN".
# If there is no such variable, we take the contents of the file
# /etc/ifconfig.xxN, and run "ifconfig xxN" repeatedly, using each
# line of the file as the arguments for a seperate "ifconfig" invocation.
#
# In order to configure an interface reasonably, you at the very least
# need to specify "[addr_family] [hostname]" (as in "inet my.domain.org"),
# and probably a netmask (as in "netmask 0xffffffe0"). You will
# frequently need to specify a media type, as in "media UTP", for
# interface cards with multiple media connections that do not autoconfigure.
# see the ifconfig manual page for details.

if [ "$net_interfaces" != NO ]; then
	if checkyesno auto_ifconfig; then
		tmp="`ifconfig -l`"
	else
		tmp="$net_interfaces"
	fi
	echo -n 'configuring network interfaces:'
	for int in $tmp; do
		eval `echo 'args=$ifconfig_'$int`
		if [ -n "$args" ]; then
			echo -n " $int"
			ifconfig $int $args
		elif [ -f /etc/ifconfig.$int ]; then
			echo -n " $int"
			(while read args; do
				if [ -n "`eval echo '$args'`" ] ; then
					ifconfig $int $args
				fi
			done) < /etc/ifconfig.$int
		else
			if ! checkyesno auto_ifconfig; then
				echo
				echo "WARNING: /etc/ifconfig.$int missing " \
				    "and ifconfig_$int not set; " \
				    "interface $int not configured."
			fi
			continue
		fi
		configured_interfaces="$configured_interfaces $int"
	done
	echo '.'
fi

# Check $defaultroute, then /etc/mygate, for the name of my gateway host.
# That name must be in /etc/hosts.
if [ -z "$defaultroute" -a -f /etc/mygate ]; then
	defaultroute=`cat /etc/mygate`
fi
if [ -n "$defaultroute" ]; then
	route add default $defaultroute
fi

# Check if each configured interface xxN has an $ifaliases_xxN variable
# associated, then configure additional IP addresses for that interface.
# The variable contains a list of "address netmask" pairs, with "netmask"
# set to "-" if the interface default netmask is to be used.
#
# Note that $ifaliases_xxN works only with IPv4 addresses and considered
# not recommended.  See below (/etc/ifaliases section) for alternative.
# 
if [ -n "$configured_interfaces" ]; then
	echo 'adding interface aliases:';
	done_aliases_message=yes
fi
for int in $configured_interfaces; do
	eval `echo 'args=$ifaliases_'$int`
	if [ -n "$args" ]; then
		set -- $args
		while [ $# -ge 2 ]; do
			addr=$1 ; net=$2 ; shift 2
			if [ "$net" = "-" ]; then
				ifconfig $int inet alias $addr
			else
				ifconfig $int inet alias $addr netmask $net
			fi
			# Use loopback, not the wire
			route add $addr 127.0.0.1
		done
	fi
done

# /etc/ifaliases, if it exists, contains the names of additional IP
# addresses for each interface. It is formatted as a series of lines
# that contain
#	address interface netmask
#
# Note that /etc/ifaliases works only with IPv4 addresses and considered
# not recommended.  Recommend using /etc/ifconfig.xxN like below instead
# (/etc/ifconfig.xxN allows multiple lines):
#	inet 10.1.1.1 netmask 0xffffff00
#	inet 10.1.1.2 netmask 0xffffff00 alias
#	inet6 fec0::1 prefixlen 64 alias
#
if [ -f /etc/ifaliases ]; then
(
	if [ "$done_aliases_message" != yes ]; then
		echo 'adding interface aliases:';
	fi
	while read addr int net; do
		if [ -z "$net" ]; then
			ifconfig $int inet alias $addr
		else
			ifconfig $int inet alias $addr netmask $net
		fi
		# use loopback, not the wire
		route add $addr 127.0.0.1
	done
) < /etc/ifaliases
fi

# /etc/ppp/peers and $ppp_peers contain boot configuration information
# for pppd.  each value in $ppp_peers that has a file in /etc/ppp/peers
# of the same name, will be run as `pppd <peer>'.
if [ -n "$ppp_peers" ]; then
	# pppd is in /usr - need to ensure it is mounted
	mount /usr >/dev/null 2>&1	
	set -- $ppp_peers
	echo -n "starting pppd:"
	while [ $# -ge 1 ]; do
		peer=$1; shift
		if [ -f /etc/ppp/peers/$peer ]; then
			pppd call $peer
			echo -n " $peer"
		fi
	done
	echo "."
fi

if checkyesno dhclient; then
	echo -n "starting dhcp client...";
	dhclient $dhclient_flags
fi

# IPv6
# Note that manual configuration can be done in the above, using ifconfig.
if ifconfig lo0 inet6 >/dev/null 2>&1; then
	# We have IPv6 support in kernel.

	# disallow scoped unicast dest without outgoing scope identifiers.
	route add -inet6 fe80:: -prefixlen 10 ::1 -reject
	route add -inet6 fc80:: -prefixlen 10 ::1 -reject

	# disallow "internal" addresses to appear on the wire.
	# you may want to enable them for experiments.
	route add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
	route add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject

	# sysctl is in /usr - need to ensure it is mounted
	mount /usr >/dev/null 2>&1	

	sysctl -w net.inet6.ip6.forwarding=0
	sysctl -w net.inet6.ip6.accept_rtadv=0
	if checkyesno ip6forwarding; then
		if checkyesno rtsol; then
			echo "WARNING: rtsol cannot be used on IPv6 router."
		else
			sysctl -w net.inet6.ip6.forwarding=1
		fi
	else
		if checkyesno rtsol; then
			echo -n "sending IPv6 router solicitation...";
			sysctl -w net.inet6.ip6.accept_rtadv=1
			rtsol $rtsol_flags
		fi
	fi

	# wait till DAD is completed.
	# always invoke it in case if are configured manually by ifconfig
	dadcount=`sysctl -n net.inet6.ip6.dad_count 2>/dev/null`
	sleep $dadcount
	sleep 1
else
	# We do not have IPv6 support in kernel.
	if checkyesno ip6forwarding || checkyesno rtsol; then
		echo "WARNING: ip6 requested without kernel IPv6 config"
	fi
fi

if [ -s /etc/netstart.local ]; then
	. /etc/netstart.local
fi