From 40f667f2cdde02eb2e55b9c78fd18ded83f737bc Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Sat, 31 May 2008 06:03:26 +0000 Subject: [PATCH] Add ifa_listmask field in ifaddr_container; currently it is mainly used to do sanity checks. --- sys/net/if.c | 28 ++++++++++++++++++---------- sys/net/if_var.h | 5 ++++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 2c84996eef..3602f653e4 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -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); diff --git a/sys/net/if_var.h b/sys/net/if_var.h index f7d87dd979..c976103599 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -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, -- 2.41.0