NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: setting up IPv6 addresses in rc.conf?



> Is it possible to specify more than one interface address solely in
> rc.conf via ifconfig_xxN variables?  I don't see a way to do it.

With stock networking startup, there isn't.

I found this unacceptable and added support for ifalias_xxN_M, a la

ifconfig_vlan0="216.46.5.9/28"
ifalias_vlan0_1="10.0.2.9/24"
ifalias_vlan0_2="inet6 2610:98:8001::9:0 prefixlen 96"

Here's the patch for 3.1 (network,v 1.47.2.1), that being the most
recent OS I can easily produce such a patch for.  (I had to move the
default routing stuff because on at least one of my machines, a default
route depends on an alias address.  Specifically, my v6 default route
depends on an alias; the ifconfig_xxN setting for that interface
specifies its primary v4 address.)

--- OLD/etc/rc.d/network        Sat Jul  2 19:29:48 2005
+++ NEW/etc/rc.d/network        Wed Jan 30 15:58:50 2008
@@ -224,34 +224,6 @@
                echo "."
        fi
 
-       # Check $defaultroute, then /etc/mygate, for the name or address
-       # of my IPv4 gateway host. If using a name, that name must be in
-       # /etc/hosts.
-       #
-       if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then
-               defaultroute=$(cat /etc/mygate)
-       fi
-       if [ -n "$defaultroute" ]; then
-               route add default $defaultroute
-       fi
-
-       # Check $defaultroute6, then /etc/mygate6, for the name or address
-       # of my IPv6 gateway host. If using a name, that name must be in
-       # /etc/hosts.  Note that the gateway host address must be a link-local
-       # address if it is not using an stf* interface.
-       #
-       if [ -z "$defaultroute6" ] && [ -f /etc/mygate6 ]; then
-               defaultroute6=$(cat /etc/mygate6)
-       fi
-       if [ -n "$defaultroute6" ]; then
-               if [ "$ip6mode" = "autohost" ]; then
-                       echo
-                       warn \
-           "ip6mode is set to 'autohost' and a v6 default route is also set."
-               fi
-               route add -inet6 default $defaultroute6
-       fi
-
        # Check if each configured interface xxN has an $ifaliases_xxN variable
        # associated, then configure additional IP addresses for that interface.
        # The variable contains a list of "address netmask" pairs, with
@@ -262,7 +234,7 @@
        # 
        #
        if [ -n "$configured_interfaces" ]; then
-               echo "Adding interface aliases:"
+               echo -n "Adding interface aliases:"
                done_aliases_message=yes
        fi
        for int in $configured_interfaces; do
@@ -280,6 +252,17 @@
                                fi
                        done
                fi
+               n=1
+               while :; do
+                       eval args=\$ifalias_$int\_$n
+                       if [ -n "$args" ]; then
+                               ifconfig $int $args alias
+                               echo -n \ $int\#$n
+                               n=$(($n+1))
+                       else
+                               break
+                       fi
+               done
        done
 
        # /etc/ifaliases, if it exists, contains the names of additional IP
@@ -293,9 +276,11 @@
        #
        if [ -f /etc/ifaliases ]; then
                if [ "$done_aliases_message" != yes ]; then
-                       echo "Adding interface aliases:"
+                       echo -n "Adding interface aliases:"
+                       done_aliases_message=yes
                fi
                while read addr int net; do
+                       echo -n " $int"
                        if [ -z "$net" ]; then
                                # for compatibility only, obsolete
                                ifconfig $int inet alias $addr
@@ -303,6 +288,38 @@
                                ifconfig $int inet alias $addr netmask $net
                        fi
                done < /etc/ifaliases
+       fi
+
+       if [ "$done_aliases_message" = "yes" ]; then
+               echo ""
+       fi
+
+       # Check $defaultroute, then /etc/mygate, for the name or address
+       # of my IPv4 gateway host. If using a name, that name must be in
+       # /etc/hosts.
+       #
+       if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then
+               defaultroute=$(cat /etc/mygate)
+       fi
+       if [ -n "$defaultroute" ]; then
+               route add default $defaultroute
+       fi
+
+       # Check $defaultroute6, then /etc/mygate6, for the name or address
+       # of my IPv6 gateway host. If using a name, that name must be in
+       # /etc/hosts.  Note that the gateway host address must be a link-local
+       # address if it is not using an stf* interface.
+       #
+       if [ -z "$defaultroute6" ] && [ -f /etc/mygate6 ]; then
+               defaultroute6=$(cat /etc/mygate6)
+       fi
+       if [ -n "$defaultroute6" ]; then
+               if [ "$ip6mode" = "autohost" ]; then
+                       echo
+                       warn \
+           "ip6mode is set to 'autohost' and a v6 default route is also set."
+               fi
+               route add -inet6 default $defaultroute6
        fi
 
        # IPv6 interface autoconfiguration.


Home | Main Index | Thread Index | Old Index