Tue Jul 1 07:51:29 2014 UTC ()
Stop using callout randomly

nd6_dad_start uses callout when xtick > 0 while doesn't when
xtick == 0. So if we pass a random value ranging from 0 to N,
nd6_dad_start uses callout randomly. This behavior makes
debugging difficult.

Discussed in http://mail-index.netbsd.org/tech-kern/2014/06/25/msg017278.html


(ozaki-r)
diff -r1.172 -r1.173 src/sys/netinet6/in6.c
diff -r1.99 -r1.100 src/sys/netinet6/nd6_nbr.c

cvs diff -r1.172 -r1.173 src/sys/netinet6/in6.c (expand / switch to unified diff)

--- src/sys/netinet6/in6.c 2014/07/01 05:49:19 1.172
+++ src/sys/netinet6/in6.c 2014/07/01 07:51:29 1.173
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in6.c,v 1.172 2014/07/01 05:49:19 rtr Exp $ */ 1/* $NetBSD: in6.c,v 1.173 2014/07/01 07:51:29 ozaki-r Exp $ */
2/* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */ 2/* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -52,27 +52,27 @@ @@ -52,27 +52,27 @@
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE. 59 * SUCH DAMAGE.
60 * 60 *
61 * @(#)in.c 8.2 (Berkeley) 11/15/93 61 * @(#)in.c 8.2 (Berkeley) 11/15/93
62 */ 62 */
63 63
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.172 2014/07/01 05:49:19 rtr Exp $"); 65__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.173 2014/07/01 07:51:29 ozaki-r Exp $");
66 66
67#include "opt_inet.h" 67#include "opt_inet.h"
68#include "opt_compat_netbsd.h" 68#include "opt_compat_netbsd.h"
69 69
70#include <sys/param.h> 70#include <sys/param.h>
71#include <sys/ioctl.h> 71#include <sys/ioctl.h>
72#include <sys/errno.h> 72#include <sys/errno.h>
73#include <sys/malloc.h> 73#include <sys/malloc.h>
74#include <sys/socket.h> 74#include <sys/socket.h>
75#include <sys/socketvar.h> 75#include <sys/socketvar.h>
76#include <sys/sockio.h> 76#include <sys/sockio.h>
77#include <sys/systm.h> 77#include <sys/systm.h>
78#include <sys/proc.h> 78#include <sys/proc.h>
@@ -1321,27 +1321,28 @@ in6_update_ifa1(struct ifnet *ifp, struc @@ -1321,27 +1321,28 @@ in6_update_ifa1(struct ifnet *ifp, struc
1321 if (in6m_sol != NULL && 1321 if (in6m_sol != NULL &&
1322 in6m_sol->in6m_state == MLD_REPORTPENDING) { 1322 in6m_sol->in6m_state == MLD_REPORTPENDING) {
1323 mindelay = in6m_sol->in6m_timer; 1323 mindelay = in6m_sol->in6m_timer;
1324 } 1324 }
1325 maxdelay = MAX_RTR_SOLICITATION_DELAY * hz; 1325 maxdelay = MAX_RTR_SOLICITATION_DELAY * hz;
1326 if (maxdelay - mindelay == 0) 1326 if (maxdelay - mindelay == 0)
1327 dad_delay = 0; 1327 dad_delay = 0;
1328 else { 1328 else {
1329 dad_delay = 1329 dad_delay =
1330 (cprng_fast32() % (maxdelay - mindelay)) + 1330 (cprng_fast32() % (maxdelay - mindelay)) +
1331 mindelay; 1331 mindelay;
1332 } 1332 }
1333 } 1333 }
1334 nd6_dad_start(&ia->ia_ifa, dad_delay); 1334 /* +1 ensures callout is always used */
 1335 nd6_dad_start(&ia->ia_ifa, dad_delay + 1);
