Module Name:    src
Committed By:   ozaki-r
Date:           Thu Sep  3 02:04:31 UTC 2015

Modified Files:
        src/sys/net: route.c

Log Message:
Add refcnt constraint checks for debugging

It's useful to know where the constraint is violated (by extra rtfree).
It's enabled only if DEBUG because it's heavy (O(n)).


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/sys/net/route.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.150 src/sys/net/route.c:1.151
--- src/sys/net/route.c:1.150	Mon Aug 31 06:25:15 2015
+++ src/sys/net/route.c	Thu Sep  3 02:04:31 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.150 2015/08/31 06:25:15 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.151 2015/09/03 02:04:31 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.150 2015/08/31 06:25:15 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.151 2015/09/03 02:04:31 ozaki-r Exp $");
 
 #include <sys/param.h>
 #ifdef RTFLUSH_DEBUG
@@ -410,6 +410,26 @@ rtalloc1(const struct sockaddr *dst, int
 	return newrt;
 }
 
+#ifdef DEBUG
+/*
+ * Check the following constraint for each rtcache:
+ *   if a rtcache holds a rtentry, the rtentry's refcnt is more than zero,
+ *   i.e., the rtentry should be referenced at least by the rtcache.
+ */
+static void
+rtcache_check_rtrefcnt(int family)
+{
+	struct domain *dom = pffinddomain(family);
+	struct route *ro;
+
+	if (dom == NULL)
+		return;
+
+	LIST_FOREACH(ro, &dom->dom_rtcache, ro_rtcache_next)
+		KDASSERT(ro->_ro_rt == NULL || ro->_ro_rt->rt_refcnt > 0);
+}
+#endif
+
 void
 rtfree(struct rtentry *rt)
 {
@@ -419,6 +439,10 @@ rtfree(struct rtentry *rt)
 	KASSERT(rt->rt_refcnt > 0);
 
 	rt->rt_refcnt--;
+#ifdef DEBUG
+	if (rt_getkey(rt) != NULL)
+		rtcache_check_rtrefcnt(rt_getkey(rt)->sa_family);
+#endif
 	if (rt->rt_refcnt == 0 && (rt->rt_flags & RTF_UP) == 0) {
 		rt_assert_inactive(rt);
 		rttrash--;

Reply via email to