Annotation of src/etc/netstart, Revision 1.46
1.1 deraadt 1: #!/bin/sh -
2: #
1.46 ! millert 3: # $OpenBSD: netstart,v 1.45 1998/10/28 19:17:10 millert 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: #
57: # dhcp
58: #
1.1 deraadt 59: # addr_family is the address family of the interface, generally inet
60: # hostname is the host name that belongs to the interface, in /etc/hosts.
61: # netmask is the network mask for the interface.
62: # broadcast_addr is the broadcast address for the interface
63: # options are misc. options to ifconfig for the interface.
64: #
65: # dest is simply the string "dest" (no quotes, though) if the interface
66: # has a "destination" (i.e. it's a point-to-point link, like SLIP).
67: # dest_addr is the hostname of the other end of the link, in /etc/hosts
68: #
1.42 marc 69: # dhcp is simply the string "dhcp" (no quotes, though) if the interface
70: # is to be configured using DHCP. See dhclient(8) and dhclient.conf(5)
71: # for details.
72: #
1.1 deraadt 73: # the only required contents of the file are the addr_family field
74: # and the hostname.
75:
1.42 marc 76: (
1.45 millert 77: for hn in /etc/hostname.*; do
78: # Strip off /etc/hostname. prefix
79: if=${hn#/etc/hostname.}
80:
81: # Interface names must be alphanumeric only. We check to avoid
82: # configuring backup or temp files, and to catch the "*" case.
83: if ! isalphanumeric "$if"; then
84: continue
85: fi
1.1 deraadt 86:
1.45 millert 87: # Now parse the hostname.* file
1.1 deraadt 88: (
89: read af name mask bcaddr extras
1.31 deraadt 90: read dt dtaddr
1.1 deraadt 91:
1.46 ! millert 92: # $af can be either "up", "dhcp", or an address family.
! 93: if [ "$af" = "up" ]; then
! 94: # The only one of these guaranteed to be set is $if
! 95: ifconfig $if $name $mask $bcaddr $extras up
! 96: elif [ "$af" = "dhcp" ]; then
1.45 millert 97: ifconfig $if $extras down
98: cmd="/sbin/dhclient $if";
1.42 marc 99: else
100: if [ ! -n "$name" ]; then
1.45 millert 101: echo "/etc/hostname.$if: invalid network configuration file"
1.42 marc 102: exit
103: fi
104:
1.45 millert 105: cmd="ifconfig $if $af $name "
1.42 marc 106: if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
107: if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
108: if [ -n "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
109: cmd="$cmd broadcast $bcaddr";
110: fi
111: cmd="$cmd $extras";
1.1 deraadt 112: fi
113:
114: $cmd
1.45 millert 115: ) < /etc/hostname.$if
1.1 deraadt 116: done
1.42 marc 117: )
1.1 deraadt 118:
1.14 deraadt 119: # /etc/mygate, if it exists, contains the name of my gateway host
120: # that name must be in /etc/hosts.
1.42 marc 121: if [ -f /etc/mygate ]; then
1.38 deraadt 122: route -n add -host default `cat /etc/mygate`
1.40 downsj 123:
124: # default multicast route for hosts with a gateway
125: route -n add -net 224.0.0.0 -interface default
1.42 marc 126: else
1.40 downsj 127: # default multicast route
128: route -n add -net 224.0.0.0 -interface $hostname
1.14 deraadt 129: fi
1.44 deraadt 130:
131: # Configure NAT after configuring network interfaces
132: if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
133: echo 'configuring NAT'
134: ipnat -CF -f ${ipnat_rules}
135: else
136: ipnat=NO
137: fi