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