svn commit: r292333 - in head: sys/net sys/netinet6 usr.sbin/ndp

Alexander V. Chernikov melifaro at FreeBSD.org
Wed Dec 16 13:48:41 UTC 2015


Author: melifaro
Date: Wed Dec 16 10:14:16 2015
New Revision: 292333
URL: https://svnweb.freebsd.org/changeset/base/292333

Log:
  Provide additional lle data in IPv6 lltable dump used by ndp(8).
  
  Before the change, things like lle state were queried via
    SIOCGNBRINFO_IN6 by ndp(8) for _each_ lle entry in dump.
  This ioctl was added in 1999, probably to avoid touching rtsock code.
  
  This change maps SIOCGNBRINFO_IN6 data to standard rtsock dump the
   following way:
    expire (already) maps to rtm_rmx.rmx_expire
    isrouter -> rtm_flags & RTF_GATEWAY
    asked -> rtm_rmx.rmx_pksent
    state -> rtm_rmx.rmx_state (maps to rmx_weight via define)
  
  Reviewed by:	ae

Modified:
  head/sys/net/route.h
  head/sys/netinet6/in6.c
  head/sys/netinet6/nd6.c
  head/usr.sbin/ndp/ndp.c

Modified: head/sys/net/route.h
==============================================================================
--- head/sys/net/route.h	Wed Dec 16 09:20:45 2015	(r292332)
+++ head/sys/net/route.h	Wed Dec 16 10:14:16 2015	(r292333)
@@ -83,6 +83,9 @@ struct rt_metrics {
 #define	RTM_RTTUNIT	1000000	/* units for rtt, rttvar, as units per sec */
 #define	RTTTOPRHZ(r)	((r) / (RTM_RTTUNIT / PR_SLOWHZ))
 
+/* lle state is exported in rmx_state rt_metrics field */
+#define	rmx_state	rmx_weight
+
 #define	RT_DEFAULT_FIB	0	/* Explicitly mark fib=0 restricted cases */
 #define	RT_ALL_FIBS	-1	/* Announce event for every fib */
 #ifdef _KERNEL

Modified: head/sys/netinet6/in6.c
==============================================================================
--- head/sys/netinet6/in6.c	Wed Dec 16 09:20:45 2015	(r292332)
+++ head/sys/netinet6/in6.c	Wed Dec 16 10:14:16 2015	(r292333)
@@ -2359,13 +2359,20 @@ in6_lltable_dump_entry(struct lltable *l
 			sdl->sdl_index = ifp->if_index;
 			sdl->sdl_type = ifp->if_type;
 			bcopy(&lle->ll_addr, LLADDR(sdl), ifp->if_addrlen);
-			ndpc.rtm.rtm_rmx.rmx_expire = lle->la_expire +
-			    lle->lle_remtime / hz;
+			if (lle->la_expire != 0)
+				ndpc.rtm.rtm_rmx.rmx_expire = lle->la_expire +
+				    lle->lle_remtime / hz +
+				    time_second - time_uptime;
 			ndpc.rtm.rtm_flags |= (RTF_HOST | RTF_LLDATA);
 			if (lle->la_flags & LLE_STATIC)
 				ndpc.rtm.rtm_flags |= RTF_STATIC;
 			if (lle->la_flags & LLE_IFADDR)
 				ndpc.rtm.rtm_flags |= RTF_PINNED;
+			if (lle->ln_router != 0)
+				ndpc.rtm.rtm_flags |= RTF_GATEWAY;
+			ndpc.rtm.rtm_rmx.rmx_pksent = lle->la_asked;
+			/* Store state in rmx_weight value */
+			ndpc.rtm.rtm_rmx.rmx_state = lle->ln_state;
 			ndpc.rtm.rtm_index = ifp->if_index;
 			error = SYSCTL_OUT(wr, &ndpc, sizeof(ndpc));
 

Modified: head/sys/netinet6/nd6.c
==============================================================================
--- head/sys/netinet6/nd6.c	Wed Dec 16 09:20:45 2015	(r292332)
+++ head/sys/netinet6/nd6.c	Wed Dec 16 10:14:16 2015	(r292333)
@@ -1748,7 +1748,7 @@ nd6_ioctl(u_long cmd, caddr_t data, stru
 		if (ln->la_expire == 0)
 			nbi->expire = 0;
 		else
-			nbi->expire = ln->la_expire +
+			nbi->expire = ln->la_expire + ln->lle_remtime / hz +
 			    (time_second - time_uptime);
 		LLE_RUNLOCK(ln);
 		break;

Modified: head/usr.sbin/ndp/ndp.c
==============================================================================
--- head/usr.sbin/ndp/ndp.c	Wed Dec 16 09:20:45 2015	(r292332)
+++ head/usr.sbin/ndp/ndp.c	Wed Dec 16 10:14:16 2015	(r292333)
@@ -563,8 +563,8 @@ dump(struct sockaddr_in6 *addr, int cfla
 	struct sockaddr_in6 *sin;
 	struct sockaddr_dl *sdl;
 	extern int h_errno;
-	struct in6_nbrinfo *nbi;
 	struct timeval now;
+	u_long expire;
 	int addrwidth;
 	int llwidth;
 	int ifwidth;
@@ -676,52 +676,46 @@ again:;
 		    llwidth, llwidth, ether_str(sdl), ifwidth, ifwidth, ifname);
 
 		/* Print neighbor discovery specific information */
-		nbi = getnbrinfo(&sin->sin6_addr, sdl->sdl_index, 1);
-		if (nbi) {
-			if (nbi->expire > now.tv_sec) {
-				printf(" %-9.9s",
-				    sec2str(nbi->expire - now.tv_sec));
-			} else if (nbi->expire == 0)
-				printf(" %-9.9s", "permanent");
-			else
-				printf(" %-9.9s", "expired");
-
-			switch (nbi->state) {
-			case ND6_LLINFO_NOSTATE:
-				 printf(" N");
-				 break;
-#ifdef ND6_LLINFO_WAITDELETE
-			case ND6_LLINFO_WAITDELETE:
-				 printf(" W");
-				 break;
-#endif
-			case ND6_LLINFO_INCOMPLETE:
-				 printf(" I");
-				 break;
-			case ND6_LLINFO_REACHABLE:
-				 printf(" R");
-				 break;
-			case ND6_LLINFO_STALE:
-				 printf(" S");
-				 break;
-			case ND6_LLINFO_DELAY:
-				 printf(" D");
-				 break;
-			case ND6_LLINFO_PROBE:
-				 printf(" P");
-				 break;
-			default:
-				 printf(" ?");
-				 break;
-			}
+		expire = rtm->rtm_rmx.rmx_expire;
+		if (expire > now.tv_sec)
+			printf(" %-9.9s", sec2str(expire - now.tv_sec));
+		else if (expire == 0)
+			printf(" %-9.9s", "permanent");
+		else
+			printf(" %-9.9s", "expired");
 
-			isrouter = nbi->isrouter;
-			prbs = nbi->asked;
-		} else {
-			warnx("failed to get neighbor information");
-			printf("  ");
+		switch (rtm->rtm_rmx.rmx_state) {
+		case ND6_LLINFO_NOSTATE:
+			 printf(" N");
+			 break;
+#ifdef ND6_LLINFO_WAITDELETE
+		case ND6_LLINFO_WAITDELETE:
+			 printf(" W");
+			 break;
+#endif
+		case ND6_LLINFO_INCOMPLETE:
+			 printf(" I");
+			 break;
+		case ND6_LLINFO_REACHABLE:
+			 printf(" R");
+			 break;
+		case ND6_LLINFO_STALE:
+			 printf(" S");
+			 break;
+		case ND6_LLINFO_DELAY:
+			 printf(" D");
+			 break;
+		case ND6_LLINFO_PROBE:
+			 printf(" P");
+			 break;
+		default:
+			 printf(" ?");
+			 break;
 		}
 
+		isrouter = rtm->rtm_flags & RTF_GATEWAY;
+		prbs = rtm->rtm_rmx.rmx_pksent;
+
 		/*
 		 * other flags. R: router, P: proxy, W: ??
 		 */


More information about the svn-src-head mailing list