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