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

Annotation of src/etc/netstart, Revision 1.51

1.1       deraadt     1: #!/bin/sh -
                      2: #
1.51    ! deraadt     3: #      $OpenBSD: netstart,v 1.50 1999/09/01 05:07:50 deraadt 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.50      deraadt    46: # refer to hostname.if(5) and bridgename.if(5)
1.47      niklas     47: for hn in /etc/hostname.*; do
                     48:     # Strip off /etc/hostname. prefix
                     49:     if=${hn#/etc/hostname.}
                     50:
                     51:     # Interface names must be alphanumeric only.  We check to avoid
                     52:     # configuring backup or temp files, and to catch the "*" case.
                     53:     if ! isalphanumeric "$if"; then
                     54:         continue
1.49      angelos    55:     fi
1.50      deraadt    56:     ifconfig $if > /dev/null 2>&1
1.49      angelos    57:     if [ "$?" != "0" ]; then
                     58:        continue
1.47      niklas     59:     fi
                     60:
                     61:     # Now parse the hostname.* file
                     62:     {
                     63:         read af name mask bcaddr extras
                     64:
1.50      deraadt    65:        # $af can be either "dhcp", "up" or an address family.
1.47      niklas     66:        case "$af" in
                     67:        "bridge")
1.50      deraadt    68:            cmd="echo ${hn}: bridges now supported via bridgename.* files"
                     69:            ;;
1.47      niklas     70:        "dhcp")
1.50      deraadt    71:            ifconfig $if $name $mask $bcaddr $extras down
                     72:            cmd="dhclient $if"
1.47      niklas     73:            ;;
                     74:        "up")
                     75:            # The only one of these guaranteed to be set is $if
1.50      deraadt    76:            # the remaining ones exist so that media controls work
1.47      niklas     77:            cmd="ifconfig $if $name $mask $bcaddr $extras up"
                     78:            ;;
                     79:        *)
1.31      deraadt    80:             read dt dtaddr
1.47      niklas     81:            if [ ! -n "$name" ]; then
                     82:                echo "/etc/hostname.$if: invalid network configuration file"
1.50      deraadt    83:                continue
1.47      niklas     84:            fi
1.1       deraadt    85:
1.47      niklas     86:            cmd="ifconfig $if $af $name "
                     87:            if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
                     88:            if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
                     89:            if [ -n "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
                     90:                cmd="$cmd broadcast $bcaddr";
1.1       deraadt    91:            fi
1.47      niklas     92:            cmd="$cmd $extras";
                     93:            ;;
                     94:        esac
                     95:
                     96:        eval "$cmd"
                     97:     } < /etc/hostname.$if
1.50      deraadt    98: done
                     99: for bn in /etc/bridgename.*; do
                    100:     # Strip off /etc/bridgename. prefix
                    101:     if=${bn#/etc/bridgename.}
                    102:
                    103:     # Interface names must be alphanumeric only.  We check to avoid
                    104:     # configuring backup or temp files, and to catch the "*" case.
                    105:     if ! isalphanumeric "$if"; then
                    106:         continue
                    107:     fi
                    108:     brconfig $if > /dev/null 2>&1
                    109:     if [ "$?" != "0" ]; then
                    110:        continue
                    111:     fi
                    112:
                    113:     # Now parse the bridgename.* file
                    114:     {
                    115:        # All lines are run as brconfig(8) commands.
                    116:        while read line ; do
1.51    ! deraadt   117:            line=${line%%#*}            # strip comments
        !           118:            test -z "$line" && continue
1.50      deraadt   119:            brconfig $if $line
                    120:        done
                    121:     } < /etc/bridgename.$if
1.47      niklas    122: done
1.1       deraadt   123:
1.14      deraadt   124: # /etc/mygate, if it exists, contains the name of my gateway host
                    125: # that name must be in /etc/hosts.
1.42      marc      126: if [ -f /etc/mygate ]; then
1.38      deraadt   127:        route -n add -host default `cat /etc/mygate`
1.14      deraadt   128: fi
1.44      deraadt   129:
1.48      niklas    130: # Multicast routing.
                    131: #
                    132: # The routing to the 224.0.0.0/4 net is setup according to these rules:
                    133: # multicast_host       multicast_router        route           comment
                    134: # NO                   NO                      -reject         no multicast
                    135: # NO                   YES                     none installed  daemon will run
                    136: # YES/interface                NO                      -interface      YES=def. iface
                    137: #         Any other combination                -reject         config error
                    138: case "$multicast_host:$multicast_router" in
                    139: NO:NO)
                    140:        route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
                    141: NO:YES)
                    142:        ;;
                    143: *:NO)
                    144:        set `if [ $multicast_host = YES ]; then
                    145:                ed -s '!route -n show' <<EOF
                    146: /^default/p
                    147: EOF
                    148:        else
                    149:                ed -s "!ifconfig $multicast_host" <<EOF
                    150: /^     inet /p
                    151: EOF
                    152:        fi`
                    153:        route -n add -net 224.0.0.0/4 -interface $2;;
                    154: *:*)
                    155:        echo 'config error, multicasting disabled until rc.conf is fixed'
                    156:        route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
                    157: esac
                    158:
1.44      deraadt   159: # Configure NAT after configuring network interfaces
                    160: if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
                    161:        echo 'configuring NAT'
                    162:        ipnat -CF -f ${ipnat_rules}
                    163: else
                    164:        ipnat=NO
                    165: fi