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

Annotation of src/etc/netstart, Revision 1.63

1.1       deraadt     1: #!/bin/sh -
                      2: #
1.63    ! todd        3: #      $OpenBSD: netstart,v 1.62 2000/01/02 06:50:09 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
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
1.56      itojun     56:
                     57:        rtsolif=""
1.54      itojun     58: else
                     59:        ip6kernel=NO
                     60: fi
                     61:
1.24      kstailey   62: # configure all of the non-loopback interfaces which we know about.
1.50      deraadt    63: # refer to hostname.if(5) and bridgename.if(5)
1.47      niklas     64: for hn in /etc/hostname.*; do
                     65:     # Strip off /etc/hostname. prefix
                     66:     if=${hn#/etc/hostname.}
                     67:
                     68:     # Interface names must be alphanumeric only.  We check to avoid
                     69:     # configuring backup or temp files, and to catch the "*" case.
                     70:     if ! isalphanumeric "$if"; then
1.55      todd       71:        continue
1.49      angelos    72:     fi
1.50      deraadt    73:     ifconfig $if > /dev/null 2>&1
1.49      angelos    74:     if [ "$?" != "0" ]; then
                     75:        continue
1.47      niklas     76:     fi
                     77:
                     78:     # Now parse the hostname.* file
1.55      todd       79:     while :; do
                     80:        if [ "$cmd2" ]; then
                     81:            # we are carrying over from the 'read dt dtaddr' last time
                     82:            set -- $cmd2
                     83:            af="$1" name="$2" mask="$3" bcaddr="$4" ext1="$5" ext2="$6"
                     84:            cmd2=
                     85:        else
                     86:            # read the next line or exit the while loop
                     87:            read af name mask bcaddr ext1 ext2 || break
                     88:        fi
1.63    ! todd       89:        # $af can be "dhcp", "up", "rtsol", an address family, commands, or
        !            90:        # a comment.
1.47      niklas     91:        case "$af" in
1.63    ! todd       92:        "#"*) # skip comments
        !            93:            continue
        !            94:            ;;
        !            95:        "!"*) # parse commands
        !            96:            cmd="${af#*!} ${name} ${mask} ${bcaddr} ${ext1} ${ext2}"
        !            97:            ;;
1.47      niklas     98:        "bridge")
1.50      deraadt    99:            cmd="echo ${hn}: bridges now supported via bridgename.* files"
                    100:            ;;
1.47      niklas    101:        "dhcp")
1.55      todd      102:            ifconfig $if $name $mask $bcaddr $ext1 $ext2 down
1.50      deraadt   103:            cmd="dhclient $if"
1.47      niklas    104:            ;;
1.56      itojun    105:        "rtsol")
1.62      deraadt   106:            ifconfig $if $name $mask $bcaddr $ext1 $ext2 up
1.56      itojun    107:            rtsolif="$rtsolif $if"
1.59      todd      108:            cmd=
1.56      itojun    109:            ;;
1.47      niklas    110:        "up")
                    111:            # The only one of these guaranteed to be set is $if
1.50      deraadt   112:            # the remaining ones exist so that media controls work
1.55      todd      113:            cmd="ifconfig $if $name $mask $bcaddr $ext1 $ext2 up"
                    114:            ;;
                    115:        *)
                    116:            read dt dtaddr
                    117:            if [ "$name"  = "alias" ]; then
                    118:                # perform a 'shift' of sorts
                    119:                alias=$name
                    120:                name=$mask
                    121:                mask=$bcaddr
                    122:                bcaddr=$ext1
                    123:                ext1=$ext2
                    124:                ext2=
1.47      niklas    125:            fi
1.55      todd      126:            cmd="ifconfig $if $af $alias $name "
                    127:            case $dt in
                    128:            dest)
                    129:                cmd="$cmd $dtaddr"
                    130:                ;;
                    131:            [a-z]*)
                    132:                cmd2="$dt $dtaddr"
                    133:                ;;
1.60      itojun    134:            esac
                    135:            if [ ! -n "$name" ]; then
1.55      todd      136:                    echo "/etc/hostname.$if: invalid network configuration file"
                    137:                return
1.60      itojun    138:            fi
                    139:            case $af in
                    140:            inet)
1.55      todd      141:                [ "$mask" ] && cmd="$cmd netmask $mask"
                    142:                if [ "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
                    143:                    cmd="$cmd broadcast $bcaddr"
                    144:                fi
                    145:                [ "$alias" ] && rtcmd="; route -n add -host $name 127.0.0.1"
1.61      itojun    146:                ;;
1.60      itojun    147:            inet6) [ "$mask" ] && cmd="$cmd prefixlen $mask"
1.55      todd      148:                cmd="$cmd $bcaddr"
                    149:                ;;
