netstart revision 1.42
1#!/bin/sh -
2#
3#	$OpenBSD: netstart,v 1.42 1998/09/10 16:01:32 marc Exp $
4
5# /etc/myname contains my symbolic name
6#
7hostname=`cat /etc/myname`
8hostname $hostname
9if [ -f /etc/defaultdomain ]; then
10	domainname `cat /etc/defaultdomain`
11fi
12
13# pick up option configuration
14. /etc/rc.conf
15
16# Configure the IP filter before configuring network interfaces
17#
18if [ X"${ipfilter}" = X"YES" -a -f "${ipfilter_rules}" ]; then
19	echo 'configuring IP filter'
20	ipf -Fa -f ${ipfilter_rules} -E
21else
22	ipfilter=NO
23fi
24
25# Configure NAT before configuring network interfaces
26#
27if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
28	echo 'configuring NAT'
29	ipnat -CF -f ${ipnat_rules}
30else
31	ipnat=NO
32fi
33
34# set the address for the loopback interface
35ifconfig lo0 inet localhost
36
37# use loopback, not the wire
38route -n add -host $hostname localhost
39route -n add -net 127 127.0.0.1 -reject
40
41# configure all of the non-loopback interfaces which we know about.
42# do this by reading /etc/hostname.* files, where * is the name
43# of a given interface.
44#
45# these files are formatted like the following, but with no # at the
46# beginning of the line
47#
48# addr_family hostname netmask broadcast_addr options
49# dest dest_addr
50#
51# OR
52#
53# dhcp 
54#
55# addr_family is the address family of the interface, generally inet
56# hostname is the host name that belongs to the interface, in /etc/hosts.
57# netmask is the network mask for the interface.
58# broadcast_addr is the broadcast address for the interface
59# options are misc. options to ifconfig for the interface.
60#
61# dest is simply the string "dest" (no quotes, though) if the interface
62# has a "destination" (i.e. it's a point-to-point link, like SLIP).
63# dest_addr is the hostname of the other end of the link, in /etc/hosts
64#
65# dhcp is simply the string "dhcp" (no quotes, though) if the interface
66# is to be configured using DHCP.  See dhclient(8) and dhclient.conf(5)
67# for details.
68#
69# the only required contents of the file are the addr_family field
70# and the hostname.
71
72(
73    tmp="$IFS"
74    IFS="$IFS."
75    set -- `echo /etc/hostname*`
76    IFS=$tmp
77    unset tmp
78
79    while [ $# -ge 2 ] ; do
80        shift            # get rid of "hostname"
81        (
82            read af name mask bcaddr extras
83            read dt dtaddr
84
85	    # check to see if device should be configure by dhcp
86	    if [ "$af" = "dhcp" ]; then
87		cmd="/sbin/dhclient $1";
88	    else
89		if [ ! -n "$name" ]; then
90		    echo "/etc/hostname.$1: invalid network configuration file"
91		    exit
92		fi
93
94		cmd="ifconfig $1 $af $name "
95		if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
96		if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
97		if [ -n "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
98		    cmd="$cmd broadcast $bcaddr";
99		fi
100		cmd="$cmd $extras";
101	    fi
102
103	    $cmd
104        ) < /etc/hostname.$1
105        shift
106    done
107)
108
109# /etc/mygate, if it exists, contains the name of my gateway host
110# that name must be in /etc/hosts.
111if [ -f /etc/mygate ]; then
112	route -n add -host default `cat /etc/mygate`
113
114	# default multicast route for hosts with a gateway
115	route -n add -net 224.0.0.0 -interface default
116else
117	# default multicast route
118	route -n add -net 224.0.0.0 -interface $hostname
119fi
120