Index: net/route.c
===================================================================
RCS file: /home/ncvs/src/sys/net/route.c,v
retrieving revision 1.120
diff -u -r1.120 route.c
--- net/route.c	11 Jun 2007 12:19:34 -0000	1.120
+++ net/route.c	16 Oct 2007 03:01:18 -0000
@@ -40,7 +40,7 @@
 #include <sys/socket.h>
 #include <sys/domain.h>
 #include <sys/kernel.h>
-
+#include <sys/ktr.h>
 #include <net/if.h>
 #include <net/route.h>
 
@@ -235,7 +235,7 @@
 	KASSERT(rt != NULL,("%s: NULL rt", __func__));
 	rnh = rt_tables[rt_key(rt)->sa_family];
 	KASSERT(rnh != NULL,("%s: NULL rnh", __func__));
-
+ CTR2(KTR_NET, "%p>rtfree %p",curthread, rt);
 	RT_LOCK_ASSERT(rt);
 
 	/*
@@ -299,13 +299,13 @@
 		 */
 		RT_LOCK_DESTROY(rt);
 		uma_zfree(rtzone, rt);
-		return;
+ CTR2(KTR_NET, "%p<rtfree %p destroyed",curthread,rt);		return;
 	}
-done:
+ done:
 	RT_UNLOCK(rt);
+ CTR2(KTR_NET, "%p<rtfree %p",curthread, rt);
 }
 
-
 /*
  * Force a routing table entry to the specified
  * destination to go through the given gateway.
@@ -1282,27 +1282,27 @@
 
 	KASSERT(*lrt0 != NULL, ("rt_check"));
 	rt = rt0 = *lrt0;
-
+ CTR2(KTR_NET, "%p>rt_check %p", curthread, rt);
 	/* NB: the locking here is tortuous... */
 	RT_LOCK(rt);
 	if ((rt->rt_flags & RTF_UP) == 0) {
 		RT_UNLOCK(rt);
-		rt = rtalloc1(dst, 1, 0UL);
+ CTR2(KTR_NET, "%p discard %p in rt_check", curthread, rt);		rt = rtalloc1(dst, 1, 0UL);
 		if (rt != NULL) {
 			RT_REMREF(rt);
 			/* XXX what about if change? */
-		} else
-			return (EHOSTUNREACH);
+		} else {
+ CTR1(KTR_NET, "%p<rt_check EHOSTUNREACH", curthread);			return (EHOSTUNREACH);		
+		}
 		rt0 = rt;
-	}
-	/* XXX BSD/OS checks dst->sa_family != AF_NS */
+	}	/* XXX BSD/OS checks dst->sa_family != AF_NS */
 	if (rt->rt_flags & RTF_GATEWAY) {
 		if (rt->rt_gwroute == NULL)
 			goto lookup;
 		rt = rt->rt_gwroute;
 		RT_LOCK(rt);		/* NB: gwroute */
 		if ((rt->rt_flags & RTF_UP) == 0) {
-			RTFREE_LOCKED(rt);	/* unlock gwroute */
+ CTR2(KTR_NET, "%p free %p", curthread, rt);			RTFREE_LOCKED(rt);	/* unlock gwroute */
 			rt = rt0;
 		lookup:
 			RT_UNLOCK(rt0);
@@ -1311,13 +1311,13 @@
 				rt0->rt_gwroute = NULL;
 				RT_REMREF(rt0);
 				RT_UNLOCK(rt0);
-				return (ENETUNREACH);
+ CTR1(KTR_NET, "%p<rt_check ENETUNREACH",curthread);				return (ENETUNREACH);
 			}
 			RT_LOCK(rt0);
 			rt0->rt_gwroute = rt;
 			if (rt == NULL) {
 				RT_UNLOCK(rt0);
-				return (EHOSTUNREACH);
+ CTR1(KTR_NET, "%p<rt_check EHOSTUNREACH",curthread);				return (EHOSTUNREACH);
 			}
 		}
 		RT_UNLOCK(rt0);
