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

Annotation of src/etc/netstart, Revision 1.65

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