On Mon, Jul 04, 2016 at 01:12:24PM +0200, Martin Pieuchot wrote:
> I find IPv6 address states (flags) really hard to follow.  This macro
> doesn't seem to help as it is not always used.  I'd like to get rid of
> it, any concern?

OK bluhm@

> 
> After applying this diff you'll see that some patterns appear and they
> make me wonder, are some IN6_IFF_DETACHED missing?
> 
> Index: netinet6/icmp6.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/icmp6.c,v
> retrieving revision 1.185
> diff -u -p -r1.185 icmp6.c
> --- netinet6/icmp6.c  29 Mar 2016 11:57:51 -0000      1.185
> +++ netinet6/icmp6.c  4 Jul 2016 11:06:29 -0000
> @@ -1229,13 +1229,14 @@ icmp6_reflect(struct mbuf *m, size_t off
>       /*
>        * If the incoming packet was addressed directly to us (i.e. unicast),
>        * use dst as the src for the reply.
> -      * The IN6_IFF_NOTREADY case would be VERY rare, but is possible
> -      * (for example) when we encounter an error while forwarding procedure
> -      * destined to a duplicated address of ours.
> +      * The IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED case would be VERY rare,
> +      * but is possible (for example) when we encounter an error while
> +      * forwarding procedure destined to a duplicated address of ours.
>        */
>       TAILQ_FOREACH(ia6, &in6_ifaddr, ia_list)
>               if (IN6_ARE_ADDR_EQUAL(&t, &ia6->ia_addr.sin6_addr) &&
> -                 (ia6->ia6_flags & (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY)) == 0) 
> {
> +                 (ia6->ia6_flags & (IN6_IFF_ANYCAST|IN6_IFF_TENTATIVE|
> +                 IN6_IFF_DUPLICATED)) == 0) {
>                       src = &t;
>                       break;
>               }
> @@ -1621,9 +1622,8 @@ icmp6_redirect_output(struct mbuf *m0, s
>       {
>               /* get ip6 linklocal address for ifp(my outgoing interface). */
>               struct in6_ifaddr *ia6;
> -             if ((ia6 = in6ifa_ifpforlinklocal(ifp,
> -                                              IN6_IFF_NOTREADY|
> -                                              IN6_IFF_ANYCAST)) == NULL)
> +             if ((ia6 = in6ifa_ifpforlinklocal(ifp, IN6_IFF_TENTATIVE|
> +                 IN6_IFF_DUPLICATED|IN6_IFF_ANYCAST)) == NULL)
>                       goto fail;
>               ifp_ll6 = &ia6->ia_addr.sin6_addr;
>       }
> Index: netinet6/in6.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/in6.c,v
> retrieving revision 1.187
> diff -u -p -r1.187 in6.c
> --- netinet6/in6.c    13 Jun 2016 10:34:40 -0000      1.187
> +++ netinet6/in6.c    4 Jul 2016 11:06:29 -0000
> @@ -1637,7 +1637,8 @@ in6_ifawithscope(struct ifnet *oifp, str
>                        * Don't use an address before completing DAD
>                        * nor a duplicated address.
>                        */
> -                     if (ifatoia6(ifa)->ia6_flags & IN6_IFF_NOTREADY)
> +                     if (ifatoia6(ifa)->ia6_flags &
> +                         (IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED))
>                               continue;
>  
>                       /* XXX: is there any case to allow anycasts? */
> Index: netinet6/in6_pcb.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/in6_pcb.c,v
> retrieving revision 1.92
> diff -u -p -r1.92 in6_pcb.c
> --- netinet6/in6_pcb.c        11 Apr 2016 21:24:29 -0000      1.92
> +++ netinet6/in6_pcb.c        4 Jul 2016 11:06:29 -0000
> @@ -208,9 +208,8 @@ in6_pcbaddrisavail(struct inpcb *inp, st
>                * flag to control the bind(2) behavior against
>                * deprecated addresses (default: forbid bind(2)).
>                */
> -             if (ifa &&
> -                 ifatoia6(ifa)->ia6_flags &
> -                 (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY|IN6_IFF_DETACHED))
> +             if (ifa && ifatoia6(ifa)->ia6_flags & (IN6_IFF_ANYCAST|
> +                 IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED|IN6_IFF_DETACHED))
>                       return (EADDRNOTAVAIL);
>       }
>       if (lport) {
> Index: netinet6/in6_src.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/in6_src.c,v
> retrieving revision 1.74
> diff -u -p -r1.74 in6_src.c
> --- netinet6/in6_src.c        30 Jun 2016 12:36:27 -0000      1.74
> +++ netinet6/in6_src.c        4 Jul 2016 11:06:29 -0000
> @@ -130,8 +130,8 @@ in6_selectsrc(struct in6_addr **in6src, 
>               if_put(ifp); /* put reference from in6_selectif */
>  
>               ia6 = ifatoia6(ifa_ifwithaddr(sin6tosa(&sa6), rtableid));
> -             if (ia6 == NULL ||
> -                 (ia6->ia6_flags & (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY)))
> +             if (ia6 == NULL || (ia6->ia6_flags &
> +                  (IN6_IFF_ANYCAST|IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED)))
>                       return (EADDRNOTAVAIL);
>  
>               pi->ipi6_addr = sa6.sin6_addr; /* XXX: this overrides pi */
> Index: netinet6/in6_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/in6_var.h,v
> retrieving revision 1.63
> diff -u -p -r1.63 in6_var.h
> --- netinet6/in6_var.h        13 Jun 2016 10:34:40 -0000      1.63
> +++ netinet6/in6_var.h        4 Jul 2016 11:06:29 -0000
> @@ -328,9 +328,6 @@ struct    in6_aliasreq {
>  #define IN6_IFF_AUTOCONF     0x40    /* autoconfigurable address. */
>  #define IN6_IFF_PRIVACY              0x80    /* RFC 4941 temporary address */
>  
> -/* do not input/output */
> -#define IN6_IFF_NOTREADY (IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED)
> -
>  #ifdef _KERNEL
>  #define IN6_ARE_SCOPE_CMP(a,b) ((a)-(b))
>  #define IN6_ARE_SCOPE_EQUAL(a,b) ((a)==(b))
> Index: netinet6/ip6_input.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_input.c,v
> retrieving revision 1.160
> diff -u -p -r1.160 ip6_input.c
> --- netinet6/ip6_input.c      19 May 2016 11:34:40 -0000      1.160
> +++ netinet6/ip6_input.c      4 Jul 2016 11:06:29 -0000
> @@ -461,11 +461,7 @@ ip6_input(struct mbuf *m)
>                * packets to a tentative, duplicated, or somehow invalid
>                * address must not be accepted.
>                */
> -             if (!(ia6->ia6_flags & IN6_IFF_NOTREADY)) {
> -                     /* this address is ready */
> -                     ours = 1;
> -                     goto hbhcheck;
> -             } else {
> +             if ((ia6->ia6_flags & (IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED))) {
>                       char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
>  
>                       inet_ntop(AF_INET6, &ip6->ip6_src, src, sizeof(src));
> @@ -476,6 +472,10 @@ ip6_input(struct mbuf *m)
>                           src, dst));
>  
>                       goto bad;
> +             } else {
> +                     /* this address is ready */
> +                     ours = 1;
> +                     goto hbhcheck;
>               }
>       }
>  
> Index: netinet6/mld6.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/mld6.c,v
> retrieving revision 1.47
> diff -u -p -r1.47 mld6.c
> --- netinet6/mld6.c   7 Mar 2016 18:44:00 -0000       1.47
> +++ netinet6/mld6.c   4 Jul 2016 11:06:29 -0000
> @@ -391,7 +391,7 @@ mld6_sendpkt(struct in6_multi *in6m, int
>        * We do not reject tentative addresses for MLD report to deal with
>        * the case where we first join a link-local address.
>        */
> -     ignflags = (IN6_IFF_NOTREADY|IN6_IFF_ANYCAST) & ~IN6_IFF_TENTATIVE;
> +     ignflags = IN6_IFF_DUPLICATED|IN6_IFF_ANYCAST;
>       if ((ia6 = in6ifa_ifpforlinklocal(ifp, ignflags)) == NULL) {
>               if_put(ifp);
>               return;
> Index: netinet6/nd6_nbr.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/nd6_nbr.c,v
> retrieving revision 1.104
> diff -u -p -r1.104 nd6_nbr.c
> --- netinet6/nd6_nbr.c        15 Jun 2016 11:49:35 -0000      1.104
> +++ netinet6/nd6_nbr.c        4 Jul 2016 11:06:29 -0000
> @@ -238,8 +238,8 @@ nd6_ns_input(struct mbuf *m, int off, in
>                       /*
>                        * proxy NDP for single entry
>                        */
> -                     ifa = &in6ifa_ifpforlinklocal(ifp,
> -                         IN6_IFF_NOTREADY | IN6_IFF_ANYCAST)->ia_ifa;
> +                     ifa = &in6ifa_ifpforlinklocal(ifp, IN6_IFF_TENTATIVE|
> +                         IN6_IFF_DUPLICATED|IN6_IFF_ANYCAST)->ia_ifa;
>                       if (ifa) {
>                               proxy = 1;
>                               proxydl = satosdl(rt->rt_gateway);
> Index: netinet6/nd6_rtr.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/nd6_rtr.c,v
> retrieving revision 1.139
> diff -u -p -r1.139 nd6_rtr.c
> --- netinet6/nd6_rtr.c        2 May 2016 22:15:49 -0000       1.139
> +++ netinet6/nd6_rtr.c        4 Jul 2016 11:06:29 -0000
> @@ -1877,14 +1877,6 @@ in6_ifadd(struct nd_prefix *pr, int priv
>       else
>               return NULL;
>  
> -#if 0 /* don't care link local addr state, and always do DAD */
> -     /* if link-local address is not eligible, do not autoconfigure. */
> -     if (ifatoia6(ifa)->ia6_flags & IN6_IFF_NOTREADY) {
> -             printf("in6_ifadd: link-local address not ready\n");
> -             return NULL;
> -     }
> -#endif
> -
>       /* prefixlen + ifidlen must be equal to 128 */
>       plen0 = in6_mask2len(&ia6->ia_prefixmask.sin6_addr, NULL);
>       if (prefixlen != plen0) {
> Index: netinet6/raw_ip6.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
> retrieving revision 1.90
> diff -u -p -r1.90 raw_ip6.c
> --- netinet6/raw_ip6.c        11 Apr 2016 15:28:03 -0000      1.90
> +++ netinet6/raw_ip6.c        4 Jul 2016 11:06:29 -0000
> @@ -676,7 +676,7 @@ rip6_usrreq(struct socket *so, int req, 
>                       break;
>               }
>               if (ifa && ifatoia6(ifa)->ia6_flags &
> -                 (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY|
> +                 (IN6_IFF_ANYCAST|IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED|
>                    IN6_IFF_DETACHED|IN6_IFF_DEPRECATED)) {
>                       error = EADDRNOTAVAIL;
>                       break;

Reply via email to