@@ -1328,12 +1328,12 @@
 			time_uptime < rt->rt_rmx.rmx_expire);
 	if (error) {
 		RT_UNLOCK(rt);
-		return (rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
+ CTR1(KTR_NET, "%p<rt_check EHOSTUNREACH/DOWN",curthread);		return (rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
 	}
 
 	*lrt = rt;
 	*lrt0 = rt0;
-	return (0);
+ CTR3(KTR_NET, "%p<rt_check %p %p", curthread, rt, rt0);	return (0);
 }
 
 /* This must be before ip6_init2(), which is now SI_ORDER_MIDDLE */
Index: net/route.h
===================================================================
RCS file: /home/ncvs/src/sys/net/route.h,v
retrieving revision 1.65
diff -u -r1.65 route.h
--- net/route.h	15 Mar 2006 19:39:09 -0000	1.65
+++ net/route.h	15 Oct 2007 18:54:32 -0000
@@ -288,21 +288,27 @@
 
 #define	RT_LOCK_INIT(_rt) \
 	mtx_init(&(_rt)->rt_mtx, "rtentry", NULL, MTX_DEF | MTX_DUPOK)
-#define	RT_LOCK(_rt)		mtx_lock(&(_rt)->rt_mtx)
-#define	RT_UNLOCK(_rt)		mtx_unlock(&(_rt)->rt_mtx)
-#define	RT_LOCK_DESTROY(_rt)	mtx_destroy(&(_rt)->rt_mtx)
+#define	RT_LOCK(_rt)		do { CTR3(KTR_NET,"%p lock %p in %s", curthread,_rt,__func__); mtx_lock(&(_rt)->rt_mtx); } while(0)
+#define	RT_UNLOCK(_rt)		do { CTR3(KTR_NET,"%p unlock %p in %s", curthread,_rt,__func__); mtx_unlock(&(_rt)->rt_mtx); } while(0)
+#define	RT_LOCK_DESTROY(_rt)	do { CTR3(KTR_NET,"%p destroy %p in %s", curthread,_rt,__func__); mtx_destroy(&(_rt)->rt_mtx); } while(0)
 #define	RT_LOCK_ASSERT(_rt)	mtx_assert(&(_rt)->rt_mtx, MA_OWNED)
 
 #define	RT_ADDREF(_rt)	do {					\
 	RT_LOCK_ASSERT(_rt);					\
 	KASSERT((_rt)->rt_refcnt >= 0,				\
 		("negative refcnt %ld", (_rt)->rt_refcnt));	\
+	CTR5(KTR_NET,"%p addref %p %d->%d in %s", curthread, _rt,	\
+		(_rt)->rt_refcnt, (_rt)->rt_refcnt+1,		\
+		__func__);			\
 	(_rt)->rt_refcnt++;					\
 } while (0)
 #define	RT_REMREF(_rt)	do {					\
 	RT_LOCK_ASSERT(_rt);					\
 	KASSERT((_rt)->rt_refcnt > 0,				\
 		("bogus refcnt %ld", (_rt)->rt_refcnt));	\
+	CTR5(KTR_NET,"%p remref %p %d->%d in %s", curthread, _rt,	\
+		(_rt)->rt_refcnt, (_rt)->rt_refcnt-1,		\
+		__func__);			\
 	(_rt)->rt_refcnt--;					\
 } while (0)
 
Index: netinet/if_ether.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/if_ether.c,v
retrieving revision 1.162
diff -u -r1.162 if_ether.c
--- netinet/if_ether.c	7 Oct 2007 20:44:22 -0000	1.162
+++ netinet/if_ether.c	15 Oct 2007 21:02:46 -0000
@@ -362,20 +362,20 @@
 	struct sockaddr_dl *sdl;
 	int error;
 
-	if (m->m_flags & M_BCAST) {	/* broadcast */
+ CTR2(KTR_NET,"%p>arpresolve %p", curthread,rt0);	if (m->m_flags & M_BCAST) {	/* broadcast */
 		(void)memcpy(desten, ifp->if_broadcastaddr, ifp->if_addrlen);
-		return (0);
+ CTR1(KTR_NET,"%p<arpresolve broadcast",curthread);		return (0);
 	}
 	if (m->m_flags & M_MCAST && ifp->if_type != IFT_ARCNET) {/* multicast */
 		ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten);
-		return (0);
+ CTR1(KTR_NET,"%p<arpresolve multicast",curthread);		return (0);
 	}
 
 	if (rt0 != NULL) {
 		error = rt_check(&rt, &rt0, dst);
 		if (error) {
 			m_freem(m);
-			return error;
+ CTR2(KTR_NET,"%p<arpresolve errno %d", curthread, error);			return error;
 		}
 		la = (struct llinfo_arp *)rt->rt_llinfo;
 		if (la == NULL)
@@ -392,7 +392,7 @@
 			    "arpresolve: can't allocate route for %s\n",
 			    inet_ntoa(SIN(dst)->sin_addr));
 			m_freem(m);
-			return (EINVAL); /* XXX */
+ CTR1(KTR_NET,"%p<arpresolve can't allocate route",curthread);			return (EINVAL); /* XXX */
 		}
 		la = (struct llinfo_arp *)rt->rt_llinfo;
 		if (la == NULL) {
@@ -401,7 +401,7 @@
 			    "arpresolve: can't allocate llinfo for %s\n",
 			    inet_ntoa(SIN(dst)->sin_addr));
 			m_freem(m);
-			return (EINVAL); /* XXX */
+ CTR1(KTR_NET,"%p<arpresolve can't allocate llinfo",curthread);			return (EINVAL); /* XXX */
 		}
 	}
 	sdl = SDL(rt->rt_gateway);
@@ -427,11 +427,11 @@
 			RT_UNLOCK(rt);
 			arprequest(ifp, &sin, &SIN(dst)->sin_addr,
 			    IF_LLADDR(ifp));
-			return (0);
+ CTR1(KTR_NET,"%p<arpresolve sent refresh arp",curthread);			return (0);
 		} 
 
 		RT_UNLOCK(rt);
-		return (0);
+ CTR1(KTR_NET,"%p<arpresolve hit",curthread);		return (0);
 	}
 	/*
 	 * If ARP is disabled or static on this interface, stop.
@@ -442,7 +442,7 @@
 	if (ifp->if_flags & (IFF_NOARP | IFF_STATICARP)) {
 		RT_UNLOCK(rt);
 		m_freem(m);
-		return (EINVAL);
+ CTR1(KTR_NET,"%p<arpresolve NOARP",curthread);		return (EINVAL);
 	}
 	/*
 	 * There is an arptab entry, but no ethernet address
@@ -480,7 +480,7 @@
 	} else
 		RT_UNLOCK(rt);
 
-	return (error);
+ CTR2(KTR_NET,"%p<arpresolve %d",curthread, error);	return (error);
 }
 
 /*

