Annotation of src/etc/netstart, Revision 1.70
1.1 deraadt 1: #!/bin/sh -
2: #
1.69 deraadt 3: # $OpenBSD: netstart,v 1.68 2000/04/04 13:44:51 millert Exp $
1.45 millert 4:
5: # Returns true if $1 contains only alphanumerics
6: isalphanumeric() {
7: local _n
8: _n=$1
9: while [ ${#_n} != 0 ]; do
10: case $_n in
11: [A-Za-z0-9]*) ;;
12: *) return 1;;
13: esac
14: _n=${_n#?}
15: done
16: return 0
17: }
1.1 deraadt 18:
19: # /etc/myname contains my symbolic name
20: #
21: hostname=`cat /etc/myname`
22: hostname $hostname
23: if [ -f /etc/defaultdomain ]; then
24: domainname `cat /etc/defaultdomain`
1.4 dm 25: fi
1.30 deraadt 26:
27: # pick up option configuration
28: . /etc/rc.conf
1.69 deraadt 29: if [ -f $local_rcconf ]; then
30: . $local_rcconf
31: fi
1.4 dm 32:
33: # Configure the IP filter before configuring network interfaces
34: if [ X"${ipfilter}" = X"YES" -a -f "${ipfilter_rules}" ]; then
35: echo 'configuring IP filter'
1.68 millert 36: ipf -Fa -f ${ipfilter_rules}
1.4 dm 37: else
38: ipfilter=NO
1.1 deraadt 39: fi
1.17 kstailey 40:
1.24 kstailey 41: # set the address for the loopback interface
1.52 itojun 42: # it will also initialize IPv6 address for lo0 (::1 and others).
1.24 kstailey 43: ifconfig lo0 inet localhost
1.1 deraadt 44:
1.24 kstailey 45: # use loopback, not the wire
1.67 deraadt 46: route -n add -host $hostname localhost > /dev/null
47: route -n add -net 127 127.0.0.1 -reject > /dev/null
1.24 kstailey 48:
1.54 itojun 49: if ifconfig lo0 inet6 >/dev/null 2>&1; then
50: # IPv6 configurations.
51: ip6kernel=YES
52:
1.66 itojun 53: # disallow link-local unicast dest without outgoing scope identifiers.
1.67 deraadt 54: route add -inet6 fe80:: -prefixlen 10 ::1 -reject > /dev/null
1.66 itojun 55:
56: # disallow site-local unicast dest without outgoing scope identifiers..
57: # If you configure site-locals without scope id (it is permissible
58: # config for routers that are not on scope boundary), you may want
59: # to comment the line out.
1.67 deraadt 60: route add -inet6 fec0:: -prefixlen 10 ::1 -reject > /dev/null
1.66 itojun 61:
1.54 itojun 62: # disallow "internal" addresses to appear on the wire.
1.67 deraadt 63: route add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject > /dev/null
1.66 itojun 64:
65: # disallow packets to malicious IPv4 compatible prefix.
1.67 deraadt 66: route add -inet6 ::224.0.0.0 -prefixlen 100 ::1 -reject > /dev/null
67: route add -inet6 ::127.0.0.0 -prefixlen 104 ::1 -reject > /dev/null
68: route add -inet6 ::0.0.0.0 -prefixlen 104 ::1 -reject > /dev/null
69: route add -inet6 ::255.0.0.0 -prefixlen 104 ::1 -reject > /dev/null
1.66 itojun 70:
71: # disallow packets to malicious 6to4 prefix.
1.67 deraadt 72: route add -inet6 2002:e000:: -prefixlen 20 ::1 -reject > /dev/null
73: route add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject > /dev/null
74: route add -inet6 2002:0000:: -prefixlen 24 ::1 -reject > /dev/null
75: route add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject > /dev/null
1.66 itojun 76:
77: # Completely disallow packets to IPv4 compatible prefix.
78: # This may conflict with RFC1933 under following circumstances:
79: # (1) An IPv6-only KAME node tries to originate packets to IPv4
80: # comatible destination. The KAME node has no IPv4 compatible
81: # support. Under RFC1933, it should transmit native IPv6
82: # packets toward IPv4 compatible destination, hoping it would
83: # reach a router that forwards the packet toward auto-tunnel
84: # interface.
85: # (2) An IPv6-only node originates a packet to IPv4 compatible
86: # destination. A KAME node is acting as an IPv6 router, and
87: # asked to forward it.
88: # Due to rare use of IPv4 compatible address, and security issues
89: # with it, we disable it by default.
1.67 deraadt 90: route add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject > /dev/null
1.56 itojun 91:
92: rtsolif=""
1.54 itojun 93: else
94: ip6kernel=NO
95: fi
96:
1.24 kstailey 97: # configure all of the non-loopback interfaces which we know about.
1.50 deraadt 98: # refer to hostname.if(5) and bridgename.if(5)
1.47 niklas 99: for hn in /etc/hostname.*; do
100: # Strip off /etc/hostname. prefix
101: if=${hn#/etc/hostname.}
102:
103: # Interface names must be alphanumeric only. We check to avoid
104: # configuring backup or temp files, and to catch the "*" case.
105: if ! isalphanumeric "$if"; then
1.55 todd 106: continue
1.49 angelos 107: fi
1.50 deraadt 108: ifconfig $if > /dev/null 2>&1
1.49 angelos 109: if [ "$?" != "0" ]; then
110: continue
1.47 niklas 111: fi
112:
113: # Now parse the hostname.* file
1.55 todd 114: while :; do
115: if [ "$cmd2" ]; then
116: # we are carrying over from the 'read dt dtaddr' last time
117: set -- $cmd2
118: af="$1" name="$2" mask="$3" bcaddr="$4" ext1="$5" ext2="$6"
119: cmd2=
120: else
121: # read the next line or exit the while loop
122: read af name mask bcaddr ext1 ext2 || break
123: fi
1.63 todd 124: # $af can be "dhcp", "up", "rtsol", an address family, commands, or
125: # a comment.
1.47 niklas 126: case "$af" in
1.63 todd 127: "#"*) # skip comments
128: continue
129: ;;
130: "!"*) # parse commands
131: cmd="${af#*!} ${name} ${mask} ${bcaddr} ${ext1} ${ext2}"
132: ;;
1.47 niklas 133: "bridge")
1.50 deraadt 134: cmd="echo ${hn}: bridges now supported via bridgename.* files"
135: ;;
1.47 niklas 136: "dhcp")
1.70 ! todd 137: [ "$name" = "NONE" ] && name=
! 138: [ "$mask" = "NONE" ] && mask=
! 139: [ "$bcaddr" = "NONE" ] && bcaddr=
1.55 todd 140: ifconfig $if $name $mask $bcaddr $ext1 $ext2 down
1.50 deraadt 141: cmd="dhclient $if"
1.47 niklas 142: ;;
1.56 itojun 143: "rtsol")
1.62 deraadt 144: ifconfig $if $name $mask $bcaddr $ext1 $ext2 up
1.56 itojun 145: rtsolif="$rtsolif $if"
1.59 todd 146: cmd=
1.56 itojun 147: ;;
1.47 niklas 148: "up")
149: # The only one of these guaranteed to be set is $if
1.50 deraadt 150: # the remaining ones exist so that media controls work
1.55 todd 151: cmd="ifconfig $if $name $mask $bcaddr $ext1 $ext2 up"
152: ;;
153: *)
154: read dt dtaddr
155: if [ "$name" = "alias" ]; then
156: # perform a 'shift' of sorts
157: alias=$name
158: name=$mask
159: mask=$bcaddr
160: bcaddr=$ext1
161: ext1=$ext2
162: ext2=
1.47 niklas 163: fi
1.55 todd 164: cmd="ifconfig $if $af $alias $name "
1.64 todd 165: case "$dt" in
1.55 todd 166: dest)
167: cmd="$cmd $dtaddr"
168: ;;
1.64 todd 169: [a-z!]*)
1.55 todd 170: cmd2="$dt $dtaddr"
171: ;;
1.60 itojun 172: esac
173: if [ ! -n "$name" ]; then
1.55 todd 174: echo "/etc/hostname.$if: invalid network configuration file"
175: return
1.60 itojun 176: fi
177: case $af in
178: inet)
1.55 todd 179: [ "$mask" ] && cmd="$cmd netmask $mask"
180: if [ "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
181: cmd="$cmd broadcast $bcaddr"
182: fi
183: [ "$alias" ] && rtcmd="; route -n add -host $name 127.0.0.1"
1.61 itojun 184: ;;
1.60 itojun 185: inet6) [ "$mask" ] && cmd="$cmd prefixlen $mask"
1.55 todd 186: cmd="$cmd $bcaddr"
187: ;;
1.60 itojun 188: *) cmd="$cmd $mask $bcaddr"
189: esac
190: cmd="$cmd $ext1 $ext2$rtcmd" rtcmd=
191: ;;
1.47 niklas 192: esac
193: eval "$cmd"
1.55 todd 194: done < /etc/hostname.$if
1.50 deraadt 195: done
1.56 itojun 196:
197: if [ "$ip6kernel" = "YES" -a "x$rtsolif" != "x" ]; then
198: fw=`sysctl -n net.inet6.ip6.forwarding`
199: ra=`sysctl -n net.inet6.ip6.accept_rtadv`
200: if [ "x$fw" = "x0" -a "x$ra" = "x1" ]; then
1.57 itojun 201: echo "IPv6 autoconf:$rtsolif"
1.56 itojun 202: rtsol $rtsolif
203: else
204: echo "WARNING: inconsistent config - check /etc/sysctl.conf for IPv6 autoconf"
205: fi
1.57 itojun 206: fi
207: if [ "$ip6kernel" = "YES" ]; then
208: # this is to make sure DAD is completed before going further.
209: sleep `sysctl -n net.inet6.ip6.dad_count`
210: sleep 1
1.56 itojun 211: fi
212:
1.50 deraadt 213: for bn in /etc/bridgename.*; do
214: # Strip off /etc/bridgename. prefix
215: if=${bn#/etc/bridgename.}
216:
217: # Interface names must be alphanumeric only. We check to avoid
218: # configuring backup or temp files, and to catch the "*" case.
219: if ! isalphanumeric "$if"; then
220: continue
221: fi
222: brconfig $if > /dev/null 2>&1
223: if [ "$?" != "0" ]; then
224: continue
225: fi
226:
227: # Now parse the bridgename.* file
228: {
229: # All lines are run as brconfig(8) commands.
230: while read line ; do
1.51 deraadt 231: line=${line%%#*} # strip comments
232: test -z "$line" && continue
1.50 deraadt 233: brconfig $if $line
234: done
235: } < /etc/bridgename.$if
1.47 niklas 236: done
1.1 deraadt 237:
1.14 deraadt 238: # /etc/mygate, if it exists, contains the name of my gateway host
239: # that name must be in /etc/hosts.
1.42 marc 240: if [ -f /etc/mygate ]; then
1.38 deraadt 241: route -n add -host default `cat /etc/mygate`
1.14 deraadt 242: fi
1.44 deraadt 243:
1.48 niklas 244: # Multicast routing.
245: #
246: # The routing to the 224.0.0.0/4 net is setup according to these rules:
247: # multicast_host multicast_router route comment
248: # NO NO -reject no multicast
249: # NO YES none installed daemon will run
250: # YES/interface NO -interface YES=def. iface
251: # Any other combination -reject config error
252: case "$multicast_host:$multicast_router" in
253: NO:NO)
1.67 deraadt 254: route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject> /dev/null
255: ;;
1.48 niklas 256: NO:YES)
257: ;;
258: *:NO)
259: set `if [ $multicast_host = YES ]; then
260: ed -s '!route -n show' <<EOF
261: /^default/p
262: EOF
263: else
264: ed -s "!ifconfig $multicast_host" <<EOF
265: /^ inet /p
266: EOF
267: fi`
1.67 deraadt 268: route -n add -net 224.0.0.0/4 -interface $2 > /dev/null
269: ;;
1.48 niklas 270: *:*)
271: echo 'config error, multicasting disabled until rc.conf is fixed'
1.67 deraadt 272: route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject > /dev/null
273: ;;
1.48 niklas 274: esac
1.53 itojun 275:
1.44 deraadt 276: # Configure NAT after configuring network interfaces
277: if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
278: echo 'configuring NAT'
279: ipnat -CF -f ${ipnat_rules}
280: else
281: ipnat=NO
282: fi