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