Annotation of src/etc/netstart, Revision 1.53
1.1 deraadt 1: #!/bin/sh -
2: #
1.53 ! itojun 3: # $OpenBSD: netstart,v 1.52 1999/12/09 13:59:57 itojun 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.4 dm 29:
30: # Configure the IP filter before configuring network interfaces
31: if [ X"${ipfilter}" = X"YES" -a -f "${ipfilter_rules}" ]; then
32: echo 'configuring IP filter'
33: ipf -Fa -f ${ipfilter_rules} -E
34: else
35: ipfilter=NO
1.1 deraadt 36: fi
1.17 kstailey 37:
1.24 kstailey 38: # set the address for the loopback interface
1.52 itojun 39: # it will also initialize IPv6 address for lo0 (::1 and others).
1.24 kstailey 40: ifconfig lo0 inet localhost
1.1 deraadt 41:
1.24 kstailey 42: # use loopback, not the wire
1.38 deraadt 43: route -n add -host $hostname localhost
44: route -n add -net 127 127.0.0.1 -reject
1.24 kstailey 45:
46: # configure all of the non-loopback interfaces which we know about.
1.50 deraadt 47: # refer to hostname.if(5) and bridgename.if(5)
1.47 niklas 48: for hn in /etc/hostname.*; do
49: # Strip off /etc/hostname. prefix
50: if=${hn#/etc/hostname.}
51:
52: # Interface names must be alphanumeric only. We check to avoid
53: # configuring backup or temp files, and to catch the "*" case.
54: if ! isalphanumeric "$if"; then
55: continue
1.49 angelos 56: fi
1.50 deraadt 57: ifconfig $if > /dev/null 2>&1
1.49 angelos 58: if [ "$?" != "0" ]; then
59: continue
1.47 niklas 60: fi
61:
62: # Now parse the hostname.* file
63: {
64: read af name mask bcaddr extras
65:
1.50 deraadt 66: # $af can be either "dhcp", "up" or an address family.
1.47 niklas 67: case "$af" in
68: "bridge")
1.50 deraadt 69: cmd="echo ${hn}: bridges now supported via bridgename.* files"
70: ;;
1.47 niklas 71: "dhcp")
1.50 deraadt 72: ifconfig $if $name $mask $bcaddr $extras down
73: cmd="dhclient $if"
1.47 niklas 74: ;;
75: "up")
76: # The only one of these guaranteed to be set is $if
1.50 deraadt 77: # the remaining ones exist so that media controls work
1.47 niklas 78: cmd="ifconfig $if $name $mask $bcaddr $extras up"
79: ;;
80: *)
1.31 deraadt 81: read dt dtaddr
1.47 niklas 82: if [ ! -n "$name" ]; then
83: echo "/etc/hostname.$if: invalid network configuration file"
1.50 deraadt 84: continue
1.47 niklas 85: fi
1.1 deraadt 86:
1.47 niklas 87: cmd="ifconfig $if $af $name "
88: if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
89: if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
90: if [ -n "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
91: cmd="$cmd broadcast $bcaddr";
1.1 deraadt 92: fi
1.47 niklas 93: cmd="$cmd $extras";
94: ;;
95: esac
96:
97: eval "$cmd"
98: } < /etc/hostname.$if
1.50 deraadt 99: done
100: for bn in /etc/bridgename.*; do
101: # Strip off /etc/bridgename. prefix
102: if=${bn#/etc/bridgename.}
103:
104: # Interface names must be alphanumeric only. We check to avoid
105: # configuring backup or temp files, and to catch the "*" case.
106: if ! isalphanumeric "$if"; then
107: continue
108: fi
109: brconfig $if > /dev/null 2>&1
110: if [ "$?" != "0" ]; then
111: continue
112: fi
113:
114: # Now parse the bridgename.* file
115: {
116: # All lines are run as brconfig(8) commands.
117: while read line ; do
1.51 deraadt 118: line=${line%%#*} # strip comments
119: test -z "$line" && continue
1.50 deraadt 120: brconfig $if $line
121: done
122: } < /etc/bridgename.$if
1.47 niklas 123: done
1.1 deraadt 124:
1.14 deraadt 125: # /etc/mygate, if it exists, contains the name of my gateway host
126: # that name must be in /etc/hosts.
1.42 marc 127: if [ -f /etc/mygate ]; then
1.38 deraadt 128: route -n add -host default `cat /etc/mygate`
1.14 deraadt 129: fi
1.44 deraadt 130:
1.48 niklas 131: # Multicast routing.
132: #
133: # The routing to the 224.0.0.0/4 net is setup according to these rules:
134: # multicast_host multicast_router route comment
135: # NO NO -reject no multicast
136: # NO YES none installed daemon will run
137: # YES/interface NO -interface YES=def. iface
138: # Any other combination -reject config error
139: case "$multicast_host:$multicast_router" in
140: NO:NO)
141: route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
142: NO:YES)
143: ;;
144: *:NO)
145: set `if [ $multicast_host = YES ]; then
146: ed -s '!route -n show' <<EOF
147: /^default/p
148: EOF
149: else
150: ed -s "!ifconfig $multicast_host" <<EOF
151: /^ inet /p
152: EOF
153: fi`
154: route -n add -net 224.0.0.0/4 -interface $2;;
155: *:*)
156: echo 'config error, multicasting disabled until rc.conf is fixed'
157: route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
158: esac
1.53 ! itojun 159:
! 160: # IPv6 configurations.
! 161: # disallow scoped unicast dest without outgoing scope identifiers.
! 162: route add -inet6 fe80:: -prefixlen 10 ::1 -reject
! 163: route add -inet6 fc80:: -prefixlen 10 ::1 -reject
! 164: # disallow "internal" addresses to appear on the wire.
! 165: route add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
! 166: route add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
1.48 niklas 167:
1.44 deraadt 168: # Configure NAT after configuring network interfaces
169: if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
170: echo 'configuring NAT'
171: ipnat -CF -f ${ipnat_rules}
172: else
173: ipnat=NO
174: fi