blob: c370bda71b84dd987345e401209705aa23f0f27d [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
22 */
23
Elliott Hughese2e3bd12017-05-15 10:59:29 -070024/* \summary: Open Shortest Path First (OSPF) printer */
25
The Android Open Source Project2949f582009-03-03 19:30:46 -080026#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070027#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080028#endif
29
Elliott Hughes820eced2021-08-20 18:00:50 -070030#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080031
Elliott Hughese2e3bd12017-05-15 10:59:29 -070032#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080033#include "addrtoname.h"
34#include "extract.h"
35#include "gmpls.h"
36
37#include "ospf.h"
38
The Android Open Source Project2949f582009-03-03 19:30:46 -080039
JP Abgrall53f17a92014-02-12 14:02:41 -080040static const struct tok ospf_option_values[] = {
Elliott Hughes820eced2021-08-20 18:00:50 -070041 { OSPF_OPTION_MT, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
The Android Open Source Project2949f582009-03-03 19:30:46 -080042 { OSPF_OPTION_E, "External" },
43 { OSPF_OPTION_MC, "Multicast" },
44 { OSPF_OPTION_NP, "NSSA" },
Elliott Hughes820eced2021-08-20 18:00:50 -070045 { OSPF_OPTION_L, "LLS" },
The Android Open Source Project2949f582009-03-03 19:30:46 -080046 { OSPF_OPTION_DC, "Demand Circuit" },
47 { OSPF_OPTION_O, "Opaque" },
48 { OSPF_OPTION_DN, "Up/Down" },
49 { 0, NULL }
50};
51
JP Abgrall53f17a92014-02-12 14:02:41 -080052static const struct tok ospf_authtype_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080053 { OSPF_AUTH_NONE, "none" },
54 { OSPF_AUTH_SIMPLE, "simple" },
55 { OSPF_AUTH_MD5, "MD5" },
56 { 0, NULL }
57};
58
JP Abgrall53f17a92014-02-12 14:02:41 -080059static const struct tok ospf_rla_flag_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080060 { RLA_FLAG_B, "ABR" },
61 { RLA_FLAG_E, "ASBR" },
62 { RLA_FLAG_W1, "Virtual" },
63 { RLA_FLAG_W2, "W2" },
64 { 0, NULL }
65};
66
JP Abgrall53f17a92014-02-12 14:02:41 -080067static const struct tok type2str[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080068 { OSPF_TYPE_HELLO, "Hello" },
69 { OSPF_TYPE_DD, "Database Description" },
70 { OSPF_TYPE_LS_REQ, "LS-Request" },
71 { OSPF_TYPE_LS_UPDATE, "LS-Update" },
72 { OSPF_TYPE_LS_ACK, "LS-Ack" },
73 { 0, NULL }
74};
75
JP Abgrall53f17a92014-02-12 14:02:41 -080076static const struct tok lsa_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080077 { LS_TYPE_ROUTER, "Router" },
78 { LS_TYPE_NETWORK, "Network" },
79 { LS_TYPE_SUM_IP, "Summary" },
80 { LS_TYPE_SUM_ABR, "ASBR Summary" },
81 { LS_TYPE_ASE, "External" },
82 { LS_TYPE_GROUP, "Multicast Group" },
83 { LS_TYPE_NSSA, "NSSA" },
84 { LS_TYPE_OPAQUE_LL, "Link Local Opaque" },
85 { LS_TYPE_OPAQUE_AL, "Area Local Opaque" },
86 { LS_TYPE_OPAQUE_DW, "Domain Wide Opaque" },
87 { 0, NULL }
88};
89
JP Abgrall53f17a92014-02-12 14:02:41 -080090static const struct tok ospf_dd_flag_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080091 { OSPF_DB_INIT, "Init" },
92 { OSPF_DB_MORE, "More" },
93 { OSPF_DB_MASTER, "Master" },
JP Abgrall53f17a92014-02-12 14:02:41 -080094 { OSPF_DB_RESYNC, "OOBResync" },
The Android Open Source Project2949f582009-03-03 19:30:46 -080095 { 0, NULL }
96};
97
JP Abgrall53f17a92014-02-12 14:02:41 -080098static const struct tok lsa_opaque_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080099 { LS_OPAQUE_TYPE_TE, "Traffic Engineering" },
100 { LS_OPAQUE_TYPE_GRACE, "Graceful restart" },
101 { LS_OPAQUE_TYPE_RI, "Router Information" },
102 { 0, NULL }
103};
104
JP Abgrall53f17a92014-02-12 14:02:41 -0800105static const struct tok lsa_opaque_te_tlv_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800106 { LS_OPAQUE_TE_TLV_ROUTER, "Router Address" },
107 { LS_OPAQUE_TE_TLV_LINK, "Link" },
108 { 0, NULL }
109};
110
JP Abgrall53f17a92014-02-12 14:02:41 -0800111static const struct tok lsa_opaque_te_link_tlv_subtlv_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800112 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE, "Link Type" },
113 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID, "Link ID" },
114 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP, "Local Interface IP address" },
115 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP, "Remote Interface IP address" },
116 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC, "Traffic Engineering Metric" },
117 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW, "Maximum Bandwidth" },
118 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW, "Maximum Reservable Bandwidth" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW, "Unreserved Bandwidth" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP, "Administrative Group" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE, "Link Protection Type" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP, "Shared Risk Link Group" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS, "Bandwidth Constraints" },
126 { 0, NULL }
127};
128
JP Abgrall53f17a92014-02-12 14:02:41 -0800129static const struct tok lsa_opaque_grace_tlv_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800130 { LS_OPAQUE_GRACE_TLV_PERIOD, "Grace Period" },
131 { LS_OPAQUE_GRACE_TLV_REASON, "Graceful restart Reason" },
132 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS, "IPv4 interface address" },
133 { 0, NULL }
134};
135
JP Abgrall53f17a92014-02-12 14:02:41 -0800136static const struct tok lsa_opaque_grace_tlv_reason_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800137 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN, "Unknown" },
138 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART, "Software Restart" },
139 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE, "Software Reload/Upgrade" },
140 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH, "Control Processor Switch" },
141 { 0, NULL }
142};
143
JP Abgrall53f17a92014-02-12 14:02:41 -0800144static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800145 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP, "Point-to-point" },
146 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA, "Multi-Access" },
147 { 0, NULL }
148};
149
JP Abgrall53f17a92014-02-12 14:02:41 -0800150static const struct tok lsa_opaque_ri_tlv_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800151 { LS_OPAQUE_RI_TLV_CAP, "Router Capabilities" },
152 { 0, NULL }
153};
154
JP Abgrall53f17a92014-02-12 14:02:41 -0800155static const struct tok lsa_opaque_ri_tlv_cap_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800156 { 1, "Reserved" },
157 { 2, "Reserved" },
158 { 4, "Reserved" },
159 { 8, "Reserved" },
160 { 16, "graceful restart capable" },
161 { 32, "graceful restart helper" },
162 { 64, "Stub router support" },
163 { 128, "Traffic engineering" },
164 { 256, "p2p over LAN" },
165 { 512, "path computation server" },
166 { 0, NULL }
167};
168
JP Abgrall53f17a92014-02-12 14:02:41 -0800169static const struct tok ospf_lls_tlv_values[] = {
170 { OSPF_LLS_EO, "Extended Options" },
171 { OSPF_LLS_MD5, "MD5 Authentication" },
172 { 0, NULL }
173};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800174
JP Abgrall53f17a92014-02-12 14:02:41 -0800175static const struct tok ospf_lls_eo_options[] = {
176 { OSPF_LLS_EO_LR, "LSDB resync" },
177 { OSPF_LLS_EO_RS, "Restart" },
178 { 0, NULL }
179};
180
JP Abgrall53f17a92014-02-12 14:02:41 -0800181int
Elliott Hughes820eced2021-08-20 18:00:50 -0700182ospf_grace_lsa_print(netdissect_options *ndo,
183 const u_char *tptr, u_int ls_length)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700184{
JP Abgrall53f17a92014-02-12 14:02:41 -0800185 u_int tlv_type, tlv_length;
186
187
188 while (ls_length > 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700189 ND_TCHECK_4(tptr);
JP Abgrall53f17a92014-02-12 14:02:41 -0800190 if (ls_length < 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700191 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800192 return -1;
193 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700194 tlv_type = GET_BE_U_2(tptr);
195 tlv_length = GET_BE_U_2(tptr + 2);
JP Abgrall53f17a92014-02-12 14:02:41 -0800196 tptr+=4;
197 ls_length-=4;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700198
Elliott Hughes820eced2021-08-20 18:00:50 -0700199 ND_PRINT("\n\t %s TLV (%u), length %u, value: ",
JP Abgrall53f17a92014-02-12 14:02:41 -0800200 tok2str(lsa_opaque_grace_tlv_values,"unknown",tlv_type),
201 tlv_type,
Elliott Hughes820eced2021-08-20 18:00:50 -0700202 tlv_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800203
204 if (tlv_length > ls_length) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700205 ND_PRINT("\n\t Bogus length %u > %u", tlv_length,
206 ls_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800207 return -1;
208 }
209
210 /* Infinite loop protection. */
211 if (tlv_type == 0 || tlv_length ==0) {
212 return -1;
213 }
214
Elliott Hughes820eced2021-08-20 18:00:50 -0700215 ND_TCHECK_LEN(tptr, tlv_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800216 switch(tlv_type) {
217
218 case LS_OPAQUE_GRACE_TLV_PERIOD:
219 if (tlv_length != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700220 ND_PRINT("\n\t Bogus length %u != 4", tlv_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800221 return -1;
222 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700223 ND_PRINT("%us", GET_BE_U_4(tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800224 break;
225
226 case LS_OPAQUE_GRACE_TLV_REASON:
227 if (tlv_length != 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700228 ND_PRINT("\n\t Bogus length %u != 1", tlv_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800229 return -1;
230 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700231 ND_PRINT("%s (%u)",
232 tok2str(lsa_opaque_grace_tlv_reason_values, "Unknown", GET_U_1(tptr)),
233 GET_U_1(tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800234 break;
235
236 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS:
237 if (tlv_length != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700238 ND_PRINT("\n\t Bogus length %u != 4", tlv_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800239 return -1;
240 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700241 ND_PRINT("%s", GET_IPADDR_STRING(tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800242 break;
243
244 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700245 if (ndo->ndo_vflag <= 1) {
246 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
JP Abgrall53f17a92014-02-12 14:02:41 -0800247 return -1;
248 }
249 break;
250
251 }
252 /* in OSPF everything has to be 32-bit aligned, including TLVs */
253 if (tlv_length%4 != 0)
254 tlv_length+=4-(tlv_length%4);
255 ls_length-=tlv_length;
256 tptr+=tlv_length;
257 }
258
259 return 0;
260trunc:
261 return -1;
262}
263
264int
Elliott Hughes820eced2021-08-20 18:00:50 -0700265ospf_te_lsa_print(netdissect_options *ndo,
266 const u_char *tptr, u_int ls_length)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700267{
JP Abgrall53f17a92014-02-12 14:02:41 -0800268 u_int tlv_type, tlv_length, subtlv_type, subtlv_length;
269 u_int priority_level, te_class, count_srlg;
270 union { /* int to float conversion buffer for several subTLVs */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700271 float f;
272 uint32_t i;
JP Abgrall53f17a92014-02-12 14:02:41 -0800273 } bw;
274
275 while (ls_length != 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700276 ND_TCHECK_4(tptr);
JP Abgrall53f17a92014-02-12 14:02:41 -0800277 if (ls_length < 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700278 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800279 return -1;
280 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700281 tlv_type = GET_BE_U_2(tptr);
282 tlv_length = GET_BE_U_2(tptr + 2);
JP Abgrall53f17a92014-02-12 14:02:41 -0800283 tptr+=4;
284 ls_length-=4;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700285
Elliott Hughes820eced2021-08-20 18:00:50 -0700286 ND_PRINT("\n\t %s TLV (%u), length: %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800287 tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
288 tlv_type,
Elliott Hughes820eced2021-08-20 18:00:50 -0700289 tlv_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800290
291 if (tlv_length > ls_length) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700292 ND_PRINT("\n\t Bogus length %u > %u", tlv_length,
293 ls_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800294 return -1;
295 }
296
297 /* Infinite loop protection. */
298 if (tlv_type == 0 || tlv_length ==0) {
299 return -1;
300 }
301
302 switch(tlv_type) {
303 case LS_OPAQUE_TE_TLV_LINK:
Elliott Hughes820eced2021-08-20 18:00:50 -0700304 while (tlv_length != 0) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800305 if (tlv_length < 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700306 ND_PRINT("\n\t Remaining TLV length %u < 4",
307 tlv_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800308 return -1;
309 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700310 subtlv_type = GET_BE_U_2(tptr);
311 subtlv_length = GET_BE_U_2(tptr + 2);
JP Abgrall53f17a92014-02-12 14:02:41 -0800312 tptr+=4;
313 tlv_length-=4;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700314
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700315 /* Infinite loop protection */
316 if (subtlv_type == 0 || subtlv_length == 0)
317 goto invalid;
318
Elliott Hughes820eced2021-08-20 18:00:50 -0700319 ND_PRINT("\n\t %s subTLV (%u), length: %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800320 tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type),
321 subtlv_type,
Elliott Hughes820eced2021-08-20 18:00:50 -0700322 subtlv_length);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700323
Elliott Hughes820eced2021-08-20 18:00:50 -0700324 if (tlv_length < subtlv_length) {
325 ND_PRINT("\n\t Remaining TLV length %u < %u",
326 tlv_length + 4, subtlv_length + 4);
327 return -1;
328 }
329 ND_TCHECK_LEN(tptr, subtlv_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800330 switch(subtlv_type) {
331 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700332 if (subtlv_length != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700333 ND_PRINT(" != 4");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700334 goto invalid;
335 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700336 ND_PRINT(", 0x%08x", GET_BE_U_4(tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800337 break;
338 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
339 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700340 if (subtlv_length != 4 && subtlv_length != 8) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700341 ND_PRINT(" != 4 && != 8");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700342 goto invalid;
343 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700344 ND_PRINT(", %s (0x%08x)",
345 GET_IPADDR_STRING(tptr),
346 GET_BE_U_4(tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800347 if (subtlv_length == 8) /* rfc4203 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700348 ND_PRINT(", %s (0x%08x)",
349 GET_IPADDR_STRING(tptr+4),
350 GET_BE_U_4(tptr + 4));
JP Abgrall53f17a92014-02-12 14:02:41 -0800351 break;
352 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
353 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700354 if (subtlv_length != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700355 ND_PRINT(" != 4");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700356 goto invalid;
357 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700358 ND_PRINT(", %s", GET_IPADDR_STRING(tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800359 break;
360 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
361 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700362 if (subtlv_length != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700363 ND_PRINT(" != 4");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700364 goto invalid;
365 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700366 bw.i = GET_BE_U_4(tptr);
367 ND_PRINT(", %.3f Mbps", bw.f * 8 / 1000000);
JP Abgrall53f17a92014-02-12 14:02:41 -0800368 break;
369 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700370 if (subtlv_length != 32) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700371 ND_PRINT(" != 32");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700372 goto invalid;
373 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800374 for (te_class = 0; te_class < 8; te_class++) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700375 bw.i = GET_BE_U_4(tptr + te_class * 4);
376 ND_PRINT("\n\t\tTE-Class %u: %.3f Mbps",
JP Abgrall53f17a92014-02-12 14:02:41 -0800377 te_class,
Elliott Hughes820eced2021-08-20 18:00:50 -0700378 bw.f * 8 / 1000000);
JP Abgrall53f17a92014-02-12 14:02:41 -0800379 }
380 break;
381 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700382 if (subtlv_length < 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700383 ND_PRINT(" < 4");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700384 goto invalid;
385 }
386 /* BC Model Id (1 octet) + Reserved (3 octets) */
Elliott Hughes820eced2021-08-20 18:00:50 -0700387 ND_PRINT("\n\t\tBandwidth Constraints Model ID: %s (%u)",
388 tok2str(diffserv_te_bc_values, "unknown", GET_U_1(tptr)),
389 GET_U_1(tptr));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700390 if (subtlv_length % 4 != 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700391 ND_PRINT("\n\t\tlength %u != N x 4", subtlv_length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700392 goto invalid;
393 }
394 if (subtlv_length > 36) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700395 ND_PRINT("\n\t\tlength %u > 36", subtlv_length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700396 goto invalid;
397 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800398 /* decode BCs until the subTLV ends */
399 for (te_class = 0; te_class < (subtlv_length-4)/4; te_class++) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700400 bw.i = GET_BE_U_4(tptr + 4 + te_class * 4);
401 ND_PRINT("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
JP Abgrall53f17a92014-02-12 14:02:41 -0800402 te_class,
Elliott Hughes820eced2021-08-20 18:00:50 -0700403 bw.f * 8 / 1000000);
JP Abgrall53f17a92014-02-12 14:02:41 -0800404 }
405 break;
406 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700407 if (subtlv_length != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700408 ND_PRINT(" != 4");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700409 goto invalid;
410 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700411 ND_PRINT(", Metric %u", GET_BE_U_4(tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800412 break;
413 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700414 /* Protection Cap (1 octet) + Reserved ((3 octets) */
415 if (subtlv_length != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700416 ND_PRINT(" != 4");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700417 goto invalid;
418 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700419 ND_PRINT(", %s",
420 bittok2str(gmpls_link_prot_values, "none", GET_U_1(tptr)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800421 break;
422 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700423 if (subtlv_length < 36) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700424 ND_PRINT(" < 36");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700425 goto invalid;
426 }
427 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
Elliott Hughes820eced2021-08-20 18:00:50 -0700428 ND_PRINT("\n\t\tInterface Switching Capability: %s",
429 tok2str(gmpls_switch_cap_values, "Unknown", GET_U_1((tptr))));
430 ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
431 tok2str(gmpls_encoding_values, "Unknown", GET_U_1((tptr + 1))));
JP Abgrall53f17a92014-02-12 14:02:41 -0800432 for (priority_level = 0; priority_level < 8; priority_level++) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700433 bw.i = GET_BE_U_4(tptr + 4 + (priority_level * 4));
434 ND_PRINT("\n\t\t priority level %u: %.3f Mbps",
JP Abgrall53f17a92014-02-12 14:02:41 -0800435 priority_level,
Elliott Hughes820eced2021-08-20 18:00:50 -0700436 bw.f * 8 / 1000000);
JP Abgrall53f17a92014-02-12 14:02:41 -0800437 }
438 break;
439 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700440 if (subtlv_length != 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700441 ND_PRINT(" != 1");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700442 goto invalid;
443 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700444 ND_PRINT(", %s (%u)",
445 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",GET_U_1(tptr)),
446 GET_U_1(tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800447 break;
448
449 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700450 if (subtlv_length % 4 != 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700451 ND_PRINT(" != N x 4");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700452 goto invalid;
453 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800454 count_srlg = subtlv_length / 4;
455 if (count_srlg != 0)
Elliott Hughes820eced2021-08-20 18:00:50 -0700456 ND_PRINT("\n\t\t Shared risk group: ");
JP Abgrall53f17a92014-02-12 14:02:41 -0800457 while (count_srlg > 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700458 bw.i = GET_BE_U_4(tptr);
459 ND_PRINT("%u", bw.i);
JP Abgrall53f17a92014-02-12 14:02:41 -0800460 tptr+=4;
461 count_srlg--;
462 if (count_srlg > 0)
Elliott Hughes820eced2021-08-20 18:00:50 -0700463 ND_PRINT(", ");
JP Abgrall53f17a92014-02-12 14:02:41 -0800464 }
465 break;
466
467 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700468 if (ndo->ndo_vflag <= 1) {
469 if (!print_unknown_data(ndo, tptr, "\n\t\t", subtlv_length))
JP Abgrall53f17a92014-02-12 14:02:41 -0800470 return -1;
471 }
472 break;
473 }
474 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
475 if (subtlv_length%4 != 0)
476 subtlv_length+=4-(subtlv_length%4);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700477
Elliott Hughes820eced2021-08-20 18:00:50 -0700478 if (tlv_length < subtlv_length) {
479 ND_PRINT("\n\t Remaining TLV length %u < %u",
480 tlv_length + 4, subtlv_length + 4);
481 return -1;
482 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800483 tlv_length-=subtlv_length;
484 tptr+=subtlv_length;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700485
JP Abgrall53f17a92014-02-12 14:02:41 -0800486 }
487 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700488
JP Abgrall53f17a92014-02-12 14:02:41 -0800489 case LS_OPAQUE_TE_TLV_ROUTER:
490 if (tlv_length < 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700491 ND_PRINT("\n\t TLV length %u < 4", tlv_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800492 return -1;
493 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700494 ND_PRINT(", %s", GET_IPADDR_STRING(tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800495 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700496
JP Abgrall53f17a92014-02-12 14:02:41 -0800497 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700498 if (ndo->ndo_vflag <= 1) {
499 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
JP Abgrall53f17a92014-02-12 14:02:41 -0800500 return -1;
501 }
502 break;
503 }
504 /* in OSPF everything has to be 32-bit aligned, including TLVs */
505 if (tlv_length%4 != 0)
506 tlv_length+=4-(tlv_length%4);
Elliott Hughes820eced2021-08-20 18:00:50 -0700507 if (tlv_length > ls_length) {
508 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length,
509 ls_length);
510 return -1;
511 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800512 ls_length-=tlv_length;
513 tptr+=tlv_length;
514 }
515 return 0;
516trunc:
517 return -1;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700518invalid:
Elliott Hughes820eced2021-08-20 18:00:50 -0700519 nd_print_invalid(ndo);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700520 return -1;
JP Abgrall53f17a92014-02-12 14:02:41 -0800521}
522
The Android Open Source Project2949f582009-03-03 19:30:46 -0800523static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700524ospf_print_lshdr(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700525 const struct lsa_hdr *lshp)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800526{
Elliott Hughes820eced2021-08-20 18:00:50 -0700527 u_int ls_type;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800528 u_int ls_length;
529
Elliott Hughes820eced2021-08-20 18:00:50 -0700530 ls_length = GET_BE_U_2(lshp->ls_length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800531 if (ls_length < sizeof(struct lsa_hdr)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700532 ND_PRINT("\n\t Bogus length %u < header (%zu)", ls_length,
533 sizeof(struct lsa_hdr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800534 return(-1);
535 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700536 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %zu",
537 GET_IPADDR_STRING(lshp->ls_router),
538 GET_BE_U_4(lshp->ls_seq),
539 GET_BE_U_2(lshp->ls_age),
540 ls_length - sizeof(struct lsa_hdr));
541 ls_type = GET_U_1(lshp->ls_type);
542 switch (ls_type) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700543 /* the LSA header for opaque LSAs was slightly changed */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800544 case LS_TYPE_OPAQUE_LL:
545 case LS_TYPE_OPAQUE_AL:
546 case LS_TYPE_OPAQUE_DW:
Elliott Hughes820eced2021-08-20 18:00:50 -0700547 ND_PRINT("\n\t %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u",
548 tok2str(lsa_values,"unknown",ls_type),
549 ls_type,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800550
551 tok2str(lsa_opaque_values,
552 "unknown",
Elliott Hughes820eced2021-08-20 18:00:50 -0700553 GET_U_1(lshp->un_lsa_id.opaque_field.opaque_type)),
554 GET_U_1(lshp->un_lsa_id.opaque_field.opaque_type),
555 GET_BE_U_3(lshp->un_lsa_id.opaque_field.opaque_id)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700556
Elliott Hughes820eced2021-08-20 18:00:50 -0700557 );
The Android Open Source Project2949f582009-03-03 19:30:46 -0800558 break;
559
Elliott Hughes892a68b2015-10-19 14:43:53 -0700560 /* all other LSA types use regular style LSA headers */
561 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700562 ND_PRINT("\n\t %s LSA (%u), LSA-ID: %s",
563 tok2str(lsa_values,"unknown",ls_type),
564 ls_type,
565 GET_IPADDR_STRING(lshp->un_lsa_id.lsa_id));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800566 break;
567 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700568 ND_PRINT("\n\t Options: [%s]",
569 bittok2str(ospf_option_values, "none", GET_U_1(lshp->ls_options)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800570
571 return (ls_length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800572}
573
JP Abgrall53f17a92014-02-12 14:02:41 -0800574/* draft-ietf-ospf-mt-09 */
575static const struct tok ospf_topology_values[] = {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700576 { 0, "default" },
577 { 1, "multicast" },
578 { 2, "management" },
JP Abgrall53f17a92014-02-12 14:02:41 -0800579 { 0, NULL }
580};
581
582/*
583 * Print all the per-topology metrics.
584 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700585static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700586ospf_print_tos_metrics(netdissect_options *ndo,
587 const union un_tos *tos)
JP Abgrall53f17a92014-02-12 14:02:41 -0800588{
Elliott Hughes820eced2021-08-20 18:00:50 -0700589 u_int metric_count;
590 u_int toscount;
591 u_int tos_type;
JP Abgrall53f17a92014-02-12 14:02:41 -0800592
Elliott Hughes820eced2021-08-20 18:00:50 -0700593 toscount = GET_U_1(tos->link.link_tos_count)+1;
JP Abgrall53f17a92014-02-12 14:02:41 -0800594 metric_count = 0;
595
596 /*
597 * All but the first metric contain a valid topology id.
598 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700599 while (toscount != 0) {
600 tos_type = GET_U_1(tos->metrics.tos_type);
601 ND_PRINT("\n\t\ttopology %s (%u), metric %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700602 tok2str(ospf_topology_values, "Unknown",
Elliott Hughes820eced2021-08-20 18:00:50 -0700603 metric_count ? tos_type : 0),
604 metric_count ? tos_type : 0,
605 GET_BE_U_2(tos->metrics.tos_metric));
JP Abgrall53f17a92014-02-12 14:02:41 -0800606 metric_count++;
607 tos++;
608 toscount--;
609 }
610}
611
The Android Open Source Project2949f582009-03-03 19:30:46 -0800612/*
613 * Print a single link state advertisement. If truncated or if LSA length
614 * field is less than the length of the LSA header, return NULl, else
615 * return pointer to data past end of LSA.
616 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700617static const uint8_t *
618ospf_print_lsa(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700619 const struct lsa *lsap)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800620{
Elliott Hughes820eced2021-08-20 18:00:50 -0700621 const uint8_t *ls_end;
622 const struct rlalink *rlp;
623 const nd_ipv4 *ap;
624 const struct aslametric *almp;
625 const struct mcla *mcp;
626 const uint8_t *lp;
627 u_int tlv_type, tlv_length, rla_count, topology;
628 int ospf_print_lshdr_ret;
629 u_int ls_length;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700630 const uint8_t *tptr;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800631
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700632 tptr = (const uint8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
Elliott Hughes820eced2021-08-20 18:00:50 -0700633 ospf_print_lshdr_ret = ospf_print_lshdr(ndo, &lsap->ls_hdr);
634 if (ospf_print_lshdr_ret < 0)
635 return(NULL);
636 ls_length = (u_int)ospf_print_lshdr_ret;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700637 ls_end = (const uint8_t *)lsap + ls_length;
Elliott Hughes820eced2021-08-20 18:00:50 -0700638 /*
639 * ospf_print_lshdr() returns -1 if the length is too short,
640 * so we know ls_length is >= sizeof(struct lsa_hdr).
641 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800642 ls_length -= sizeof(struct lsa_hdr);
643
Elliott Hughes820eced2021-08-20 18:00:50 -0700644 switch (GET_U_1(lsap->ls_hdr.ls_type)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800645
646 case LS_TYPE_ROUTER:
Elliott Hughes820eced2021-08-20 18:00:50 -0700647 ND_PRINT("\n\t Router LSA Options: [%s]",
648 bittok2str(ospf_rla_flag_values, "none", GET_U_1(lsap->lsa_un.un_rla.rla_flags)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800649
Elliott Hughes820eced2021-08-20 18:00:50 -0700650 rla_count = GET_BE_U_2(lsap->lsa_un.un_rla.rla_count);
651 ND_TCHECK_SIZE(lsap->lsa_un.un_rla.rla_link);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800652 rlp = lsap->lsa_un.un_rla.rla_link;
Elliott Hughes820eced2021-08-20 18:00:50 -0700653 for (u_int i = rla_count; i != 0; i--) {
654 ND_TCHECK_SIZE(rlp);
655 switch (GET_U_1(rlp->un_tos.link.link_type)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800656
657 case RLA_TYPE_VIRTUAL:
Elliott Hughes820eced2021-08-20 18:00:50 -0700658 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
659 GET_IPADDR_STRING(rlp->link_id),
660 GET_IPADDR_STRING(rlp->link_data));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700661 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800662
663 case RLA_TYPE_ROUTER:
Elliott Hughes820eced2021-08-20 18:00:50 -0700664 ND_PRINT("\n\t Neighbor Router-ID: %s, Interface Address: %s",
665 GET_IPADDR_STRING(rlp->link_id),
666 GET_IPADDR_STRING(rlp->link_data));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800667 break;
668
669 case RLA_TYPE_TRANSIT:
Elliott Hughes820eced2021-08-20 18:00:50 -0700670 ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s",
671 GET_IPADDR_STRING(rlp->link_id),
672 GET_IPADDR_STRING(rlp->link_data));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800673 break;
674
675 case RLA_TYPE_STUB:
Elliott Hughes820eced2021-08-20 18:00:50 -0700676 ND_PRINT("\n\t Stub Network: %s, Mask: %s",
677 GET_IPADDR_STRING(rlp->link_id),
678 GET_IPADDR_STRING(rlp->link_data));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800679 break;
680
681 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700682 ND_PRINT("\n\t Unknown Router Link Type (%u)",
683 GET_U_1(rlp->un_tos.link.link_type));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800684 return (ls_end);
685 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800686
Elliott Hughes820eced2021-08-20 18:00:50 -0700687 ospf_print_tos_metrics(ndo, &rlp->un_tos);
JP Abgrall53f17a92014-02-12 14:02:41 -0800688
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700689 rlp = (const struct rlalink *)((const u_char *)(rlp + 1) +
Elliott Hughes820eced2021-08-20 18:00:50 -0700690 (GET_U_1(rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800691 }
692 break;
693
694 case LS_TYPE_NETWORK:
Elliott Hughes820eced2021-08-20 18:00:50 -0700695 ND_PRINT("\n\t Mask %s\n\t Connected Routers:",
696 GET_IPADDR_STRING(lsap->lsa_un.un_nla.nla_mask));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800697 ap = lsap->lsa_un.un_nla.nla_router;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700698 while ((const u_char *)ap < ls_end) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700699 ND_TCHECK_SIZE(ap);
700 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800701 ++ap;
702 }
703 break;
704
705 case LS_TYPE_SUM_IP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700706 ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
707 ND_PRINT("\n\t Mask %s",
708 GET_IPADDR_STRING(lsap->lsa_un.un_sla.sla_mask));
709 ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
710 lp = (const uint8_t *)lsap->lsa_un.un_sla.sla_tosmetric;
711 while (lp < ls_end) {
712 uint32_t ul;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800713
Elliott Hughes820eced2021-08-20 18:00:50 -0700714 ul = GET_BE_U_4(lp);
JP Abgrall53f17a92014-02-12 14:02:41 -0800715 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
Elliott Hughes820eced2021-08-20 18:00:50 -0700716 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700717 tok2str(ospf_topology_values, "Unknown", topology),
JP Abgrall53f17a92014-02-12 14:02:41 -0800718 topology,
Elliott Hughes820eced2021-08-20 18:00:50 -0700719 ul & SLA_MASK_METRIC);
720 lp += 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800721 }
722 break;
723
724 case LS_TYPE_SUM_ABR:
Elliott Hughes820eced2021-08-20 18:00:50 -0700725 ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
726 lp = (const uint8_t *)lsap->lsa_un.un_sla.sla_tosmetric;
727 while (lp < ls_end) {
728 uint32_t ul;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800729
Elliott Hughes820eced2021-08-20 18:00:50 -0700730 ul = GET_BE_U_4(lp);
JP Abgrall53f17a92014-02-12 14:02:41 -0800731 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
Elliott Hughes820eced2021-08-20 18:00:50 -0700732 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700733 tok2str(ospf_topology_values, "Unknown", topology),
JP Abgrall53f17a92014-02-12 14:02:41 -0800734 topology,
Elliott Hughes820eced2021-08-20 18:00:50 -0700735 ul & SLA_MASK_METRIC);
736 lp += 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800737 }
738 break;
739
740 case LS_TYPE_ASE:
741 case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */
Elliott Hughes820eced2021-08-20 18:00:50 -0700742 ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
743 ND_PRINT("\n\t Mask %s",
744 GET_IPADDR_STRING(lsap->lsa_un.un_asla.asla_mask));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800745
Elliott Hughes820eced2021-08-20 18:00:50 -0700746 ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800747 almp = lsap->lsa_un.un_asla.asla_metric;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700748 while ((const u_char *)almp < ls_end) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700749 uint32_t ul;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800750
Elliott Hughes820eced2021-08-20 18:00:50 -0700751 ul = GET_BE_U_4(almp->asla_tosmetric);
JP Abgrall53f17a92014-02-12 14:02:41 -0800752 topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
Elliott Hughes820eced2021-08-20 18:00:50 -0700753 ND_PRINT("\n\t\ttopology %s (%u), type %u, metric",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700754 tok2str(ospf_topology_values, "Unknown", topology),
JP Abgrall53f17a92014-02-12 14:02:41 -0800755 topology,
Elliott Hughes820eced2021-08-20 18:00:50 -0700756 (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700757 if ((ul & ASLA_MASK_METRIC) == 0xffffff)
Elliott Hughes820eced2021-08-20 18:00:50 -0700758 ND_PRINT(" infinite");
Elliott Hughes892a68b2015-10-19 14:43:53 -0700759 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700760 ND_PRINT(" %u", (ul & ASLA_MASK_METRIC));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800761
Elliott Hughes820eced2021-08-20 18:00:50 -0700762 if (GET_IPV4_TO_NETWORK_ORDER(almp->asla_forward) != 0) {
763 ND_PRINT(", forward %s", GET_IPADDR_STRING(almp->asla_forward));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800764 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700765 if (GET_IPV4_TO_NETWORK_ORDER(almp->asla_tag) != 0) {
766 ND_PRINT(", tag %s", GET_IPADDR_STRING(almp->asla_tag));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800767 }
768 ++almp;
769 }
770 break;
771
772 case LS_TYPE_GROUP:
773 /* Multicast extensions as of 23 July 1991 */
774 mcp = lsap->lsa_un.un_mcla;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700775 while ((const u_char *)mcp < ls_end) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700776 switch (GET_BE_U_4(mcp->mcla_vtype)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800777
778 case MCLA_VERTEX_ROUTER:
Elliott Hughes820eced2021-08-20 18:00:50 -0700779 ND_PRINT("\n\t Router Router-ID %s",
780 GET_IPADDR_STRING(mcp->mcla_vid));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800781 break;
782
783 case MCLA_VERTEX_NETWORK:
Elliott Hughes820eced2021-08-20 18:00:50 -0700784 ND_PRINT("\n\t Network Designated Router %s",
785 GET_IPADDR_STRING(mcp->mcla_vid));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800786 break;
787
788 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700789 ND_PRINT("\n\t unknown VertexType (%u)",
790 GET_BE_U_4(mcp->mcla_vtype));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800791 break;
792 }
793 ++mcp;
794 }
795 break;
796
797 case LS_TYPE_OPAQUE_LL: /* fall through */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700798 case LS_TYPE_OPAQUE_AL:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800799 case LS_TYPE_OPAQUE_DW:
800
Elliott Hughes820eced2021-08-20 18:00:50 -0700801 switch (GET_U_1(lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800802 case LS_OPAQUE_TYPE_RI:
Elliott Hughes820eced2021-08-20 18:00:50 -0700803 tptr = (const uint8_t *)(lsap->lsa_un.un_ri_tlv);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800804
Elliott Hughes820eced2021-08-20 18:00:50 -0700805 u_int ls_length_remaining = ls_length;
806 while (ls_length_remaining != 0) {
807 ND_TCHECK_4(tptr);
808 if (ls_length_remaining < 4) {
809 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length_remaining);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800810 return(ls_end);
811 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700812 tlv_type = GET_BE_U_2(tptr);
813 tlv_length = GET_BE_U_2(tptr + 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800814 tptr+=4;
Elliott Hughes820eced2021-08-20 18:00:50 -0700815 ls_length_remaining-=4;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700816
Elliott Hughes820eced2021-08-20 18:00:50 -0700817 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800818 tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
819 tlv_type,
Elliott Hughes820eced2021-08-20 18:00:50 -0700820 tlv_length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800821
Elliott Hughes820eced2021-08-20 18:00:50 -0700822 if (tlv_length > ls_length_remaining) {
823 ND_PRINT("\n\t Bogus length %u > remaining LS length %u", tlv_length,
824 ls_length_remaining);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800825 return(ls_end);
826 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700827 ND_TCHECK_LEN(tptr, tlv_length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800828 switch(tlv_type) {
829
830 case LS_OPAQUE_RI_TLV_CAP:
831 if (tlv_length != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700832 ND_PRINT("\n\t Bogus length %u != 4", tlv_length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800833 return(ls_end);
834 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700835 ND_PRINT("Capabilities: %s",
836 bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", GET_BE_U_4(tptr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800837 break;
838 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700839 if (ndo->ndo_vflag <= 1) {
840 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
The Android Open Source Project2949f582009-03-03 19:30:46 -0800841 return(ls_end);
842 }
843 break;
844
845 }
846 tptr+=tlv_length;
Elliott Hughes820eced2021-08-20 18:00:50 -0700847 ls_length_remaining-=tlv_length;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800848 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800849 break;
JP Abgrall53f17a92014-02-12 14:02:41 -0800850
The Android Open Source Project2949f582009-03-03 19:30:46 -0800851 case LS_OPAQUE_TYPE_GRACE:
Elliott Hughes820eced2021-08-20 18:00:50 -0700852 if (ospf_grace_lsa_print(ndo, (const u_char *)(lsap->lsa_un.un_grace_tlv),
JP Abgrall53f17a92014-02-12 14:02:41 -0800853 ls_length) == -1) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800854 return(ls_end);
JP Abgrall53f17a92014-02-12 14:02:41 -0800855 }
856 break;
857
858 case LS_OPAQUE_TYPE_TE:
Elliott Hughes820eced2021-08-20 18:00:50 -0700859 if (ospf_te_lsa_print(ndo, (const u_char *)(lsap->lsa_un.un_te_lsa_tlv),
JP Abgrall53f17a92014-02-12 14:02:41 -0800860 ls_length) == -1) {
861 return(ls_end);
862 }
863 break;
864
865 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700866 if (ndo->ndo_vflag <= 1) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700867 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
JP Abgrall53f17a92014-02-12 14:02:41 -0800868 "\n\t ", ls_length))
869 return(ls_end);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700870 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800871 break;
872 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800873 }
874
875 /* do we want to see an additionally hexdump ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700876 if (ndo->ndo_vflag> 1)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700877 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800878 "\n\t ", ls_length)) {
879 return(ls_end);
880 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700881
The Android Open Source Project2949f582009-03-03 19:30:46 -0800882 return (ls_end);
883trunc:
884 return (NULL);
885}
886
Elliott Hughes820eced2021-08-20 18:00:50 -0700887static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700888ospf_decode_lls(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700889 const struct ospfhdr *op, u_int length)
JP Abgrall53f17a92014-02-12 14:02:41 -0800890{
Elliott Hughes820eced2021-08-20 18:00:50 -0700891 const u_char *dptr;
892 const u_char *dataend;
893 u_int length2;
894 uint16_t lls_type, lls_len;
895 uint32_t lls_flags;
JP Abgrall53f17a92014-02-12 14:02:41 -0800896
Elliott Hughes820eced2021-08-20 18:00:50 -0700897 switch (GET_U_1(op->ospf_type)) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800898
899 case OSPF_TYPE_HELLO:
Elliott Hughes820eced2021-08-20 18:00:50 -0700900 if (!(GET_U_1(op->ospf_hello.hello_options) & OSPF_OPTION_L))
901 return;
JP Abgrall53f17a92014-02-12 14:02:41 -0800902 break;
903
904 case OSPF_TYPE_DD:
Elliott Hughes820eced2021-08-20 18:00:50 -0700905 if (!(GET_U_1(op->ospf_db.db_options) & OSPF_OPTION_L))
906 return;
JP Abgrall53f17a92014-02-12 14:02:41 -0800907 break;
908
909 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700910 return;
JP Abgrall53f17a92014-02-12 14:02:41 -0800911 }
912
913 /* dig deeper if LLS data is available; see RFC4813 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700914 length2 = GET_BE_U_2(op->ospf_len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700915 dptr = (const u_char *)op + length2;
916 dataend = (const u_char *)op + length;
JP Abgrall53f17a92014-02-12 14:02:41 -0800917
Elliott Hughes820eced2021-08-20 18:00:50 -0700918 if (GET_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) {
919 dptr = dptr + GET_U_1(op->ospf_authdata + 3);
920 length2 += GET_U_1(op->ospf_authdata + 3);
JP Abgrall53f17a92014-02-12 14:02:41 -0800921 }
922 if (length2 >= length) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700923 ND_PRINT("\n\t[LLS truncated]");
924 return;
JP Abgrall53f17a92014-02-12 14:02:41 -0800925 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700926 ND_PRINT("\n\t LLS: checksum: 0x%04x", (u_int) GET_BE_U_2(dptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800927
928 dptr += 2;
Elliott Hughes820eced2021-08-20 18:00:50 -0700929 length2 = GET_BE_U_2(dptr);
930 ND_PRINT(", length: %u", length2);
JP Abgrall53f17a92014-02-12 14:02:41 -0800931
932 dptr += 2;
JP Abgrall53f17a92014-02-12 14:02:41 -0800933 while (dptr < dataend) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700934 lls_type = GET_BE_U_2(dptr);
935 ND_PRINT("\n\t %s (%u)",
JP Abgrall53f17a92014-02-12 14:02:41 -0800936 tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
Elliott Hughes820eced2021-08-20 18:00:50 -0700937 lls_type);
JP Abgrall53f17a92014-02-12 14:02:41 -0800938 dptr += 2;
Elliott Hughes820eced2021-08-20 18:00:50 -0700939 lls_len = GET_BE_U_2(dptr);
940 ND_PRINT(", length: %u", lls_len);
JP Abgrall53f17a92014-02-12 14:02:41 -0800941 dptr += 2;
942 switch (lls_type) {
943
944 case OSPF_LLS_EO:
945 if (lls_len != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700946 ND_PRINT(" [should be 4]");
JP Abgrall53f17a92014-02-12 14:02:41 -0800947 lls_len = 4;
948 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700949 lls_flags = GET_BE_U_4(dptr);
950 ND_PRINT("\n\t Options: 0x%08x [%s]", lls_flags,
951 bittok2str(ospf_lls_eo_options, "?", lls_flags));
JP Abgrall53f17a92014-02-12 14:02:41 -0800952
953 break;
954
955 case OSPF_LLS_MD5:
956 if (lls_len != 20) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700957 ND_PRINT(" [should be 20]");
JP Abgrall53f17a92014-02-12 14:02:41 -0800958 lls_len = 20;
959 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700960 ND_PRINT("\n\t Sequence number: 0x%08x", GET_BE_U_4(dptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800961 break;
962 }
963
964 dptr += lls_len;
965 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800966}
967
968static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700969ospf_decode_v2(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700970 const struct ospfhdr *op, const u_char *dataend)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800971{
Elliott Hughes820eced2021-08-20 18:00:50 -0700972 const nd_ipv4 *ap;
973 const struct lsr *lsrp;
974 const struct lsa_hdr *lshp;
975 const struct lsa *lsap;
976 uint32_t lsa_count,lsa_count_max;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800977
Elliott Hughes820eced2021-08-20 18:00:50 -0700978 switch (GET_U_1(op->ospf_type)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800979
980 case OSPF_TYPE_HELLO:
Elliott Hughes820eced2021-08-20 18:00:50 -0700981 ND_PRINT("\n\tOptions [%s]",
982 bittok2str(ospf_option_values,"none",GET_U_1(op->ospf_hello.hello_options)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800983
Elliott Hughes820eced2021-08-20 18:00:50 -0700984 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
985 GET_BE_U_2(op->ospf_hello.hello_helloint),
986 GET_BE_U_4(op->ospf_hello.hello_deadint),
987 GET_IPADDR_STRING(op->ospf_hello.hello_mask),
988 GET_U_1(op->ospf_hello.hello_priority));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800989
Elliott Hughes820eced2021-08-20 18:00:50 -0700990 if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_dr) != 0)
991 ND_PRINT("\n\t Designated Router %s",
992 GET_IPADDR_STRING(op->ospf_hello.hello_dr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800993
Elliott Hughes820eced2021-08-20 18:00:50 -0700994 if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_bdr) != 0)
995 ND_PRINT(", Backup Designated Router %s",
996 GET_IPADDR_STRING(op->ospf_hello.hello_bdr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800997
Elliott Hughes892a68b2015-10-19 14:43:53 -0700998 ap = op->ospf_hello.hello_neighbor;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700999 if ((const u_char *)ap < dataend)
Elliott Hughes820eced2021-08-20 18:00:50 -07001000 ND_PRINT("\n\t Neighbor List:");
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001001 while ((const u_char *)ap < dataend) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001002 ND_TCHECK_SIZE(ap);
1003 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001004 ++ap;
1005 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001006 break; /* HELLO */
1007
1008 case OSPF_TYPE_DD:
Elliott Hughes820eced2021-08-20 18:00:50 -07001009 ND_PRINT("\n\tOptions [%s]",
1010 bittok2str(ospf_option_values, "none", GET_U_1(op->ospf_db.db_options)));
1011 ND_PRINT(", DD Flags [%s]",
1012 bittok2str(ospf_dd_flag_values, "none", GET_U_1(op->ospf_db.db_flags)));
1013 if (GET_BE_U_2(op->ospf_db.db_ifmtu)) {
1014 ND_PRINT(", MTU: %u",
1015 GET_BE_U_2(op->ospf_db.db_ifmtu));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001016 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001017 ND_PRINT(", Sequence: 0x%08x", GET_BE_U_4(op->ospf_db.db_seq));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001018
Elliott Hughes892a68b2015-10-19 14:43:53 -07001019 /* Print all the LS adv's */
1020 lshp = op->ospf_db.db_lshdr;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001021 while (((const u_char *)lshp < dataend) && ospf_print_lshdr(ndo, lshp) != -1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001022 ++lshp;
1023 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001024 break;
1025
1026 case OSPF_TYPE_LS_REQ:
1027 lsrp = op->ospf_lsr;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001028 while ((const u_char *)lsrp < dataend) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001029 ND_TCHECK_SIZE(lsrp);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001030
Elliott Hughes820eced2021-08-20 18:00:50 -07001031 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1032 GET_IPADDR_STRING(lsrp->ls_router),
1033 tok2str(lsa_values,"unknown",GET_BE_U_4(lsrp->ls_type)),
1034 GET_BE_U_4(lsrp->ls_type));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001035
Elliott Hughes820eced2021-08-20 18:00:50 -07001036 switch (GET_BE_U_4(lsrp->ls_type)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001037 /* the LSA header for opaque LSAs was slightly changed */
1038 case LS_TYPE_OPAQUE_LL:
1039 case LS_TYPE_OPAQUE_AL:
1040 case LS_TYPE_OPAQUE_DW:
Elliott Hughes820eced2021-08-20 18:00:50 -07001041 ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1042 tok2str(lsa_opaque_values, "unknown",GET_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type)),
1043 GET_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type),
1044 GET_BE_U_3(lsrp->un_ls_stateid.opaque_field.opaque_id));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001045 break;
1046 default:
Elliott Hughes820eced2021-08-20 18:00:50 -07001047 ND_PRINT(", LSA-ID: %s",
1048 GET_IPADDR_STRING(lsrp->un_ls_stateid.ls_stateid));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001049 break;
1050 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001051
The Android Open Source Project2949f582009-03-03 19:30:46 -08001052 ++lsrp;
1053 }
1054 break;
1055
1056 case OSPF_TYPE_LS_UPDATE:
1057 lsap = op->ospf_lsu.lsu_lsa;
Elliott Hughes820eced2021-08-20 18:00:50 -07001058 lsa_count_max = GET_BE_U_4(op->ospf_lsu.lsu_count);
1059 ND_PRINT(", %u LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001060 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001061 ND_PRINT("\n\t LSA #%u", lsa_count);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001062 lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001063 if (lsap == NULL)
1064 goto trunc;
1065 }
1066 break;
1067
1068 case OSPF_TYPE_LS_ACK:
1069 lshp = op->ospf_lsa.lsa_lshdr;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001070 while (ospf_print_lshdr(ndo, lshp) != -1) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001071 ++lshp;
1072 }
1073 break;
1074
1075 default:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001076 break;
1077 }
1078 return (0);
1079trunc:
1080 return (1);
1081}
1082
1083void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001084ospf_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -07001085 const u_char *bp, u_int length,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001086 const u_char *bp2 _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001087{
Elliott Hughes820eced2021-08-20 18:00:50 -07001088 const struct ospfhdr *op;
1089 const u_char *dataend;
1090 const char *cp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001091
Elliott Hughes820eced2021-08-20 18:00:50 -07001092 ndo->ndo_protocol = "ospf2";
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001093 op = (const struct ospfhdr *)bp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001094
Elliott Hughes892a68b2015-10-19 14:43:53 -07001095 /* XXX Before we do anything else, strip off the MD5 trailer */
Elliott Hughes820eced2021-08-20 18:00:50 -07001096 if (GET_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001097 length -= OSPF_AUTH_MD5_LEN;
1098 ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN;
1099 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001100
1101 /* If the type is valid translate it, or just print the type */
1102 /* value. If it's not valid, say so and return */
Elliott Hughes820eced2021-08-20 18:00:50 -07001103 cp = tok2str(type2str, "unknown LS-type %u", GET_U_1(op->ospf_type));
1104 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op->ospf_version), cp,
1105 length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001106 if (*cp == 'u')
1107 return;
1108
Elliott Hughes892a68b2015-10-19 14:43:53 -07001109 if (!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
1110 return;
1111 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001112
Elliott Hughes820eced2021-08-20 18:00:50 -07001113 if (length != GET_BE_U_2(op->ospf_len)) {
1114 ND_PRINT(" [len %u]", GET_BE_U_2(op->ospf_len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001115 }
JP Abgrall53f17a92014-02-12 14:02:41 -08001116
Elliott Hughes820eced2021-08-20 18:00:50 -07001117 if (length > GET_BE_U_2(op->ospf_len)) {
1118 dataend = bp + GET_BE_U_2(op->ospf_len);
JP Abgrall53f17a92014-02-12 14:02:41 -08001119 } else {
1120 dataend = bp + length;
1121 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001122
Elliott Hughes820eced2021-08-20 18:00:50 -07001123 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op->ospf_routerid));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001124
Elliott Hughes820eced2021-08-20 18:00:50 -07001125 if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_areaid) != 0)
1126 ND_PRINT(", Area %s", GET_IPADDR_STRING(op->ospf_areaid));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001127 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001128 ND_PRINT(", Backbone Area");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001129
Elliott Hughes892a68b2015-10-19 14:43:53 -07001130 if (ndo->ndo_vflag) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001131 /* Print authentication data (should we really do this?) */
Elliott Hughes820eced2021-08-20 18:00:50 -07001132 ND_TCHECK_LEN(op->ospf_authdata, sizeof(op->ospf_authdata));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001133
Elliott Hughes820eced2021-08-20 18:00:50 -07001134 ND_PRINT(", Authentication Type: %s (%u)",
1135 tok2str(ospf_authtype_values, "unknown", GET_BE_U_2(op->ospf_authtype)),
1136 GET_BE_U_2(op->ospf_authtype));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001137
Elliott Hughes820eced2021-08-20 18:00:50 -07001138 switch (GET_BE_U_2(op->ospf_authtype)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001139
1140 case OSPF_AUTH_NONE:
1141 break;
1142
1143 case OSPF_AUTH_SIMPLE:
Elliott Hughes820eced2021-08-20 18:00:50 -07001144 ND_PRINT("\n\tSimple text password: ");
1145 nd_printjnp(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001146 break;
1147
1148 case OSPF_AUTH_MD5:
Elliott Hughes820eced2021-08-20 18:00:50 -07001149 ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1150 GET_U_1(op->ospf_authdata + 2),
1151 GET_U_1(op->ospf_authdata + 3),
1152 GET_BE_U_4((op->ospf_authdata) + 4));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001153 break;
1154
1155 default:
1156 return;
1157 }
1158 }
1159 /* Do rest according to version. */
Elliott Hughes820eced2021-08-20 18:00:50 -07001160 switch (GET_U_1(op->ospf_version)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001161
1162 case 2:
1163 /* ospf version 2 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001164 if (ospf_decode_v2(ndo, op, dataend))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001165 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001166 if (length > GET_BE_U_2(op->ospf_len))
1167 ospf_decode_lls(ndo, op, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001168 break;
1169
1170 default:
Elliott Hughes820eced2021-08-20 18:00:50 -07001171 ND_PRINT(" ospf [version %u]", GET_U_1(op->ospf_version));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001172 break;
1173 } /* end switch on version */
1174
1175 return;
1176trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001177 nd_trunc_longjmp(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001178}