Add ifa_listmask field in ifaddr_container; currently it is mainly used
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 31 May 2008 06:03:26 +0000 (06:03 +0000)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 31 May 2008 06:03:26 +0000 (06:03 +0000)
to do sanity checks.

sys/net/if.c
sys/net/if_var.h

index 2c84996..3602f65 100644 (file)
@@ -32,7 +32,7 @@
  *
  *     @(#)if.c        8.3 (Berkeley) 1/4/94
  * $FreeBSD: src/sys/net/if.c,v 1.185 2004/03/13 02:35:03 brooks Exp $
- * $DragonFly: src/sys/net/if.c,v 1.67 2008/05/28 12:11:13 sephe Exp $
+ * $DragonFly: src/sys/net/if.c,v 1.68 2008/05/31 06:03:26 sephe Exp $
  */
 
 #include "opt_compat.h"
@@ -2211,6 +2211,8 @@ ifac_free(struct ifaddr_container *ifac, int cpu_id)
 
        KKASSERT(ifac->ifa_magic == IFA_CONTAINER_MAGIC);
        KKASSERT(ifac->ifa_refcnt == 0);
+       KASSERT(ifac->ifa_listmask == 0,
+               ("ifa is still on %#x lists\n", ifac->ifa_listmask));
 
        ifac->ifa_magic = IFA_CONTAINER_DEAD;
 
@@ -2244,15 +2246,17 @@ ifa_iflink_dispatch(struct netmsg *nmsg)
        struct ifaddr *ifa = msg->ifa;
        struct ifnet *ifp = msg->ifp;
        int cpu = mycpuid;
+       struct ifaddr_container *ifac;
 
        crit_enter();
-       if (msg->tail) {
-               TAILQ_INSERT_TAIL(&ifp->if_addrheads[cpu],
-                                 &ifa->ifa_containers[cpu], ifa_link);
-       } else {
-               TAILQ_INSERT_HEAD(&ifp->if_addrheads[cpu],
-                                 &ifa->ifa_containers[cpu], ifa_link);
-       }
+       ifac = &ifa->ifa_containers[cpu];
+       KASSERT((ifac->ifa_listmask & IFA_LIST_IFADDRHEAD) == 0,
+               ("ifaddr is on if_addrheads\n"));
+       ifac->ifa_listmask |= IFA_LIST_IFADDRHEAD;
+       if (msg->tail)
+               TAILQ_INSERT_TAIL(&ifp->if_addrheads[cpu], ifac, ifa_link);
+       else
+               TAILQ_INSERT_HEAD(&ifp->if_addrheads[cpu], ifac, ifa_link);
        crit_exit();
 
        ifa_forwardmsg(&nmsg->nm_lmsg, cpu + 1);
@@ -2279,10 +2283,14 @@ ifa_ifunlink_dispatch(struct netmsg *nmsg)
        struct ifaddr *ifa = msg->ifa;
        struct ifnet *ifp = msg->ifp;
        int cpu = mycpuid;
+       struct ifaddr_container *ifac;
 
        crit_enter();
-       TAILQ_REMOVE(&ifp->if_addrheads[cpu],
-                    &ifa->ifa_containers[cpu], ifa_link);
+       ifac = &ifa->ifa_containers[cpu];
+       KASSERT(ifac->ifa_listmask & IFA_LIST_IFADDRHEAD,
+               ("ifaddr is not on if_addrhead\n"));
+       TAILQ_REMOVE(&ifp->if_addrheads[cpu], ifac, ifa_link);
+       ifac->ifa_listmask &= ~IFA_LIST_IFADDRHEAD;
        crit_exit();
 
        ifa_forwardmsg(&nmsg->nm_lmsg, cpu + 1);
index f7d87dd..c976103 100644 (file)
@@ -32,7 +32,7 @@
  *
  *     From: @(#)if.h  8.1 (Berkeley) 6/10/93
  * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.16 2003/04/15 18:11:19 fjoe Exp $
- * $DragonFly: src/sys/net/if_var.h,v 1.50 2008/05/14 11:59:23 sephe Exp $
+ * $DragonFly: src/sys/net/if_var.h,v 1.51 2008/05/31 06:03:26 sephe Exp $
  */
 
 #ifndef        _NET_IF_VAR_H_
@@ -369,8 +369,11 @@ struct ifaddr_container {
        struct ifaddr           *ifa;
        TAILQ_ENTRY(ifaddr_container)   ifa_link;   /* queue macro glue */
        u_int                   ifa_refcnt; /* references to this structure */
+       uint32_t                ifa_listmask;   /* IFA_LIST_ */
 };
 
+#define IFA_LIST_IFADDRHEAD    0x1     /* on ifnet.if_addrheads[cpuid] */
+
 /*
  * The ifaddr structure contains information about one address
  * of an interface.  They are maintained by the different address families,