On 09/08/18(Thu) 22:14, Stuart Henderson wrote:
> While looking into something unrelated I found a strange extra ::1
> address on lo1 (I usually hang my loopback addresses for IBGP off lo1).
> 
> lo1: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 32768
>         index 12 priority 0 llprio 3
>         groups: lo
>         inet xxx.xx.xxx.1 netmask 0xffffffff
>         inet6 ::1 prefixlen 128
>         inet6 fe80::1%lo1 prefixlen 64 scopeid 0xc
>         inet6 xxxx:xxxx:x:xxx::1 prefixlen 128
> 
> I haven't run into problems as a result of this (fortunately ospf6d
> picked the correct address to redistribute) but it doesn't seem right.
> 
> $ ifconfig lo | grep -e ^lo -e 'inet6 ::1'
> lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 32768
>         inet6 ::1 prefixlen 128
> lo1: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 32768
>         inet6 ::1 prefixlen 128
> 
> It seems we did this a while ago to fix breakage after NOINET6 but
> reading commit log, it definitely doesn't seem expected that ::1
> would appear on additional loopback interfaces (see lines marked with

Apparently using 'ifconfig loX inet6' would still insert ::1.  Only 'up'
was fixed.  The reason is that I had to revert a change because pf(4)
expects that lo:0 is ::1 on the 'default' loopback interface.

Here's a correct fix, ok?

Index: netinet6/in6_ifattach.c
===================================================================
RCS file: /cvs/src/sys/netinet6/in6_ifattach.c,v
retrieving revision 1.109
diff -u -p -r1.109 in6_ifattach.c
--- netinet6/in6_ifattach.c     10 Jul 2018 20:44:39 -0000      1.109
+++ netinet6/in6_ifattach.c     22 Aug 2018 15:16:38 -0000
@@ -391,10 +391,14 @@ in6_ifattach_linklocal(struct ifnet *ifp
 int
 in6_ifattach_loopback(struct ifnet *ifp)
 {
+       struct in6_addr in6 = in6addr_loopback;
        struct in6_aliasreq ifra;
 
        KASSERT(ifp->if_flags & IFF_LOOPBACK);
 
+       if (in6ifa_ifpwithaddr(ifp, &in6) != NULL)
+               return (0);
+
        bzero(&ifra, sizeof(ifra));
        strncpy(ifra.ifra_name, ifp->if_xname, sizeof(ifra.ifra_name));
        ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
@@ -503,13 +507,13 @@ in6_ifattach(struct ifnet *ifp)
        if ((ifp->if_flags & IFF_MULTICAST) == 0)
                return (EINVAL);
 
-       /* Assign loopback address, if there's none. */
-       if (ifp->if_flags & IFF_LOOPBACK) {
-               struct in6_addr in6 = in6addr_loopback;
+       /*
+        * Assign loopback address if this lo(4) interface is the
+        * default for its rdomain.
+        */
+       if ((ifp->if_flags & IFF_LOOPBACK) &&
+           (ifp->if_index == rtable_loindex(ifp->if_rdomain))) {
                int error;
-
-               if (in6ifa_ifpwithaddr(ifp, &in6) != NULL)
-                       return (0);
 
                error = in6_ifattach_loopback(ifp);
                if (error)

Reply via email to