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
49*7c478bd9Sstevel@tonic-gate char *ospf_types[] = {
50*7c478bd9Sstevel@tonic-gate "umd", /* 0 */
51*7c478bd9Sstevel@tonic-gate "Hello", /* 1 */
52*7c478bd9Sstevel@tonic-gate "DD", /* 2 */
53*7c478bd9Sstevel@tonic-gate "LSReq", /* 3 */
54*7c478bd9Sstevel@tonic-gate "LSUpd", /* 4 */
55*7c478bd9Sstevel@tonic-gate "LSAck", /* 5 */
56*7c478bd9Sstevel@tonic-gate };
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gate static char *ospf_authtypes[] = {
59*7c478bd9Sstevel@tonic-gate "None", /* 0 */
60*7c478bd9Sstevel@tonic-gate "simple", /* 1 */
61*7c478bd9Sstevel@tonic-gate "md5", /* 2 */
62*7c478bd9Sstevel@tonic-gate };
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate const struct bits ospf_rla_flag_bits[] = {
65*7c478bd9Sstevel@tonic-gate { RLA_FLAG_B, "B" },
66*7c478bd9Sstevel@tonic-gate { RLA_FLAG_E, "E" },
67*7c478bd9Sstevel@tonic-gate { RLA_FLAG_V, "V" },
68*7c478bd9Sstevel@tonic-gate { RLA_FLAG_W, "W" },
69*7c478bd9Sstevel@tonic-gate { 0, NULL }
70*7c478bd9Sstevel@tonic-gate };
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate const struct bits ospf_db_flags_bits[] = {
73*7c478bd9Sstevel@tonic-gate { OSPF_DB_INIT, "I" },
74*7c478bd9Sstevel@tonic-gate { OSPF_DB_MORE, "M" },
75*7c478bd9Sstevel@tonic-gate { OSPF_DB_MASTER, "MS" },
76*7c478bd9Sstevel@tonic-gate { 0, NULL }
77*7c478bd9Sstevel@tonic-gate };
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate const struct bits ospf_option_bits[] = {
80*7c478bd9Sstevel@tonic-gate { OSPF_OPTION_T, "T" },
81*7c478bd9Sstevel@tonic-gate { OSPF_OPTION_E, "E" },
82*7c478bd9Sstevel@tonic-gate { OSPF_OPTION_MC, "MC" },
83*7c478bd9Sstevel@tonic-gate { 0, NULL }
84*7c478bd9Sstevel@tonic-gate };
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate static int interpret_ospf_hello(int, struct ospfhdr *, int);
87*7c478bd9Sstevel@tonic-gate static void ospf_print_ls_type(int, uint32_t, struct in_addr, struct in_addr);
88*7c478bd9Sstevel@tonic-gate static void interpret_ospf_lsa_hdr(int, struct lsa_hdr *);
89*7c478bd9Sstevel@tonic-gate static int interpret_ospf_lsa(int flags, struct lsa *lsa, uchar_t *);
90*7c478bd9Sstevel@tonic-gate
91*7c478bd9Sstevel@tonic-gate char *
ospf_print_bits(const struct bits * bp,uchar_t options)92*7c478bd9Sstevel@tonic-gate ospf_print_bits(const struct bits *bp, uchar_t options)
93*7c478bd9Sstevel@tonic-gate {
94*7c478bd9Sstevel@tonic-gate static char bitstring[32];
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gate bitstring[0] = '\0';
97*7c478bd9Sstevel@tonic-gate do {
98*7c478bd9Sstevel@tonic-gate if (options & bp->bit) {
99*7c478bd9Sstevel@tonic-gate strcat(bitstring, bp->str);
100*7c478bd9Sstevel@tonic-gate strcat(bitstring, "/");
101*7c478bd9Sstevel@tonic-gate }
102*7c478bd9Sstevel@tonic-gate } while ((++bp)->bit);
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate /* wipe out the trailing "/" */
105*7c478bd9Sstevel@tonic-gate bitstring[strlen(bitstring) - 1] = '\0';
106*7c478bd9Sstevel@tonic-gate return (bitstring);
107*7c478bd9Sstevel@tonic-gate }
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate char *
ospf_print_lsa_age(long age)110*7c478bd9Sstevel@tonic-gate ospf_print_lsa_age(long age)
111*7c478bd9Sstevel@tonic-gate {
112*7c478bd9Sstevel@tonic-gate long sec, mins, hour;
113*7c478bd9Sstevel@tonic-gate static char lsa_age[16];
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate sec = age % 60;
116*7c478bd9Sstevel@tonic-gate mins = (age / 60) % 60;
117*7c478bd9Sstevel@tonic-gate hour = age / 3600;
118*7c478bd9Sstevel@tonic-gate if (hour != 0)
119*7c478bd9Sstevel@tonic-gate snprintf(lsa_age, sizeof (lsa_age), "%u:%02u:%02u",
120*7c478bd9Sstevel@tonic-gate hour, mins, sec);
121*7c478bd9Sstevel@tonic-gate else if (mins != 0)
122*7c478bd9Sstevel@tonic-gate snprintf(lsa_age, sizeof (lsa_age), "%u:%02u", mins, sec);
123*7c478bd9Sstevel@tonic-gate else
124*7c478bd9Sstevel@tonic-gate snprintf(lsa_age, sizeof (lsa_age), "%u", sec);
125*7c478bd9Sstevel@tonic-gate return (lsa_age);
126*7c478bd9Sstevel@tonic-gate }
127*7c478bd9Sstevel@tonic-gate
128*7c478bd9Sstevel@tonic-gate static int
interpret_ospf_hello(int flags,struct ospfhdr * op,int fraglen)129*7c478bd9Sstevel@tonic-gate interpret_ospf_hello(int flags, struct ospfhdr *op, int fraglen)
130*7c478bd9Sstevel@tonic-gate {
131*7c478bd9Sstevel@tonic-gate struct in_addr *nbr;
132*7c478bd9Sstevel@tonic-gate int j;
133*7c478bd9Sstevel@tonic-gate
134*7c478bd9Sstevel@tonic-gate if (fraglen < OSPF_MIN_HEADER_SIZE + OSPF_MIN_HELLO_HEADER_SIZE)
135*7c478bd9Sstevel@tonic-gate return (-1); /* truncated packet */
136*7c478bd9Sstevel@tonic-gate
137*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
138*7c478bd9Sstevel@tonic-gate if (op->ospf_hello.hello_dr.s_addr != 0) {
139*7c478bd9Sstevel@tonic-gate (void) sprintf(sum_line, "DR=%s ",
140*7c478bd9Sstevel@tonic-gate inet_ntoa(op->ospf_hello.hello_dr));
141*7c478bd9Sstevel@tonic-gate }
142*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
143*7c478bd9Sstevel@tonic-gate if (op->ospf_hello.hello_bdr.s_addr != 0) {
144*7c478bd9Sstevel@tonic-gate (void) sprintf(sum_line, "BDR=%s ",
145*7c478bd9Sstevel@tonic-gate inet_ntoa(op->ospf_hello.hello_bdr));
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
148*7c478bd9Sstevel@tonic-gate nbr = op->ospf_hello.hello_neighbor;
149*7c478bd9Sstevel@tonic-gate j = 0;
150*7c478bd9Sstevel@tonic-gate while ((uchar_t *)nbr < ((uchar_t *)op + fraglen)) {
151*7c478bd9Sstevel@tonic-gate if ((uchar_t *)nbr + sizeof (struct in_addr) >
152*7c478bd9Sstevel@tonic-gate ((uchar_t *)op + fraglen))
153*7c478bd9Sstevel@tonic-gate return (-1); /* truncated */
154*7c478bd9Sstevel@tonic-gate j++;
155*7c478bd9Sstevel@tonic-gate ++nbr;
156*7c478bd9Sstevel@tonic-gate }
157*7c478bd9Sstevel@tonic-gate (void) sprintf(sum_line, "%d nbrs", j);
158*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
159*7c478bd9Sstevel@tonic-gate
160*7c478bd9Sstevel@tonic-gate }
161*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
162*7c478bd9Sstevel@tonic-gate show_header("OSPF HELLO: ", "Hello Packet",
163*7c478bd9Sstevel@tonic-gate ntohs(op->ospf_len));
164*7c478bd9Sstevel@tonic-gate show_space();
165*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
166*7c478bd9Sstevel@tonic-gate "Options = %s", ospf_print_bits(ospf_option_bits,
167*7c478bd9Sstevel@tonic-gate op->ospf_hello.hello_options));
168*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(), "Mask = %s",
169*7c478bd9Sstevel@tonic-gate inet_ntoa(op->ospf_hello.hello_mask));
170*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
171*7c478bd9Sstevel@tonic-gate "Hello interval = %d",
172*7c478bd9Sstevel@tonic-gate ntohs(op->ospf_hello.hello_helloint));
173*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
174*7c478bd9Sstevel@tonic-gate "Priority = %d", op->ospf_hello.hello_priority);
175*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
176*7c478bd9Sstevel@tonic-gate "Dead interval = %u", ntohl(op->ospf_hello.hello_deadint));
177*7c478bd9Sstevel@tonic-gate if (op->ospf_hello.hello_dr.s_addr != 0) {
178*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
179*7c478bd9Sstevel@tonic-gate "Designated Router = %s",
180*7c478bd9Sstevel@tonic-gate inet_ntoa(op->ospf_hello.hello_dr));
181*7c478bd9Sstevel@tonic-gate }
182*7c478bd9Sstevel@tonic-gate if (op->ospf_hello.hello_bdr.s_addr != 0) {
183*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
184*7c478bd9Sstevel@tonic-gate "Backup Designated Router = %s",
185*7c478bd9Sstevel@tonic-gate inet_ntoa(op->ospf_hello.hello_bdr));
186*7c478bd9Sstevel@tonic-gate }
187*7c478bd9Sstevel@tonic-gate nbr = op->ospf_hello.hello_neighbor;
188*7c478bd9Sstevel@tonic-gate while ((uchar_t *)nbr < ((uchar_t *)op + fraglen)) {
189*7c478bd9Sstevel@tonic-gate if ((uchar_t *)nbr + sizeof (struct in_addr) >
190*7c478bd9Sstevel@tonic-gate ((uchar_t *)op + fraglen))
191*7c478bd9Sstevel@tonic-gate return (-1); /* truncated */
192*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
193*7c478bd9Sstevel@tonic-gate "Neighbor: %s", inet_ntoa(*nbr));
194*7c478bd9Sstevel@tonic-gate ++nbr;
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate }
197*7c478bd9Sstevel@tonic-gate return (fraglen);
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate
200*7c478bd9Sstevel@tonic-gate static void
ospf_print_ls_type(int flags,uint32_t ls_type,struct in_addr ls_stateid,struct in_addr ls_router)201*7c478bd9Sstevel@tonic-gate ospf_print_ls_type(int flags, uint32_t ls_type, struct in_addr ls_stateid,
202*7c478bd9Sstevel@tonic-gate struct in_addr ls_router)
203*7c478bd9Sstevel@tonic-gate {
204*7c478bd9Sstevel@tonic-gate switch (ls_type) {
205*7c478bd9Sstevel@tonic-gate case LS_TYPE_ROUTER:
206*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
207*7c478bd9Sstevel@tonic-gate sprintf(sum_line, " rtr %s ", inet_ntoa(ls_router));
208*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
209*7c478bd9Sstevel@tonic-gate }
210*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
211*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
212*7c478bd9Sstevel@tonic-gate "Router LSA; Router = %s ", inet_ntoa(ls_router));
213*7c478bd9Sstevel@tonic-gate }
214*7c478bd9Sstevel@tonic-gate break;
215*7c478bd9Sstevel@tonic-gate case LS_TYPE_NETWORK:
216*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
217*7c478bd9Sstevel@tonic-gate sprintf(sum_line, " net dr %s ", inet_ntoa(ls_router));
218*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
219*7c478bd9Sstevel@tonic-gate sprintf(sum_line, "if %s ", inet_ntoa(ls_stateid));
220*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
221*7c478bd9Sstevel@tonic-gate }
222*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
223*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
224*7c478bd9Sstevel@tonic-gate "Network LSA Router = %s ", inet_ntoa(ls_router));
225*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
226*7c478bd9Sstevel@tonic-gate " Interface = %s ",
227*7c478bd9Sstevel@tonic-gate inet_ntoa(ls_stateid));
228*7c478bd9Sstevel@tonic-gate }
229*7c478bd9Sstevel@tonic-gate break;
230*7c478bd9Sstevel@tonic-gate case LS_TYPE_SUM_IP:
231*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
232*7c478bd9Sstevel@tonic-gate sprintf(sum_line, " sum %s ", inet_ntoa(ls_stateid));
233*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
234*7c478bd9Sstevel@tonic-gate sprintf(sum_line, "abr %s ", inet_ntoa(ls_router));
235*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
236*7c478bd9Sstevel@tonic-gate }
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 "Summary LSA IP = %s ", inet_ntoa(ls_stateid));
240*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
241*7c478bd9Sstevel@tonic-gate " Area Border Router = %s ",
242*7c478bd9Sstevel@tonic-gate inet_ntoa(ls_router));
243*7c478bd9Sstevel@tonic-gate }
244*7c478bd9Sstevel@tonic-gate break;
245*7c478bd9Sstevel@tonic-gate case LS_TYPE_SUM_ABR:
246*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
247*7c478bd9Sstevel@tonic-gate sprintf(sum_line, "abr %s ", inet_ntoa(ls_stateid));
248*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
249*7c478bd9Sstevel@tonic-gate sprintf(sum_line, "asbr %s ", inet_ntoa(ls_router));
250*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
251*7c478bd9Sstevel@tonic-gate }
252*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
253*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
254*7c478bd9Sstevel@tonic-gate "ASBR Summary abr = %s ", inet_ntoa(ls_stateid));
255*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
256*7c478bd9Sstevel@tonic-gate " asbr = %s ", inet_ntoa(ls_router));
257*7c478bd9Sstevel@tonic-gate }
258*7c478bd9Sstevel@tonic-gate break;
259*7c478bd9Sstevel@tonic-gate case LS_TYPE_ASE:
260*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
261*7c478bd9Sstevel@tonic-gate sprintf(sum_line, " ase %s", inet_ntoa(ls_stateid));
262*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
263*7c478bd9Sstevel@tonic-gate sprintf(sum_line, " asbr %s", inet_ntoa(ls_router));
264*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
265*7c478bd9Sstevel@tonic-gate }
266*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
267*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
268*7c478bd9Sstevel@tonic-gate "AS External LSA ase = %s ", inet_ntoa(ls_stateid));
269*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
270*7c478bd9Sstevel@tonic-gate " asbr = %s ", inet_ntoa(ls_router));
271*7c478bd9Sstevel@tonic-gate }
272*7c478bd9Sstevel@tonic-gate
273*7c478bd9Sstevel@tonic-gate break;
274*7c478bd9Sstevel@tonic-gate case LS_TYPE_GROUP:
275*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
276*7c478bd9Sstevel@tonic-gate sprintf(sum_line, " group %s", inet_ntoa(ls_stateid));
277*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
278*7c478bd9Sstevel@tonic-gate sprintf(sum_line, " rtr %s", inet_ntoa(ls_router));
279*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
280*7c478bd9Sstevel@tonic-gate }
281*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
282*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
283*7c478bd9Sstevel@tonic-gate "Group LSA %s ", inet_ntoa(ls_stateid));
284*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
285*7c478bd9Sstevel@tonic-gate " rtr = %s ", inet_ntoa(ls_router));
286*7c478bd9Sstevel@tonic-gate }
287*7c478bd9Sstevel@tonic-gate break;
288*7c478bd9Sstevel@tonic-gate default:
289*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
290*7c478bd9Sstevel@tonic-gate sprintf(sum_line, " unknown LSA type %d", ls_type);
291*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
292*7c478bd9Sstevel@tonic-gate }
293*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
294*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
295*7c478bd9Sstevel@tonic-gate "Unknown LSA type %d", ls_type);
296*7c478bd9Sstevel@tonic-gate }
297*7c478bd9Sstevel@tonic-gate break;
298*7c478bd9Sstevel@tonic-gate }
299*7c478bd9Sstevel@tonic-gate }
300*7c478bd9Sstevel@tonic-gate
301*7c478bd9Sstevel@tonic-gate static void
interpret_ospf_lsa_hdr(int flags,struct lsa_hdr * lsah)302*7c478bd9Sstevel@tonic-gate interpret_ospf_lsa_hdr(int flags, struct lsa_hdr *lsah)
303*7c478bd9Sstevel@tonic-gate {
304*7c478bd9Sstevel@tonic-gate if (flags & F_SUM)
305*7c478bd9Sstevel@tonic-gate return;
306*7c478bd9Sstevel@tonic-gate
307*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
308*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
309*7c478bd9Sstevel@tonic-gate "Options = %s",
310*7c478bd9Sstevel@tonic-gate ospf_print_bits(ospf_option_bits, lsah->ls_options));
311*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
312*7c478bd9Sstevel@tonic-gate "Sequence = %X ", ntohl(lsah->ls_seq));
313*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
314*7c478bd9Sstevel@tonic-gate "Age = %X ", ospf_print_lsa_age(ntohs(lsah->ls_age)));
315*7c478bd9Sstevel@tonic-gate }
316*7c478bd9Sstevel@tonic-gate
317*7c478bd9Sstevel@tonic-gate ospf_print_ls_type(flags, lsah->ls_type, lsah->ls_stateid,
318*7c478bd9Sstevel@tonic-gate lsah->ls_router);
319*7c478bd9Sstevel@tonic-gate
320*7c478bd9Sstevel@tonic-gate }
321*7c478bd9Sstevel@tonic-gate
322*7c478bd9Sstevel@tonic-gate #define TRUNC(addr) ((uchar_t *)(addr) > fragend)
323*7c478bd9Sstevel@tonic-gate static int
interpret_ospf_lsa(int flags,struct lsa * lsa,uchar_t * fragend)324*7c478bd9Sstevel@tonic-gate interpret_ospf_lsa(int flags, struct lsa *lsa, uchar_t *fragend)
325*7c478bd9Sstevel@tonic-gate {
326*7c478bd9Sstevel@tonic-gate uchar_t *ls_end;
327*7c478bd9Sstevel@tonic-gate int rla_count, k;
328*7c478bd9Sstevel@tonic-gate struct rlalink *rl;
329*7c478bd9Sstevel@tonic-gate struct tos_metric *tosp;
330*7c478bd9Sstevel@tonic-gate struct in_addr *addr;
331*7c478bd9Sstevel@tonic-gate uint32_t *tosmetric;
332*7c478bd9Sstevel@tonic-gate struct aslametric *am;
333*7c478bd9Sstevel@tonic-gate uint32_t tm;
334*7c478bd9Sstevel@tonic-gate int tos, metric;
335*7c478bd9Sstevel@tonic-gate
336*7c478bd9Sstevel@tonic-gate interpret_ospf_lsa_hdr(flags, &lsa->ls_hdr);
337*7c478bd9Sstevel@tonic-gate
338*7c478bd9Sstevel@tonic-gate ls_end = (uchar_t *)lsa + ntohs(lsa->ls_hdr.ls_length);
339*7c478bd9Sstevel@tonic-gate
340*7c478bd9Sstevel@tonic-gate if (TRUNC(ls_end))
341*7c478bd9Sstevel@tonic-gate return (-1);
342*7c478bd9Sstevel@tonic-gate
343*7c478bd9Sstevel@tonic-gate switch (lsa->ls_hdr.ls_type) {
344*7c478bd9Sstevel@tonic-gate
345*7c478bd9Sstevel@tonic-gate case LS_TYPE_ROUTER:
346*7c478bd9Sstevel@tonic-gate if (TRUNC(&lsa->lsa_un.un_rla.rla_flags))
347*7c478bd9Sstevel@tonic-gate return (-1);
348*7c478bd9Sstevel@tonic-gate
349*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
350*7c478bd9Sstevel@tonic-gate (void) ospf_print_bits(ospf_rla_flag_bits,
351*7c478bd9Sstevel@tonic-gate lsa->lsa_un.un_rla.rla_flags);
352*7c478bd9Sstevel@tonic-gate }
353*7c478bd9Sstevel@tonic-gate
354*7c478bd9Sstevel@tonic-gate if (TRUNC(&lsa->lsa_un.un_rla.rla_count))
355*7c478bd9Sstevel@tonic-gate return (-1);
356*7c478bd9Sstevel@tonic-gate rla_count = ntohs(lsa->lsa_un.un_rla.rla_count);
357*7c478bd9Sstevel@tonic-gate
358*7c478bd9Sstevel@tonic-gate rl = lsa->lsa_un.un_rla.rla_link;
359*7c478bd9Sstevel@tonic-gate if (TRUNC(rl))
360*7c478bd9Sstevel@tonic-gate return (-1);
361*7c478bd9Sstevel@tonic-gate
362*7c478bd9Sstevel@tonic-gate while (rla_count-- != 0) {
363*7c478bd9Sstevel@tonic-gate if (TRUNC((uchar_t *)rl + sizeof (*rl)))
364*7c478bd9Sstevel@tonic-gate return (-1);
365*7c478bd9Sstevel@tonic-gate switch (rl->link_type) {
366*7c478bd9Sstevel@tonic-gate case RLA_TYPE_VIRTUAL:
367*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
368*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
369*7c478bd9Sstevel@tonic-gate get_line_remain(), "Virtual Link");
370*7c478bd9Sstevel@tonic-gate }
371*7c478bd9Sstevel@tonic-gate /* fall through */
372*7c478bd9Sstevel@tonic-gate case RLA_TYPE_ROUTER:
373*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
374*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
375*7c478bd9Sstevel@tonic-gate get_line_remain(), "Neighbor = %s",
376*7c478bd9Sstevel@tonic-gate inet_ntoa(rl->link_id));
377*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
378*7c478bd9Sstevel@tonic-gate get_line_remain(), "Interface = %s",
379*7c478bd9Sstevel@tonic-gate inet_ntoa(rl->link_data));
380*7c478bd9Sstevel@tonic-gate }
381*7c478bd9Sstevel@tonic-gate break;
382*7c478bd9Sstevel@tonic-gate case RLA_TYPE_TRANSIT:
383*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
384*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
385*7c478bd9Sstevel@tonic-gate get_line_remain(),
386*7c478bd9Sstevel@tonic-gate "Designated Router = %s",
387*7c478bd9Sstevel@tonic-gate inet_ntoa(rl->link_id));
388*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
389*7c478bd9Sstevel@tonic-gate get_line_remain(), "Interface = %s",
390*7c478bd9Sstevel@tonic-gate inet_ntoa(rl->link_data));
391*7c478bd9Sstevel@tonic-gate }
392*7c478bd9Sstevel@tonic-gate break;
393*7c478bd9Sstevel@tonic-gate case RLA_TYPE_STUB:
394*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
395*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
396*7c478bd9Sstevel@tonic-gate get_line_remain(), "Network = %s",
397*7c478bd9Sstevel@tonic-gate inet_ntoa(rl->link_id));
398*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
399*7c478bd9Sstevel@tonic-gate get_line_remain(), "Mask = %s",
400*7c478bd9Sstevel@tonic-gate inet_ntoa(rl->link_data));
401*7c478bd9Sstevel@tonic-gate }
402*7c478bd9Sstevel@tonic-gate break;
403*7c478bd9Sstevel@tonic-gate default:
404*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
405*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
406*7c478bd9Sstevel@tonic-gate get_line_remain(),
407*7c478bd9Sstevel@tonic-gate "Unknown link type %d",
408*7c478bd9Sstevel@tonic-gate rl->link_type);
409*7c478bd9Sstevel@tonic-gate }
410*7c478bd9Sstevel@tonic-gate
411*7c478bd9Sstevel@tonic-gate }
412*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
413*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0),
414*7c478bd9Sstevel@tonic-gate get_line_remain(), "TOS 0 metric = %d",
415*7c478bd9Sstevel@tonic-gate ntohs(rl->link_tos0metric));
416*7c478bd9Sstevel@tonic-gate }
417*7c478bd9Sstevel@tonic-gate tosp = (struct tos_metric *)(
418*7c478bd9Sstevel@tonic-gate (uchar_t *)rl + sizeof (rl->link_tos0metric));
419*7c478bd9Sstevel@tonic-gate for (k = 0; k > (int)rl->link_toscount; ++k, ++tosp) {
420*7c478bd9Sstevel@tonic-gate if (TRUNC(tosp))
421*7c478bd9Sstevel@tonic-gate return (-1);
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 "TOS %d metric = %d",
426*7c478bd9Sstevel@tonic-gate tosp->tos_type,
427*7c478bd9Sstevel@tonic-gate ntohs(tosp->tos_metric));
428*7c478bd9Sstevel@tonic-gate }
429*7c478bd9Sstevel@tonic-gate
430*7c478bd9Sstevel@tonic-gate }
431*7c478bd9Sstevel@tonic-gate rl = (struct rlalink *)((uchar_t *)(rl + 1) +
432*7c478bd9Sstevel@tonic-gate ((rl->link_toscount) * sizeof (*tosp)));
433*7c478bd9Sstevel@tonic-gate if (TRUNC(rl))
434*7c478bd9Sstevel@tonic-gate return (-1); /* truncated */
435*7c478bd9Sstevel@tonic-gate }
436*7c478bd9Sstevel@tonic-gate break;
437*7c478bd9Sstevel@tonic-gate case LS_TYPE_NETWORK:
438*7c478bd9Sstevel@tonic-gate
439*7c478bd9Sstevel@tonic-gate if (TRUNC(&lsa->lsa_un.un_nla.nla_mask))
440*7c478bd9Sstevel@tonic-gate return (-1);
441*7c478bd9Sstevel@tonic-gate
442*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
443*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
444*7c478bd9Sstevel@tonic-gate "Mask = %s",
445*7c478bd9Sstevel@tonic-gate inet_ntoa(lsa->lsa_un.un_nla.nla_mask));
446*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
447*7c478bd9Sstevel@tonic-gate "Routers:");
448*7c478bd9Sstevel@tonic-gate }
449*7c478bd9Sstevel@tonic-gate addr = lsa->lsa_un.un_nla.nla_router;
450*7c478bd9Sstevel@tonic-gate while ((uchar_t *)addr < ls_end) {
451*7c478bd9Sstevel@tonic-gate if ((uchar_t *)addr + sizeof (struct in_addr) > ls_end)
452*7c478bd9Sstevel@tonic-gate return (-1); /* truncated */
453*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
454*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
455*7c478bd9Sstevel@tonic-gate "\t%s", inet_ntoa(*addr));
456*7c478bd9Sstevel@tonic-gate }
457*7c478bd9Sstevel@tonic-gate ++addr;
458*7c478bd9Sstevel@tonic-gate }
459*7c478bd9Sstevel@tonic-gate break;
460*7c478bd9Sstevel@tonic-gate case LS_TYPE_SUM_IP:
461*7c478bd9Sstevel@tonic-gate
462*7c478bd9Sstevel@tonic-gate if (TRUNC((uchar_t *)&lsa->lsa_un.un_sla.sla_mask +
463*7c478bd9Sstevel@tonic-gate sizeof (struct in_addr)))
464*7c478bd9Sstevel@tonic-gate return (-1);
465*7c478bd9Sstevel@tonic-gate
466*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
467*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(), "Mask = %s",
468*7c478bd9Sstevel@tonic-gate inet_ntoa(lsa->lsa_un.un_sla.sla_mask));
469*7c478bd9Sstevel@tonic-gate }
470*7c478bd9Sstevel@tonic-gate /* FALLTHROUGH */
471*7c478bd9Sstevel@tonic-gate case LS_TYPE_SUM_ABR:
472*7c478bd9Sstevel@tonic-gate if (TRUNC(&lsa->lsa_un.un_sla.sla_tosmetric))
473*7c478bd9Sstevel@tonic-gate return (-1);
474*7c478bd9Sstevel@tonic-gate tosmetric = lsa->lsa_un.un_sla.sla_tosmetric;
475*7c478bd9Sstevel@tonic-gate while ((uchar_t *)tosmetric < ls_end) {
476*7c478bd9Sstevel@tonic-gate if ((uchar_t *)tosmetric + sizeof (tm) > fragend)
477*7c478bd9Sstevel@tonic-gate return (-1); /* truncated */
478*7c478bd9Sstevel@tonic-gate tm = ntohl(*tosmetric);
479*7c478bd9Sstevel@tonic-gate tos = (tm & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
480*7c478bd9Sstevel@tonic-gate metric = tm & SLA_MASK_METRIC;
481*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
482*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
483*7c478bd9Sstevel@tonic-gate " tos %d metric %d", tos, metric);
484*7c478bd9Sstevel@tonic-gate }
485*7c478bd9Sstevel@tonic-gate ++tosmetric;
486*7c478bd9Sstevel@tonic-gate }
487*7c478bd9Sstevel@tonic-gate break;
488*7c478bd9Sstevel@tonic-gate case LS_TYPE_ASE:
489*7c478bd9Sstevel@tonic-gate if (TRUNC(&lsa->lsa_un.un_asla.asla_mask))
490*7c478bd9Sstevel@tonic-gate return (-1);
491*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
492*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(), "Mask = %s",
493*7c478bd9Sstevel@tonic-gate inet_ntoa(lsa->lsa_un.un_asla.asla_mask));
494*7c478bd9Sstevel@tonic-gate }
495*7c478bd9Sstevel@tonic-gate am = lsa->lsa_un.un_asla.asla_metric;
496*7c478bd9Sstevel@tonic-gate while ((uchar_t *)am < ls_end) {
497*7c478bd9Sstevel@tonic-gate if ((uchar_t *)am + sizeof (tm) > fragend)
498*7c478bd9Sstevel@tonic-gate return (-1); /* truncated */
499*7c478bd9Sstevel@tonic-gate tm = ntohl(am->asla_tosmetric);
500*7c478bd9Sstevel@tonic-gate tos = (tm & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS;
501*7c478bd9Sstevel@tonic-gate metric = tm & ASLA_MASK_METRIC;
502*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
503*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
504*7c478bd9Sstevel@tonic-gate " type %d tos %d metric %d",
505*7c478bd9Sstevel@tonic-gate (tm & ASLA_FLAG_EXTERNAL) ? 2 : 1,
506*7c478bd9Sstevel@tonic-gate tos, metric);
507*7c478bd9Sstevel@tonic-gate }
508*7c478bd9Sstevel@tonic-gate if (am->asla_forward.s_addr != 0) {
509*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
510*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0),
511*7c478bd9Sstevel@tonic-gate get_line_remain(), " Forward %s",
512*7c478bd9Sstevel@tonic-gate inet_ntoa(am->asla_forward));
513*7c478bd9Sstevel@tonic-gate }
514*7c478bd9Sstevel@tonic-gate }
515*7c478bd9Sstevel@tonic-gate if (am->asla_tag.s_addr != 0) {
516*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
517*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0),
518*7c478bd9Sstevel@tonic-gate get_line_remain(), " Tag %s",
519*7c478bd9Sstevel@tonic-gate inet_ntoa(am->asla_tag));
520*7c478bd9Sstevel@tonic-gate }
521*7c478bd9Sstevel@tonic-gate }
522*7c478bd9Sstevel@tonic-gate ++am;
523*7c478bd9Sstevel@tonic-gate }
524*7c478bd9Sstevel@tonic-gate break;
525*7c478bd9Sstevel@tonic-gate default:
526*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
527*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
528*7c478bd9Sstevel@tonic-gate " Unknown LSA type %d", lsa->ls_hdr.ls_type);
529*7c478bd9Sstevel@tonic-gate
530*7c478bd9Sstevel@tonic-gate }
531*7c478bd9Sstevel@tonic-gate break;
532*7c478bd9Sstevel@tonic-gate }
533*7c478bd9Sstevel@tonic-gate return (0);
534*7c478bd9Sstevel@tonic-gate }
535*7c478bd9Sstevel@tonic-gate #undef TRUNC
536*7c478bd9Sstevel@tonic-gate
537*7c478bd9Sstevel@tonic-gate int
interpret_ospf(int flags,struct ospfhdr * ospf,int iplen,int fraglen)538*7c478bd9Sstevel@tonic-gate interpret_ospf(int flags, struct ospfhdr *ospf, int iplen, int fraglen)
539*7c478bd9Sstevel@tonic-gate {
540*7c478bd9Sstevel@tonic-gate int nlsa, nlsah = 0;
541*7c478bd9Sstevel@tonic-gate struct lsa_hdr *lsah;
542*7c478bd9Sstevel@tonic-gate struct lsr *lsr;
543*7c478bd9Sstevel@tonic-gate struct lsa *lsa;
544*7c478bd9Sstevel@tonic-gate boolean_t trunc = B_FALSE;
545*7c478bd9Sstevel@tonic-gate
546*7c478bd9Sstevel@tonic-gate if ((fraglen < OSPF_MIN_HEADER_SIZE) ||
547*7c478bd9Sstevel@tonic-gate (fraglen < ntohs(ospf->ospf_len)))
548*7c478bd9Sstevel@tonic-gate return (fraglen); /* incomplete header */
549*7c478bd9Sstevel@tonic-gate
550*7c478bd9Sstevel@tonic-gate if (fraglen > ntohs(ospf->ospf_len))
551*7c478bd9Sstevel@tonic-gate fraglen = ntohs(ospf->ospf_len);
552*7c478bd9Sstevel@tonic-gate
553*7c478bd9Sstevel@tonic-gate
554*7c478bd9Sstevel@tonic-gate if (ospf->ospf_type > OSPF_TYPE_MAX) {
555*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
556*7c478bd9Sstevel@tonic-gate (void) sprintf(sum_line, "Unknown OSPF TYPE %d \n",
557*7c478bd9Sstevel@tonic-gate ospf->ospf_type);
558*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
559*7c478bd9Sstevel@tonic-gate }
560*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
561*7c478bd9Sstevel@tonic-gate show_header("OSPF: ", "OSPF Header", fraglen);
562*7c478bd9Sstevel@tonic-gate show_space();
563*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
564*7c478bd9Sstevel@tonic-gate "Unknown OSPF Type = %d", ospf->ospf_type);
565*7c478bd9Sstevel@tonic-gate }
566*7c478bd9Sstevel@tonic-gate return (fraglen);
567*7c478bd9Sstevel@tonic-gate }
568*7c478bd9Sstevel@tonic-gate
569*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
570*7c478bd9Sstevel@tonic-gate sum_line = (char *)get_sum_line();
571*7c478bd9Sstevel@tonic-gate (void) sprintf(sum_line, "OSPF %s RTRID=%s ",
572*7c478bd9Sstevel@tonic-gate ospf_types[ospf->ospf_type],
573*7c478bd9Sstevel@tonic-gate inet_ntoa(ospf->ospf_routerid));
574*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
575*7c478bd9Sstevel@tonic-gate (void) sprintf(sum_line, "AREA=%s LEN=%d ",
576*7c478bd9Sstevel@tonic-gate inet_ntoa(ospf->ospf_areaid),
577*7c478bd9Sstevel@tonic-gate ntohs((ushort_t)ospf->ospf_len));
578*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
579*7c478bd9Sstevel@tonic-gate }
580*7c478bd9Sstevel@tonic-gate
581*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
582*7c478bd9Sstevel@tonic-gate show_header("OSPF: ", "OSPF Header", fraglen);
583*7c478bd9Sstevel@tonic-gate show_space();
584*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
585*7c478bd9Sstevel@tonic-gate "Version = %d", ospf->ospf_version);
586*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
587*7c478bd9Sstevel@tonic-gate "Type = %s", ospf_types[ospf->ospf_type]);
588*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
589*7c478bd9Sstevel@tonic-gate "Router ID = %s", inet_ntoa(ospf->ospf_routerid));
590*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
591*7c478bd9Sstevel@tonic-gate "Area ID = %s", inet_ntoa(ospf->ospf_areaid));
592*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
593*7c478bd9Sstevel@tonic-gate "Checksum = 0x%x", ospf->ospf_chksum);
594*7c478bd9Sstevel@tonic-gate
595*7c478bd9Sstevel@tonic-gate if (ospf->ospf_authtype > OSPF_AUTH_TYPE_MAX) {
596*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
597*7c478bd9Sstevel@tonic-gate "Auth = %d (unknown auth type)",
598*7c478bd9Sstevel@tonic-gate ospf->ospf_authtype);
599*7c478bd9Sstevel@tonic-gate } else {
600*7c478bd9Sstevel@tonic-gate (void) snprintf(get_line(0, 0), get_line_remain(),
601*7c478bd9Sstevel@tonic-gate "Auth = %s", ospf_authtypes[ospf->ospf_authtype]);
602*7c478bd9Sstevel@tonic-gate }
603*7c478bd9Sstevel@tonic-gate }
604*7c478bd9Sstevel@tonic-gate
605*7c478bd9Sstevel@tonic-gate if (ospf->ospf_version != 2) {
606*7c478bd9Sstevel@tonic-gate if (ospf->ospf_version == 3) {
607*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL)
608*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
609*7c478bd9Sstevel@tonic-gate "ospfv3 packet in ipv4 header");
610*7c478bd9Sstevel@tonic-gate return (interpret_ospf6(flags, ospf, iplen, fraglen));
611*7c478bd9Sstevel@tonic-gate } else {
612*7c478bd9Sstevel@tonic-gate return (fraglen);
613*7c478bd9Sstevel@tonic-gate }
614*7c478bd9Sstevel@tonic-gate }
615*7c478bd9Sstevel@tonic-gate
616*7c478bd9Sstevel@tonic-gate switch (ospf->ospf_type) {
617*7c478bd9Sstevel@tonic-gate case OSPF_TYPE_HELLO:
618*7c478bd9Sstevel@tonic-gate if (interpret_ospf_hello(flags, ospf, fraglen) < 0)
619*7c478bd9Sstevel@tonic-gate trunc = B_TRUE;
620*7c478bd9Sstevel@tonic-gate break;
621*7c478bd9Sstevel@tonic-gate
622*7c478bd9Sstevel@tonic-gate case OSPF_TYPE_DB:
623*7c478bd9Sstevel@tonic-gate if (fraglen < OSPF_MIN_HEADER_SIZE + OSPF_MIN_DB_HEADER_SIZE) {
624*7c478bd9Sstevel@tonic-gate trunc = B_TRUE;
625*7c478bd9Sstevel@tonic-gate break;
626*7c478bd9Sstevel@tonic-gate }
627*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
628*7c478bd9Sstevel@tonic-gate sprintf(sum_line, " %s %s S %X", ospf_print_bits(
629*7c478bd9Sstevel@tonic-gate ospf_option_bits, ospf->ospf_db.db_options),
630*7c478bd9Sstevel@tonic-gate ospf_print_bits(ospf_db_flags_bits,
631*7c478bd9Sstevel@tonic-gate ospf->ospf_db.db_flags),
632*7c478bd9Sstevel@tonic-gate ntohl(ospf->ospf_db.db_seq));
633*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
634*7c478bd9Sstevel@tonic-gate }
635*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
636*7c478bd9Sstevel@tonic-gate show_header("OSPF DB: ", "Database Description Packet",
637*7c478bd9Sstevel@tonic-gate fraglen);
638*7c478bd9Sstevel@tonic-gate show_space();
639*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
640*7c478bd9Sstevel@tonic-gate "Options = %s", ospf_print_bits(
641*7c478bd9Sstevel@tonic-gate ospf_option_bits, ospf->ospf_db.db_options));
642*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
643*7c478bd9Sstevel@tonic-gate "Flags = %s", ospf_print_bits(
644*7c478bd9Sstevel@tonic-gate ospf_db_flags_bits, ospf->ospf_db.db_flags));
645*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
646*7c478bd9Sstevel@tonic-gate "Sequence = 0x%X", ntohl(ospf->ospf_db.db_seq));
647*7c478bd9Sstevel@tonic-gate /* Print all the LS advs */
648*7c478bd9Sstevel@tonic-gate lsah = ospf->ospf_db.db_lshdr;
649*7c478bd9Sstevel@tonic-gate while ((uchar_t *)lsah < ((uchar_t *)ospf + fraglen)) {
650*7c478bd9Sstevel@tonic-gate if ((uchar_t *)lsah + sizeof (struct lsa_hdr) >
651*7c478bd9Sstevel@tonic-gate ((uchar_t *)ospf + fraglen)) {
652*7c478bd9Sstevel@tonic-gate trunc = B_TRUE;
653*7c478bd9Sstevel@tonic-gate break;
654*7c478bd9Sstevel@tonic-gate }
655*7c478bd9Sstevel@tonic-gate interpret_ospf_lsa_hdr(flags, lsah);
656*7c478bd9Sstevel@tonic-gate ++lsah;
657*7c478bd9Sstevel@tonic-gate }
658*7c478bd9Sstevel@tonic-gate }
659*7c478bd9Sstevel@tonic-gate break;
660*7c478bd9Sstevel@tonic-gate
661*7c478bd9Sstevel@tonic-gate case OSPF_TYPE_LSR:
662*7c478bd9Sstevel@tonic-gate if (fraglen < OSPF_MIN_HEADER_SIZE + OSPF_MIN_LSR_HEADER_SIZE) {
663*7c478bd9Sstevel@tonic-gate trunc = B_TRUE;
664*7c478bd9Sstevel@tonic-gate break;
665*7c478bd9Sstevel@tonic-gate }
666*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
667*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
668*7c478bd9Sstevel@tonic-gate "Link State Request Packet");
669*7c478bd9Sstevel@tonic-gate }
670*7c478bd9Sstevel@tonic-gate lsr = ospf->ospf_lsr;
671*7c478bd9Sstevel@tonic-gate while ((uchar_t *)lsr < ((uchar_t *)ospf + fraglen)) {
672*7c478bd9Sstevel@tonic-gate if ((uchar_t *)lsr + sizeof (struct lsr) >
673*7c478bd9Sstevel@tonic-gate ((uchar_t *)ospf + fraglen)) {
674*7c478bd9Sstevel@tonic-gate trunc = B_TRUE;
675*7c478bd9Sstevel@tonic-gate break;
676*7c478bd9Sstevel@tonic-gate }
677*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
678*7c478bd9Sstevel@tonic-gate nlsah++;
679*7c478bd9Sstevel@tonic-gate }
680*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
681*7c478bd9Sstevel@tonic-gate ospf_print_ls_type(flags, ntohl(lsr->ls_type),
682*7c478bd9Sstevel@tonic-gate lsr->ls_stateid, lsr->ls_router);
683*7c478bd9Sstevel@tonic-gate }
684*7c478bd9Sstevel@tonic-gate ++lsr;
685*7c478bd9Sstevel@tonic-gate }
686*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
687*7c478bd9Sstevel@tonic-gate sprintf(sum_line, " %d LSAs", nlsah);
688*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
689*7c478bd9Sstevel@tonic-gate }
690*7c478bd9Sstevel@tonic-gate break;
691*7c478bd9Sstevel@tonic-gate
692*7c478bd9Sstevel@tonic-gate case OSPF_TYPE_LSU:
693*7c478bd9Sstevel@tonic-gate if (fraglen < OSPF_MIN_HEADER_SIZE + OSPF_MIN_LSU_HEADER_SIZE) {
694*7c478bd9Sstevel@tonic-gate trunc = B_TRUE;
695*7c478bd9Sstevel@tonic-gate break;
696*7c478bd9Sstevel@tonic-gate }
697*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
698*7c478bd9Sstevel@tonic-gate show_header("OSPF LSU: ", "Link State Update Packet",
699*7c478bd9Sstevel@tonic-gate fraglen);
700*7c478bd9Sstevel@tonic-gate show_space();
701*7c478bd9Sstevel@tonic-gate }
702*7c478bd9Sstevel@tonic-gate lsa = ospf->ospf_lsu.lsu_lsa;
703*7c478bd9Sstevel@tonic-gate nlsa = ntohl(ospf->ospf_lsu.lsu_count);
704*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
705*7c478bd9Sstevel@tonic-gate sprintf(sum_line, "%d LSAs", nlsa);
706*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
707*7c478bd9Sstevel@tonic-gate break;
708*7c478bd9Sstevel@tonic-gate }
709*7c478bd9Sstevel@tonic-gate while (nlsa-- != 0) {
710*7c478bd9Sstevel@tonic-gate uchar_t *fragend = (uchar_t *)ospf + fraglen;
711*7c478bd9Sstevel@tonic-gate if (((uchar_t *)lsa >= fragend) ||
712*7c478bd9Sstevel@tonic-gate ((uchar_t *)lsa + sizeof (struct lsa_hdr) >
713*7c478bd9Sstevel@tonic-gate fragend) ||
714*7c478bd9Sstevel@tonic-gate ((uchar_t *)lsa + ntohs(lsa->ls_hdr.ls_length) >
715*7c478bd9Sstevel@tonic-gate fragend)) {
716*7c478bd9Sstevel@tonic-gate trunc = B_TRUE;
717*7c478bd9Sstevel@tonic-gate break;
718*7c478bd9Sstevel@tonic-gate }
719*7c478bd9Sstevel@tonic-gate
720*7c478bd9Sstevel@tonic-gate if (interpret_ospf_lsa(flags, lsa, fragend) < 0) {
721*7c478bd9Sstevel@tonic-gate trunc = B_TRUE;
722*7c478bd9Sstevel@tonic-gate break;
723*7c478bd9Sstevel@tonic-gate }
724*7c478bd9Sstevel@tonic-gate lsa = (struct lsa *)((uchar_t *)lsa +
725*7c478bd9Sstevel@tonic-gate ntohs(lsa->ls_hdr.ls_length));
726*7c478bd9Sstevel@tonic-gate }
727*7c478bd9Sstevel@tonic-gate
728*7c478bd9Sstevel@tonic-gate break;
729*7c478bd9Sstevel@tonic-gate
730*7c478bd9Sstevel@tonic-gate case OSPF_TYPE_LSA:
731*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL) {
732*7c478bd9Sstevel@tonic-gate show_header("OSPF LSA: ", "Link State Ack Packet",
733*7c478bd9Sstevel@tonic-gate fraglen);
734*7c478bd9Sstevel@tonic-gate show_space();
735*7c478bd9Sstevel@tonic-gate }
736*7c478bd9Sstevel@tonic-gate lsah = ospf->ospf_lsa.lsa_lshdr;
737*7c478bd9Sstevel@tonic-gate nlsah = 0;
738*7c478bd9Sstevel@tonic-gate while ((uchar_t *)lsah < ((uchar_t *)ospf + fraglen)) {
739*7c478bd9Sstevel@tonic-gate if ((uchar_t *)lsah + sizeof (struct lsa_hdr) >
740*7c478bd9Sstevel@tonic-gate ((uchar_t *)ospf + fraglen)) {
741*7c478bd9Sstevel@tonic-gate trunc = B_TRUE;
742*7c478bd9Sstevel@tonic-gate break;
743*7c478bd9Sstevel@tonic-gate }
744*7c478bd9Sstevel@tonic-gate nlsah++;
745*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL)
746*7c478bd9Sstevel@tonic-gate interpret_ospf_lsa_hdr(flags, lsah);
747*7c478bd9Sstevel@tonic-gate ++lsah;
748*7c478bd9Sstevel@tonic-gate }
749*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
750*7c478bd9Sstevel@tonic-gate sprintf(sum_line, "%d LSAs", nlsah);
751*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
752*7c478bd9Sstevel@tonic-gate }
753*7c478bd9Sstevel@tonic-gate break;
754*7c478bd9Sstevel@tonic-gate
755*7c478bd9Sstevel@tonic-gate default:
756*7c478bd9Sstevel@tonic-gate /* NOTREACHED */
757*7c478bd9Sstevel@tonic-gate break;
758*7c478bd9Sstevel@tonic-gate }
759*7c478bd9Sstevel@tonic-gate if (trunc) {
760*7c478bd9Sstevel@tonic-gate if (flags & F_SUM) {
761*7c478bd9Sstevel@tonic-gate sprintf(sum_line, "--truncated");
762*7c478bd9Sstevel@tonic-gate sum_line += strlen(sum_line);
763*7c478bd9Sstevel@tonic-gate }
764*7c478bd9Sstevel@tonic-gate if (flags & F_DTAIL)
765*7c478bd9Sstevel@tonic-gate snprintf(get_line(0, 0), get_line_remain(),
766*7c478bd9Sstevel@tonic-gate "--truncated");
767*7c478bd9Sstevel@tonic-gate }
768*7c478bd9Sstevel@tonic-gate
769*7c478bd9Sstevel@tonic-gate return (fraglen);
770*7c478bd9Sstevel@tonic-gate }
771