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

Annotation of src/etc/netstart, Revision 1.55

1.1       deraadt     1: #!/bin/sh -
                      2: #
1.55    ! todd        3: #      $OpenBSD: netstart,v 1.54 1999/12/31 04:32:53 itojun 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
1.52      itojun     39: # it will also initialize IPv6 address for lo0 (::1 and others).
1.24      kstailey   40: ifconfig lo0 inet localhost
1.1       deraadt    41:
1.24      kstailey   42: # use loopback, not the wire
1.38      deraadt    43: route -n add -host $hostname localhost
                     44: route -n add -net 127 127.0.0.1 -reject
1.24      kstailey   45:
1.54      itojun     46: if ifconfig lo0 inet6 >/dev/null 2>&1; then
                     47:        # IPv6 configurations.
                     48:        ip6kernel=YES
                     49:
                     50:        # disallow scoped unicast dest without outgoing scope identifiers.
                     51:        route add -inet6 fe80:: -prefixlen 10 ::1 -reject
                     52:        route add -inet6 fc80:: -prefixlen 10 ::1 -reject
                     53:        # disallow "internal" addresses to appear on the wire.
                     54:        route add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
                     55:        route add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
                     56: else
                     57:        ip6kernel=NO
                     58: fi
                     59:
1.24      kstailey   60: # configure all of the non-loopback interfaces which we know about.
1.50      deraadt    61: # refer to hostname.if(5) and bridgename.if(5)
1.47      niklas     62: for hn in /etc/hostname.*; do
                     63:     # Strip off /etc/hostname. prefix
                     64:     if=${hn#/etc/hostname.}
                     65:
                     66:     # Interface names must be alphanumeric only.  We check to avoid
                     67:     # configuring backup or temp files, and to catch the "*" case.
                     68:     if ! isalphanumeric "$if"; then
1.55    ! todd       69:        continue
1.49      angelos    70:     fi
1.50      deraadt    71:     ifconfig $if > /dev/null 2>&1
1.49      angelos    72:     if [ "$?" != "0" ]; then
                     73:        continue
1.47      niklas     74:     fi
                     75:
                     76:     # Now parse the hostname.* file
1.55    ! todd       77:     while :; do
        !            78:        if [ "$cmd2" ]; then
        !            79:            # we are carrying over from the 'read dt dtaddr' last time
        !            80:            set -- $cmd2
        !            81:            af="$1" name="$2" mask="$3" bcaddr="$4" ext1="$5" ext2="$6"
        !            82:            cmd2=
        !            83:        else
        !            84:            # read the next line or exit the while loop
        !            85:            read af name mask bcaddr ext1 ext2 || break
        !            86:        fi
        !            87:        # skip comments
        !            88:        [ "${af#*#}" = "${af}" ] || continue
1.50      deraadt    89:        # $af can be either "dhcp", "up" or an address family.
1.47      niklas     90:        case "$af" in
                     91:        "bridge")
1.50      deraadt    92:            cmd="echo ${hn}: bridges now supported via bridgename.* files"
                     93:            ;;
1.47      niklas     94:        "dhcp")
1.55    ! todd       95:            ifconfig $if $name $mask $bcaddr $ext1 $ext2 down
1.50      deraadt    96:            cmd="dhclient $if"
1.47      niklas     97:            ;;
                     98:        "up")
                     99:            # The only one of these guaranteed to be set is $if
1.50      deraadt   100:            # the remaining ones exist so that media controls work
1.55    ! todd      101:            cmd="ifconfig $if $name $mask $bcaddr $ext1 $ext2 up"
        !           102:            ;;
        !           103:        *)
        !           104:            read dt dtaddr
        !           105:            if [ "$name"  = "alias" ]; then
        !           106:                # perform a 'shift' of sorts
        !           107:                alias=$name
        !           108:                name=$mask
        !           109:                mask=$bcaddr
        !           110:                bcaddr=$ext1
        !           111:                ext1=$ext2
        !           112:                ext2=
