aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet6/nd6_nbr.c
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2016-09-24 21:40:24 +0000
committerMark Johnston <markj@FreeBSD.org>2016-09-24 21:40:24 +0000
commit970fe0938e0c22d391f45cf3fed16dc53725ec49 (patch)
tree5eee4d544d70dec0647e0641f1d3e88ae2128104 /sys/netinet6/nd6_nbr.c
parent9e579a58c364cb29e76e8e4c630df63e97d42780 (diff)
downloadsrc-970fe0938e0c22d391f45cf3fed16dc53725ec49.tar.gz
src-970fe0938e0c22d391f45cf3fed16dc53725ec49.zip
Convert checks in nd6_dad_start() and nd6_dad_timer() to assertions.
In particular, these functions can assume they are operating on tentative addresses. MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=306305
Diffstat (limited to 'sys/netinet6/nd6_nbr.c')
-rw-r--r--sys/netinet6/nd6_nbr.c52
1 files changed, 15 insertions, 37 deletions
diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c
index 2ac1d7a10a72..6df012ba4dcc 100644
--- a/sys/netinet6/nd6_nbr.c
+++ b/sys/netinet6/nd6_nbr.c
@@ -1217,40 +1217,26 @@ nd6_dad_start(struct ifaddr *ifa, int delay)
struct dadq *dp;
char ip6buf[INET6_ADDRSTRLEN];
+ KASSERT((ia->ia6_flags & IN6_IFF_TENTATIVE) != 0,
+ ("starting DAD on non-tentative address %p", ifa));
+
/*
* If we don't need DAD, don't do it.
* There are several cases:
- * - DAD is disabled (ip6_dad_count == 0)
+ * - DAD is disabled globally or on the interface
* - the interface address is anycast
*/
- if (!(ia->ia6_flags & IN6_IFF_TENTATIVE)) {
- log(LOG_DEBUG,
- "nd6_dad_start: called with non-tentative address "
- "%s(%s)\n",
- ip6_sprintf(ip6buf, &ia->ia_addr.sin6_addr),
- ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???");
- return;
- }
- if (ia->ia6_flags & IN6_IFF_ANYCAST) {
- ia->ia6_flags &= ~IN6_IFF_TENTATIVE;
- return;
- }
- if (!V_ip6_dad_count) {
- ia->ia6_flags &= ~IN6_IFF_TENTATIVE;
- return;
- }
- if (ifa->ifa_ifp == NULL)
- panic("nd6_dad_start: ifa->ifa_ifp == NULL");
- if (ND_IFINFO(ifa->ifa_ifp)->flags & ND6_IFF_NO_DAD) {
+ if ((ia->ia6_flags & IN6_IFF_ANYCAST) != 0 ||
+ V_ip6_dad_count == 0 ||
+ (ND_IFINFO(ifa->ifa_ifp)->flags & ND6_IFF_NO_DAD) != 0) {
ia->ia6_flags &= ~IN6_IFF_TENTATIVE;
return;
}
- if (!(ifa->ifa_ifp->if_flags & IFF_UP) ||
- !(ifa->ifa_ifp->if_drv_flags & IFF_DRV_RUNNING) ||
- (ND_IFINFO(ifa->ifa_ifp)->flags & ND6_IFF_IFDISABLED)) {
- ia->ia6_flags |= IN6_IFF_TENTATIVE;
+ if ((ifa->ifa_ifp->if_flags & IFF_UP) == 0 ||
+ (ifa->ifa_ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
+ (ND_IFINFO(ifa->ifa_ifp)->flags & ND6_IFF_IFDISABLED) != 0)
return;
- }
+
if ((dp = nd6_dad_find(ifa, NULL)) != NULL) {
/*
* DAD is already in progress. Let the existing entry
@@ -1329,11 +1315,10 @@ nd6_dad_timer(struct dadq *dp)
struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa;
char ip6buf[INET6_ADDRSTRLEN];
- /* Sanity check */
- if (ia == NULL) {
- log(LOG_ERR, "nd6_dad_timer: called with null parameter\n");
- goto err;
- }
+ KASSERT(ia != NULL, ("DAD entry %p with no address", dp));
+ KASSERT((ia->ia6_flags & IN6_IFF_TENTATIVE) != 0,
+ ("DAD entry %p for non-tentative address", dp));
+
if (ND_IFINFO(ifp)->flags & ND6_IFF_IFDISABLED) {
/* Do not need DAD for ifdisabled interface. */
log(LOG_ERR, "nd6_dad_timer: cancel DAD on %s because of "
@@ -1347,13 +1332,6 @@ nd6_dad_timer(struct dadq *dp)
ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???");
goto err;
}
- if ((ia->ia6_flags & IN6_IFF_TENTATIVE) == 0) {
- log(LOG_ERR, "nd6_dad_timer: called with non-tentative address "
- "%s(%s)\n",
- ip6_sprintf(ip6buf, &ia->ia_addr.sin6_addr),
- ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???");
- goto err;
- }
/* Stop DAD if the interface is down even after dad_maxtry attempts. */
if ((dp->dad_ns_tcount > V_dad_maxtry) &&