xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_rip6.c (revision 410:51e39f6c6311)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*410Skcpoon  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*410Skcpoon  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <ctype.h>
300Sstevel@tonic-gate #include <fcntl.h>
310Sstevel@tonic-gate #include <sys/socket.h>
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <net/if.h>
340Sstevel@tonic-gate #include <netinet/in_systm.h>
350Sstevel@tonic-gate #include <netinet/in.h>
360Sstevel@tonic-gate #include <netinet/ip.h>
370Sstevel@tonic-gate #include <inet/led.h>
380Sstevel@tonic-gate #include <inet/ip6.h>
390Sstevel@tonic-gate #include <arpa/inet.h>
400Sstevel@tonic-gate #include <protocols/routed.h>
410Sstevel@tonic-gate #include <protocols/ripngd.h>
420Sstevel@tonic-gate #include "snoop.h"
430Sstevel@tonic-gate 
440Sstevel@tonic-gate extern char *dlc_header;
450Sstevel@tonic-gate static char *show_cmd6();
460Sstevel@tonic-gate 
470Sstevel@tonic-gate static struct in6_addr all_zeroes_addr = { {	0x0, 0x0, 0x0, 0x0,
480Sstevel@tonic-gate 						0x0, 0x0, 0x0, 0x0,
490Sstevel@tonic-gate 						0x0, 0x0, 0x0, 0x0,
500Sstevel@tonic-gate 						0x0, 0x0, 0x0, 0x0 } };
510Sstevel@tonic-gate 
52*410Skcpoon int
interpret_rip6(int flags,struct rip6 * rip6,int fraglen)53*410Skcpoon interpret_rip6(int flags, struct rip6 *rip6, int fraglen)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate 	char *p;
560Sstevel@tonic-gate 	struct netinfo6 *n;
570Sstevel@tonic-gate 	int len, count;
580Sstevel@tonic-gate 	struct in6_addr *dst;
590Sstevel@tonic-gate 	int notdefault = 0;
600Sstevel@tonic-gate 	char dststr[INET6_ADDRSTRLEN];
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	if (flags & F_SUM) {
630Sstevel@tonic-gate 		switch (rip6->rip6_cmd) {
640Sstevel@tonic-gate 		case RIPCMD6_REQUEST:	p = "C";		break;
650Sstevel@tonic-gate 		case RIPCMD6_RESPONSE:	p = "R";		break;
660Sstevel@tonic-gate 		default: p = "?"; break;
670Sstevel@tonic-gate 		}
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 		switch (rip6->rip6_cmd) {
700Sstevel@tonic-gate 		case RIPCMD6_REQUEST:
710Sstevel@tonic-gate 		case RIPCMD6_RESPONSE:
720Sstevel@tonic-gate 			len = fraglen - 4;
730Sstevel@tonic-gate 			count = 0;
740Sstevel@tonic-gate 			for (n = rip6->rip6_nets;
750Sstevel@tonic-gate 			    len >= sizeof (struct netinfo6); n++) {
760Sstevel@tonic-gate 				count++;
770Sstevel@tonic-gate 				len -= sizeof (struct netinfo6);
780Sstevel@tonic-gate 			}
790Sstevel@tonic-gate 			(void) sprintf(get_sum_line(),
800Sstevel@tonic-gate 			    "RIPng %s (%d destinations)", p, count);
810Sstevel@tonic-gate 			break;
820Sstevel@tonic-gate 		default:
830Sstevel@tonic-gate 			(void) sprintf(get_sum_line(), "RIPng %s", p);
840Sstevel@tonic-gate 			break;
850Sstevel@tonic-gate 		}
860Sstevel@tonic-gate 	}
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	if (flags & F_DTAIL) {
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 		show_header("RIPng:  ", "Routing Information Protocol for IPv6",
910Sstevel@tonic-gate 		    fraglen);
920Sstevel@tonic-gate 		show_space();
93*410Skcpoon 		(void) sprintf(get_line((char *)(uintptr_t)rip6->rip6_cmd -
94*410Skcpoon 		    dlc_header, 1), "Opcode = %d (%s)", rip6->rip6_cmd,
950Sstevel@tonic-gate 		    show_cmd6(rip6->rip6_cmd));
96*410Skcpoon 		(void) sprintf(get_line((char *)(uintptr_t)rip6->rip6_vers -
97*410Skcpoon 		    dlc_header, 1), "Version = %d", rip6->rip6_vers);
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 		switch (rip6->rip6_cmd) {
1000Sstevel@tonic-gate 		case RIPCMD6_REQUEST:
1010Sstevel@tonic-gate 		case RIPCMD6_RESPONSE:
1020Sstevel@tonic-gate 			show_space();
1030Sstevel@tonic-gate 			(void) sprintf(get_line(0, 0), "Address"
1040Sstevel@tonic-gate 			    "                       Prefix        Metric");
1050Sstevel@tonic-gate 			len = fraglen - 4;
1060Sstevel@tonic-gate 			for (n = rip6->rip6_nets;
1070Sstevel@tonic-gate 			    len >= sizeof (struct netinfo6); n++) {
1080Sstevel@tonic-gate 				if (rip6->rip6_vers > 0) {
1090Sstevel@tonic-gate 					n->rip6_metric = n->rip6_metric;
1100Sstevel@tonic-gate 				}
1110Sstevel@tonic-gate 				dst = &n->rip6_prefix;
1120Sstevel@tonic-gate 				notdefault = bcmp((caddr_t *)dst,
1130Sstevel@tonic-gate 				    (caddr_t *)&all_zeroes_addr, sizeof (*dst));
1140Sstevel@tonic-gate 				(void) inet_ntop(AF_INET6, (char *)dst, dststr,
1150Sstevel@tonic-gate 				    INET6_ADDRSTRLEN);
1160Sstevel@tonic-gate 				(void) sprintf(get_line((char *)n - dlc_header,
1170Sstevel@tonic-gate 				    sizeof (struct netinfo6)),
1180Sstevel@tonic-gate 				    "%-30s %-10d     %-5d %s",
1190Sstevel@tonic-gate 				    notdefault ? dststr :
1200Sstevel@tonic-gate 				    " (default)", n->rip6_prefix_length,
1210Sstevel@tonic-gate 				    n->rip6_metric, n->rip6_metric == 16 ?
1220Sstevel@tonic-gate 				    " (not reachable)":"");
1230Sstevel@tonic-gate 				len -= sizeof (struct netinfo);
1240Sstevel@tonic-gate 			}
1250Sstevel@tonic-gate 			break;
1260Sstevel@tonic-gate 		}
1270Sstevel@tonic-gate 	}
1280Sstevel@tonic-gate 	return (fraglen);
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate static char *
show_cmd6(c)1320Sstevel@tonic-gate show_cmd6(c)
1330Sstevel@tonic-gate 	int c;
1340Sstevel@tonic-gate {
1350Sstevel@tonic-gate 	switch (c) {
1360Sstevel@tonic-gate 	case RIPCMD6_REQUEST:	return ("route request");
1370Sstevel@tonic-gate 	case RIPCMD6_RESPONSE:	return ("route response");
1380Sstevel@tonic-gate 	}
1390Sstevel@tonic-gate 	return ("?");
1400Sstevel@tonic-gate }
141