diff options
author | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 1997-06-18 01:52:28 +0000 |
---|---|---|
committer | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 1997-06-18 01:52:28 +0000 |
commit | 96d7abcc7bc22ee4518a073bacde919794d6cc0c (patch) | |
tree | 6ae1893770af78cd2439cc83c1b22faa3e2a7b3e | |
parent | 5e3757242ef3957773ecbe5d17f0bf1ccf88ab86 (diff) |
Be a bit more verbose for AF_ENCAP "routing" entries.
-rw-r--r-- | usr.bin/netstat/main.c | 6 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 3 | ||||
-rw-r--r-- | usr.bin/netstat/route.c | 72 |
3 files changed, 70 insertions, 11 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index f95a5f320b3..555b1534802 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.9 1997/02/22 04:35:24 angelos Exp $ */ +/* $OpenBSD: main.c,v 1.10 1997/06/18 01:52:27 angelos Exp $ */ /* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* @@ -44,7 +44,7 @@ char copyright[] = #if 0 static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94"; #else -static char *rcsid = "$OpenBSD: main.c,v 1.9 1997/02/22 04:35:24 angelos Exp $"; +static char *rcsid = "$OpenBSD: main.c,v 1.10 1997/06/18 01:52:27 angelos Exp $"; #endif #endif /* not lint */ @@ -262,6 +262,8 @@ main(argc, argv) af = AF_NS; else if (strcmp(optarg, "iso") == 0) af = AF_ISO; + else if (strcmp(optarg, "encap") == 0) + af = AF_ENCAP; else { (void)fprintf(stderr, "%s: %s: unknown address family\n", diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index 3feb7ac98d3..af0160f5f67 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.h,v 1.5 1997/02/21 09:09:53 angelos Exp $ */ +/* $OpenBSD: netstat.h,v 1.6 1997/06/18 01:52:27 angelos Exp $ */ /* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* @@ -82,6 +82,7 @@ void impstats __P((u_long, u_long)); void intpr __P((int, u_long)); void pr_rthdr __P(()); +void pr_encaphdr __P(()); void pr_family __P((int)); void rt_stats __P((u_long)); char *ns_phost __P((struct sockaddr *)); diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 5a0438156e4..31c117e97ee 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.8 1997/01/25 23:26:42 tholo Exp $ */ +/* $OpenBSD: route.c,v 1.9 1997/06/18 01:52:27 angelos Exp $ */ /* $NetBSD: route.c,v 1.15 1996/05/07 02:55:06 thorpej Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94"; #else -static char *rcsid = "$OpenBSD: route.c,v 1.8 1997/01/25 23:26:42 tholo Exp $"; +static char *rcsid = "$OpenBSD: route.c,v 1.9 1997/06/18 01:52:27 angelos Exp $"; #endif #endif /* not lint */ @@ -66,6 +66,12 @@ static char *rcsid = "$OpenBSD: route.c,v 1.8 1997/01/25 23:26:42 tholo Exp $"; #include <stdlib.h> #include <string.h> #include <unistd.h> + +#ifndef INET +#define INET +#endif + +#include <net/encap.h> #include "netstat.h" #define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d))) @@ -114,6 +120,7 @@ static void np_rtentry __P((struct rt_msghdr *)); static void p_sockaddr __P((struct sockaddr *, int, int)); static void p_flags __P((int, char *)); static void p_rtentry __P((struct rtentry *)); +static void encap_print __P((struct rtentry *)); /* * Print routing tables. @@ -148,7 +155,10 @@ routepr(rtree) } else if (af == AF_UNSPEC || af == i) { pr_family(i); do_rtent = 1; - pr_rthdr(); + if (i != AF_ENCAP) + pr_rthdr(); + else + pr_encaphdr(); p_tree(head.rnh_treetop); } } @@ -180,6 +190,9 @@ pr_family(af) case AF_CCITT: afname = "X.25"; break; + case AF_ENCAP: + afname = "Encap"; + break; default: afname = NULL; break; @@ -209,6 +222,20 @@ pr_rthdr() "Flags", "Refs", "Use", "Mtu", "Interface"); } +/* + * Print header for AF_ENCAP entries. + */ +void +pr_encaphdr() +{ + if (Aflag) + printf("%-8s ", "Address"); + printf("%-15s %-15s %-5s %-15s %-15s %-5s %-5s %-15s %-15s %-8s %-9s %s\n", + "Source address", "Source mask", "Port", "Dest. address", + "Dest. mask", "Port", "Proto", "Tunnel entry", "Tunnel exit", + "SPI", "Interface", "Use"); +} + static struct sockaddr * kgetsa(dst) register struct sockaddr *dst; @@ -347,9 +374,9 @@ np_rtentry(rtm) if (rtm->rtm_addrs == RTA_DST) p_sockaddr(sa, 0, 36); else { - p_sockaddr(sa, rtm->rtm_flags, 16); + p_sockaddr(sa, rtm->rtm_flags, 16); if (sa->sa_len == 0) - sa->sa_len = sizeof(long); + sa->sa_len = sizeof(long); sa = (struct sockaddr *)(sa->sa_len + (char *)sa); p_sockaddr(sa, 0, 18); } @@ -384,7 +411,7 @@ p_sockaddr(sa, flags, width) case AF_IPX: cp = ipx_print(sa); break; - + case AF_LINK: { register struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa; @@ -464,8 +491,17 @@ p_rtentry(rt) register struct rtentry *rt; { static struct ifnet ifnet, *lastif; - - p_sockaddr(kgetsa(rt_key(rt)), rt->rt_flags, WID_DST); + struct sockaddr *sa; + + sa = kgetsa(rt_key(rt)); + + if (sa->sa_family == AF_ENCAP) + { + encap_print(rt); + return; + } + + p_sockaddr(sa, rt->rt_flags, WID_DST); p_sockaddr(kgetsa(rt->rt_gateway), RTF_HOST, WID_GW); p_flags(rt->rt_flags, "%-6.6s "); printf("%6d %8d ", rt->rt_refcnt, rt->rt_use); @@ -746,6 +782,26 @@ ipx_phost(sa) return(p); } +static void +encap_print(rt) + register struct rtentry *rt; +{ + struct sockaddr_encap sen1, sen2, sen3; + + bcopy(kgetsa(rt_key(rt)), &sen1, sizeof(sen1)); + bcopy(kgetsa(rt_mask(rt)), &sen2, sizeof(sen2)); + bcopy(kgetsa(rt->rt_gateway), &sen3, sizeof(sen3)); + + printf("%-15s ", inet_ntoa(sen1.sen_ip_src)); + printf("%-15s %-5u ", inet_ntoa(sen2.sen_ip_src), sen1.sen_sport); + printf("%-15s ", inet_ntoa(sen1.sen_ip_dst)); + printf("%-15s %-5u %-5u ", inet_ntoa(sen2.sen_ip_dst), + sen1.sen_dport, sen1.sen_proto); + printf("%-15s ", inet_ntoa(sen3.sen_ipsp_src)); + printf("%-15s %08x enc%-6u %-u\n", inet_ntoa(sen3.sen_ipsp_dst), + ntohl(sen3.sen_ipsp_spi), sen3.sen_ipsp_ifn, rt->rt_use); +} + void upHex(p0) char *p0; |