xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_rip6.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1991-1999 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS */
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <ctype.h>
30*0Sstevel@tonic-gate #include <fcntl.h>
31*0Sstevel@tonic-gate #include <sys/socket.h>
32*0Sstevel@tonic-gate #include <sys/types.h>
33*0Sstevel@tonic-gate #include <net/if.h>
34*0Sstevel@tonic-gate #include <netinet/in_systm.h>
35*0Sstevel@tonic-gate #include <netinet/in.h>
36*0Sstevel@tonic-gate #include <netinet/ip.h>
37*0Sstevel@tonic-gate #include <inet/led.h>
38*0Sstevel@tonic-gate #include <inet/ip6.h>
39*0Sstevel@tonic-gate #include <arpa/inet.h>
40*0Sstevel@tonic-gate #include <protocols/routed.h>
41*0Sstevel@tonic-gate #include <protocols/ripngd.h>
42*0Sstevel@tonic-gate #include "snoop.h"
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate extern char *dlc_header;
45*0Sstevel@tonic-gate static char *show_cmd6();
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate static struct in6_addr all_zeroes_addr = { {	0x0, 0x0, 0x0, 0x0,
48*0Sstevel@tonic-gate 						0x0, 0x0, 0x0, 0x0,
49*0Sstevel@tonic-gate 						0x0, 0x0, 0x0, 0x0,
50*0Sstevel@tonic-gate 						0x0, 0x0, 0x0, 0x0 } };
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate interpret_rip6(flags, rip6, fraglen)
53*0Sstevel@tonic-gate 	int flags;
54*0Sstevel@tonic-gate 	struct rip6 *rip6;
55*0Sstevel@tonic-gate 	int fraglen;
56*0Sstevel@tonic-gate {
57*0Sstevel@tonic-gate 	char *p;
58*0Sstevel@tonic-gate 	struct netinfo6 *n;
59*0Sstevel@tonic-gate 	int len, count;
60*0Sstevel@tonic-gate 	struct in6_addr *dst;
61*0Sstevel@tonic-gate 	int notdefault = 0;
62*0Sstevel@tonic-gate 	char dststr[INET6_ADDRSTRLEN];
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate 	if (flags & F_SUM) {
65*0Sstevel@tonic-gate 		switch (rip6->rip6_cmd) {
66*0Sstevel@tonic-gate 		case RIPCMD6_REQUEST:	p = "C";		break;
67*0Sstevel@tonic-gate 		case RIPCMD6_RESPONSE:	p = "R";		break;
68*0Sstevel@tonic-gate 		default: p = "?"; break;
69*0Sstevel@tonic-gate 		}
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate 		switch (rip6->rip6_cmd) {
72*0Sstevel@tonic-gate 		case RIPCMD6_REQUEST:
73*0Sstevel@tonic-gate 		case RIPCMD6_RESPONSE:
74*0Sstevel@tonic-gate 			len = fraglen - 4;
75*0Sstevel@tonic-gate 			count = 0;
76*0Sstevel@tonic-gate 			for (n = rip6->rip6_nets;
77*0Sstevel@tonic-gate 			    len >= sizeof (struct netinfo6); n++) {
78*0Sstevel@tonic-gate 				count++;
79*0Sstevel@tonic-gate 				len -= sizeof (struct netinfo6);
80*0Sstevel@tonic-gate 			}
81*0Sstevel@tonic-gate 			(void) sprintf(get_sum_line(),
82*0Sstevel@tonic-gate 			    "RIPng %s (%d destinations)", p, count);
83*0Sstevel@tonic-gate 			break;
84*0Sstevel@tonic-gate 		default:
85*0Sstevel@tonic-gate 			(void) sprintf(get_sum_line(), "RIPng %s", p);
86*0Sstevel@tonic-gate 			break;
87*0Sstevel@tonic-gate 		}
88*0Sstevel@tonic-gate 	}
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	if (flags & F_DTAIL) {
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate 		show_header("RIPng:  ", "Routing Information Protocol for IPv6",
93*0Sstevel@tonic-gate 		    fraglen);
94*0Sstevel@tonic-gate 		show_space();
95*0Sstevel@tonic-gate 		(void) sprintf(get_line((char *)rip6->rip6_cmd - dlc_header, 1),
96*0Sstevel@tonic-gate 		    "Opcode = %d (%s)",
97*0Sstevel@tonic-gate 		    rip6->rip6_cmd,
98*0Sstevel@tonic-gate 		    show_cmd6(rip6->rip6_cmd));
99*0Sstevel@tonic-gate 		(void) sprintf(get_line((char *)rip6->rip6_vers -
100*0Sstevel@tonic-gate 		    dlc_header, 1), "Version = %d",
101*0Sstevel@tonic-gate 		    rip6->rip6_vers);
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate 		switch (rip6->rip6_cmd) {
104*0Sstevel@tonic-gate 		case RIPCMD6_REQUEST:
105*0Sstevel@tonic-gate 		case RIPCMD6_RESPONSE:
106*0Sstevel@tonic-gate 			show_space();
107*0Sstevel@tonic-gate 			(void) sprintf(get_line(0, 0), "Address"
108*0Sstevel@tonic-gate 			    "                       Prefix        Metric");
109*0Sstevel@tonic-gate 			len = fraglen - 4;
110*0Sstevel@tonic-gate 			for (n = rip6->rip6_nets;
111*0Sstevel@tonic-gate 			    len >= sizeof (struct netinfo6); n++) {
112*0Sstevel@tonic-gate 				if (rip6->rip6_vers > 0) {
113*0Sstevel@tonic-gate 					n->rip6_metric = n->rip6_metric;
114*0Sstevel@tonic-gate 				}
115*0Sstevel@tonic-gate 				dst = &n->rip6_prefix;
116*0Sstevel@tonic-gate 				notdefault = bcmp((caddr_t *)dst,
117*0Sstevel@tonic-gate 				    (caddr_t *)&all_zeroes_addr, sizeof (*dst));
118*0Sstevel@tonic-gate 				(void) inet_ntop(AF_INET6, (char *)dst, dststr,
119*0Sstevel@tonic-gate 				    INET6_ADDRSTRLEN);
120*0Sstevel@tonic-gate 				(void) sprintf(get_line((char *)n - dlc_header,
121*0Sstevel@tonic-gate 				    sizeof (struct netinfo6)),
122*0Sstevel@tonic-gate 				    "%-30s %-10d     %-5d %s",
123*0Sstevel@tonic-gate 				    notdefault ? dststr :
124*0Sstevel@tonic-gate 				    " (default)", n->rip6_prefix_length,
125*0Sstevel@tonic-gate 				    n->rip6_metric, n->rip6_metric == 16 ?
126*0Sstevel@tonic-gate 				    " (not reachable)":"");
127*0Sstevel@tonic-gate 				len -= sizeof (struct netinfo);
128*0Sstevel@tonic-gate 			}
129*0Sstevel@tonic-gate 			break;
130*0Sstevel@tonic-gate 		}
131*0Sstevel@tonic-gate 	}
132*0Sstevel@tonic-gate 	return (fraglen);
133*0Sstevel@tonic-gate }
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate static char *
136*0Sstevel@tonic-gate show_cmd6(c)
137*0Sstevel@tonic-gate 	int c;
138*0Sstevel@tonic-gate {
139*0Sstevel@tonic-gate 	switch (c) {
140*0Sstevel@tonic-gate 	case RIPCMD6_REQUEST:	return ("route request");
141*0Sstevel@tonic-gate 	case RIPCMD6_RESPONSE:	return ("route response");
142*0Sstevel@tonic-gate 	}
143*0Sstevel@tonic-gate 	return ("?");
144*0Sstevel@tonic-gate }
145