xref: /openbsd/etc/netstart (revision bd498c62)
1df930be7Sderaadt#!/bin/sh -
2df930be7Sderaadt#
3*bd498c62Sderaadt#	$OpenBSD: netstart,v 1.38 1998/05/22 04:25:50 deraadt Exp $
4df930be7Sderaadt
5df930be7Sderaadt# /etc/myname contains my symbolic name
6df930be7Sderaadt#
7df930be7Sderaadthostname=`cat /etc/myname`
8df930be7Sderaadthostname $hostname
9df930be7Sderaadtif [ -f /etc/defaultdomain ]; then
10df930be7Sderaadt	domainname `cat /etc/defaultdomain`
11df930be7Sderaadtfi
12df930be7Sderaadt
137fafbaa4Sderaadt# pick up option configuration
147fafbaa4Sderaadt. /etc/rc.conf
157fafbaa4Sderaadt
169a844b63Sdm# Configure the IP filter before configuring network interfaces
179a844b63Sdm#
189a844b63Sdmif [ X"${ipfilter}" = X"YES" -a -f "${ipfilter_rules}" ]; then
199a844b63Sdm	echo 'configuring IP filter'
209a844b63Sdm	ipf -Fa -f ${ipfilter_rules} -E
219a844b63Sdmelse
229a844b63Sdm	ipfilter=NO
239a844b63Sdmfi
249a844b63Sdm
25ead8d7f6Skstailey# Configure NAT before configuring network interfaces
26ead8d7f6Skstailey#
27ca8b9769Sderaadtif [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
28ead8d7f6Skstailey	echo 'configuring NAT'
29ca8b9769Sderaadt	ipnat -CF -f ${ipnat_rules}
30ead8d7f6Skstaileyelse
31ca8b9769Sderaadt	ipnat=NO
32ead8d7f6Skstaileyfi
33ead8d7f6Skstailey
3498c28033Skstailey# set the address for the loopback interface
3598c28033Skstaileyifconfig lo0 inet localhost
36ead8d7f6Skstailey
3798c28033Skstailey# use loopback, not the wire
38*bd498c62Sderaadtroute -n add -host $hostname localhost
39*bd498c62Sderaadtroute -n add -net 127 127.0.0.1 -reject
4098c28033Skstailey
4198c28033Skstailey# configure all of the non-loopback interfaces which we know about.
42df930be7Sderaadt# do this by reading /etc/hostname.* files, where * is the name
43df930be7Sderaadt# of a given interface.
44df930be7Sderaadt#
45df930be7Sderaadt# these files are formatted like the following, but with no # at the
46df930be7Sderaadt# beginning of the line
47df930be7Sderaadt#
48df930be7Sderaadt# addr_family hostname netmask broadcast_addr options
49df930be7Sderaadt# dest dest_addr
50df930be7Sderaadt#
51df930be7Sderaadt# addr_family is the address family of the interface, generally inet
52df930be7Sderaadt# hostname is the host name that belongs to the interface, in /etc/hosts.
53df930be7Sderaadt# netmask is the network mask for the interface.
54df930be7Sderaadt# broadcast_addr is the broadcast address for the interface
55df930be7Sderaadt# options are misc. options to ifconfig for the interface.
56df930be7Sderaadt#
57df930be7Sderaadt# dest is simply the string "dest" (no quotes, though) if the interface
58df930be7Sderaadt# has a "destination" (i.e. it's a point-to-point link, like SLIP).
59df930be7Sderaadt# dest_addr is the hostname of the other end of the link, in /etc/hosts
60df930be7Sderaadt#
61df930be7Sderaadt# the only required contents of the file are the addr_family field
62df930be7Sderaadt# and the hostname.
63df930be7Sderaadt
64df930be7Sderaadt(
65df930be7Sderaadt    tmp="$IFS"
66df930be7Sderaadt    IFS="$IFS."
67df930be7Sderaadt    set -- `echo /etc/hostname*`
68df930be7Sderaadt    IFS=$tmp
69df930be7Sderaadt    unset tmp
70df930be7Sderaadt
71df930be7Sderaadt    while [ $# -ge 2 ] ; do
72df930be7Sderaadt        shift            # get rid of "hostname"
73df930be7Sderaadt        (
74df930be7Sderaadt            read af name mask bcaddr extras
75df930be7Sderaadt            read dt dtaddr
76df930be7Sderaadt
77df930be7Sderaadt            if [ ! -n "$name" ]; then
78df930be7Sderaadt                echo "/etc/hostname.$1: invalid network configuration file"
79df930be7Sderaadt                exit
80df930be7Sderaadt            fi
81df930be7Sderaadt
82df930be7Sderaadt	    cmd="ifconfig $1 $af $name "
83df930be7Sderaadt	    if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
84df930be7Sderaadt	    if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
85df930be7Sderaadt	    if [ -n "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
86df930be7Sderaadt		cmd="$cmd broadcast $bcaddr";
87df930be7Sderaadt	    fi
88df930be7Sderaadt	    cmd="$cmd $extras"
89df930be7Sderaadt
90df930be7Sderaadt	    $cmd
91df930be7Sderaadt        ) < /etc/hostname.$1
92df930be7Sderaadt        shift
93df930be7Sderaadt    done
94df930be7Sderaadt)
95df930be7Sderaadt
96d747464dSderaadt# /etc/mygate, if it exists, contains the name of my gateway host
97d747464dSderaadt# that name must be in /etc/hosts.
98d747464dSderaadtif [ -f /etc/mygate ]; then
99*bd498c62Sderaadt	route -n add -host default `cat /etc/mygate`
100d747464dSderaadtfi
101d747464dSderaadt
1022fc42166Stholo# default multicast route
103*bd498c62Sderaadtroute -n add -net 224.0.0.0 -interface $hostname
104