Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Mar 2012 17:51:52 -0800
From:      prabhakar lakhera <prabhakar.lakhera@gmail.com>
To:        freebsd-net@freebsd.org
Subject:   Doubt regarding IPv6 DAD detection code
Message-ID:  <CALg%2BrhVkcisVSP39v18UkwP90MdLDRWGAS-ci5uCBb3BWZecog@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi,

I was puzzled to look at DAD detection code in FreeBSD. We check for
counters for any received NA/NS for DAD in nd6_dad_timer:

  if (dp->dad_na_icount) {
 1326                         /*
 1327                          * the check is in nd6_dad_na_input(),
 1328                          * but just in case
 1329                          */
 1330                         duplicate++;
 1331                 }
 1332
 1333                 if (dp->dad_ns_icount) {
 1334                         /* We've seen NS, means DAD has failed. */
 1335                         duplicate++;
 1336                 }
 1337
 1338                 if (duplicate) {
 1339                         /* (*dp) will be freed in
nd6_dad_duplicated() */
 1340                         dp = NULL;
 1341                         nd6_dad_duplicated(ifa);

the function later calls nd6_dad_duplicated to perform the remaining work
if the address is detected duplicate.

nd6_dad_duplicated also gets called from nd6_dad_na_input
and  nd6_dad_ns_input, both the functions are the only places which
increment the input NA/NS counters respectively.

 1505 static void
 1506 nd6_dad_na_input(struct ifaddr *ifa)
 1507 {
 1508         struct dadq *dp;
 1509
 1510         if (ifa == NULL)
 1511                 panic("ifa == NULL in nd6_dad_na_input");
 1512
 1513         dp = nd6_dad_find(ifa);
 1514         if (dp)
 1515                 dp->dad_na_icount++;
 1516
 1517         /* remove the address. */
 1518         nd6_dad_duplicated(ifa);
 1519 }

nd6_dad_duplicated stops the timer among other things.

Why nd6_dad_timer need check on these counters if we stop the timer on DAD
failure anyways?
Ok.. may be just an optimization which just "hopes" that the counters have
been updated but the nd6_dad_*_input has not yet called nd6_dad_duplicated.

Can the this timer and na packet processing ever run in parallel, I don;t
see dp being protected by any locks, nor does it seem that it's been
reference counted.
Any explanation will be highly appreciated.

Best,

Prabhakar



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CALg%2BrhVkcisVSP39v18UkwP90MdLDRWGAS-ci5uCBb3BWZecog>