Annotation of src/etc/netstart, Revision 1.49
1.1 deraadt 1: #!/bin/sh -
2: #
1.49 ! angelos 3: # $OpenBSD: netstart,v 1.48 1999/03/29 22:09:58 niklas 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.1 deraadt 46: # do this by reading /etc/hostname.* files, where * is the name
47: # of a given interface.
48: #
49: # these files are formatted like the following, but with no # at the
50: # beginning of the line
51: #
52: # addr_family hostname netmask broadcast_addr options
53: # dest dest_addr
54: #
1.42 marc 55: # OR
56: #
1.47 niklas 57: # dhcp
58: #
59: # OR
60: #
61: # bridge
62: # brconfig-arguments [ several lines if needed ]
1.42 marc 63: #
1.1 deraadt 64: # addr_family is the address family of the interface, generally inet
65: # hostname is the host name that belongs to the interface, in /etc/hosts.
66: # netmask is the network mask for the interface.
67: # broadcast_addr is the broadcast address for the interface
68: # options are misc. options to ifconfig for the interface.
69: #
70: # dest is simply the string "dest" (no quotes, though) if the interface
71: # has a "destination" (i.e. it's a point-to-point link, like SLIP).
72: # dest_addr is the hostname of the other end of the link, in /etc/hosts
73: #
1.47 niklas 74: # the only required contents of the file in this mode are the addr_family field
75: # and the hostname.
76: #
1.42 marc 77: # dhcp is simply the string "dhcp" (no quotes, though) if the interface
78: # is to be configured using DHCP. See dhclient(8) and dhclient.conf(5)
79: # for details.
80: #
1.47 niklas 81: # bridge is the string "bridge" (still no quotes). Bridge interfaces
82: # are just configured "up" and then brconfig(8) is called for each
83: # line of arguments following this first line.
84:
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
92: continue
1.49 ! angelos 93: fi
! 94:
! 95: # If the interface does not exist, just skip processing the file
! 96: /sbin/ifconfig $if > /dev/null 2>&1
! 97: if [ "$?" != "0" ]; then
! 98: continue
1.47 niklas 99: fi
100:
101: # Now parse the hostname.* file
102: {
103: read af name mask bcaddr extras
104:
105: # $af can be either "bridge", "dhcp", "up" or an address family.
106: case "$af" in
107: "bridge")
108: ifconfig $if up
109: cmd=`sed "s/\(.*\)/brconfig $if \1;/"`
110: ;;
111: "dhcp")
112: ifconfig $if $extras down
113: cmd="/sbin/dhclient $if"
114: ;;
115: "up")
116: # The only one of these guaranteed to be set is $if
117: cmd="ifconfig $if $name $mask $bcaddr $extras up"
118: ;;
119: *)
1.31 deraadt 120: read dt dtaddr
1.47 niklas 121: if [ ! -n "$name" ]; then
122: echo "/etc/hostname.$if: invalid network configuration file"
123: exit
124: fi
1.1 deraadt 125:
1.47 niklas 126: cmd="ifconfig $if $af $name "
127: if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
128: if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
129: if [ -n "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
130: cmd="$cmd broadcast $bcaddr";
1.1 deraadt 131: fi
1.47 niklas 132: cmd="$cmd $extras";
133: ;;
134: esac
135:
136: eval "$cmd"
137: } < /etc/hostname.$if
138: done
1.1 deraadt 139:
1.14 deraadt 140: # /etc/mygate, if it exists, contains the name of my gateway host
141: # that name must be in /etc/hosts.
1.42 marc 142: if [ -f /etc/mygate ]; then
1.38 deraadt 143: route -n add -host default `cat /etc/mygate`
1.14 deraadt 144: fi
1.44 deraadt 145:
1.48 niklas 146: # Multicast routing.
147: #
148: # The routing to the 224.0.0.0/4 net is setup according to these rules:
149: # multicast_host multicast_router route comment
150: # NO NO -reject no multicast
151: # NO YES none installed daemon will run
152: # YES/interface NO -interface YES=def. iface
153: # Any other combination -reject config error
154: case "$multicast_host:$multicast_router" in
155: NO:NO)
156: route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
157: NO:YES)
158: ;;
159: *:NO)
160: set `if [ $multicast_host = YES ]; then
161: ed -s '!route -n show' <<EOF
162: /^default/p
163: EOF
164: else
165: ed -s "!ifconfig $multicast_host" <<EOF
166: /^ inet /p
167: EOF
168: fi`
169: route -n add -net 224.0.0.0/4 -interface $2;;
170: *:*)
171: echo 'config error, multicasting disabled until rc.conf is fixed'
172: route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
173: esac
174:
1.44 deraadt 175: # Configure NAT after configuring network interfaces
176: if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
177: echo 'configuring NAT'
178: ipnat -CF -f ${ipnat_rules}
179: else
180: ipnat=NO
181: fi