1.47      niklas    113:            fi
1.55    ! todd      114:            cmd="ifconfig $if $af $alias $name "
        !           115:            case $dt in
        !           116:            dest)
        !           117:                cmd="$cmd $dtaddr"
        !           118:                ;;
        !           119:            [a-z]*)
        !           120:                cmd2="$dt $dtaddr"
        !           121:                ;;
        !           122:             esac
        !           123:             if [ ! -n "$name" ]; then
        !           124:                    echo "/etc/hostname.$if: invalid network configuration file"
        !           125:                return
        !           126:             fi
        !           127:             case $af in
        !           128:             inet)
        !           129:                [ "$mask" ] && cmd="$cmd netmask $mask"
        !           130:                if [ "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
        !           131:                    cmd="$cmd broadcast $bcaddr"
        !           132:                fi
        !           133:                [ "$alias" ] && rtcmd="; route -n add -host $name 127.0.0.1"
        !           134:             ;;
        !           135:             inet6) [ "$mask" ] && cmd="$cmd prefixlen $mask"
        !           136:                cmd="$cmd $bcaddr"
        !           137:                ;;
        !           138:             *) cmd="$cmd $mask $bcaddr"
        !           139:             esac
        !           140:             cmd="$cmd $ext1 $ext2$rtcmd" rtcmd=
        !           141:             ;;
1.47      niklas    142:        esac
                    143:        eval "$cmd"
1.55    ! todd      144:     done < /etc/hostname.$if
1.50      deraadt   145: done
                    146: for bn in /etc/bridgename.*; do
                    147:     # Strip off /etc/bridgename. prefix
                    148:     if=${bn#/etc/bridgename.}
                    149:
                    150:     # Interface names must be alphanumeric only.  We check to avoid
                    151:     # configuring backup or temp files, and to catch the "*" case.
                    152:     if ! isalphanumeric "$if"; then
                    153:         continue
                    154:     fi
                    155:     brconfig $if > /dev/null 2>&1
                    156:     if [ "$?" != "0" ]; then
                    157:        continue
                    158:     fi
                    159:
                    160:     # Now parse the bridgename.* file
                    161:     {
                    162:        # All lines are run as brconfig(8) commands.
                    163:        while read line ; do
1.51      deraadt   164:            line=${line%%#*}            # strip comments
                    165:            test -z "$line" && continue
1.50      deraadt   166:            brconfig $if $line
                    167:        done
                    168:     } < /etc/bridgename.$if
1.47      niklas    169: done
1.1       deraadt   170:
1.14      deraadt   171: # /etc/mygate, if it exists, contains the name of my gateway host
                    172: # that name must be in /etc/hosts.
1.42      marc      173: if [ -f /etc/mygate ]; then
1.38      deraadt   174:        route -n add -host default `cat /etc/mygate`
1.14      deraadt   175: fi
1.44      deraadt   176:
1.48      niklas    177: # Multicast routing.
                    178: #
                    179: # The routing to the 224.0.0.0/4 net is setup according to these rules:
                    180: # multicast_host       multicast_router        route           comment
                    181: # NO                   NO                      -reject         no multicast
                    182: # NO                   YES                     none installed  daemon will run
                    183: # YES/interface                NO                      -interface      YES=def. iface
                    184: #         Any other combination                -reject         config error
                    185: case "$multicast_host:$multicast_router" in
                    186: NO:NO)
                    187:        route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
                    188: NO:YES)
                    189:        ;;
                    190: *:NO)
                    191:        set `if [ $multicast_host = YES ]; then
                    192:                ed -s '!route -n show' <<EOF
                    193: /^default/p
                    194: EOF
                    195:        else
                    196:                ed -s "!ifconfig $multicast_host" <<EOF
                    197: /^     inet /p
                    198: EOF
                    199:        fi`
                    200:        route -n add -net 224.0.0.0/4 -interface $2;;
                    201: *:*)
                    202:        echo 'config error, multicasting disabled until rc.conf is fixed'
                    203:        route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
                    204: esac
1.53      itojun    205:
1.44      deraadt   206: # Configure NAT after configuring network interfaces
                    207: if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
                    208:        echo 'configuring NAT'
                    209:        ipnat -CF -f ${ipnat_rules}
                    210: else
                    211:        ipnat=NO
                    212: fi