[BACK]Return to netstart CVS log [TXT][DIR] Up to [local] / src / etc

Annotation of src/etc/netstart, Revision 1.45

1.1       deraadt     1: #!/bin/sh -
                      2: #
1.45    ! millert     3: #      $OpenBSD: netstart,v 1.44 1998/10/06 23:25:21 deraadt Exp $
        !             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.42      marc       92:            # check to see if device should be configure by dhcp
                     93:            if [ "$af" = "dhcp" ]; then
1.45    ! millert    94:                ifconfig $if $extras down
        !            95:                cmd="/sbin/dhclient $if";
1.42      marc       96:            else
                     97:                if [ ! -n "$name" ]; then
1.45    ! millert    98:                    echo "/etc/hostname.$if: invalid network configuration file"
1.42      marc       99:                    exit
                    100:                fi
                    101:
1.45    ! millert   102:                cmd="ifconfig $if $af $name "
1.42      marc      103:                if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
                    104:                if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
                    105:                if [ -n "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
                    106:                    cmd="$cmd broadcast $bcaddr";
                    107:                fi
                    108:                cmd="$cmd $extras";
1.1       deraadt   109:            fi
                    110:
                    111:            $cmd
1.45    ! millert   112:         ) < /etc/hostname.$if
1.1       deraadt   113:     done
1.42      marc      114: )
1.1       deraadt   115:
1.14      deraadt   116: # /etc/mygate, if it exists, contains the name of my gateway host
                    117: # that name must be in /etc/hosts.
1.42      marc      118: if [ -f /etc/mygate ]; then
1.38      deraadt   119:        route -n add -host default `cat /etc/mygate`
1.40      downsj    120:
                    121:        # default multicast route for hosts with a gateway
                    122:        route -n add -net 224.0.0.0 -interface default
1.42      marc      123: else
1.40      downsj    124:        # default multicast route
                    125:        route -n add -net 224.0.0.0 -interface $hostname
1.14      deraadt   126: fi
1.44      deraadt   127:
                    128: # Configure NAT after configuring network interfaces
                    129: if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
                    130:        echo 'configuring NAT'
                    131:        ipnat -CF -f ${ipnat_rules}
                    132: else
                    133:        ipnat=NO
                    134: fi