xref: /titanic_44/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_ospf6.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include <ctype.h>
31*7c478bd9Sstevel@tonic-gate #include <string.h>
32*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
33*7c478bd9Sstevel@tonic-gate #include <string.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/socket.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/sockio.h>
38*7c478bd9Sstevel@tonic-gate #include <net/if.h>
39*7c478bd9Sstevel@tonic-gate #include <netinet/in_systm.h>
40*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
41*7c478bd9Sstevel@tonic-gate #include <netinet/ip.h>
42*7c478bd9Sstevel@tonic-gate #include <netinet/if_ether.h>
43*7c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
44*7c478bd9Sstevel@tonic-gate #include "snoop.h"
45*7c478bd9Sstevel@tonic-gate #include "snoop_ospf.h"
46*7c478bd9Sstevel@tonic-gate #include "snoop_ospf6.h"
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate extern char *dlc_header;
49*7c478bd9Sstevel@tonic-gate static char *sum_line;
50*7c478bd9Sstevel@tonic-gate extern const struct bits ospf_db_flags_bits[];
51*7c478bd9Sstevel@tonic-gate extern const struct bits ospf_rla_flag_bits[];
52*7c478bd9Sstevel@tonic-gate extern const struct bits ospf_option_bits[];
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate const struct bits ospf6_option_bits[] = {
55*7c478bd9Sstevel@tonic-gate 	{ OSPF_OPTION_V6,	"V6" },
56*7c478bd9Sstevel@tonic-gate 	{ OSPF_OPTION_E,	"E" },
57*7c478bd9Sstevel@tonic-gate 	{ OSPF_OPTION_MC,	"MC" },
58*7c478bd9Sstevel@tonic-gate 	{ OSPF_OPTION_N,	"N" },
59*7c478bd9Sstevel@tonic-gate 	{ OSPF_OPTION_R,	"R" },
60*7c478bd9Sstevel@tonic-gate 	{ OSPF_OPTION_DC,	"DC" },
61*7c478bd9Sstevel@tonic-gate 	{ 0,			NULL }
62*7c478bd9Sstevel@tonic-gate };
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate /*
65*7c478bd9Sstevel@tonic-gate  * return a printable string in dotted-decimal notation
66*7c478bd9Sstevel@tonic-gate  * for id.
67*7c478bd9Sstevel@tonic-gate  */
68*7c478bd9Sstevel@tonic-gate static char *
print_ipaddr(uint32_t id)69*7c478bd9Sstevel@tonic-gate print_ipaddr(uint32_t id)
70*7c478bd9Sstevel@tonic-gate {
71*7c478bd9Sstevel@tonic-gate 	struct in_addr tmp;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 	tmp.s_addr = id;
74*7c478bd9Sstevel@tonic-gate 	return (inet_ntoa(tmp));
75*7c478bd9Sstevel@tonic-gate }
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate static int
interpret_ospf6_hello(int flags,struct ospf6hdr * op,int fraglen)78*7c478bd9Sstevel@tonic-gate interpret_ospf6_hello(int flags, struct ospf6hdr *op, int fraglen)
79*7c478bd9Sstevel@tonic-gate {
80*7c478bd9Sstevel@tonic-gate 	uint32_t *nbr;
81*7c478bd9Sstevel@tonic-gate 	int j;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	if (fraglen < OSPF6_MIN_HEADER_SIZE + OSPF_MIN_HELLO_HEADER_SIZE)
84*7c478bd9Sstevel@tonic-gate 		return (-1); /* truncated packet */
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	if (flags & F_SUM) {
87*7c478bd9Sstevel@tonic-gate 		if (op->ospf6_hello.hello_dr != 0) {
88*7c478bd9Sstevel@tonic-gate 			(void) sprintf(sum_line, "DR=%s ",
89*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(op->ospf6_hello.hello_dr));
90*7c478bd9Sstevel@tonic-gate 		}
91*7c478bd9Sstevel@tonic-gate 		sum_line += strlen(sum_line);
92*7c478bd9Sstevel@tonic-gate 		if (op->ospf6_hello.hello_bdr != 0) {
93*7c478bd9Sstevel@tonic-gate 			(void) sprintf(sum_line, "BDR=%s ",
94*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(op->ospf6_hello.hello_bdr));
95*7c478bd9Sstevel@tonic-gate 		}
96*7c478bd9Sstevel@tonic-gate 		sum_line += strlen(sum_line);
97*7c478bd9Sstevel@tonic-gate 		j = 0;
98*7c478bd9Sstevel@tonic-gate 		nbr = op->ospf6_hello.hello_neighbor;
99*7c478bd9Sstevel@tonic-gate 		while ((uchar_t *)nbr < ((uchar_t *)op + fraglen)) {
100*7c478bd9Sstevel@tonic-gate 			if ((uchar_t *)nbr + sizeof (struct in_addr) >
101*7c478bd9Sstevel@tonic-gate 			    ((uchar_t *)op + fraglen))
102*7c478bd9Sstevel@tonic-gate 				return (-1); /* truncated */
103*7c478bd9Sstevel@tonic-gate 			++nbr;
104*7c478bd9Sstevel@tonic-gate 			j++;
105*7c478bd9Sstevel@tonic-gate 		}
106*7c478bd9Sstevel@tonic-gate 		(void) sprintf(sum_line, "%d nbrs", j);
107*7c478bd9Sstevel@tonic-gate 		sum_line += strlen(sum_line);
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 	}
110*7c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
111*7c478bd9Sstevel@tonic-gate 		show_header("OSPF HELLO:  ", "Hello Packet",
112*7c478bd9Sstevel@tonic-gate 		    ntohs(op->ospf6_len));
113*7c478bd9Sstevel@tonic-gate 		show_space();
114*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
115*7c478bd9Sstevel@tonic-gate 		    "Options = %s", ospf_print_bits(ospf6_option_bits,
116*7c478bd9Sstevel@tonic-gate 		    op->ospf6_hello.hello6_options));
117*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
118*7c478bd9Sstevel@tonic-gate 		    "Interface ID = %s",
119*7c478bd9Sstevel@tonic-gate 		    print_ipaddr(op->ospf6_hello.hello_ifid));
120*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
121*7c478bd9Sstevel@tonic-gate 		    "Hello interval = %d",
122*7c478bd9Sstevel@tonic-gate 		    ntohs(op->ospf6_hello.hello_helloint));
123*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
124*7c478bd9Sstevel@tonic-gate 		    "Priority = %d", op->ospf6_hello.hello6_priority);
125*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
126*7c478bd9Sstevel@tonic-gate 		    "Dead interval = %u", ntohl(op->ospf6_hello.hello_deadint));
127*7c478bd9Sstevel@tonic-gate 		if (op->ospf6_hello.hello_dr != 0) {
128*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
129*7c478bd9Sstevel@tonic-gate 			    "Designated Router = %s",
130*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(op->ospf6_hello.hello_dr));
131*7c478bd9Sstevel@tonic-gate 		}
132*7c478bd9Sstevel@tonic-gate 		if (op->ospf6_hello.hello_bdr != 0) {
133*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
134*7c478bd9Sstevel@tonic-gate 			    "Backup Designated Router = %s",
135*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(op->ospf6_hello.hello_bdr));
136*7c478bd9Sstevel@tonic-gate 		}
137*7c478bd9Sstevel@tonic-gate 		nbr = op->ospf6_hello.hello_neighbor;
138*7c478bd9Sstevel@tonic-gate 		while ((uchar_t *)nbr < ((uchar_t *)op + fraglen)) {
139*7c478bd9Sstevel@tonic-gate 			if ((uchar_t *)nbr + sizeof (struct in_addr) >
140*7c478bd9Sstevel@tonic-gate 			    ((uchar_t *)op + fraglen))
141*7c478bd9Sstevel@tonic-gate 				return (-1); /* truncated */
142*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
143*7c478bd9Sstevel@tonic-gate 			    "Neigbor: %s", print_ipaddr(*nbr));
144*7c478bd9Sstevel@tonic-gate 			++nbr;
145*7c478bd9Sstevel@tonic-gate 		}
146*7c478bd9Sstevel@tonic-gate 	}
147*7c478bd9Sstevel@tonic-gate 	return (fraglen);
148*7c478bd9Sstevel@tonic-gate }
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate static void
ospf6_print_ls_type(int flags,uint_t ls6_type,uint32_t ls6_stateid,uint32_t ls6_router)151*7c478bd9Sstevel@tonic-gate ospf6_print_ls_type(int flags, uint_t ls6_type, uint32_t ls6_stateid,
152*7c478bd9Sstevel@tonic-gate     uint32_t ls6_router)
153*7c478bd9Sstevel@tonic-gate {
154*7c478bd9Sstevel@tonic-gate 	char scope[15];
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 	if (flags & F_SUM)
157*7c478bd9Sstevel@tonic-gate 		return;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 	switch (ls6_type & LS6_SCOPE_MASK) {
160*7c478bd9Sstevel@tonic-gate 	case LS6_SCOPE_LINKLOCAL:
161*7c478bd9Sstevel@tonic-gate 		snprintf(scope, sizeof (scope), "linklocal");
162*7c478bd9Sstevel@tonic-gate 		break;
163*7c478bd9Sstevel@tonic-gate 	case LS6_SCOPE_AREA:
164*7c478bd9Sstevel@tonic-gate 		snprintf(scope, sizeof (scope), "area");
165*7c478bd9Sstevel@tonic-gate 		break;
166*7c478bd9Sstevel@tonic-gate 	case LS6_SCOPE_AS:
167*7c478bd9Sstevel@tonic-gate 		snprintf(scope, sizeof (scope), "AS");
168*7c478bd9Sstevel@tonic-gate 		break;
169*7c478bd9Sstevel@tonic-gate 	default:
170*7c478bd9Sstevel@tonic-gate 		snprintf(scope, sizeof (scope), "");
171*7c478bd9Sstevel@tonic-gate 		break;
172*7c478bd9Sstevel@tonic-gate 	}
173*7c478bd9Sstevel@tonic-gate 	switch (ls6_type & LS_TYPE_MASK) {
174*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_ROUTER:
175*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
176*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
177*7c478bd9Sstevel@tonic-gate 			    "%s Router = %s", scope, print_ipaddr(ls6_router));
178*7c478bd9Sstevel@tonic-gate 		}
179*7c478bd9Sstevel@tonic-gate 		break;
180*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_NETWORK:
181*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
182*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
183*7c478bd9Sstevel@tonic-gate 			    "%s Net DR %s IF %s", scope,
184*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_router),
185*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_stateid));
186*7c478bd9Sstevel@tonic-gate 		}
187*7c478bd9Sstevel@tonic-gate 		break;
188*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_INTER_AP:
189*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
190*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
191*7c478bd9Sstevel@tonic-gate 			    "%s Inter-area-prefix = %s ABR %s", scope,
192*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_stateid),
193*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_router));
194*7c478bd9Sstevel@tonic-gate 		}
195*7c478bd9Sstevel@tonic-gate 		break;
196*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_INTER_AR:
197*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
198*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
199*7c478bd9Sstevel@tonic-gate 			    "%s Inter-area-router = %s Router %s", scope,
200*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_router),
201*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_stateid));
202*7c478bd9Sstevel@tonic-gate 		}
203*7c478bd9Sstevel@tonic-gate 		break;
204*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_ASE:
205*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
206*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
207*7c478bd9Sstevel@tonic-gate 			    "%s ASE = %s ASBR %s", scope,
208*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_stateid),
209*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_router));
210*7c478bd9Sstevel@tonic-gate 		}
211*7c478bd9Sstevel@tonic-gate 		break;
212*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_GROUP:
213*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
214*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
215*7c478bd9Sstevel@tonic-gate 			    "%s group = %s Router %s", scope,
216*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_stateid),
217*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_router));
218*7c478bd9Sstevel@tonic-gate 		}
219*7c478bd9Sstevel@tonic-gate 		break;
220*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_TYPE7:
221*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
222*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
223*7c478bd9Sstevel@tonic-gate 			    "%s Type 7 = %s Router %s", scope,
224*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_stateid),
225*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_router));
226*7c478bd9Sstevel@tonic-gate 		}
227*7c478bd9Sstevel@tonic-gate 		break;
228*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_LINK:
229*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
230*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
231*7c478bd9Sstevel@tonic-gate 			    "%s link = %s Router %s", scope,
232*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_stateid),
233*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_router));
234*7c478bd9Sstevel@tonic-gate 		}
235*7c478bd9Sstevel@tonic-gate 		break;
236*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_INTRA_AP:
237*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
238*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
239*7c478bd9Sstevel@tonic-gate 			    "%s Inter-area-prefix = %s Router %s", scope,
240*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_stateid),
241*7c478bd9Sstevel@tonic-gate 			    print_ipaddr(ls6_router));
242*7c478bd9Sstevel@tonic-gate 		}
243*7c478bd9Sstevel@tonic-gate 		break;
244*7c478bd9Sstevel@tonic-gate 	default:
245*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
246*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
247*7c478bd9Sstevel@tonic-gate 			    "%s Unknown type = 0x%x", ls6_type);
248*7c478bd9Sstevel@tonic-gate 		}
249*7c478bd9Sstevel@tonic-gate 		break;
250*7c478bd9Sstevel@tonic-gate 	}
251*7c478bd9Sstevel@tonic-gate }
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate static int
ospf6_print_lsaprefix(int flags,struct lsa6_prefix * lpfx)254*7c478bd9Sstevel@tonic-gate ospf6_print_lsaprefix(int flags, struct lsa6_prefix *lpfx)
255*7c478bd9Sstevel@tonic-gate {
256*7c478bd9Sstevel@tonic-gate 	int k;
257*7c478bd9Sstevel@tonic-gate 	struct in6_addr prefix;
258*7c478bd9Sstevel@tonic-gate 	char prefixstr[INET6_ADDRSTRLEN];
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate 	k = (lpfx->lsa6_plen + 31)/32;
261*7c478bd9Sstevel@tonic-gate 	if (k * 4 > sizeof (struct in6_addr)) {
262*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
263*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, "Unknown prefix len %d",
264*7c478bd9Sstevel@tonic-gate 			    lpfx->lsa6_plen);
265*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
266*7c478bd9Sstevel@tonic-gate 		}
267*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
268*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
269*7c478bd9Sstevel@tonic-gate 			    "Unknown prefix len %d", lpfx->lsa6_plen);
270*7c478bd9Sstevel@tonic-gate 		}
271*7c478bd9Sstevel@tonic-gate 	}
272*7c478bd9Sstevel@tonic-gate 	memset((void *)&prefix, 0, sizeof (prefix));
273*7c478bd9Sstevel@tonic-gate 	memcpy((void *)&prefix, lpfx->lsa6_pfx, k * 4);
274*7c478bd9Sstevel@tonic-gate 	(void) inet_ntop(AF_INET6, (char *)&prefix, prefixstr,
275*7c478bd9Sstevel@tonic-gate 	    INET6_ADDRSTRLEN);
276*7c478bd9Sstevel@tonic-gate 	if (flags & F_SUM) {
277*7c478bd9Sstevel@tonic-gate 		sprintf(sum_line, "%s/%d", prefixstr, lpfx->lsa6_plen);
278*7c478bd9Sstevel@tonic-gate 		sum_line += strlen(sum_line);
279*7c478bd9Sstevel@tonic-gate 	}
280*7c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
281*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
282*7c478bd9Sstevel@tonic-gate 		    "%s/%d", prefixstr, lpfx->lsa6_plen);
283*7c478bd9Sstevel@tonic-gate 	}
284*7c478bd9Sstevel@tonic-gate 	if (lpfx->lsa6_popt != 0) {
285*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
286*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, "(opt = %x)", lpfx->lsa6_popt);
287*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
288*7c478bd9Sstevel@tonic-gate 		}
289*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
290*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
291*7c478bd9Sstevel@tonic-gate 			    "(opt = %x)", lpfx->lsa6_popt);
292*7c478bd9Sstevel@tonic-gate 		}
293*7c478bd9Sstevel@tonic-gate 	}
294*7c478bd9Sstevel@tonic-gate 	return (sizeof (*lpfx) - 4 + k * 4);
295*7c478bd9Sstevel@tonic-gate }
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate static void
interpret_ospf6_lsa_hdr(int flags,struct lsa6_hdr * lsah)298*7c478bd9Sstevel@tonic-gate interpret_ospf6_lsa_hdr(int flags, struct lsa6_hdr *lsah)
299*7c478bd9Sstevel@tonic-gate {
300*7c478bd9Sstevel@tonic-gate 	if (flags & F_SUM)
301*7c478bd9Sstevel@tonic-gate 		return;
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
304*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
305*7c478bd9Sstevel@tonic-gate 		    "Sequence = %X ", ntohl(lsah->ls6_seq));
306*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
307*7c478bd9Sstevel@tonic-gate 		    "Age = %X ", ospf_print_lsa_age(ntohl(lsah->ls6_age)));
308*7c478bd9Sstevel@tonic-gate 	}
309*7c478bd9Sstevel@tonic-gate 
310*7c478bd9Sstevel@tonic-gate 	ospf6_print_ls_type(flags, lsah->ls6_type, lsah->ls6_stateid,
311*7c478bd9Sstevel@tonic-gate 	    lsah->ls6_router);
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate }
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate #define	TRUNC(addr)	((uchar_t *)(addr) > fragend)
316*7c478bd9Sstevel@tonic-gate static int
interpret_ospf6_lsa(int flags,struct lsa6 * lsa,uchar_t * fragend)317*7c478bd9Sstevel@tonic-gate interpret_ospf6_lsa(int flags, struct lsa6 *lsa, uchar_t *fragend)
318*7c478bd9Sstevel@tonic-gate {
319*7c478bd9Sstevel@tonic-gate 	uchar_t *ls_end;
320*7c478bd9Sstevel@tonic-gate 	int  k, j;
321*7c478bd9Sstevel@tonic-gate 	struct rla6link *rl;
322*7c478bd9Sstevel@tonic-gate 	uint32_t *addr;
323*7c478bd9Sstevel@tonic-gate 	struct lsa6_prefix *lpfx;
324*7c478bd9Sstevel@tonic-gate 	struct llsa *llsa;
325*7c478bd9Sstevel@tonic-gate 	char addrstr[INET6_ADDRSTRLEN];
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate 	interpret_ospf6_lsa_hdr(flags, &lsa->ls6_hdr);
328*7c478bd9Sstevel@tonic-gate 
329*7c478bd9Sstevel@tonic-gate 	ls_end = (uchar_t *)lsa + ntohs(lsa->ls6_hdr.ls6_length);
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 	if (TRUNC(ls_end))
332*7c478bd9Sstevel@tonic-gate 		return (-1);
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 	switch (ntohs(lsa->ls6_hdr.ls6_type)) {
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_ROUTER|LS6_SCOPE_AREA:
337*7c478bd9Sstevel@tonic-gate 		if (TRUNC(&lsa->lsa_un.un_rla.rla6_flags))
338*7c478bd9Sstevel@tonic-gate 			return (-1);
339*7c478bd9Sstevel@tonic-gate 
340*7c478bd9Sstevel@tonic-gate 		(void) ospf_print_bits(ospf_rla_flag_bits,
341*7c478bd9Sstevel@tonic-gate 		    lsa->lsa_un.un_rla.rla6_flags);
342*7c478bd9Sstevel@tonic-gate 
343*7c478bd9Sstevel@tonic-gate 		if (TRUNC(&lsa->lsa_un.un_rla.rla6_options))
344*7c478bd9Sstevel@tonic-gate 			return (-1);
345*7c478bd9Sstevel@tonic-gate 		(void) ospf_print_bits(ospf_option_bits,
346*7c478bd9Sstevel@tonic-gate 		    ntohl(lsa->lsa_un.un_rla.rla6_options));
347*7c478bd9Sstevel@tonic-gate 
348*7c478bd9Sstevel@tonic-gate 		rl = lsa->lsa_un.un_rla.rla_link;
349*7c478bd9Sstevel@tonic-gate 		if (TRUNC(rl))
350*7c478bd9Sstevel@tonic-gate 			return (-1);
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate 		while (rl + sizeof (*rl) <= (struct rla6link *)ls_end) {
353*7c478bd9Sstevel@tonic-gate 			if (TRUNC((uchar_t *)rl + sizeof (*rl)))
354*7c478bd9Sstevel@tonic-gate 				return (-1);
355*7c478bd9Sstevel@tonic-gate 			if (flags & F_SUM) {
356*7c478bd9Sstevel@tonic-gate 				sprintf(sum_line, "{");		/* } (ctags) */
357*7c478bd9Sstevel@tonic-gate 				sum_line += strlen(sum_line);
358*7c478bd9Sstevel@tonic-gate 			}
359*7c478bd9Sstevel@tonic-gate 			switch (rl->link_type) {
360*7c478bd9Sstevel@tonic-gate 			case RLA_TYPE_VIRTUAL:
361*7c478bd9Sstevel@tonic-gate 				if (flags & F_SUM) {
362*7c478bd9Sstevel@tonic-gate 					sprintf(sum_line, "virt ");
363*7c478bd9Sstevel@tonic-gate 					sum_line += strlen(sum_line);
364*7c478bd9Sstevel@tonic-gate 				}
365*7c478bd9Sstevel@tonic-gate 				if (flags & F_DTAIL) {
366*7c478bd9Sstevel@tonic-gate 					(void) snprintf(get_line(0, 0),
367*7c478bd9Sstevel@tonic-gate 					    get_line_remain(), "Virtual Link");
368*7c478bd9Sstevel@tonic-gate 				}
369*7c478bd9Sstevel@tonic-gate 				/* FALLTHROUGH */
370*7c478bd9Sstevel@tonic-gate 			case RLA_TYPE_ROUTER:
371*7c478bd9Sstevel@tonic-gate 				if (flags & F_SUM) {
372*7c478bd9Sstevel@tonic-gate 					sprintf(sum_line, "nbrid %s",
373*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_nrtid));
374*7c478bd9Sstevel@tonic-gate 					sum_line += strlen(sum_line);
375*7c478bd9Sstevel@tonic-gate 					sprintf(sum_line, " nbrif %s",
376*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_nifid));
377*7c478bd9Sstevel@tonic-gate 					sum_line += strlen(sum_line);
378*7c478bd9Sstevel@tonic-gate 					sprintf(sum_line, " if %s",
379*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_ifid));
380*7c478bd9Sstevel@tonic-gate 					sum_line += strlen(sum_line);
381*7c478bd9Sstevel@tonic-gate 				}
382*7c478bd9Sstevel@tonic-gate 				if (flags & F_DTAIL) {
383*7c478bd9Sstevel@tonic-gate 					(void) snprintf(get_line(0, 0),
384*7c478bd9Sstevel@tonic-gate 					    get_line_remain(), "Neighbor = %s",
385*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_nrtid));
386*7c478bd9Sstevel@tonic-gate 					(void) snprintf(get_line(0, 0),
387*7c478bd9Sstevel@tonic-gate 					    get_line_remain(),
388*7c478bd9Sstevel@tonic-gate 					    "Interface = %s id %s",
389*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_nifid),
390*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_ifid));
391*7c478bd9Sstevel@tonic-gate 				}
392*7c478bd9Sstevel@tonic-gate 				break;
393*7c478bd9Sstevel@tonic-gate 			case RLA_TYPE_TRANSIT:
394*7c478bd9Sstevel@tonic-gate 				if (flags & F_SUM) {
395*7c478bd9Sstevel@tonic-gate 					sprintf(sum_line, "dr %s",
396*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_nrtid));
397*7c478bd9Sstevel@tonic-gate 					sum_line += strlen(sum_line);
398*7c478bd9Sstevel@tonic-gate 					sprintf(sum_line, " drif %s",
399*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_nifid));
400*7c478bd9Sstevel@tonic-gate 					sum_line += strlen(sum_line);
401*7c478bd9Sstevel@tonic-gate 					sprintf(sum_line, " if %s",
402*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_ifid));
403*7c478bd9Sstevel@tonic-gate 					sum_line += strlen(sum_line);
404*7c478bd9Sstevel@tonic-gate 				}
405*7c478bd9Sstevel@tonic-gate 				if (flags & F_DTAIL) {
406*7c478bd9Sstevel@tonic-gate 					(void) snprintf(get_line(0, 0),
407*7c478bd9Sstevel@tonic-gate 					    get_line_remain(),
408*7c478bd9Sstevel@tonic-gate 					    "Designated Router = %s",
409*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_nrtid));
410*7c478bd9Sstevel@tonic-gate 					(void) snprintf(get_line(0, 0),
411*7c478bd9Sstevel@tonic-gate 					    get_line_remain(),
412*7c478bd9Sstevel@tonic-gate 					    "DR Interface = %s id %s",
413*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_nifid),
414*7c478bd9Sstevel@tonic-gate 					    print_ipaddr(rl->link_ifid));
415*7c478bd9Sstevel@tonic-gate 				}
416*7c478bd9Sstevel@tonic-gate 				break;
417*7c478bd9Sstevel@tonic-gate 			default:
418*7c478bd9Sstevel@tonic-gate 				if (flags & F_SUM) {
419*7c478bd9Sstevel@tonic-gate 					sprintf(sum_line,
420*7c478bd9Sstevel@tonic-gate 					    "Unknown link type %d",
421*7c478bd9Sstevel@tonic-gate 					    rl->link_type);
422*7c478bd9Sstevel@tonic-gate 					sum_line += strlen(sum_line);
423*7c478bd9Sstevel@tonic-gate 				}
424*7c478bd9Sstevel@tonic-gate 				if (flags & F_DTAIL) {
425*7c478bd9Sstevel@tonic-gate 					(void) snprintf(get_line(0, 0),
426*7c478bd9Sstevel@tonic-gate 					    get_line_remain(),
427*7c478bd9Sstevel@tonic-gate 					    "Unknown link type %d",
428*7c478bd9Sstevel@tonic-gate 					    rl->link_type);
429*7c478bd9Sstevel@tonic-gate 				}
430*7c478bd9Sstevel@tonic-gate 
431*7c478bd9Sstevel@tonic-gate 			}
432*7c478bd9Sstevel@tonic-gate 			if (flags & F_SUM) {
433*7c478bd9Sstevel@tonic-gate 				sprintf(sum_line, " metric %d",
434*7c478bd9Sstevel@tonic-gate 				    ntohs(rl->link_metric));
435*7c478bd9Sstevel@tonic-gate 				sum_line += strlen(sum_line);
436*7c478bd9Sstevel@tonic-gate 			}
437*7c478bd9Sstevel@tonic-gate 			if (flags & F_DTAIL) {
438*7c478bd9Sstevel@tonic-gate 				(void) snprintf(get_line(0, 0),
439*7c478bd9Sstevel@tonic-gate 				    get_line_remain(), " metric = %d",
440*7c478bd9Sstevel@tonic-gate 				    ntohs(rl->link_metric));
441*7c478bd9Sstevel@tonic-gate 			}
442*7c478bd9Sstevel@tonic-gate 			if (flags & F_SUM) { 			/* { (ctags) */
443*7c478bd9Sstevel@tonic-gate 				sprintf(sum_line,  " }");
444*7c478bd9Sstevel@tonic-gate 				sum_line += strlen(sum_line);
445*7c478bd9Sstevel@tonic-gate 			}
446*7c478bd9Sstevel@tonic-gate 			rl++;
447*7c478bd9Sstevel@tonic-gate 			if ((uchar_t *)rl > fragend)
448*7c478bd9Sstevel@tonic-gate 				return (-1); /* truncated */
449*7c478bd9Sstevel@tonic-gate 		}
450*7c478bd9Sstevel@tonic-gate 		break;
451*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_NETWORK | LS6_SCOPE_AREA:
452*7c478bd9Sstevel@tonic-gate 
453*7c478bd9Sstevel@tonic-gate 		if (TRUNC(&lsa->lsa_un.un_nla.nla_options))
454*7c478bd9Sstevel@tonic-gate 			return (-1);
455*7c478bd9Sstevel@tonic-gate 
456*7c478bd9Sstevel@tonic-gate 		(void) ospf_print_bits(ospf6_option_bits,
457*7c478bd9Sstevel@tonic-gate 		    ntohl(lsa->lsa_un.un_nla.nla_options));
458*7c478bd9Sstevel@tonic-gate 
459*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
460*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, " rtrs");
461*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
462*7c478bd9Sstevel@tonic-gate 		}
463*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
464*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
465*7c478bd9Sstevel@tonic-gate 			    "Routers:");
466*7c478bd9Sstevel@tonic-gate 		}
467*7c478bd9Sstevel@tonic-gate 		addr = lsa->lsa_un.un_nla.nla_router;
468*7c478bd9Sstevel@tonic-gate 		while ((uchar_t *)addr < ls_end) {
469*7c478bd9Sstevel@tonic-gate 			if ((uchar_t *)addr + sizeof (struct in_addr) > ls_end)
470*7c478bd9Sstevel@tonic-gate 				return (-1); /* truncated */
471*7c478bd9Sstevel@tonic-gate 			if (flags & F_SUM) {
472*7c478bd9Sstevel@tonic-gate 				sprintf(sum_line, " %s", print_ipaddr(*addr));
473*7c478bd9Sstevel@tonic-gate 				sum_line += strlen(sum_line);
474*7c478bd9Sstevel@tonic-gate 			}
475*7c478bd9Sstevel@tonic-gate 			if (flags & F_DTAIL) {
476*7c478bd9Sstevel@tonic-gate 				snprintf(get_line(0, 0), get_line_remain(),
477*7c478bd9Sstevel@tonic-gate 				    "\t%s", print_ipaddr(*addr));
478*7c478bd9Sstevel@tonic-gate 			}
479*7c478bd9Sstevel@tonic-gate 			++addr;
480*7c478bd9Sstevel@tonic-gate 		}
481*7c478bd9Sstevel@tonic-gate 		break;
482*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_INTER_AP | LS6_SCOPE_AREA:
483*7c478bd9Sstevel@tonic-gate 
484*7c478bd9Sstevel@tonic-gate 		if (TRUNC(&lsa->lsa_un.un_inter_ap.inter_ap_metric))
485*7c478bd9Sstevel@tonic-gate 			return (-1);
486*7c478bd9Sstevel@tonic-gate 
487*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
488*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, " metric %s",
489*7c478bd9Sstevel@tonic-gate 			    ntohl(lsa->lsa_un.un_inter_ap.inter_ap_metric) &
490*7c478bd9Sstevel@tonic-gate 			    SLA_MASK_METRIC);
491*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
492*7c478bd9Sstevel@tonic-gate 		}
493*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
494*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
495*7c478bd9Sstevel@tonic-gate 			    "Metric = %s",
496*7c478bd9Sstevel@tonic-gate 			    ntohl(lsa->lsa_un.un_inter_ap.inter_ap_metric) &
497*7c478bd9Sstevel@tonic-gate 			    SLA_MASK_METRIC);
498*7c478bd9Sstevel@tonic-gate 		}
499*7c478bd9Sstevel@tonic-gate 		lpfx = lsa->lsa_un.un_inter_ap.inter_ap_prefix;
500*7c478bd9Sstevel@tonic-gate 		if (lpfx > (struct lsa6_prefix *)ls_end)
501*7c478bd9Sstevel@tonic-gate 			return (-1);
502*7c478bd9Sstevel@tonic-gate 		while (lpfx + sizeof (*lpfx) <= (struct lsa6_prefix *)ls_end) {
503*7c478bd9Sstevel@tonic-gate 			k = ospf6_print_lsaprefix(flags, lpfx);
504*7c478bd9Sstevel@tonic-gate 			lpfx = (struct lsa6_prefix *)(((uchar_t *)lpfx) + k);
505*7c478bd9Sstevel@tonic-gate 			if (lpfx > (struct lsa6_prefix *)ls_end)
506*7c478bd9Sstevel@tonic-gate 				return (-1);
507*7c478bd9Sstevel@tonic-gate 		}
508*7c478bd9Sstevel@tonic-gate 		break;
509*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_LINK:
510*7c478bd9Sstevel@tonic-gate 		llsa = &lsa->lsa_un.un_llsa;
511*7c478bd9Sstevel@tonic-gate 		if (TRUNC(llsa->llsa_options))
512*7c478bd9Sstevel@tonic-gate 			return (-1);
513*7c478bd9Sstevel@tonic-gate 		ospf_print_bits(ospf6_option_bits, ntohl(llsa->llsa_options));
514*7c478bd9Sstevel@tonic-gate 		if (TRUNC(llsa->llsa_nprefix))
515*7c478bd9Sstevel@tonic-gate 			return (-1);
516*7c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, &llsa->llsa_lladdr,
517*7c478bd9Sstevel@tonic-gate 		    addrstr, INET6_ADDRSTRLEN);
518*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM)  {
519*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, " pri %d lladdr %s npref %d",
520*7c478bd9Sstevel@tonic-gate 			    ntohl(llsa->llsa_priority), addrstr,
521*7c478bd9Sstevel@tonic-gate 			    ntohl(llsa->llsa_nprefix));
522*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
523*7c478bd9Sstevel@tonic-gate 		}
524*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL)  {
525*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
526*7c478bd9Sstevel@tonic-gate 			    "Priority %d", ntohl(llsa->llsa_priority));
527*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
528*7c478bd9Sstevel@tonic-gate 			    "Link Local addr %d", addrstr);
529*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
530*7c478bd9Sstevel@tonic-gate 			    "npref %d", ntohl(llsa->llsa_nprefix));
531*7c478bd9Sstevel@tonic-gate 		}
532*7c478bd9Sstevel@tonic-gate 		lpfx = llsa->llsa_prefix;
533*7c478bd9Sstevel@tonic-gate 		for (j = 0; j < ntohl(llsa->llsa_nprefix); j++) {
534*7c478bd9Sstevel@tonic-gate 			if (TRUNC(lpfx))
535*7c478bd9Sstevel@tonic-gate 				return (-1);
536*7c478bd9Sstevel@tonic-gate 			k = ospf6_print_lsaprefix(flags, lpfx);
537*7c478bd9Sstevel@tonic-gate 			lpfx = (struct lsa6_prefix *)(((uchar_t *)lpfx) + k);
538*7c478bd9Sstevel@tonic-gate 		}
539*7c478bd9Sstevel@tonic-gate 		break;
540*7c478bd9Sstevel@tonic-gate 
541*7c478bd9Sstevel@tonic-gate 	case LS_TYPE_INTRA_AP | LS6_SCOPE_AREA:
542*7c478bd9Sstevel@tonic-gate 		if (TRUNC(&lsa->lsa_un.un_intra_ap.intra_ap_rtid))
543*7c478bd9Sstevel@tonic-gate 			return (-1);
544*7c478bd9Sstevel@tonic-gate 		ospf6_print_ls_type(flags,
545*7c478bd9Sstevel@tonic-gate 		    ntohs(lsa->lsa_un.un_intra_ap.intra_ap_lstype),
546*7c478bd9Sstevel@tonic-gate 		    lsa->lsa_un.un_intra_ap.intra_ap_lsid,
547*7c478bd9Sstevel@tonic-gate 		    lsa->lsa_un.un_intra_ap.intra_ap_rtid);
548*7c478bd9Sstevel@tonic-gate 		if (TRUNC(&lsa->lsa_un.un_intra_ap.intra_ap_nprefix))
549*7c478bd9Sstevel@tonic-gate 			return (-1);
550*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
551*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, " npref %d",
552*7c478bd9Sstevel@tonic-gate 			    ntohs(lsa->lsa_un.un_intra_ap.intra_ap_nprefix));
553*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
554*7c478bd9Sstevel@tonic-gate 		}
555*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
556*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(), "NPref %d",
557*7c478bd9Sstevel@tonic-gate 			    ntohs(lsa->lsa_un.un_intra_ap.intra_ap_nprefix));
558*7c478bd9Sstevel@tonic-gate 		}
559*7c478bd9Sstevel@tonic-gate 
560*7c478bd9Sstevel@tonic-gate 		lpfx = lsa->lsa_un.un_intra_ap.intra_ap_prefix;
561*7c478bd9Sstevel@tonic-gate 		for (j = 0;
562*7c478bd9Sstevel@tonic-gate 		    j < ntohs(lsa->lsa_un.un_intra_ap.intra_ap_nprefix); j++) {
563*7c478bd9Sstevel@tonic-gate 			if (TRUNC(lpfx))
564*7c478bd9Sstevel@tonic-gate 				return (-1);
565*7c478bd9Sstevel@tonic-gate 			k = ospf6_print_lsaprefix(flags, lpfx);
566*7c478bd9Sstevel@tonic-gate 			lpfx = (struct lsa6_prefix *)(((uchar_t *)lpfx) + k);
567*7c478bd9Sstevel@tonic-gate 		}
568*7c478bd9Sstevel@tonic-gate 		break;
569*7c478bd9Sstevel@tonic-gate 
570*7c478bd9Sstevel@tonic-gate 	default:
571*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM)  {
572*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, " Unknown LSA type (%d)",
573*7c478bd9Sstevel@tonic-gate 			    lsa->ls6_hdr.ls6_type);
574*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
575*7c478bd9Sstevel@tonic-gate 		}
576*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL)  {
577*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
578*7c478bd9Sstevel@tonic-gate 			    " Unknown LSA type %d", lsa->ls6_hdr.ls6_type);
579*7c478bd9Sstevel@tonic-gate 
580*7c478bd9Sstevel@tonic-gate 		}
581*7c478bd9Sstevel@tonic-gate 		break;
582*7c478bd9Sstevel@tonic-gate 	}
583*7c478bd9Sstevel@tonic-gate 	return (0);
584*7c478bd9Sstevel@tonic-gate }
585*7c478bd9Sstevel@tonic-gate #undef TRUNC
586*7c478bd9Sstevel@tonic-gate int
interpret_ospf6(int flags,struct ospf6hdr * ospf,int iplen,int fraglen)587*7c478bd9Sstevel@tonic-gate interpret_ospf6(int flags, struct ospf6hdr *ospf, int iplen, int fraglen)
588*7c478bd9Sstevel@tonic-gate {
589*7c478bd9Sstevel@tonic-gate 	boolean_t trunc = B_FALSE;
590*7c478bd9Sstevel@tonic-gate 	struct lsa6_hdr *lsah;
591*7c478bd9Sstevel@tonic-gate 	struct lsr6 *lsr;
592*7c478bd9Sstevel@tonic-gate 	struct lsa6 *lsa;
593*7c478bd9Sstevel@tonic-gate 	int nlsa, nlsah;
594*7c478bd9Sstevel@tonic-gate 
595*7c478bd9Sstevel@tonic-gate 	if ((fraglen < OSPF6_MIN_HEADER_SIZE) ||
596*7c478bd9Sstevel@tonic-gate 	    (fraglen < ntohs(ospf->ospf6_len)))
597*7c478bd9Sstevel@tonic-gate 		return (fraglen);	/* incomplete header */
598*7c478bd9Sstevel@tonic-gate 
599*7c478bd9Sstevel@tonic-gate 	if (ospf->ospf6_version != 3) {
600*7c478bd9Sstevel@tonic-gate 		if (ospf->ospf6_version == 2) {
601*7c478bd9Sstevel@tonic-gate 			if (flags & F_DTAIL)
602*7c478bd9Sstevel@tonic-gate 				snprintf(get_line(0, 0), get_line_remain(),
603*7c478bd9Sstevel@tonic-gate 				    "ospfv2 packet in ipv6 header");
604*7c478bd9Sstevel@tonic-gate 			return (interpret_ospf(flags, ospf, iplen, fraglen));
605*7c478bd9Sstevel@tonic-gate 		} else  {
606*7c478bd9Sstevel@tonic-gate 			return (fraglen);
607*7c478bd9Sstevel@tonic-gate 		}
608*7c478bd9Sstevel@tonic-gate 	}
609*7c478bd9Sstevel@tonic-gate 
610*7c478bd9Sstevel@tonic-gate 	if (fraglen > ntohs(ospf->ospf6_len))
611*7c478bd9Sstevel@tonic-gate 		fraglen = ntohs(ospf->ospf6_len);
612*7c478bd9Sstevel@tonic-gate 
613*7c478bd9Sstevel@tonic-gate 	if (ospf->ospf6_type > OSPF_TYPE_MAX) {
614*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
615*7c478bd9Sstevel@tonic-gate 			(void) sprintf(sum_line, "Unknown OSPF TYPE %d \n",
616*7c478bd9Sstevel@tonic-gate 			    ospf->ospf6_type);
617*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
618*7c478bd9Sstevel@tonic-gate 		}
619*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
620*7c478bd9Sstevel@tonic-gate 			show_header("OSPFv3:  ", "OSPFv3 Header", fraglen);
621*7c478bd9Sstevel@tonic-gate 			show_space();
622*7c478bd9Sstevel@tonic-gate 			(void) snprintf(get_line(0, 0), get_line_remain(),
623*7c478bd9Sstevel@tonic-gate 			    "Unknown OSPF Type = %d", ospf->ospf6_type);
624*7c478bd9Sstevel@tonic-gate 		}
625*7c478bd9Sstevel@tonic-gate 		return (fraglen);
626*7c478bd9Sstevel@tonic-gate 	}
627*7c478bd9Sstevel@tonic-gate 
628*7c478bd9Sstevel@tonic-gate 	if (flags & F_SUM) {
629*7c478bd9Sstevel@tonic-gate 		sum_line = (char *)get_sum_line();
630*7c478bd9Sstevel@tonic-gate 		(void) sprintf(sum_line, "OSPFv3 %s RTRID=%s ",
631*7c478bd9Sstevel@tonic-gate 		    ospf_types[ospf->ospf6_type],
632*7c478bd9Sstevel@tonic-gate 		    print_ipaddr(ospf->ospf6_routerid));
633*7c478bd9Sstevel@tonic-gate 		sum_line += strlen(sum_line);
634*7c478bd9Sstevel@tonic-gate 		(void) sprintf(sum_line, "AREA=%s LEN=%d instance %u ",
635*7c478bd9Sstevel@tonic-gate 		    print_ipaddr(ospf->ospf6_areaid),
636*7c478bd9Sstevel@tonic-gate 		    ntohs((ushort_t)ospf->ospf6_len), ospf->ospf6_instanceid);
637*7c478bd9Sstevel@tonic-gate 		sum_line += strlen(sum_line);
638*7c478bd9Sstevel@tonic-gate 	}
639*7c478bd9Sstevel@tonic-gate 
640*7c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
641*7c478bd9Sstevel@tonic-gate 		show_header("OSPFv3:  ", "OSPF Header", fraglen);
642*7c478bd9Sstevel@tonic-gate 		show_space();
643*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
644*7c478bd9Sstevel@tonic-gate 		    "Version = %d", ospf->ospf6_version);
645*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
646*7c478bd9Sstevel@tonic-gate 		    "Type = %s", ospf_types[ospf->ospf6_type]);
647*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
648*7c478bd9Sstevel@tonic-gate 		    "Router ID = %s", print_ipaddr(ospf->ospf6_routerid));
649*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
650*7c478bd9Sstevel@tonic-gate 		    "Area ID = %s", print_ipaddr(ospf->ospf6_areaid));
651*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
652*7c478bd9Sstevel@tonic-gate 		    "Checksum = 0x%x", ospf->ospf6_chksum);
653*7c478bd9Sstevel@tonic-gate 		(void) snprintf(get_line(0, 0), get_line_remain(),
654*7c478bd9Sstevel@tonic-gate 		    "Instance = %u", ospf->ospf6_instanceid);
655*7c478bd9Sstevel@tonic-gate 	}
656*7c478bd9Sstevel@tonic-gate 
657*7c478bd9Sstevel@tonic-gate 	switch (ospf->ospf6_type) {
658*7c478bd9Sstevel@tonic-gate 	case OSPF_TYPE_HELLO:
659*7c478bd9Sstevel@tonic-gate 		if (interpret_ospf6_hello(flags, ospf, fraglen) < 0)
660*7c478bd9Sstevel@tonic-gate 			trunc = B_TRUE;
661*7c478bd9Sstevel@tonic-gate 		break;
662*7c478bd9Sstevel@tonic-gate 
663*7c478bd9Sstevel@tonic-gate 	case OSPF_TYPE_DB:
664*7c478bd9Sstevel@tonic-gate 		if (fraglen < OSPF6_MIN_HEADER_SIZE +
665*7c478bd9Sstevel@tonic-gate 		    OSPF6_MIN_DB_HEADER_SIZE) {
666*7c478bd9Sstevel@tonic-gate 			trunc = B_TRUE;
667*7c478bd9Sstevel@tonic-gate 			break;
668*7c478bd9Sstevel@tonic-gate 		}
669*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
670*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, " %s %s mtu %u S %X", ospf_print_bits(
671*7c478bd9Sstevel@tonic-gate 			    ospf6_option_bits,
672*7c478bd9Sstevel@tonic-gate 			    ntohl(ospf->ospf6_db.db_options)),
673*7c478bd9Sstevel@tonic-gate 			    ospf_print_bits(ospf_db_flags_bits,
674*7c478bd9Sstevel@tonic-gate 			    ospf->ospf6_db.db_flags),
675*7c478bd9Sstevel@tonic-gate 			    ntohs(ospf->ospf6_db.db_mtu),
676*7c478bd9Sstevel@tonic-gate 			    ntohl(ospf->ospf6_db.db_seq));
677*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
678*7c478bd9Sstevel@tonic-gate 		}
679*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
680*7c478bd9Sstevel@tonic-gate 			show_header("OSPF DB:  ", "Database Description Packet",
681*7c478bd9Sstevel@tonic-gate 			    fraglen);
682*7c478bd9Sstevel@tonic-gate 			show_space();
683*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
684*7c478bd9Sstevel@tonic-gate 			    "Options = %s", ospf_print_bits(
685*7c478bd9Sstevel@tonic-gate 			    ospf6_option_bits, ospf->ospf6_db.db_options));
686*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
687*7c478bd9Sstevel@tonic-gate 			    "Flags = %s", ospf_print_bits(
688*7c478bd9Sstevel@tonic-gate 			    ospf_db_flags_bits, ospf->ospf6_db.db_flags));
689*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
690*7c478bd9Sstevel@tonic-gate 			    "MTU = %u", ntohl(ospf->ospf6_db.db_seq));
691*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
692*7c478bd9Sstevel@tonic-gate 			    "Sequence = 0x%X", ntohl(ospf->ospf6_db.db_seq));
693*7c478bd9Sstevel@tonic-gate 			/*  Print all the LS advs */
694*7c478bd9Sstevel@tonic-gate 			lsah = ospf->ospf6_db.db_lshdr;
695*7c478bd9Sstevel@tonic-gate 			while ((uchar_t *)lsah < ((uchar_t *)ospf + fraglen)) {
696*7c478bd9Sstevel@tonic-gate 				if ((uchar_t *)lsah + sizeof (struct lsa6_hdr) >
697*7c478bd9Sstevel@tonic-gate 				    ((uchar_t *)ospf + fraglen)) {
698*7c478bd9Sstevel@tonic-gate 					trunc = B_TRUE;
699*7c478bd9Sstevel@tonic-gate 					break;
700*7c478bd9Sstevel@tonic-gate 				}
701*7c478bd9Sstevel@tonic-gate 				interpret_ospf6_lsa_hdr(flags, lsah);
702*7c478bd9Sstevel@tonic-gate 				++lsah;
703*7c478bd9Sstevel@tonic-gate 			}
704*7c478bd9Sstevel@tonic-gate 		}
705*7c478bd9Sstevel@tonic-gate 		break;
706*7c478bd9Sstevel@tonic-gate 
707*7c478bd9Sstevel@tonic-gate 	case OSPF_TYPE_LSR:
708*7c478bd9Sstevel@tonic-gate 		if (fraglen < OSPF6_MIN_HEADER_SIZE +
709*7c478bd9Sstevel@tonic-gate 		    OSPF_MIN_LSR_HEADER_SIZE) {
710*7c478bd9Sstevel@tonic-gate 			trunc = B_TRUE;
711*7c478bd9Sstevel@tonic-gate 			break;
712*7c478bd9Sstevel@tonic-gate 		}
713*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
714*7c478bd9Sstevel@tonic-gate 			show_header("OSPF LSR:  ", "Link State Request Packet",
715*7c478bd9Sstevel@tonic-gate 			    fraglen);
716*7c478bd9Sstevel@tonic-gate 			show_space();
717*7c478bd9Sstevel@tonic-gate 		}
718*7c478bd9Sstevel@tonic-gate 		lsr = ospf->ospf6_lsr;
719*7c478bd9Sstevel@tonic-gate 		nlsah = 0;
720*7c478bd9Sstevel@tonic-gate 		while ((uchar_t *)lsr < ((uchar_t *)ospf + fraglen)) {
721*7c478bd9Sstevel@tonic-gate 			if ((uchar_t *)lsr + sizeof (struct lsr6) >
722*7c478bd9Sstevel@tonic-gate 			    ((uchar_t *)ospf + fraglen)) {
723*7c478bd9Sstevel@tonic-gate 				trunc = B_TRUE;
724*7c478bd9Sstevel@tonic-gate 				break;
725*7c478bd9Sstevel@tonic-gate 			}
726*7c478bd9Sstevel@tonic-gate 			nlsah++;
727*7c478bd9Sstevel@tonic-gate 			if (flags & F_DTAIL) {
728*7c478bd9Sstevel@tonic-gate 				ospf6_print_ls_type(flags, ntohl(lsr->ls_type),
729*7c478bd9Sstevel@tonic-gate 				    lsr->ls_stateid, lsr->ls_router);
730*7c478bd9Sstevel@tonic-gate 			}
731*7c478bd9Sstevel@tonic-gate 			++lsr;
732*7c478bd9Sstevel@tonic-gate 		}
733*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
734*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, "%d LSAs", nlsah);
735*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
736*7c478bd9Sstevel@tonic-gate 		}
737*7c478bd9Sstevel@tonic-gate 		break;
738*7c478bd9Sstevel@tonic-gate 
739*7c478bd9Sstevel@tonic-gate 	case OSPF_TYPE_LSU:
740*7c478bd9Sstevel@tonic-gate 		if (fraglen < OSPF6_MIN_HEADER_SIZE +
741*7c478bd9Sstevel@tonic-gate 		    OSPF_MIN_LSU_HEADER_SIZE) {
742*7c478bd9Sstevel@tonic-gate 			trunc = B_TRUE;
743*7c478bd9Sstevel@tonic-gate 			break;
744*7c478bd9Sstevel@tonic-gate 		}
745*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
746*7c478bd9Sstevel@tonic-gate 			show_header("OSPF LSU:  ", "Link State Update Packet",
747*7c478bd9Sstevel@tonic-gate 			    fraglen);
748*7c478bd9Sstevel@tonic-gate 			show_space();
749*7c478bd9Sstevel@tonic-gate 		}
750*7c478bd9Sstevel@tonic-gate 		lsa = ospf->ospf6_lsu.lsu_lsa;
751*7c478bd9Sstevel@tonic-gate 		nlsa = ntohl(ospf->ospf6_lsu.lsu_count);
752*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
753*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, "%d LSAs", nlsa);
754*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
755*7c478bd9Sstevel@tonic-gate 			break;
756*7c478bd9Sstevel@tonic-gate 		}
757*7c478bd9Sstevel@tonic-gate 		while (nlsa-- != 0) {
758*7c478bd9Sstevel@tonic-gate 			uchar_t *fragend = (uchar_t *)ospf + fraglen;
759*7c478bd9Sstevel@tonic-gate 			if (((uchar_t *)lsa >= fragend) ||
760*7c478bd9Sstevel@tonic-gate 			    ((uchar_t *)lsa + sizeof (struct lsa_hdr) >
761*7c478bd9Sstevel@tonic-gate 			    fragend) ||
762*7c478bd9Sstevel@tonic-gate 			    ((uchar_t *)lsa + ntohs(lsa->ls6_hdr.ls6_length) >
763*7c478bd9Sstevel@tonic-gate 			    fragend)) {
764*7c478bd9Sstevel@tonic-gate 				trunc = B_TRUE;
765*7c478bd9Sstevel@tonic-gate 				break;
766*7c478bd9Sstevel@tonic-gate 			}
767*7c478bd9Sstevel@tonic-gate 
768*7c478bd9Sstevel@tonic-gate 			if (interpret_ospf6_lsa(flags, lsa, fragend) < 0) {
769*7c478bd9Sstevel@tonic-gate 				trunc = B_TRUE;
770*7c478bd9Sstevel@tonic-gate 				break;
771*7c478bd9Sstevel@tonic-gate 			}
772*7c478bd9Sstevel@tonic-gate 			lsa = (struct lsa6 *)((uchar_t *)lsa +
773*7c478bd9Sstevel@tonic-gate 			    ntohs(lsa->ls6_hdr.ls6_length));
774*7c478bd9Sstevel@tonic-gate 		}
775*7c478bd9Sstevel@tonic-gate 		break;
776*7c478bd9Sstevel@tonic-gate 
777*7c478bd9Sstevel@tonic-gate 	case OSPF_TYPE_LSA:
778*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL) {
779*7c478bd9Sstevel@tonic-gate 			show_header("OSPF LSA:  ", "Link State Ack Packet",
780*7c478bd9Sstevel@tonic-gate 			    fraglen);
781*7c478bd9Sstevel@tonic-gate 			show_space();
782*7c478bd9Sstevel@tonic-gate 		}
783*7c478bd9Sstevel@tonic-gate 		lsah = ospf->ospf6_lsa.lsa_lshdr;
784*7c478bd9Sstevel@tonic-gate 		nlsah = 0;
785*7c478bd9Sstevel@tonic-gate 		while ((uchar_t *)lsah < ((uchar_t *)ospf + fraglen)) {
786*7c478bd9Sstevel@tonic-gate 			if ((uchar_t *)lsah + sizeof (struct lsa6_hdr) >
787*7c478bd9Sstevel@tonic-gate 			    ((uchar_t *)ospf + fraglen)) {
788*7c478bd9Sstevel@tonic-gate 				trunc = B_TRUE;
789*7c478bd9Sstevel@tonic-gate 				break;
790*7c478bd9Sstevel@tonic-gate 			}
791*7c478bd9Sstevel@tonic-gate 			nlsah++;
792*7c478bd9Sstevel@tonic-gate 			if (flags & F_DTAIL)
793*7c478bd9Sstevel@tonic-gate 				interpret_ospf6_lsa_hdr(flags, lsah);
794*7c478bd9Sstevel@tonic-gate 			++lsah;
795*7c478bd9Sstevel@tonic-gate 		}
796*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM) {
797*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, "%d LSAs", nlsah);
798*7c478bd9Sstevel@tonic-gate 			sum_line += strlen(sum_line);
799*7c478bd9Sstevel@tonic-gate 		}
800*7c478bd9Sstevel@tonic-gate 		break;
801*7c478bd9Sstevel@tonic-gate 
802*7c478bd9Sstevel@tonic-gate 	default:
803*7c478bd9Sstevel@tonic-gate 		/* NOTREACHED */
804*7c478bd9Sstevel@tonic-gate 		break;
805*7c478bd9Sstevel@tonic-gate 	}
806*7c478bd9Sstevel@tonic-gate 	if (trunc) {
807*7c478bd9Sstevel@tonic-gate 		if (flags & F_SUM)
808*7c478bd9Sstevel@tonic-gate 			sprintf(sum_line, "--truncated");
809*7c478bd9Sstevel@tonic-gate 		if (flags & F_DTAIL)
810*7c478bd9Sstevel@tonic-gate 			snprintf(get_line(0, 0), get_line_remain(),
811*7c478bd9Sstevel@tonic-gate 			    "--truncated");
812*7c478bd9Sstevel@tonic-gate 	}
813*7c478bd9Sstevel@tonic-gate 
814*7c478bd9Sstevel@tonic-gate 	return (fraglen);
815*7c478bd9Sstevel@tonic-gate }
816