[4336] in linux-net channel archive

home help back first fref pref prev next nref lref last post

cache support for route in net-tools-1.32-alpha

daemon@ATHENA.MIT.EDU (Zach)
Mon Sep 9 22:39:46 1996

Date: 	Mon, 9 Sep 1996 18:37:15 -0700 (PDT)
From: Zach <zab@grumblesmurf.net>
To: linux-net@vger.rutgers.edu


I sent this off to net-tools@lina.inka.de but didn't get a response, so I
thought I'd give you guys a try :).  I just copied the parsing code for
/proc/net/route and tweaked it a little to read rt_cache.  I also added
the hh and arp fields. I updated the man page a little, though I guessed
what hh actually meant from browsing the kernel source.. if someone who
actually knows what that crap means could clue me in I would appreciate it
:). If this is duplicated effort I apologize for blatting it to the list,
but I couldn't find it elsewhere.

zach

ooooooooooooooooooooooooooooooooooooooooooooooooooooooo

diff -urN net-tools-1.32-alpha-dist/lib/inet_gr.c net-tools-1.32-alpha/lib/inet_gr.c
--- net-tools-1.32-alpha-dist/lib/inet_gr.c	Fri Apr 26 02:58:45 1996
+++ net-tools-1.32-alpha/lib/inet_gr.c	Tue Aug 20 15:11:09 1996
@@ -135,6 +135,12 @@

 int rprint_cache(int ext, int numeric)
 {
+  char buff[4096], iface[16], flags[16];
+  char gate_addr[128], net_addr[128];
+  char mask_addr[128];
+  struct sockaddr snet, sgate, smask;
+  int num, iflags, metric, refcnt, use, mss, window, irtt, hh, arp;
+
   FILE *fp=fopen(_PATH_PROCNET_RTCACHE, "r");

   if (!fp) {
@@ -143,8 +149,97 @@
   }

   printf(NLS_CATGETS(catfd, inetSet, inet_cache, "Kernel IP routing cache\n"));
-  fprintf(stderr,"INET CACHE: This needs to be written!\n");
-
+
+  if (ext == 1)
+	printf(NLS_CATGETS(catfd, inetSet, inet_header1,
+		"Destination     Gateway         Genmask         "
+		"Flags Metric Ref    Use Iface\n"));
+  if (ext == 2)
+	printf(NLS_CATGETS(catfd, inetSet, inet_header2,
+		"Destination     Gateway         Genmask         "
+		"Flags   MSS Window  irtt Iface\n"));
+  if (ext >= 3)
+	printf(NLS_CATGETS(catfd, inetSet, inet_header3,
+		"Destination     Gateway         Genmask         "
+		"Flags Metric Ref    Use Iface    "
+		"MSS   Window irtt   HH  Arp\n"));
+
+  irtt=0;
+  window=0;
+  mss=0;
+  hh=0;
+  arp=0;
+  while (fgets(buff, 1023, fp))
+  {
+	num = sscanf(buff, "%s %s %s %X %d %d %d %s %d %d %d %d %d\n",
+		iface, net_addr, gate_addr,
+		&iflags, &refcnt, &use, &metric, mask_addr,
+ 		&mss,&window,&irtt,&hh,&arp);
+	if (num < 12) continue;
+
+	/* Fetch and resolve the target address. */
+	(void)inet_aftype.input(1, net_addr, &snet);
+	strcpy(net_addr, inet_aftype.sprint(&snet, (numeric | 0x8000)));
+	net_addr[15] = '\0';
+
+	/* Fetch and resolve the gateway address. */
+	(void)inet_aftype.input(1, gate_addr, &sgate);
+	strcpy(gate_addr, inet_aftype.sprint(&sgate, numeric));
+	gate_addr[15] = '\0';
+
+	/* Fetch and resolve the genmask. */
+	(void)inet_aftype.input(1, mask_addr, &smask);
+	strcpy(mask_addr, inet_aftype.sprint(&smask, 1));
+	mask_addr[15] = '\0';
+
+	/* Decode the flags. */
+	flags[0] = '\0';
+	if (iflags & RTF_UP) strcat(flags, "U");
+	if (iflags & RTF_GATEWAY) strcat(flags, "G");
+#if HAVE_RTF_REJECT
+	if (iflags & RTF_REJECT) strcpy(flags,"!");
+#endif
+	if (iflags & RTF_HOST) strcat(flags, "H");
+	if (iflags & RTF_REINSTATE) strcat(flags, "R");
+	if (iflags & RTF_DYNAMIC) strcat(flags, "D");
+	if (iflags & RTF_MODIFIED) strcat(flags, "M");
+	/* Print the info. */
+	if (ext == 1) {
+#if HAVE_RTF_REJECT
+		if (iflags & RTF_REJECT)
+			printf("%-15s -               %-15s %-5s %-6d -  %7d -\n",
+				net_addr,  mask_addr, flags, metric, use);
+		else
+#endif
+			printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n",
+			net_addr, gate_addr, mask_addr, flags,
+			metric, refcnt, use, iface);
+	}
+	if (ext == 2) {
+#if HAVE_RTF_REJECT
+		if (iflags & RTF_REJECT)
+			printf("%-15s -               %-15s %-5s     - -          - -\n",
+				net_addr, mask_addr, flags);
+		else
+#endif
+			printf("%-15s %-15s %-15s %-5s %5d %-5d %6d %s\n",
+				net_addr, gate_addr, mask_addr, flags,
+				mss, window, irtt, iface);
+	}
+	if (ext >= 3) {
+#if HAVE_RTF_REJECT
+		if (iflags & RTF_REJECT)
+			printf("%-15s -               %-15s %-5s %-6d -  %7d -        -     -      -\n",
+				net_addr, mask_addr, flags, metric, use);
+		else
+#endif
+			printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s   %-5d %-6d %-6d %-3d %d\n",
+			net_addr, gate_addr, mask_addr, flags,
+			metric, refcnt, use, iface, mss, window, irtt, 	hh, arp);
+	}
+  }
+
+  (void)
   (void) fclose(fp);
   return(0);
 }
