print-ospf.c revision 1.7 1 1.1 christos /*
2 1.1 christos * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 1.1 christos * The Regents of the University of California. All rights reserved.
4 1.1 christos *
5 1.1 christos * Redistribution and use in source and binary forms, with or without
6 1.1 christos * modification, are permitted provided that: (1) source code distributions
7 1.1 christos * retain the above copyright notice and this paragraph in its entirety, (2)
8 1.1 christos * distributions including binary code include the above copyright notice and
9 1.1 christos * this paragraph in its entirety in the documentation or other materials
10 1.1 christos * provided with the distribution, and (3) all advertising materials mentioning
11 1.1 christos * features or use of this software display the following acknowledgement:
12 1.1 christos * ``This product includes software developed by the University of California,
13 1.1 christos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 1.1 christos * the University nor the names of its contributors may be used to endorse
15 1.1 christos * or promote products derived from this software without specific prior
16 1.1 christos * written permission.
17 1.1 christos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 1.1 christos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 1.1 christos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 1.1 christos *
21 1.1 christos * OSPF support contributed by Jeffrey Honig (jch (at) mitchell.cit.cornell.edu)
22 1.1 christos */
23 1.1 christos
24 1.2 christos #include <sys/cdefs.h>
25 1.1 christos #ifndef lint
26 1.7 christos __RCSID("$NetBSD: print-ospf.c,v 1.7 2017/01/24 23:29:14 christos Exp $");
27 1.1 christos #endif
28 1.1 christos
29 1.1 christos #ifdef HAVE_CONFIG_H
30 1.1 christos #include "config.h"
31 1.1 christos #endif
32 1.1 christos
33 1.7 christos #include <netdissect-stdinc.h>
34 1.1 christos
35 1.7 christos #include "netdissect.h"
36 1.1 christos #include "addrtoname.h"
37 1.1 christos #include "extract.h"
38 1.1 christos #include "gmpls.h"
39 1.1 christos
40 1.1 christos #include "ospf.h"
41 1.1 christos
42 1.5 christos static const char tstr[] = " [|ospf2]";
43 1.1 christos
44 1.4 christos static const struct tok ospf_option_values[] = {
45 1.1 christos { OSPF_OPTION_T, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
46 1.1 christos { OSPF_OPTION_E, "External" },
47 1.1 christos { OSPF_OPTION_MC, "Multicast" },
48 1.1 christos { OSPF_OPTION_NP, "NSSA" },
49 1.1 christos { OSPF_OPTION_L, "LLS" },
50 1.1 christos { OSPF_OPTION_DC, "Demand Circuit" },
51 1.1 christos { OSPF_OPTION_O, "Opaque" },
52 1.1 christos { OSPF_OPTION_DN, "Up/Down" },
53 1.1 christos { 0, NULL }
54 1.1 christos };
55 1.1 christos
56 1.4 christos static const struct tok ospf_authtype_values[] = {
57 1.1 christos { OSPF_AUTH_NONE, "none" },
58 1.1 christos { OSPF_AUTH_SIMPLE, "simple" },
59 1.1 christos { OSPF_AUTH_MD5, "MD5" },
60 1.1 christos { 0, NULL }
61 1.1 christos };
62 1.1 christos
63 1.4 christos static const struct tok ospf_rla_flag_values[] = {
64 1.1 christos { RLA_FLAG_B, "ABR" },
65 1.1 christos { RLA_FLAG_E, "ASBR" },
66 1.1 christos { RLA_FLAG_W1, "Virtual" },
67 1.1 christos { RLA_FLAG_W2, "W2" },
68 1.1 christos { 0, NULL }
69 1.1 christos };
70 1.1 christos
71 1.4 christos static const struct tok type2str[] = {
72 1.1 christos { OSPF_TYPE_UMD, "UMD" },
73 1.1 christos { OSPF_TYPE_HELLO, "Hello" },
74 1.1 christos { OSPF_TYPE_DD, "Database Description" },
75 1.1 christos { OSPF_TYPE_LS_REQ, "LS-Request" },
76 1.1 christos { OSPF_TYPE_LS_UPDATE, "LS-Update" },
77 1.1 christos { OSPF_TYPE_LS_ACK, "LS-Ack" },
78 1.1 christos { 0, NULL }
79 1.1 christos };
80 1.1 christos
81 1.4 christos static const struct tok lsa_values[] = {
82 1.1 christos { LS_TYPE_ROUTER, "Router" },
83 1.1 christos { LS_TYPE_NETWORK, "Network" },
84 1.1 christos { LS_TYPE_SUM_IP, "Summary" },
85 1.1 christos { LS_TYPE_SUM_ABR, "ASBR Summary" },
86 1.1 christos { LS_TYPE_ASE, "External" },
87 1.1 christos { LS_TYPE_GROUP, "Multicast Group" },
88 1.1 christos { LS_TYPE_NSSA, "NSSA" },
89 1.1 christos { LS_TYPE_OPAQUE_LL, "Link Local Opaque" },
90 1.1 christos { LS_TYPE_OPAQUE_AL, "Area Local Opaque" },
91 1.1 christos { LS_TYPE_OPAQUE_DW, "Domain Wide Opaque" },
92 1.1 christos { 0, NULL }
93 1.1 christos };
94 1.1 christos
95 1.4 christos static const struct tok ospf_dd_flag_values[] = {
96 1.1 christos { OSPF_DB_INIT, "Init" },
97 1.1 christos { OSPF_DB_MORE, "More" },
98 1.1 christos { OSPF_DB_MASTER, "Master" },
99 1.1 christos { OSPF_DB_RESYNC, "OOBResync" },
100 1.1 christos { 0, NULL }
101 1.1 christos };
102 1.1 christos
103 1.4 christos static const struct tok lsa_opaque_values[] = {
104 1.1 christos { LS_OPAQUE_TYPE_TE, "Traffic Engineering" },
105 1.1 christos { LS_OPAQUE_TYPE_GRACE, "Graceful restart" },
106 1.1 christos { LS_OPAQUE_TYPE_RI, "Router Information" },
107 1.1 christos { 0, NULL }
108 1.1 christos };
109 1.1 christos
110 1.4 christos static const struct tok lsa_opaque_te_tlv_values[] = {
111 1.1 christos { LS_OPAQUE_TE_TLV_ROUTER, "Router Address" },
112 1.1 christos { LS_OPAQUE_TE_TLV_LINK, "Link" },
113 1.1 christos { 0, NULL }
114 1.1 christos };
115 1.1 christos
116 1.4 christos static const struct tok lsa_opaque_te_link_tlv_subtlv_values[] = {
117 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE, "Link Type" },
118 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID, "Link ID" },
119 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP, "Local Interface IP address" },
120 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP, "Remote Interface IP address" },
121 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC, "Traffic Engineering Metric" },
122 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW, "Maximum Bandwidth" },
123 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW, "Maximum Reservable Bandwidth" },
124 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW, "Unreserved Bandwidth" },
125 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP, "Administrative Group" },
126 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
127 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE, "Link Protection Type" },
128 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
129 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP, "Shared Risk Link Group" },
130 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS, "Bandwidth Constraints" },
131 1.1 christos { 0, NULL }
132 1.1 christos };
133 1.1 christos
134 1.4 christos static const struct tok lsa_opaque_grace_tlv_values[] = {
135 1.1 christos { LS_OPAQUE_GRACE_TLV_PERIOD, "Grace Period" },
136 1.1 christos { LS_OPAQUE_GRACE_TLV_REASON, "Graceful restart Reason" },
137 1.1 christos { LS_OPAQUE_GRACE_TLV_INT_ADDRESS, "IPv4 interface address" },
138 1.1 christos { 0, NULL }
139 1.1 christos };
140 1.1 christos
141 1.4 christos static const struct tok lsa_opaque_grace_tlv_reason_values[] = {
142 1.1 christos { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN, "Unknown" },
143 1.1 christos { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART, "Software Restart" },
144 1.1 christos { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE, "Software Reload/Upgrade" },
145 1.1 christos { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH, "Control Processor Switch" },
146 1.1 christos { 0, NULL }
147 1.1 christos };
148 1.1 christos
149 1.4 christos static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = {
150 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP, "Point-to-point" },
151 1.1 christos { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA, "Multi-Access" },
152 1.1 christos { 0, NULL }
153 1.1 christos };
154 1.1 christos
155 1.4 christos static const struct tok lsa_opaque_ri_tlv_values[] = {
156 1.1 christos { LS_OPAQUE_RI_TLV_CAP, "Router Capabilities" },
157 1.1 christos { 0, NULL }
158 1.1 christos };
159 1.1 christos
160 1.4 christos static const struct tok lsa_opaque_ri_tlv_cap_values[] = {
161 1.1 christos { 1, "Reserved" },
162 1.1 christos { 2, "Reserved" },
163 1.1 christos { 4, "Reserved" },
164 1.1 christos { 8, "Reserved" },
165 1.1 christos { 16, "graceful restart capable" },
166 1.1 christos { 32, "graceful restart helper" },
167 1.1 christos { 64, "Stub router support" },
168 1.1 christos { 128, "Traffic engineering" },
169 1.1 christos { 256, "p2p over LAN" },
170 1.1 christos { 512, "path computation server" },
171 1.1 christos { 0, NULL }
172 1.1 christos };
173 1.1 christos
174 1.4 christos static const struct tok ospf_lls_tlv_values[] = {
175 1.1 christos { OSPF_LLS_EO, "Extended Options" },
176 1.1 christos { OSPF_LLS_MD5, "MD5 Authentication" },
177 1.1 christos { 0, NULL }
178 1.1 christos };
179 1.1 christos
180 1.4 christos static const struct tok ospf_lls_eo_options[] = {
181 1.1 christos { OSPF_LLS_EO_LR, "LSDB resync" },
182 1.1 christos { OSPF_LLS_EO_RS, "Restart" },
183 1.1 christos { 0, NULL }
184 1.1 christos };
185 1.1 christos
186 1.1 christos int
187 1.5 christos ospf_print_grace_lsa(netdissect_options *ndo,
188 1.6 christos const uint8_t *tptr, u_int ls_length)
189 1.6 christos {
190 1.1 christos u_int tlv_type, tlv_length;
191 1.1 christos
192 1.1 christos
193 1.1 christos while (ls_length > 0) {
194 1.5 christos ND_TCHECK2(*tptr, 4);
195 1.1 christos if (ls_length < 4) {
196 1.5 christos ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
197 1.1 christos return -1;
198 1.1 christos }
199 1.1 christos tlv_type = EXTRACT_16BITS(tptr);
200 1.1 christos tlv_length = EXTRACT_16BITS(tptr+2);
201 1.1 christos tptr+=4;
202 1.1 christos ls_length-=4;
203 1.5 christos
204 1.5 christos ND_PRINT((ndo, "\n\t %s TLV (%u), length %u, value: ",
205 1.1 christos tok2str(lsa_opaque_grace_tlv_values,"unknown",tlv_type),
206 1.1 christos tlv_type,
207 1.5 christos tlv_length));
208 1.1 christos
209 1.1 christos if (tlv_length > ls_length) {
210 1.5 christos ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
211 1.5 christos ls_length));
212 1.1 christos return -1;
213 1.1 christos }
214 1.1 christos
215 1.1 christos /* Infinite loop protection. */
216 1.1 christos if (tlv_type == 0 || tlv_length ==0) {
217 1.1 christos return -1;
218 1.1 christos }
219 1.1 christos
220 1.5 christos ND_TCHECK2(*tptr, tlv_length);
221 1.1 christos switch(tlv_type) {
222 1.1 christos
223 1.1 christos case LS_OPAQUE_GRACE_TLV_PERIOD:
224 1.1 christos if (tlv_length != 4) {
225 1.5 christos ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
226 1.1 christos return -1;
227 1.1 christos }
228 1.5 christos ND_PRINT((ndo, "%us", EXTRACT_32BITS(tptr)));
229 1.1 christos break;
230 1.1 christos
231 1.1 christos case LS_OPAQUE_GRACE_TLV_REASON:
232 1.1 christos if (tlv_length != 1) {
233 1.5 christos ND_PRINT((ndo, "\n\t Bogus length %u != 1", tlv_length));
234 1.1 christos return -1;
235 1.1 christos }
236 1.5 christos ND_PRINT((ndo, "%s (%u)",
237 1.1 christos tok2str(lsa_opaque_grace_tlv_reason_values, "Unknown", *tptr),
238 1.5 christos *tptr));
239 1.1 christos break;
240 1.1 christos
241 1.1 christos case LS_OPAQUE_GRACE_TLV_INT_ADDRESS:
242 1.1 christos if (tlv_length != 4) {
243 1.5 christos ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
244 1.1 christos return -1;
245 1.1 christos }
246 1.5 christos ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
247 1.1 christos break;
248 1.1 christos
249 1.1 christos default:
250 1.5 christos if (ndo->ndo_vflag <= 1) {
251 1.5 christos if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
252 1.1 christos return -1;
253 1.1 christos }
254 1.1 christos break;
255 1.1 christos
256 1.1 christos }
257 1.1 christos /* in OSPF everything has to be 32-bit aligned, including TLVs */
258 1.1 christos if (tlv_length%4 != 0)
259 1.1 christos tlv_length+=4-(tlv_length%4);
260 1.1 christos ls_length-=tlv_length;
261 1.1 christos tptr+=tlv_length;
262 1.1 christos }
263 1.1 christos
264 1.1 christos return 0;
265 1.1 christos trunc:
266 1.1 christos return -1;
267 1.1 christos }
268 1.1 christos
269 1.1 christos int
270 1.5 christos ospf_print_te_lsa(netdissect_options *ndo,
271 1.6 christos const uint8_t *tptr, u_int ls_length)
272 1.6 christos {
273 1.1 christos u_int tlv_type, tlv_length, subtlv_type, subtlv_length;
274 1.1 christos u_int priority_level, te_class, count_srlg;
275 1.1 christos union { /* int to float conversion buffer for several subTLVs */
276 1.5 christos float f;
277 1.5 christos uint32_t i;
278 1.1 christos } bw;
279 1.1 christos
280 1.1 christos while (ls_length != 0) {
281 1.5 christos ND_TCHECK2(*tptr, 4);
282 1.1 christos if (ls_length < 4) {
283 1.5 christos ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
284 1.1 christos return -1;
285 1.1 christos }
286 1.1 christos tlv_type = EXTRACT_16BITS(tptr);
287 1.1 christos tlv_length = EXTRACT_16BITS(tptr+2);
288 1.1 christos tptr+=4;
289 1.1 christos ls_length-=4;
290 1.5 christos
291 1.5 christos ND_PRINT((ndo, "\n\t %s TLV (%u), length: %u",
292 1.1 christos tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
293 1.1 christos tlv_type,
294 1.5 christos tlv_length));
295 1.1 christos
296 1.1 christos if (tlv_length > ls_length) {
297 1.5 christos ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
298 1.5 christos ls_length));
299 1.1 christos return -1;
300 1.1 christos }
301 1.1 christos
302 1.1 christos /* Infinite loop protection. */
303 1.1 christos if (tlv_type == 0 || tlv_length ==0) {
304 1.1 christos return -1;
305 1.1 christos }
306 1.1 christos
307 1.1 christos switch(tlv_type) {
308 1.1 christos case LS_OPAQUE_TE_TLV_LINK:
309 1.1 christos while (tlv_length >= sizeof(subtlv_type) + sizeof(subtlv_length)) {
310 1.1 christos if (tlv_length < 4) {
311 1.5 christos ND_PRINT((ndo, "\n\t Remaining TLV length %u < 4",
312 1.5 christos tlv_length));
313 1.1 christos return -1;
314 1.1 christos }
315 1.5 christos ND_TCHECK2(*tptr, 4);
316 1.1 christos subtlv_type = EXTRACT_16BITS(tptr);
317 1.1 christos subtlv_length = EXTRACT_16BITS(tptr+2);
318 1.1 christos tptr+=4;
319 1.1 christos tlv_length-=4;
320 1.5 christos
321 1.7 christos /* Infinite loop protection */
322 1.7 christos if (subtlv_type == 0 || subtlv_length == 0)
323 1.7 christos goto invalid;
324 1.7 christos
325 1.5 christos ND_PRINT((ndo, "\n\t %s subTLV (%u), length: %u",
326 1.1 christos tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type),
327 1.1 christos subtlv_type,
328 1.5 christos subtlv_length));
329 1.5 christos
330 1.5 christos ND_TCHECK2(*tptr, subtlv_length);
331 1.1 christos switch(subtlv_type) {
332 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
333 1.7 christos if (subtlv_length != 4) {
334 1.7 christos ND_PRINT((ndo, " != 4"));
335 1.7 christos goto invalid;
336 1.7 christos }
337 1.5 christos ND_PRINT((ndo, ", 0x%08x", EXTRACT_32BITS(tptr)));
338 1.1 christos break;
339 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
340 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
341 1.7 christos if (subtlv_length != 4 && subtlv_length != 8) {
342 1.7 christos ND_PRINT((ndo, " != 4 && != 8"));
343 1.7 christos goto invalid;
344 1.7 christos }
345 1.5 christos ND_PRINT((ndo, ", %s (0x%08x)",
346 1.5 christos ipaddr_string(ndo, tptr),
347 1.5 christos EXTRACT_32BITS(tptr)));
348 1.1 christos if (subtlv_length == 8) /* rfc4203 */
349 1.5 christos ND_PRINT((ndo, ", %s (0x%08x)",
350 1.5 christos ipaddr_string(ndo, tptr+4),
351 1.5 christos EXTRACT_32BITS(tptr + 4)));
352 1.1 christos break;
353 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
354 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
355 1.7 christos if (subtlv_length != 4) {
356 1.7 christos ND_PRINT((ndo, " != 4"));
357 1.7 christos goto invalid;
358 1.7 christos }
359 1.5 christos ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr)));
360 1.1 christos break;
361 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
362 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
363 1.7 christos if (subtlv_length != 4) {
364 1.7 christos ND_PRINT((ndo, " != 4"));
365 1.7 christos goto invalid;
366 1.7 christos }
367 1.1 christos bw.i = EXTRACT_32BITS(tptr);
368 1.5 christos ND_PRINT((ndo, ", %.3f Mbps", bw.f * 8 / 1000000));
369 1.1 christos break;
370 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
371 1.7 christos if (subtlv_length != 32) {
372 1.7 christos ND_PRINT((ndo, " != 32"));
373 1.7 christos goto invalid;
374 1.7 christos }
375 1.1 christos for (te_class = 0; te_class < 8; te_class++) {
376 1.1 christos bw.i = EXTRACT_32BITS(tptr+te_class*4);
377 1.5 christos ND_PRINT((ndo, "\n\t\tTE-Class %u: %.3f Mbps",
378 1.1 christos te_class,
379 1.5 christos bw.f * 8 / 1000000));
380 1.1 christos }
381 1.1 christos break;
382 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS:
383 1.7 christos if (subtlv_length < 4) {
384 1.7 christos ND_PRINT((ndo, " < 4"));
385 1.7 christos goto invalid;
386 1.7 christos }
387 1.7 christos /* BC Model Id (1 octet) + Reserved (3 octets) */
388 1.5 christos ND_PRINT((ndo, "\n\t\tBandwidth Constraints Model ID: %s (%u)",
389 1.1 christos tok2str(diffserv_te_bc_values, "unknown", *tptr),
390 1.5 christos *tptr));
391 1.7 christos if (subtlv_length % 4 != 0) {
392 1.7 christos ND_PRINT((ndo, "\n\t\tlength %u != N x 4", subtlv_length));
393 1.7 christos goto invalid;
394 1.7 christos }
395 1.7 christos if (subtlv_length > 36) {
396 1.7 christos ND_PRINT((ndo, "\n\t\tlength %u > 36", subtlv_length));
397 1.7 christos goto invalid;
398 1.7 christos }
399 1.1 christos /* decode BCs until the subTLV ends */
400 1.1 christos for (te_class = 0; te_class < (subtlv_length-4)/4; te_class++) {
401 1.1 christos bw.i = EXTRACT_32BITS(tptr+4+te_class*4);
402 1.5 christos ND_PRINT((ndo, "\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
403 1.1 christos te_class,
404 1.5 christos bw.f * 8 / 1000000));
405 1.1 christos }
406 1.1 christos break;
407 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
408 1.7 christos if (subtlv_length != 4) {
409 1.7 christos ND_PRINT((ndo, " != 4"));
410 1.7 christos goto invalid;
411 1.7 christos }
412 1.5 christos ND_PRINT((ndo, ", Metric %u", EXTRACT_32BITS(tptr)));
413 1.1 christos break;
414 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
415 1.7 christos /* Protection Cap (1 octet) + Reserved ((3 octets) */
416 1.7 christos if (subtlv_length != 4) {
417 1.7 christos ND_PRINT((ndo, " != 4"));
418 1.7 christos goto invalid;
419 1.7 christos }
420 1.7 christos ND_PRINT((ndo, ", %s",
421 1.7 christos bittok2str(gmpls_link_prot_values, "none", *tptr)));
422 1.1 christos break;
423 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
424 1.7 christos if (subtlv_length < 36) {
425 1.7 christos ND_PRINT((ndo, " < 36"));
426 1.7 christos goto invalid;
427 1.7 christos }
428 1.7 christos /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
429 1.5 christos ND_PRINT((ndo, "\n\t\tInterface Switching Capability: %s",
430 1.5 christos tok2str(gmpls_switch_cap_values, "Unknown", *(tptr))));
431 1.5 christos ND_PRINT((ndo, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
432 1.5 christos tok2str(gmpls_encoding_values, "Unknown", *(tptr + 1))));
433 1.1 christos for (priority_level = 0; priority_level < 8; priority_level++) {
434 1.1 christos bw.i = EXTRACT_32BITS(tptr+4+(priority_level*4));
435 1.5 christos ND_PRINT((ndo, "\n\t\t priority level %d: %.3f Mbps",
436 1.1 christos priority_level,
437 1.5 christos bw.f * 8 / 1000000));
438 1.1 christos }
439 1.1 christos break;
440 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
441 1.7 christos if (subtlv_length != 1) {
442 1.7 christos ND_PRINT((ndo, " != 1"));
443 1.7 christos goto invalid;
444 1.7 christos }
445 1.5 christos ND_PRINT((ndo, ", %s (%u)",
446 1.1 christos tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",*tptr),
447 1.5 christos *tptr));
448 1.1 christos break;
449 1.1 christos
450 1.1 christos case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
451 1.7 christos if (subtlv_length % 4 != 0) {
452 1.7 christos ND_PRINT((ndo, " != N x 4"));
453 1.7 christos goto invalid;
454 1.7 christos }
455 1.1 christos count_srlg = subtlv_length / 4;
456 1.1 christos if (count_srlg != 0)
457 1.5 christos ND_PRINT((ndo, "\n\t\t Shared risk group: "));
458 1.1 christos while (count_srlg > 0) {
459 1.1 christos bw.i = EXTRACT_32BITS(tptr);
460 1.5 christos ND_PRINT((ndo, "%d", bw.i));
461 1.1 christos tptr+=4;
462 1.1 christos count_srlg--;
463 1.1 christos if (count_srlg > 0)
464 1.5 christos ND_PRINT((ndo, ", "));
465 1.1 christos }
466 1.1 christos break;
467 1.1 christos
468 1.1 christos default:
469 1.5 christos if (ndo->ndo_vflag <= 1) {
470 1.5 christos if (!print_unknown_data(ndo, tptr, "\n\t\t", subtlv_length))
471 1.1 christos return -1;
472 1.1 christos }
473 1.1 christos break;
474 1.1 christos }
475 1.1 christos /* in OSPF everything has to be 32-bit aligned, including subTLVs */
476 1.1 christos if (subtlv_length%4 != 0)
477 1.1 christos subtlv_length+=4-(subtlv_length%4);
478 1.5 christos
479 1.1 christos tlv_length-=subtlv_length;
480 1.1 christos tptr+=subtlv_length;
481 1.5 christos
482 1.1 christos }
483 1.1 christos break;
484 1.5 christos
485 1.1 christos case LS_OPAQUE_TE_TLV_ROUTER:
486 1.1 christos if (tlv_length < 4) {
487 1.5 christos ND_PRINT((ndo, "\n\t TLV length %u < 4", tlv_length));
488 1.1 christos return -1;
489 1.1 christos }
490 1.5 christos ND_TCHECK2(*tptr, 4);
491 1.5 christos ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr)));
492 1.1 christos break;
493 1.5 christos
494 1.1 christos default:
495 1.5 christos if (ndo->ndo_vflag <= 1) {
496 1.5 christos if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
497 1.1 christos return -1;
498 1.1 christos }
499 1.1 christos break;
500 1.1 christos }
501 1.1 christos /* in OSPF everything has to be 32-bit aligned, including TLVs */
502 1.1 christos if (tlv_length%4 != 0)
503 1.1 christos tlv_length+=4-(tlv_length%4);
504 1.1 christos ls_length-=tlv_length;
505 1.1 christos tptr+=tlv_length;
506 1.1 christos }
507 1.1 christos return 0;
508 1.1 christos trunc:
509 1.1 christos return -1;
510 1.7 christos invalid:
511 1.7 christos ND_PRINT((ndo, "%s", istr));
512 1.7 christos return -1;
513 1.1 christos }
514 1.1 christos
515 1.1 christos static int
516 1.5 christos ospf_print_lshdr(netdissect_options *ndo,
517 1.5 christos register const struct lsa_hdr *lshp)
518 1.1 christos {
519 1.1 christos u_int ls_length;
520 1.1 christos
521 1.5 christos ND_TCHECK(lshp->ls_length);
522 1.1 christos ls_length = EXTRACT_16BITS(&lshp->ls_length);
523 1.1 christos if (ls_length < sizeof(struct lsa_hdr)) {
524 1.5 christos ND_PRINT((ndo, "\n\t Bogus length %u < header (%lu)", ls_length,
525 1.5 christos (unsigned long)sizeof(struct lsa_hdr)));
526 1.1 christos return(-1);
527 1.1 christos }
528 1.1 christos
529 1.5 christos ND_TCHECK(lshp->ls_seq); /* XXX - ls_length check checked this */
530 1.5 christos ND_PRINT((ndo, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
531 1.5 christos ipaddr_string(ndo, &lshp->ls_router),
532 1.5 christos EXTRACT_32BITS(&lshp->ls_seq),
533 1.5 christos EXTRACT_16BITS(&lshp->ls_age),
534 1.5 christos ls_length - (u_int)sizeof(struct lsa_hdr)));
535 1.1 christos
536 1.5 christos ND_TCHECK(lshp->ls_type); /* XXX - ls_length check checked this */
537 1.1 christos switch (lshp->ls_type) {
538 1.5 christos /* the LSA header for opaque LSAs was slightly changed */
539 1.1 christos case LS_TYPE_OPAQUE_LL:
540 1.1 christos case LS_TYPE_OPAQUE_AL:
541 1.1 christos case LS_TYPE_OPAQUE_DW:
542 1.5 christos ND_PRINT((ndo, "\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
543 1.1 christos tok2str(lsa_values,"unknown",lshp->ls_type),
544 1.1 christos lshp->ls_type,
545 1.1 christos
546 1.1 christos tok2str(lsa_opaque_values,
547 1.1 christos "unknown",
548 1.1 christos *(&lshp->un_lsa_id.opaque_field.opaque_type)),
549 1.1 christos *(&lshp->un_lsa_id.opaque_field.opaque_type),
550 1.1 christos EXTRACT_24BITS(&lshp->un_lsa_id.opaque_field.opaque_id)
551 1.5 christos
552 1.5 christos ));
553 1.1 christos break;
554 1.1 christos
555 1.5 christos /* all other LSA types use regular style LSA headers */
556 1.5 christos default:
557 1.5 christos ND_PRINT((ndo, "\n\t %s LSA (%d), LSA-ID: %s",
558 1.1 christos tok2str(lsa_values,"unknown",lshp->ls_type),
559 1.1 christos lshp->ls_type,
560 1.5 christos ipaddr_string(ndo, &lshp->un_lsa_id.lsa_id)));
561 1.1 christos break;
562 1.1 christos }
563 1.1 christos
564 1.5 christos ND_TCHECK(lshp->ls_options); /* XXX - ls_length check checked this */
565 1.5 christos ND_PRINT((ndo, "\n\t Options: [%s]", bittok2str(ospf_option_values, "none", lshp->ls_options)));
566 1.1 christos
567 1.1 christos return (ls_length);
568 1.1 christos trunc:
569 1.1 christos return (-1);
570 1.1 christos }
571 1.1 christos
572 1.1 christos /* draft-ietf-ospf-mt-09 */
573 1.4 christos static const struct tok ospf_topology_values[] = {
574 1.7 christos { 0, "default" },
575 1.7 christos { 1, "multicast" },
576 1.7 christos { 2, "management" },
577 1.1 christos { 0, NULL }
578 1.1 christos };
579 1.1 christos
580 1.1 christos /*
581 1.1 christos * Print all the per-topology metrics.
582 1.1 christos */
583 1.7 christos static int
584 1.5 christos ospf_print_tos_metrics(netdissect_options *ndo,
585 1.5 christos const union un_tos *tos)
586 1.1 christos {
587 1.1 christos int metric_count;
588 1.1 christos int toscount;
589 1.1 christos
590 1.1 christos toscount = tos->link.link_tos_count+1;
591 1.1 christos metric_count = 0;
592 1.1 christos
593 1.1 christos /*
594 1.1 christos * All but the first metric contain a valid topology id.
595 1.1 christos */
596 1.7 christos while (toscount > 0) {
597 1.7 christos ND_TCHECK(*tos);
598 1.7 christos ND_PRINT((ndo, "\n\t\ttopology %s (%u), metric %u",
599 1.7 christos tok2str(ospf_topology_values, "Unknown",
600 1.1 christos metric_count ? tos->metrics.tos_type : 0),
601 1.1 christos metric_count ? tos->metrics.tos_type : 0,
602 1.5 christos EXTRACT_16BITS(&tos->metrics.tos_metric)));
603 1.1 christos metric_count++;
604 1.1 christos tos++;
605 1.1 christos toscount--;
606 1.1 christos }
607 1.7 christos return 0;
608 1.7 christos trunc:
609 1.7 christos return 1;
610 1.1 christos }
611 1.1 christos
612 1.1 christos /*
613 1.1 christos * Print a single link state advertisement. If truncated or if LSA length
614 1.1 christos * field is less than the length of the LSA header, return NULl, else
615 1.1 christos * return pointer to data past end of LSA.
616 1.1 christos */
617 1.5 christos static const uint8_t *
618 1.5 christos ospf_print_lsa(netdissect_options *ndo,
619 1.5 christos register const struct lsa *lsap)
620 1.1 christos {
621 1.5 christos register const uint8_t *ls_end;
622 1.1 christos register const struct rlalink *rlp;
623 1.1 christos register const struct in_addr *ap;
624 1.1 christos register const struct aslametric *almp;
625 1.1 christos register const struct mcla *mcp;
626 1.5 christos register const uint32_t *lp;
627 1.1 christos register int j, tlv_type, tlv_length, topology;
628 1.1 christos register int ls_length;
629 1.5 christos const uint8_t *tptr;
630 1.1 christos
631 1.7 christos tptr = (const uint8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
632 1.5 christos ls_length = ospf_print_lshdr(ndo, &lsap->ls_hdr);
633 1.1 christos if (ls_length == -1)
634 1.1 christos return(NULL);
635 1.7 christos ls_end = (const uint8_t *)lsap + ls_length;
636 1.1 christos ls_length -= sizeof(struct lsa_hdr);
637 1.1 christos
638 1.1 christos switch (lsap->ls_hdr.ls_type) {
639 1.1 christos
640 1.1 christos case LS_TYPE_ROUTER:
641 1.5 christos ND_TCHECK(lsap->lsa_un.un_rla.rla_flags);
642 1.5 christos ND_PRINT((ndo, "\n\t Router LSA Options: [%s]",
643 1.5 christos bittok2str(ospf_rla_flag_values, "none", lsap->lsa_un.un_rla.rla_flags)));
644 1.1 christos
645 1.5 christos ND_TCHECK(lsap->lsa_un.un_rla.rla_count);
646 1.1 christos j = EXTRACT_16BITS(&lsap->lsa_un.un_rla.rla_count);
647 1.5 christos ND_TCHECK(lsap->lsa_un.un_rla.rla_link);
648 1.1 christos rlp = lsap->lsa_un.un_rla.rla_link;
649 1.1 christos while (j--) {
650 1.5 christos ND_TCHECK(*rlp);
651 1.1 christos switch (rlp->un_tos.link.link_type) {
652 1.1 christos
653 1.1 christos case RLA_TYPE_VIRTUAL:
654 1.5 christos ND_PRINT((ndo, "\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
655 1.5 christos ipaddr_string(ndo, &rlp->link_id),
656 1.5 christos ipaddr_string(ndo, &rlp->link_data)));
657 1.5 christos break;
658 1.1 christos
659 1.1 christos case RLA_TYPE_ROUTER:
660 1.5 christos ND_PRINT((ndo, "\n\t Neighbor Router-ID: %s, Interface Address: %s",
661 1.5 christos ipaddr_string(ndo, &rlp->link_id),
662 1.5 christos ipaddr_string(ndo, &rlp->link_data)));
663 1.1 christos break;
664 1.1 christos
665 1.1 christos case RLA_TYPE_TRANSIT:
666 1.5 christos ND_PRINT((ndo, "\n\t Neighbor Network-ID: %s, Interface Address: %s",
667 1.5 christos ipaddr_string(ndo, &rlp->link_id),
668 1.5 christos ipaddr_string(ndo, &rlp->link_data)));
669 1.1 christos break;
670 1.1 christos
671 1.1 christos case RLA_TYPE_STUB:
672 1.5 christos ND_PRINT((ndo, "\n\t Stub Network: %s, Mask: %s",
673 1.5 christos ipaddr_string(ndo, &rlp->link_id),
674 1.5 christos ipaddr_string(ndo, &rlp->link_data)));
675 1.1 christos break;
676 1.1 christos
677 1.1 christos default:
678 1.5 christos ND_PRINT((ndo, "\n\t Unknown Router Link Type (%u)",
679 1.5 christos rlp->un_tos.link.link_type));
680 1.1 christos return (ls_end);
681 1.1 christos }
682 1.1 christos
683 1.7 christos if (ospf_print_tos_metrics(ndo, &rlp->un_tos))
684 1.7 christos goto trunc;
685 1.1 christos
686 1.7 christos rlp = (const struct rlalink *)((const u_char *)(rlp + 1) +
687 1.1 christos ((rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
688 1.1 christos }
689 1.1 christos break;
690 1.1 christos
691 1.1 christos case LS_TYPE_NETWORK:
692 1.5 christos ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
693 1.5 christos ND_PRINT((ndo, "\n\t Mask %s\n\t Connected Routers:",
694 1.5 christos ipaddr_string(ndo, &lsap->lsa_un.un_nla.nla_mask)));
695 1.1 christos ap = lsap->lsa_un.un_nla.nla_router;
696 1.7 christos while ((const u_char *)ap < ls_end) {
697 1.5 christos ND_TCHECK(*ap);
698 1.5 christos ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
699 1.1 christos ++ap;
700 1.1 christos }
701 1.1 christos break;
702 1.1 christos
703 1.1 christos case LS_TYPE_SUM_IP:
704 1.5 christos ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
705 1.5 christos ND_PRINT((ndo, "\n\t Mask %s",
706 1.5 christos ipaddr_string(ndo, &lsap->lsa_un.un_sla.sla_mask)));
707 1.5 christos ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
708 1.1 christos lp = lsap->lsa_un.un_sla.sla_tosmetric;
709 1.7 christos while ((const u_char *)lp < ls_end) {
710 1.5 christos register uint32_t ul;
711 1.1 christos
712 1.5 christos ND_TCHECK(*lp);
713 1.1 christos ul = EXTRACT_32BITS(lp);
714 1.1 christos topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
715 1.7 christos ND_PRINT((ndo, "\n\t\ttopology %s (%u) metric %d",
716 1.7 christos tok2str(ospf_topology_values, "Unknown", topology),
717 1.1 christos topology,
718 1.5 christos ul & SLA_MASK_METRIC));
719 1.1 christos ++lp;
720 1.1 christos }
721 1.1 christos break;
722 1.1 christos
723 1.1 christos case LS_TYPE_SUM_ABR:
724 1.5 christos ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
725 1.1 christos lp = lsap->lsa_un.un_sla.sla_tosmetric;
726 1.7 christos while ((const u_char *)lp < ls_end) {
727 1.5 christos register uint32_t ul;
728 1.1 christos
729 1.5 christos ND_TCHECK(*lp);
730 1.1 christos ul = EXTRACT_32BITS(lp);
731 1.1 christos topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
732 1.7 christos ND_PRINT((ndo, "\n\t\ttopology %s (%u) metric %d",
733 1.7 christos tok2str(ospf_topology_values, "Unknown", topology),
734 1.1 christos topology,
735 1.5 christos ul & SLA_MASK_METRIC));
736 1.1 christos ++lp;
737 1.1 christos }
738 1.1 christos break;
739 1.1 christos
740 1.1 christos case LS_TYPE_ASE:
741 1.1 christos case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */
742 1.5 christos ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
743 1.5 christos ND_PRINT((ndo, "\n\t Mask %s",
744 1.5 christos ipaddr_string(ndo, &lsap->lsa_un.un_asla.asla_mask)));
745 1.1 christos
746 1.5 christos ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
747 1.1 christos almp = lsap->lsa_un.un_asla.asla_metric;
748 1.7 christos while ((const u_char *)almp < ls_end) {
749 1.5 christos register uint32_t ul;
750 1.1 christos
751 1.5 christos ND_TCHECK(almp->asla_tosmetric);
752 1.1 christos ul = EXTRACT_32BITS(&almp->asla_tosmetric);
753 1.1 christos topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
754 1.7 christos ND_PRINT((ndo, "\n\t\ttopology %s (%u), type %d, metric",
755 1.7 christos tok2str(ospf_topology_values, "Unknown", topology),
756 1.1 christos topology,
757 1.5 christos (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1));
758 1.5 christos if ((ul & ASLA_MASK_METRIC) == 0xffffff)
759 1.5 christos ND_PRINT((ndo, " infinite"));
760 1.5 christos else
761 1.5 christos ND_PRINT((ndo, " %d", (ul & ASLA_MASK_METRIC)));
762 1.1 christos
763 1.5 christos ND_TCHECK(almp->asla_forward);
764 1.1 christos if (almp->asla_forward.s_addr) {
765 1.5 christos ND_PRINT((ndo, ", forward %s", ipaddr_string(ndo, &almp->asla_forward)));
766 1.1 christos }
767 1.5 christos ND_TCHECK(almp->asla_tag);
768 1.1 christos if (almp->asla_tag.s_addr) {
769 1.5 christos ND_PRINT((ndo, ", tag %s", ipaddr_string(ndo, &almp->asla_tag)));
770 1.1 christos }
771 1.1 christos ++almp;
772 1.1 christos }
773 1.1 christos break;
774 1.1 christos
775 1.1 christos case LS_TYPE_GROUP:
776 1.1 christos /* Multicast extensions as of 23 July 1991 */
777 1.1 christos mcp = lsap->lsa_un.un_mcla;
778 1.7 christos while ((const u_char *)mcp < ls_end) {
779 1.5 christos ND_TCHECK(mcp->mcla_vid);
780 1.1 christos switch (EXTRACT_32BITS(&mcp->mcla_vtype)) {
781 1.1 christos
782 1.1 christos case MCLA_VERTEX_ROUTER:
783 1.5 christos ND_PRINT((ndo, "\n\t Router Router-ID %s",
784 1.5 christos ipaddr_string(ndo, &mcp->mcla_vid)));
785 1.1 christos break;
786 1.1 christos
787 1.1 christos case MCLA_VERTEX_NETWORK:
788 1.5 christos ND_PRINT((ndo, "\n\t Network Designated Router %s",
789 1.5 christos ipaddr_string(ndo, &mcp->mcla_vid)));
790 1.1 christos break;
791 1.1 christos
792 1.1 christos default:
793 1.5 christos ND_PRINT((ndo, "\n\t unknown VertexType (%u)",
794 1.5 christos EXTRACT_32BITS(&mcp->mcla_vtype)));
795 1.1 christos break;
796 1.1 christos }
797 1.1 christos ++mcp;
798 1.1 christos }
799 1.1 christos break;
800 1.1 christos
801 1.1 christos case LS_TYPE_OPAQUE_LL: /* fall through */
802 1.5 christos case LS_TYPE_OPAQUE_AL:
803 1.1 christos case LS_TYPE_OPAQUE_DW:
804 1.1 christos
805 1.1 christos switch (*(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
806 1.1 christos case LS_OPAQUE_TYPE_RI:
807 1.7 christos tptr = (const uint8_t *)(&lsap->lsa_un.un_ri_tlv.type);
808 1.1 christos
809 1.1 christos while (ls_length != 0) {
810 1.5 christos ND_TCHECK2(*tptr, 4);
811 1.1 christos if (ls_length < 4) {
812 1.5 christos ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
813 1.1 christos return(ls_end);
814 1.1 christos }
815 1.1 christos tlv_type = EXTRACT_16BITS(tptr);
816 1.1 christos tlv_length = EXTRACT_16BITS(tptr+2);
817 1.1 christos tptr+=4;
818 1.1 christos ls_length-=4;
819 1.5 christos
820 1.5 christos ND_PRINT((ndo, "\n\t %s TLV (%u), length: %u, value: ",
821 1.1 christos tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
822 1.1 christos tlv_type,
823 1.5 christos tlv_length));
824 1.1 christos
825 1.1 christos if (tlv_length > ls_length) {
826 1.5 christos ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
827 1.5 christos ls_length));
828 1.1 christos return(ls_end);
829 1.1 christos }
830 1.5 christos ND_TCHECK2(*tptr, tlv_length);
831 1.1 christos switch(tlv_type) {
832 1.1 christos
833 1.1 christos case LS_OPAQUE_RI_TLV_CAP:
834 1.1 christos if (tlv_length != 4) {
835 1.5 christos ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
836 1.1 christos return(ls_end);
837 1.1 christos }
838 1.5 christos ND_PRINT((ndo, "Capabilities: %s",
839 1.5 christos bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", EXTRACT_32BITS(tptr))));
840 1.1 christos break;
841 1.1 christos default:
842 1.5 christos if (ndo->ndo_vflag <= 1) {
843 1.5 christos if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
844 1.1 christos return(ls_end);
845 1.1 christos }
846 1.1 christos break;
847 1.1 christos
848 1.1 christos }
849 1.1 christos tptr+=tlv_length;
850 1.1 christos ls_length-=tlv_length;
851 1.1 christos }
852 1.1 christos break;
853 1.1 christos
854 1.1 christos case LS_OPAQUE_TYPE_GRACE:
855 1.7 christos if (ospf_print_grace_lsa(ndo, (const uint8_t *)(&lsap->lsa_un.un_grace_tlv.type),
856 1.1 christos ls_length) == -1) {
857 1.1 christos return(ls_end);
858 1.1 christos }
859 1.1 christos break;
860 1.1 christos
861 1.1 christos case LS_OPAQUE_TYPE_TE:
862 1.7 christos if (ospf_print_te_lsa(ndo, (const uint8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type),
863 1.1 christos ls_length) == -1) {
864 1.1 christos return(ls_end);
865 1.1 christos }
866 1.1 christos break;
867 1.1 christos
868 1.1 christos default:
869 1.5 christos if (ndo->ndo_vflag <= 1) {
870 1.7 christos if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
871 1.1 christos "\n\t ", ls_length))
872 1.1 christos return(ls_end);
873 1.5 christos }
874 1.1 christos break;
875 1.1 christos }
876 1.1 christos }
877 1.1 christos
878 1.1 christos /* do we want to see an additionally hexdump ? */
879 1.5 christos if (ndo->ndo_vflag> 1)
880 1.7 christos if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
881 1.1 christos "\n\t ", ls_length)) {
882 1.1 christos return(ls_end);
883 1.1 christos }
884 1.5 christos
885 1.1 christos return (ls_end);
886 1.1 christos trunc:
887 1.1 christos return (NULL);
888 1.1 christos }
889 1.1 christos
890 1.1 christos static int
891 1.5 christos ospf_decode_lls(netdissect_options *ndo,
892 1.5 christos register const struct ospfhdr *op, register u_int length)
893 1.1 christos {
894 1.1 christos register const u_char *dptr;
895 1.1 christos register const u_char *dataend;
896 1.1 christos register u_int length2;
897 1.5 christos register uint16_t lls_type, lls_len;
898 1.5 christos register uint32_t lls_flags;
899 1.1 christos
900 1.1 christos switch (op->ospf_type) {
901 1.1 christos
902 1.1 christos case OSPF_TYPE_HELLO:
903 1.1 christos if (!(op->ospf_hello.hello_options & OSPF_OPTION_L))
904 1.1 christos return (0);
905 1.1 christos break;
906 1.1 christos
907 1.1 christos case OSPF_TYPE_DD:
908 1.1 christos if (!(op->ospf_db.db_options & OSPF_OPTION_L))
909 1.1 christos return (0);
910 1.1 christos break;
911 1.1 christos
912 1.1 christos default:
913 1.1 christos return (0);
914 1.1 christos }
915 1.1 christos
916 1.1 christos /* dig deeper if LLS data is available; see RFC4813 */
917 1.1 christos length2 = EXTRACT_16BITS(&op->ospf_len);
918 1.7 christos dptr = (const u_char *)op + length2;
919 1.7 christos dataend = (const u_char *)op + length;
920 1.1 christos
921 1.1 christos if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
922 1.1 christos dptr = dptr + op->ospf_authdata[3];
923 1.1 christos length2 += op->ospf_authdata[3];
924 1.1 christos }
925 1.1 christos if (length2 >= length) {
926 1.5 christos ND_PRINT((ndo, "\n\t[LLS truncated]"));
927 1.1 christos return (1);
928 1.1 christos }
929 1.5 christos ND_TCHECK2(*dptr, 2);
930 1.5 christos ND_PRINT((ndo, "\n\t LLS: checksum: 0x%04x", (u_int)EXTRACT_16BITS(dptr)));
931 1.1 christos
932 1.1 christos dptr += 2;
933 1.5 christos ND_TCHECK2(*dptr, 2);
934 1.1 christos length2 = EXTRACT_16BITS(dptr);
935 1.5 christos ND_PRINT((ndo, ", length: %u", length2));
936 1.1 christos
937 1.1 christos dptr += 2;
938 1.5 christos ND_TCHECK(*dptr);
939 1.1 christos while (dptr < dataend) {
940 1.5 christos ND_TCHECK2(*dptr, 2);
941 1.1 christos lls_type = EXTRACT_16BITS(dptr);
942 1.5 christos ND_PRINT((ndo, "\n\t %s (%u)",
943 1.1 christos tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
944 1.5 christos lls_type));
945 1.1 christos dptr += 2;
946 1.5 christos ND_TCHECK2(*dptr, 2);
947 1.1 christos lls_len = EXTRACT_16BITS(dptr);
948 1.5 christos ND_PRINT((ndo, ", length: %u", lls_len));
949 1.1 christos dptr += 2;
950 1.1 christos switch (lls_type) {
951 1.1 christos
952 1.1 christos case OSPF_LLS_EO:
953 1.1 christos if (lls_len != 4) {
954 1.5 christos ND_PRINT((ndo, " [should be 4]"));
955 1.1 christos lls_len = 4;
956 1.1 christos }
957 1.5 christos ND_TCHECK2(*dptr, 4);
958 1.1 christos lls_flags = EXTRACT_32BITS(dptr);
959 1.5 christos ND_PRINT((ndo, "\n\t Options: 0x%08x [%s]", lls_flags,
960 1.5 christos bittok2str(ospf_lls_eo_options, "?", lls_flags)));
961 1.1 christos
962 1.1 christos break;
963 1.1 christos
964 1.1 christos case OSPF_LLS_MD5:
965 1.1 christos if (lls_len != 20) {
966 1.5 christos ND_PRINT((ndo, " [should be 20]"));
967 1.1 christos lls_len = 20;
968 1.1 christos }
969 1.5 christos ND_TCHECK2(*dptr, 4);
970 1.5 christos ND_PRINT((ndo, "\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr)));
971 1.1 christos break;
972 1.1 christos }
973 1.1 christos
974 1.1 christos dptr += lls_len;
975 1.1 christos }
976 1.1 christos
977 1.1 christos return (0);
978 1.1 christos trunc:
979 1.1 christos return (1);
980 1.1 christos }
981 1.1 christos
982 1.1 christos static int
983 1.5 christos ospf_decode_v2(netdissect_options *ndo,
984 1.5 christos register const struct ospfhdr *op, register const u_char *dataend)
985 1.1 christos {
986 1.1 christos register const struct in_addr *ap;
987 1.1 christos register const struct lsr *lsrp;
988 1.1 christos register const struct lsa_hdr *lshp;
989 1.1 christos register const struct lsa *lsap;
990 1.5 christos register uint32_t lsa_count,lsa_count_max;
991 1.1 christos
992 1.1 christos switch (op->ospf_type) {
993 1.1 christos
994 1.1 christos case OSPF_TYPE_UMD:
995 1.1 christos /*
996 1.1 christos * Rob Coltun's special monitoring packets;
997 1.1 christos * do nothing
998 1.1 christos */
999 1.1 christos break;
1000 1.1 christos
1001 1.1 christos case OSPF_TYPE_HELLO:
1002 1.5 christos ND_PRINT((ndo, "\n\tOptions [%s]",
1003 1.5 christos bittok2str(ospf_option_values,"none",op->ospf_hello.hello_options)));
1004 1.1 christos
1005 1.5 christos ND_TCHECK(op->ospf_hello.hello_deadint);
1006 1.5 christos ND_PRINT((ndo, "\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1007 1.5 christos EXTRACT_16BITS(&op->ospf_hello.hello_helloint),
1008 1.5 christos EXTRACT_32BITS(&op->ospf_hello.hello_deadint),
1009 1.5 christos ipaddr_string(ndo, &op->ospf_hello.hello_mask),
1010 1.5 christos op->ospf_hello.hello_priority));
1011 1.1 christos
1012 1.5 christos ND_TCHECK(op->ospf_hello.hello_dr);
1013 1.1 christos if (op->ospf_hello.hello_dr.s_addr != 0)
1014 1.5 christos ND_PRINT((ndo, "\n\t Designated Router %s",
1015 1.5 christos ipaddr_string(ndo, &op->ospf_hello.hello_dr)));
1016 1.1 christos
1017 1.5 christos ND_TCHECK(op->ospf_hello.hello_bdr);
1018 1.1 christos if (op->ospf_hello.hello_bdr.s_addr != 0)
1019 1.5 christos ND_PRINT((ndo, ", Backup Designated Router %s",
1020 1.5 christos ipaddr_string(ndo, &op->ospf_hello.hello_bdr)));
1021 1.1 christos
1022 1.5 christos ap = op->ospf_hello.hello_neighbor;
1023 1.7 christos if ((const u_char *)ap < dataend)
1024 1.5 christos ND_PRINT((ndo, "\n\t Neighbor List:"));
1025 1.7 christos while ((const u_char *)ap < dataend) {
1026 1.5 christos ND_TCHECK(*ap);
1027 1.5 christos ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
1028 1.5 christos ++ap;
1029 1.5 christos }
1030 1.1 christos break; /* HELLO */
1031 1.1 christos
1032 1.1 christos case OSPF_TYPE_DD:
1033 1.5 christos ND_TCHECK(op->ospf_db.db_options);
1034 1.5 christos ND_PRINT((ndo, "\n\tOptions [%s]",
1035 1.5 christos bittok2str(ospf_option_values, "none", op->ospf_db.db_options)));
1036 1.5 christos ND_TCHECK(op->ospf_db.db_flags);
1037 1.5 christos ND_PRINT((ndo, ", DD Flags [%s]",
1038 1.5 christos bittok2str(ospf_dd_flag_values, "none", op->ospf_db.db_flags)));
1039 1.5 christos ND_TCHECK(op->ospf_db.db_ifmtu);
1040 1.5 christos if (op->ospf_db.db_ifmtu) {
1041 1.5 christos ND_PRINT((ndo, ", MTU: %u", EXTRACT_16BITS(&op->ospf_db.db_ifmtu)));
1042 1.5 christos }
1043 1.5 christos ND_TCHECK(op->ospf_db.db_seq);
1044 1.5 christos ND_PRINT((ndo, ", Sequence: 0x%08x", EXTRACT_32BITS(&op->ospf_db.db_seq)));
1045 1.1 christos
1046 1.5 christos /* Print all the LS adv's */
1047 1.5 christos lshp = op->ospf_db.db_lshdr;
1048 1.7 christos while (((const u_char *)lshp < dataend) && ospf_print_lshdr(ndo, lshp) != -1) {
1049 1.5 christos ++lshp;
1050 1.5 christos }
1051 1.1 christos break;
1052 1.1 christos
1053 1.1 christos case OSPF_TYPE_LS_REQ:
1054 1.1 christos lsrp = op->ospf_lsr;
1055 1.7 christos while ((const u_char *)lsrp < dataend) {
1056 1.5 christos ND_TCHECK(*lsrp);
1057 1.1 christos
1058 1.5 christos ND_PRINT((ndo, "\n\t Advertising Router: %s, %s LSA (%u)",
1059 1.5 christos ipaddr_string(ndo, &lsrp->ls_router),
1060 1.1 christos tok2str(lsa_values,"unknown",EXTRACT_32BITS(lsrp->ls_type)),
1061 1.5 christos EXTRACT_32BITS(&lsrp->ls_type)));
1062 1.1 christos
1063 1.1 christos switch (EXTRACT_32BITS(lsrp->ls_type)) {
1064 1.1 christos /* the LSA header for opaque LSAs was slightly changed */
1065 1.1 christos case LS_TYPE_OPAQUE_LL:
1066 1.1 christos case LS_TYPE_OPAQUE_AL:
1067 1.1 christos case LS_TYPE_OPAQUE_DW:
1068 1.5 christos ND_PRINT((ndo, ", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1069 1.1 christos tok2str(lsa_opaque_values, "unknown",lsrp->un_ls_stateid.opaque_field.opaque_type),
1070 1.1 christos lsrp->un_ls_stateid.opaque_field.opaque_type,
1071 1.5 christos EXTRACT_24BITS(&lsrp->un_ls_stateid.opaque_field.opaque_id)));
1072 1.1 christos break;
1073 1.1 christos default:
1074 1.5 christos ND_PRINT((ndo, ", LSA-ID: %s",
1075 1.5 christos ipaddr_string(ndo, &lsrp->un_ls_stateid.ls_stateid)));
1076 1.1 christos break;
1077 1.1 christos }
1078 1.5 christos
1079 1.1 christos ++lsrp;
1080 1.1 christos }
1081 1.1 christos break;
1082 1.1 christos
1083 1.1 christos case OSPF_TYPE_LS_UPDATE:
1084 1.1 christos lsap = op->ospf_lsu.lsu_lsa;
1085 1.5 christos ND_TCHECK(op->ospf_lsu.lsu_count);
1086 1.1 christos lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count);
1087 1.5 christos ND_PRINT((ndo, ", %d LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max)));
1088 1.1 christos for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
1089 1.5 christos ND_PRINT((ndo, "\n\t LSA #%u", lsa_count));
1090 1.5 christos lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap);
1091 1.1 christos if (lsap == NULL)
1092 1.1 christos goto trunc;
1093 1.1 christos }
1094 1.1 christos break;
1095 1.1 christos
1096 1.1 christos case OSPF_TYPE_LS_ACK:
1097 1.1 christos lshp = op->ospf_lsa.lsa_lshdr;
1098 1.5 christos while (ospf_print_lshdr(ndo, lshp) != -1) {
1099 1.1 christos ++lshp;
1100 1.1 christos }
1101 1.1 christos break;
1102 1.1 christos
1103 1.1 christos default:
1104 1.1 christos break;
1105 1.1 christos }
1106 1.1 christos return (0);
1107 1.1 christos trunc:
1108 1.1 christos return (1);
1109 1.1 christos }
1110 1.1 christos
1111 1.1 christos void
1112 1.5 christos ospf_print(netdissect_options *ndo,
1113 1.5 christos register const u_char *bp, register u_int length,
1114 1.5 christos const u_char *bp2 _U_)
1115 1.1 christos {
1116 1.1 christos register const struct ospfhdr *op;
1117 1.1 christos register const u_char *dataend;
1118 1.1 christos register const char *cp;
1119 1.1 christos
1120 1.7 christos op = (const struct ospfhdr *)bp;
1121 1.1 christos
1122 1.5 christos /* XXX Before we do anything else, strip off the MD5 trailer */
1123 1.5 christos ND_TCHECK(op->ospf_authtype);
1124 1.5 christos if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
1125 1.5 christos length -= OSPF_AUTH_MD5_LEN;
1126 1.5 christos ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN;
1127 1.5 christos }
1128 1.1 christos
1129 1.1 christos /* If the type is valid translate it, or just print the type */
1130 1.1 christos /* value. If it's not valid, say so and return */
1131 1.5 christos ND_TCHECK(op->ospf_type);
1132 1.1 christos cp = tok2str(type2str, "unknown LS-type", op->ospf_type);
1133 1.5 christos ND_PRINT((ndo, "OSPFv%u, %s, length %u", op->ospf_version, cp, length));
1134 1.1 christos if (*cp == 'u')
1135 1.1 christos return;
1136 1.1 christos
1137 1.5 christos if (!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
1138 1.5 christos return;
1139 1.5 christos }
1140 1.1 christos
1141 1.5 christos ND_TCHECK(op->ospf_len);
1142 1.1 christos if (length != EXTRACT_16BITS(&op->ospf_len)) {
1143 1.5 christos ND_PRINT((ndo, " [len %d]", EXTRACT_16BITS(&op->ospf_len)));
1144 1.1 christos }
1145 1.1 christos
1146 1.1 christos if (length > EXTRACT_16BITS(&op->ospf_len)) {
1147 1.1 christos dataend = bp + EXTRACT_16BITS(&op->ospf_len);
1148 1.1 christos } else {
1149 1.1 christos dataend = bp + length;
1150 1.1 christos }
1151 1.1 christos
1152 1.5 christos ND_TCHECK(op->ospf_routerid);
1153 1.5 christos ND_PRINT((ndo, "\n\tRouter-ID %s", ipaddr_string(ndo, &op->ospf_routerid)));
1154 1.1 christos
1155 1.5 christos ND_TCHECK(op->ospf_areaid);
1156 1.1 christos if (op->ospf_areaid.s_addr != 0)
1157 1.5 christos ND_PRINT((ndo, ", Area %s", ipaddr_string(ndo, &op->ospf_areaid)));
1158 1.1 christos else
1159 1.5 christos ND_PRINT((ndo, ", Backbone Area"));
1160 1.1 christos
1161 1.5 christos if (ndo->ndo_vflag) {
1162 1.1 christos /* Print authentication data (should we really do this?) */
1163 1.5 christos ND_TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata));
1164 1.1 christos
1165 1.5 christos ND_PRINT((ndo, ", Authentication Type: %s (%u)",
1166 1.5 christos tok2str(ospf_authtype_values, "unknown", EXTRACT_16BITS(&op->ospf_authtype)),
1167 1.5 christos EXTRACT_16BITS(&op->ospf_authtype)));
1168 1.1 christos
1169 1.1 christos switch (EXTRACT_16BITS(&op->ospf_authtype)) {
1170 1.1 christos
1171 1.1 christos case OSPF_AUTH_NONE:
1172 1.1 christos break;
1173 1.1 christos
1174 1.1 christos case OSPF_AUTH_SIMPLE:
1175 1.5 christos ND_PRINT((ndo, "\n\tSimple text password: "));
1176 1.5 christos safeputs(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN);
1177 1.1 christos break;
1178 1.1 christos
1179 1.1 christos case OSPF_AUTH_MD5:
1180 1.5 christos ND_PRINT((ndo, "\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1181 1.5 christos *((op->ospf_authdata) + 2),
1182 1.5 christos *((op->ospf_authdata) + 3),
1183 1.5 christos EXTRACT_32BITS((op->ospf_authdata) + 4)));
1184 1.1 christos break;
1185 1.1 christos
1186 1.1 christos default:
1187 1.1 christos return;
1188 1.1 christos }
1189 1.1 christos }
1190 1.1 christos /* Do rest according to version. */
1191 1.1 christos switch (op->ospf_version) {
1192 1.1 christos
1193 1.1 christos case 2:
1194 1.1 christos /* ospf version 2 */
1195 1.5 christos if (ospf_decode_v2(ndo, op, dataend))
1196 1.1 christos goto trunc;
1197 1.1 christos if (length > EXTRACT_16BITS(&op->ospf_len)) {
1198 1.5 christos if (ospf_decode_lls(ndo, op, length))
1199 1.1 christos goto trunc;
1200 1.1 christos }
1201 1.1 christos break;
1202 1.1 christos
1203 1.1 christos default:
1204 1.5 christos ND_PRINT((ndo, " ospf [version %d]", op->ospf_version));
1205 1.1 christos break;
1206 1.1 christos } /* end switch on version */
1207 1.1 christos
1208 1.1 christos return;
1209 1.1 christos trunc:
1210 1.5 christos ND_PRINT((ndo, "%s", tstr));
1211 1.1 christos }
1212