1335 } 1336 }
1336 1337
1337 return error; 1338 return error;
1338 1339
1339 unlink: 1340 unlink:
1340 /* 1341 /*
1341 * XXX: if a change of an existing address failed, keep the entry 1342 * XXX: if a change of an existing address failed, keep the entry
1342 * anyway. 1343 * anyway.
1343 */ 1344 */
1344 if (hostIsNew) 1345 if (hostIsNew)
1345 in6_unlink_ifa(ia, ifp); 1346 in6_unlink_ifa(ia, ifp);
1346 return error; 1347 return error;
1347 1348
@@ -2145,35 +2146,37 @@ in6_if_link_up(struct ifnet *ifp) @@ -2145,35 +2146,37 @@ in6_if_link_up(struct ifnet *ifp)
2145 /* If detached then mark as tentative */ 2146 /* If detached then mark as tentative */
2146 if (ia->ia6_flags & IN6_IFF_DETACHED) { 2147 if (ia->ia6_flags & IN6_IFF_DETACHED) {
2147 ia->ia6_flags &= ~IN6_IFF_DETACHED; 2148 ia->ia6_flags &= ~IN6_IFF_DETACHED;
2148 if (in6if_do_dad(ifp)) { 2149 if (in6if_do_dad(ifp)) {
2149 ia->ia6_flags |= IN6_IFF_TENTATIVE; 2150 ia->ia6_flags |= IN6_IFF_TENTATIVE;
2150 nd6log((LOG_ERR, "in6_if_up: " 2151 nd6log((LOG_ERR, "in6_if_up: "
2151 "%s marked tentative\n", 2152 "%s marked tentative\n",
2152 ip6_sprintf(&ia->ia_addr.sin6_addr))); 2153 ip6_sprintf(&ia->ia_addr.sin6_addr)));
2153 } else if ((ia->ia6_flags & IN6_IFF_TENTATIVE) == 0) 2154 } else if ((ia->ia6_flags & IN6_IFF_TENTATIVE) == 0)
2154 nd6_newaddrmsg(ifa); 2155 nd6_newaddrmsg(ifa);
2155 } 2156 }
2156 2157
2157 if (ia->ia6_flags & IN6_IFF_TENTATIVE) { 2158 if (ia->ia6_flags & IN6_IFF_TENTATIVE) {
 2159 int delay;
2158 /* 2160 /*
2159 * The TENTATIVE flag was likely set by hand 2161 * The TENTATIVE flag was likely set by hand
2160 * beforehand, implicitly indicating the need for DAD. 2162 * beforehand, implicitly indicating the need for DAD.
2161 * We may be able to skip the random delay in this 2163 * We may be able to skip the random delay in this
2162 * case, but we impose delays just in case. 2164 * case, but we impose delays just in case.
2163 */ 2165 */
2164 nd6_dad_start(ifa, 2166 delay = cprng_fast32() %
2165 cprng_fast32() % 2167 (MAX_RTR_SOLICITATION_DELAY * hz);
2166 (MAX_RTR_SOLICITATION_DELAY * hz)); 2168 /* +1 ensures callout is always used */
 2169 nd6_dad_start(ifa, delay + 1);
2167 } 2170 }
2168 } 2171 }
2169 2172
2170 /* Restore any detached prefixes */ 2173 /* Restore any detached prefixes */
2171 pfxlist_onlink_check(); 2174 pfxlist_onlink_check();
2172} 2175}
2173 2176
2174void 2177void
2175in6_if_up(struct ifnet *ifp) 2178in6_if_up(struct ifnet *ifp)
2176{ 2179{
2177 2180
2178 /* 2181 /*
2179 * special cases, like 6to4, are handled in in6_ifattach 2182 * special cases, like 6to4, are handled in in6_ifattach

cvs diff -r1.99 -r1.100 src/sys/netinet6/nd6_nbr.c (expand / switch to unified diff)

--- src/sys/netinet6/nd6_nbr.c 2014/01/13 18:23:36 1.99
+++ src/sys/netinet6/nd6_nbr.c 2014/07/01 07:51:29 1.100
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nd6_nbr.c,v 1.99 2014/01/13 18:23:36 roy Exp $ */ 1/* $NetBSD: nd6_nbr.c,v 1.100 2014/07/01 07:51:29 ozaki-r Exp $ */
2/* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */ 2/* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.99 2014/01/13 18:23:36 roy Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.100 2014/07/01 07:51:29 ozaki-r Exp $");
35 35
36#include "opt_inet.h" 36#include "opt_inet.h"
37#include "opt_ipsec.h" 37#include "opt_ipsec.h"
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/malloc.h> 41#include <sys/malloc.h>
42#include <sys/mbuf.h> 42#include <sys/mbuf.h>
43#include <sys/socket.h> 43#include <sys/socket.h>
44#include <sys/socketvar.h> 44#include <sys/socketvar.h>
45#include <sys/sockio.h> 45#include <sys/sockio.h>
46#include <sys/time.h> 46#include <sys/time.h>
47#include <sys/kernel.h> 47#include <sys/kernel.h>
@@ -1087,26 +1087,28 @@ nd6_newaddrmsg(struct ifaddr *ifa) @@ -1087,26 +1087,28 @@ nd6_newaddrmsg(struct ifaddr *ifa)
1087#if 0 1087#if 0
1088 log(LOG_DEBUG, "nd6_newaddrmsg: announced %s\n", 1088 log(LOG_DEBUG, "nd6_newaddrmsg: announced %s\n",
1089 ip6_sprintf(&((struct in6_ifaddr *)ifa)->ia_addr.sin6_addr) 1089 ip6_sprintf(&((struct in6_ifaddr *)ifa)->ia_addr.sin6_addr)
1090 ); 1090 );
1091#endif 1091#endif
1092 nrt->rt_refcnt--; 1092 nrt->rt_refcnt--;
1093 } 1093 }
1094} 1094}
1095 1095
1096 1096
1097/* 1097/*
1098 * Start Duplicate Address Detection (DAD) for specified interface address. 1098 * Start Duplicate Address Detection (DAD) for specified interface address.
1099 * 1099 *
 1100 * Note that callout is used when xtick > 0 and not when xtick == 0.
 1101 *
1100 * xtick: minimum delay ticks for IFF_UP event 1102 * xtick: minimum delay ticks for IFF_UP event
1101 */ 1103 */
1102void 1104void
1103nd6_dad_start(struct ifaddr *ifa, int xtick) 1105nd6_dad_start(struct ifaddr *ifa, int xtick)
1104{ 1106{
1105 struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa; 1107 struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa;
1106 struct dadq *dp; 1108 struct dadq *dp;
1107 1109
1108 if (!dad_init) { 1110 if (!dad_init) {
1109 TAILQ_INIT(&dadq); 1111 TAILQ_INIT(&dadq);
1110 dad_init++; 1112 dad_init++;
1111 } 1113 }
1112 1114