diff -urN net-tools-1.32-alpha-dist/man/en_US.88591/route.8 net-tools-1.32-alpha/man/en_US.88591/route.8
--- net-tools-1.32-alpha-dist/man/en_US.88591/route.8	Sat Jan 27 12:20:34 1996
+++ net-tools-1.32-alpha/man/en_US.88591/route.8	Tue Aug 20 15:11:32 1996
@@ -3,7 +3,7 @@
 route \- show / manipulate the IP routing table
 .SH SYNOPSIS
 .B route
-.RB [ \-vnee ]
+.RB [ \-CFvnee ]
 .TP
 .B route
 .RB [ \-v ]
@@ -93,8 +93,16 @@
 library function).

 .TP
-.B (none)
-displays the kernel routing table. The layout can be changed with
+.B (none) -F
+displays the FIB kernel routing table. The layout can be changed with
+.B \-e
+and
+.B \-ee
+.
+
+.TP
+.B -C
+displays the kernel\'s route cache table. The layout can be changed with
 .B \-e
 and
 .B \-ee
@@ -281,8 +289,8 @@
 Number of references to this route. Not used in the Linux kernel, always 0.
 .TP
 .B Use
-Count of lookups for the route. With recent kernels this numbers are very
-low, since the sockets have its own cache and dont need to lookup routes.
+Count of lookups for the route.  Depending on the use of -F and -C this will
+be either route cache misses (-F) or hits (-C).
 .TP
 .B Iface
 Interface to which the IP Packages will be send.
@@ -294,12 +302,22 @@
 Default windowsize for TCP Connections over this route.
 .TP
 .B irtt
-Innitial RTT (Round Trip Time). The kernels use this to guess about the best
+Initial RTT (Round Trip Time). The kernels use this to guess about the best
 TCP protocol parameters without waiting on (possible slow) answers.
+.TP
+.B HH (cached only)
+The number of ARP entires and cached routes that refer to the hardware header cache
+for the cached route. This will be \-1 if a hardware address is not needed for the
+interface of the cached route (e.g. lo).
+.TP
+.B Arp (cached only)
+Whether or not the hardware address for the cached route is up to date.
 .LP
 .SH FILES
 .I /proc/net/route
 .br
+.I /proc/net/rt_cache
+.br
 .I /etc/networks
 .br
 .I /etc/hosts
@@ -315,5 +333,6 @@
 <waltje@uwalt.nl.mugnet.org> and then modified by Johannes Stille and
 Linus Torvalds for pl15. Alan Cox added the mss and window options for
 Linux 1.1.22. irtt support and merged with netstat from Bernd Eckenfels.
+Route cache support added by Zach Brown.
 .SH BUGS
 none :)



home help back first fref pref prev next nref lref last post