1.60      itojun    150:            *) cmd="$cmd $mask $bcaddr"
                    151:            esac
                    152:            cmd="$cmd $ext1 $ext2$rtcmd" rtcmd=
                    153:            ;;
1.47      niklas    154:        esac
                    155:        eval "$cmd"
1.55      todd      156:     done < /etc/hostname.$if
1.50      deraadt   157: done
1.56      itojun    158:
                    159: if [ "$ip6kernel" = "YES" -a "x$rtsolif" != "x" ]; then
                    160:        fw=`sysctl -n net.inet6.ip6.forwarding`
                    161:        ra=`sysctl -n net.inet6.ip6.accept_rtadv`
                    162:        if [ "x$fw" = "x0" -a "x$ra" = "x1" ]; then
1.57      itojun    163:                echo "IPv6 autoconf:$rtsolif"
1.56      itojun    164:                rtsol $rtsolif
                    165:        else
                    166:                echo "WARNING: inconsistent config - check /etc/sysctl.conf for IPv6 autoconf"
                    167:        fi
1.57      itojun    168: fi
                    169: if [ "$ip6kernel" = "YES" ]; then
                    170:        # this is to make sure DAD is completed before going further.
                    171:        sleep `sysctl -n net.inet6.ip6.dad_count`
                    172:        sleep 1
1.56      itojun    173: fi
                    174:
1.50      deraadt   175: for bn in /etc/bridgename.*; do
                    176:     # Strip off /etc/bridgename. prefix
                    177:     if=${bn#/etc/bridgename.}
                    178:
                    179:     # Interface names must be alphanumeric only.  We check to avoid
                    180:     # configuring backup or temp files, and to catch the "*" case.
                    181:     if ! isalphanumeric "$if"; then
                    182:         continue
                    183:     fi
                    184:     brconfig $if > /dev/null 2>&1
                    185:     if [ "$?" != "0" ]; then
                    186:        continue
                    187:     fi
                    188:
                    189:     # Now parse the bridgename.* file
                    190:     {
                    191:        # All lines are run as brconfig(8) commands.
                    192:        while read line ; do
1.51      deraadt   193:            line=${line%%#*}            # strip comments
                    194:            test -z "$line" && continue
1.50      deraadt   195:            brconfig $if $line
                    196:        done
                    197:     } < /etc/bridgename.$if
1.47      niklas    198: done
1.1       deraadt   199:
1.14      deraadt   200: # /etc/mygate, if it exists, contains the name of my gateway host
                    201: # that name must be in /etc/hosts.
1.42      marc      202: if [ -f /etc/mygate ]; then
1.38      deraadt   203:        route -n add -host default `cat /etc/mygate`
1.14      deraadt   204: fi
1.44      deraadt   205:
1.48      niklas    206: # Multicast routing.
                    207: #
                    208: # The routing to the 224.0.0.0/4 net is setup according to these rules:
                    209: # multicast_host       multicast_router        route           comment
                    210: # NO                   NO                      -reject         no multicast
                    211: # NO                   YES                     none installed  daemon will run
                    212: # YES/interface                NO                      -interface      YES=def. iface
                    213: #         Any other combination                -reject         config error
                    214: case "$multicast_host:$multicast_router" in
                    215: NO:NO)
                    216:        route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
                    217: NO:YES)
                    218:        ;;
                    219: *:NO)
                    220:        set `if [ $multicast_host = YES ]; then
                    221:                ed -s '!route -n show' <<EOF
                    222: /^default/p
                    223: EOF
                    224:        else
                    225:                ed -s "!ifconfig $multicast_host" <<EOF
                    226: /^     inet /p
                    227: EOF
                    228:        fi`
                    229:        route -n add -net 224.0.0.0/4 -interface $2;;
                    230: *:*)
                    231:        echo 'config error, multicasting disabled until rc.conf is fixed'
                    232:        route -n add -net 224.0.0.0/4 -interface 127.0.0.1 -reject;;
                    233: esac
1.53      itojun    234:
1.44      deraadt   235: # Configure NAT after configuring network interfaces
                    236: if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
                    237:        echo 'configuring NAT'
                    238:        ipnat -CF -f ${ipnat_rules}
                    239: else
                    240:        ipnat=NO
                    241: fi