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