Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Eliminate IFAREF() and IFAFREE() macros in favour of fun...
details: https://anonhg.NetBSD.org/src/rev/16603d543962
branches: trunk
changeset: 332170:16603d543962
user: rmind <rmind%NetBSD.org@localhost>
date: Tue Sep 09 20:16:12 2014 +0000
description:
Eliminate IFAREF() and IFAFREE() macros in favour of functions.
diffstat:
sys/net/if.c | 37 +++++++++++++++++++++++++++----------
sys/net/if.h | 43 ++++---------------------------------------
sys/net/route.c | 30 +++++++-----------------------
sys/netatalk/at_control.c | 8 ++++----
sys/netinet/in.c | 8 ++++----
sys/netinet6/in6.c | 8 ++++----
sys/netinet6/in6_ifattach.c | 6 +++---
sys/netinet6/mld6.c | 18 +++++++++---------
sys/netinet6/nd6_nbr.c | 14 +++++++-------
9 files changed, 69 insertions(+), 103 deletions(-)
diffs (truncated from 512 to 300 lines):
diff -r fd9a021d128d -r 16603d543962 sys/net/if.c
--- a/sys/net/if.c Tue Sep 09 19:23:46 2014 +0000
+++ b/sys/net/if.c Tue Sep 09 20:16:12 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.290 2014/08/09 05:33:01 rtr Exp $ */
+/* $NetBSD: if.c,v 1.291 2014/09/09 20:16:12 rmind Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.290 2014/08/09 05:33:01 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.291 2014/09/09 20:16:12 rmind Exp $");
#include "opt_inet.h"
@@ -362,7 +362,7 @@
(void)sockaddr_dl_setaddr(sdl, sdl->sdl_len, lla, ifp->if_addrlen);
if (factory) {
ifp->if_hwdl = ifp->if_dl;
- IFAREF(ifp->if_hwdl);
+ ifaref(ifp->if_hwdl);
}
/* TBD routing socket */
}
@@ -402,9 +402,9 @@
{
const struct sockaddr_dl *sdl;
ifnet_addrs[ifp->if_index] = ifa;
- IFAREF(ifa);
+ ifaref(ifa);
ifp->if_dl = ifa;
- IFAREF(ifa);
+ ifaref(ifa);
sdl = satosdl(ifa->ifa_addr);
ifp->if_sadl = sdl;
}
@@ -447,9 +447,9 @@
ifp->if_sadl = NULL;
ifnet_addrs[ifp->if_index] = NULL;
- IFAFREE(ifa);
+ ifafree(ifa);
ifp->if_dl = NULL;
- IFAFREE(ifa);
+ ifafree(ifa);
}
void
@@ -494,7 +494,7 @@
ifa_remove(ifp, ifa);
if_deactivate_sadl(ifp);
if (ifp->if_hwdl == ifa) {
- IFAFREE(ifa);
+ ifafree(ifa);
ifp->if_hwdl = NULL;
}
splx(s);
@@ -1101,11 +1101,28 @@
}
void
+ifaref(struct ifaddr *ifa)
+{
+ ifa->ifa_refcnt++;
+}
+
+void
+ifafree(struct ifaddr *ifa)
+{
+ KASSERT(ifa != NULL);
+ KASSERT(ifa->ifa_refcnt > 0);
+
+ if (--ifa->ifa_refcnt == 0) {
+ free(ifa, M_IFADDR);
+ }
+}
+
+void
ifa_insert(struct ifnet *ifp, struct ifaddr *ifa)
{
ifa->ifa_ifp = ifp;
TAILQ_INSERT_TAIL(&ifp->if_addrlist, ifa, ifa_list);
- IFAREF(ifa);
+ ifaref(ifa);
}
void
@@ -1113,7 +1130,7 @@
{
KASSERT(ifa->ifa_ifp == ifp);
TAILQ_REMOVE(&ifp->if_addrlist, ifa, ifa_list);
- IFAFREE(ifa);
+ ifafree(ifa);
}
static inline int
diff -r fd9a021d128d -r 16603d543962 sys/net/if.h
--- a/sys/net/if.h Tue Sep 09 19:23:46 2014 +0000
+++ b/sys/net/if.h Tue Sep 09 20:16:12 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.h,v 1.174 2014/07/31 06:35:47 ozaki-r Exp $ */
+/* $NetBSD: if.h,v 1.175 2014/09/09 20:16:12 rmind Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -718,44 +718,6 @@
#endif /* _NETBSD_SOURCE */
#ifdef _KERNEL
-#ifdef IFAREF_DEBUG
-#define IFAREF(ifa) \
-do { \
- printf("IFAREF: %s:%d %p -> %d\n", __FILE__, __LINE__, \
- (ifa), ++(ifa)->ifa_refcnt); \
-} while (/*CONSTCOND*/ 0)
-
-#define IFAFREE(ifa) \
-do { \
- if ((ifa)->ifa_refcnt <= 0) \
- panic("%s:%d: %p ifa_refcnt <= 0", __FILE__, \
- __LINE__, (ifa)); \
- printf("IFAFREE: %s:%d %p -> %d\n", __FILE__, __LINE__, \
- (ifa), --(ifa)->ifa_refcnt); \
- if ((ifa)->ifa_refcnt == 0) \
- ifafree(ifa); \
-} while (/*CONSTCOND*/ 0)
-#else
-#define IFAREF(ifa) (ifa)->ifa_refcnt++
-
-#ifdef DIAGNOSTIC
-#define IFAFREE(ifa) \
-do { \
- if ((ifa)->ifa_refcnt <= 0) \
- panic("%s:%d: %p ifa_refcnt <= 0", __FILE__, \
- __LINE__, (ifa)); \
- if (--(ifa)->ifa_refcnt == 0) \
- ifafree(ifa); \
-} while (/*CONSTCOND*/ 0)
-#else
-#define IFAFREE(ifa) \
-do { \
- if (--(ifa)->ifa_refcnt == 0) \
- ifafree(ifa); \
-} while (/*CONSTCOND*/ 0)
-#endif /* DIAGNOSTIC */
-#endif /* IFAREF_DEBUG */
-
#ifdef ALTQ
#define ALTQ_DECL(x) x
#define ALTQ_COMMA ,
@@ -922,6 +884,9 @@
void ifa_insert(struct ifnet *, struct ifaddr *);
void ifa_remove(struct ifnet *, struct ifaddr *);
+void ifaref(struct ifaddr *);
+void ifafree(struct ifaddr *);
+
struct ifaddr *ifa_ifwithaddr(const struct sockaddr *);
struct ifaddr *ifa_ifwithaf(int);
struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
diff -r fd9a021d128d -r 16603d543962 sys/net/route.c
--- a/sys/net/route.c Tue Sep 09 19:23:46 2014 +0000
+++ b/sys/net/route.c Tue Sep 09 20:16:12 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: route.c,v 1.132 2014/06/06 01:27:32 rmind Exp $ */
+/* $NetBSD: route.c,v 1.133 2014/09/09 20:16:12 rmind Exp $ */
/*-
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -93,7 +93,7 @@
#include "opt_route.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.132 2014/06/06 01:27:32 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.133 2014/09/09 20:16:12 rmind Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@@ -236,15 +236,15 @@
}
}
- IFAREF(ifa);
- IFAFREE(rt->rt_ifa);
+ ifaref(ifa);
+ ifafree(rt->rt_ifa);
rt_set_ifa1(rt, ifa);
}
static void
rt_set_ifa(struct rtentry *rt, struct ifaddr *ifa)
{
- IFAREF(ifa);
+ ifaref(ifa);
rt_set_ifa1(rt, ifa);
}
@@ -386,29 +386,13 @@
rt_timer_remove_all(rt, 0);
ifa = rt->rt_ifa;
rt->rt_ifa = NULL;
- IFAFREE(ifa);
+ ifafree(ifa);
rt->rt_ifp = NULL;
rt_destroy(rt);
pool_put(&rtentry_pool, rt);
}
}
-void
-ifafree(struct ifaddr *ifa)
-{
-
-#ifdef DIAGNOSTIC
- if (ifa == NULL)
- panic("ifafree: null ifa");
- if (ifa->ifa_refcnt != 0)
- panic("ifafree: ifa_refcnt != 0 (%d)", ifa->ifa_refcnt);
-#endif
-#ifdef IFAREF_DEBUG
- printf("ifafree: freeing ifaddr %p\n", ifa);
-#endif
- free(ifa, M_IFADDR);
-}
-
/*
* Force a routing table entry to the specified
* destination to go through the given gateway.
@@ -797,7 +781,7 @@
}
RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key);
if (rc != 0) {
- IFAFREE(ifa);
+ ifafree(ifa);
if ((rt->rt_flags & RTF_CLONED) != 0 && rt->rt_parent)
rtfree(rt->rt_parent);
if (rt->rt_gwroute)
diff -r fd9a021d128d -r 16603d543962 sys/netatalk/at_control.c
--- a/sys/netatalk/at_control.c Tue Sep 09 19:23:46 2014 +0000
+++ b/sys/netatalk/at_control.c Tue Sep 09 20:16:12 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: at_control.c,v 1.35 2014/07/01 05:49:18 rtr Exp $ */
+/* $NetBSD: at_control.c,v 1.36 2014/09/09 20:16:12 rmind Exp $ */
/*
* Copyright (c) 1990,1994 Regents of The University of Michigan.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: at_control.c,v 1.35 2014/07/01 05:49:18 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: at_control.c,v 1.36 2014/09/09 20:16:12 rmind Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -193,7 +193,7 @@
} else {
TAILQ_INSERT_TAIL(&at_ifaddr, aa, aa_list);
}
- IFAREF(&aa->aa_ifa);
+ ifaref(&aa->aa_ifa);
/*
* Find the end of the interface's addresses
@@ -336,7 +336,7 @@
*/
ifa_remove(ifp, &aa->aa_ifa);
TAILQ_REMOVE(&at_ifaddr, aa, aa_list);
- IFAFREE(&aa->aa_ifa);
+ ifafree(&aa->aa_ifa);
}
void
diff -r fd9a021d128d -r 16603d543962 sys/netinet/in.c
--- a/sys/netinet/in.c Tue Sep 09 19:23:46 2014 +0000
+++ b/sys/netinet/in.c Tue Sep 09 20:16:12 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in.c,v 1.147 2014/07/01 05:49:18 rtr Exp $ */
+/* $NetBSD: in.c,v 1.148 2014/09/09 20:16:12 rmind Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.147 2014/07/01 05:49:18 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.148 2014/09/09 20:16:12 rmind Exp $");
#include "opt_inet.h"
#include "opt_inet_conf.h"
@@ -416,7 +416,7 @@
if (ia == NULL)
return (ENOBUFS);
TAILQ_INSERT_TAIL(&in_ifaddrhead, ia, ia_list);
- IFAREF(&ia->ia_ifa);
+ ifaref(&ia->ia_ifa);
Home |
Main Index |
Thread Index |
Old Index