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