Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Add debug helper function for interface addresses
details: https://anonhg.NetBSD.org/src/rev/2bfa78dd2857
branches: trunk
changeset: 346194:2bfa78dd2857
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Fri Jul 01 05:15:40 2016 +0000
description:
Add debug helper function for interface addresses
It checks whether all addresses of an interface being destroyed
are freed (no reference remains) at the end of if_detach.
diffstat:
sys/net/if.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 68 insertions(+), 2 deletions(-)
diffs (105 lines):
diff -r 77cb40289f91 -r 2bfa78dd2857 sys/net/if.c
--- a/sys/net/if.c Thu Jun 30 20:39:54 2016 +0000
+++ b/sys/net/if.c Fri Jul 01 05:15:40 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.348 2016/06/28 02:36:54 ozaki-r Exp $ */
+/* $NetBSD: if.c,v 1.349 2016/07/01 05:15:40 ozaki-r 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.348 2016/06/28 02:36:54 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.349 2016/07/01 05:15:40 ozaki-r Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@@ -1025,6 +1025,65 @@
}
}
+#ifdef IFAREF_DEBUG
+static struct ifaddr **ifa_list;
+static int ifa_list_size;
+
+/* Depends on only one if_attach runs at once */
+static void
+if_build_ifa_list(struct ifnet *ifp)
+{
+ struct ifaddr *ifa;
+ int i;
+
+ KASSERT(ifa_list == NULL);
+ KASSERT(ifa_list_size == 0);
+
+ IFADDR_FOREACH(ifa, ifp)
+ ifa_list_size++;
+
+ ifa_list = kmem_alloc(sizeof(*ifa) * ifa_list_size, KM_SLEEP);
+ if (ifa_list == NULL)
+ return;
+
+ i = 0;
+ IFADDR_FOREACH(ifa, ifp) {
+ ifa_list[i++] = ifa;
+ ifaref(ifa);
+ }
+}
+
+static void
+if_check_and_free_ifa_list(struct ifnet *ifp)
+{
+ int i;
+ struct ifaddr *ifa;
+
+ if (ifa_list == NULL)
+ return;
+
+ for (i = 0; i < ifa_list_size; i++) {
+ char buf[64];
+
+ ifa = ifa_list[i];
+ sockaddr_format(ifa->ifa_addr, buf, sizeof(buf));
+ if (ifa->ifa_refcnt > 1) {
+ log(LOG_WARNING,
+ "ifa(%s) still referenced (refcnt=%d)\n",
+ buf, ifa->ifa_refcnt - 1);
+ } else
+ log(LOG_DEBUG,
+ "ifa(%s) not referenced (refcnt=%d)\n",
+ buf, ifa->ifa_refcnt - 1);
+ ifafree(ifa);
+ }
+
+ kmem_free(ifa_list, sizeof(*ifa) * ifa_list_size);
+ ifa_list = NULL;
+ ifa_list_size = 0;
+}
+#endif
+
/*
* Detach an interface from the list of "active" interfaces,
* freeing any resources as we go along.
@@ -1045,6 +1104,9 @@
int s, i, family, purged;
uint64_t xc;
+#ifdef IFAREF_DEBUG
+ if_build_ifa_list(ifp);
+#endif
/*
* XXX It's kind of lame that we have to have the
* XXX socket structure...
@@ -1245,6 +1307,10 @@
}
splx(s);
+
+#ifdef IFAREF_DEBUG
+ if_check_and_free_ifa_list(ifp);
+#endif
}
static void
Home |
Main Index |
Thread Index |
Old Index