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