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

Annotation of src/etc/netstart, Revision 1.48

1.1       deraadt     1: #!/bin/sh -
                      2: #
1.48    ! niklas      3: #      $OpenBSD: netstart,v 1.47 1999/03/26 14:34:31 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
                     93:     fi
                     94:
                     95:     # Now parse the hostname.* file
                     96:     {
                     97:         read af name mask bcaddr extras
                     98:
                     99:        # $af can be either "bridge", "dhcp", "up" or an address family.
                    100:        case "$af" in
                    101:        "bridge")
                    102:            ifconfig $if up
                    103:            cmd=`sed "s/\(.*\)/brconfig $if \1;/"`
                    104:            ;;
                    105:        "dhcp")
                    106:            ifconfig $if $extras down
                    107:            cmd="/sbin/dhclient $if"
                    108:            ;;
                    109:        "up")
                    110:            # The only one of these guaranteed to be set is $if
                    111:            cmd="ifconfig $if $name $mask $bcaddr $extras up"
                    112:            ;;
                    113:        *)
1.31      deraadt   114:             read dt dtaddr
1.47      niklas    115:            if [ ! -n "$name" ]; then
                    116:                echo "/etc/hostname.$if: invalid network configuration file"
                    117:                exit
                    118:            fi
1.1       deraadt   119:
1.47      niklas    120:            cmd="ifconfig $if $af $name "
                    121:            if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
                    122:            if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
                    123:            if [ -n "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
                    124:                cmd="$cmd broadcast $bcaddr";
1.1       deraadt   125:            fi
1.47      niklas    126:            cmd="$cmd $extras";
                    127:            ;;
                    128:        esac
                    129:
                    130:        eval "$cmd"
                    131:     } < /etc/hostname.$if
                    132: done
1.1       deraadt   133:
1.14      deraadt   134: # /etc/mygate, if it exists, contains the name of my gateway host
                    135: # that name must be in /etc/hosts.
1.42      marc      136: if [ -f /etc/mygate ]; then
1.38      deraadt   137:        route -n add -host default `cat /etc/mygate`
1.14      deraadt   138: fi
1.44      deraadt   139:
1.48    ! niklas    140: # Multicast routing.
        !           141: #
        !           142: # The routing to the 224.0.0.0/4 net is setup according to these rules:
        !           143: # multicast_host       multicast_router        route           comment
        !           144: # NO                   NO                      -reject         no multicast
        !           145: # NO                   YES                     none installed  daemon will run
        !           146: # YES/interface                NO                      -interface      YES=def. iface
        !           147: #         Any other combination                -reject         config error
        !           148: case "$multicast_host:$multicast_router" in
        !           149: NO:NO)
        !           150:        route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
        !           151: NO:YES)
        !           152:        ;;
        !           153: *:NO)
        !           154:        set `if [ $multicast_host = YES ]; then
        !           155:                ed -s '!route -n show' <<EOF
        !           156: /^default/p
        !           157: EOF
        !           158:        else
        !           159:                ed -s "!ifconfig $multicast_host" <<EOF
        !           160: /^     inet /p
        !           161: EOF
        !           162:        fi`
        !           163:        route -n add -net 224.0.0.0/4 -interface $2;;
        !           164: *:*)
        !           165:        echo 'config error, multicasting disabled until rc.conf is fixed'
        !           166:        route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
        !           167: esac
        !           168:
1.44      deraadt   169: # Configure NAT after configuring network interfaces
                    170: if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
                    171:        echo 'configuring NAT'
                    172:        ipnat -CF -f ${ipnat_rules}
                    173: else
                    174:        ipnat=NO
                    175: fi