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