2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
21 * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
24 /* \summary: Open Shortest Path First (OSPF) printer */
30 #include "netdissect-stdinc.h"
32 #include "netdissect.h"
33 #include "addrtoname.h"
40 static const struct tok ospf_option_values
[] = {
41 { OSPF_OPTION_MT
, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
42 { OSPF_OPTION_E
, "External" },
43 { OSPF_OPTION_MC
, "Multicast" },
44 { OSPF_OPTION_NP
, "NSSA" },
45 { OSPF_OPTION_L
, "LLS" },
46 { OSPF_OPTION_DC
, "Demand Circuit" },
47 { OSPF_OPTION_O
, "Opaque" },
48 { OSPF_OPTION_DN
, "Up/Down" },
52 static const struct tok ospf_authtype_values
[] = {
53 { OSPF_AUTH_NONE
, "none" },
54 { OSPF_AUTH_SIMPLE
, "simple" },
55 { OSPF_AUTH_MD5
, "MD5" },
59 static const struct tok ospf_rla_flag_values
[] = {
60 { RLA_FLAG_B
, "ABR" },
61 { RLA_FLAG_E
, "ASBR" },
62 { RLA_FLAG_V
, "Virtual" },
63 { RLA_FLAG_W
, "Wildcard" },
64 { RLA_FLAG_NT
, "Nt" },
65 { RLA_FLAG_H
, "Host" },
69 static const struct tok type2str
[] = {
70 { OSPF_TYPE_HELLO
, "Hello" },
71 { OSPF_TYPE_DD
, "Database Description" },
72 { OSPF_TYPE_LS_REQ
, "LS-Request" },
73 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
74 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
78 static const struct tok lsa_values
[] = {
79 { LS_TYPE_ROUTER
, "Router" },
80 { LS_TYPE_NETWORK
, "Network" },
81 { LS_TYPE_SUM_IP
, "Summary" },
82 { LS_TYPE_SUM_ABR
, "ASBR Summary" },
83 { LS_TYPE_ASE
, "External" },
84 { LS_TYPE_GROUP
, "Multicast Group" },
85 { LS_TYPE_NSSA
, "NSSA" },
86 { LS_TYPE_OPAQUE_LL
, "Link Local Opaque" },
87 { LS_TYPE_OPAQUE_AL
, "Area Local Opaque" },
88 { LS_TYPE_OPAQUE_DW
, "Domain Wide Opaque" },
92 static const struct tok ospf_dd_flag_values
[] = {
93 { OSPF_DB_INIT
, "Init" },
94 { OSPF_DB_MORE
, "More" },
95 { OSPF_DB_MASTER
, "Master" },
96 { OSPF_DB_RESYNC
, "OOBResync" },
100 static const struct tok lsa_opaque_values
[] = {
101 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
102 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
103 { LS_OPAQUE_TYPE_RI
, "Router Information" },
104 { LS_OPAQUE_TYPE_EP
, "Extended Prefix" },
105 { LS_OPAQUE_TYPE_EL
, "Extended Link" },
109 static const struct tok lsa_opaque_ri_sid_subtlv_values
[] = {
110 { LS_OPAQUE_RI_SUBTLV_SID_LABEL
, "SID/Label" },
114 static const struct tok lsa_opaque_te_tlv_values
[] = {
115 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
116 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
120 static const struct tok lsa_opaque_ep_extd_prefix_subtlv_values
[] = {
121 { LS_OPAQUE_EP_SUBTLV_PREFIX_SID
, "Prefix-SID" },
125 static const struct tok ep_range_tlv_prefix_sid_subtlv_flag_values
[] = {
127 { 0x20, "Mapping-Server"},
128 { 0x10, "Explicit-NULL"},
135 static const struct tok lsa_opaque_ep_route_type_values
[] = {
136 { 0, "Unspecified" },
139 { 5, "AS External" },
140 { 7, "NSSA External" },
144 static const struct tok lsa_opaque_ep_tlv_values
[] = {
145 { LS_OPAQUE_EP_EXTD_PREFIX_TLV
, "Extended Prefix" },
146 { LS_OPAQUE_EP_EXTD_PREFIX_RANGE_TLV
, "Extended Prefix Range" },
150 static const struct tok ep_tlv_flag_values
[] = {
151 { 0x80, "Inter-Area"},
155 static const struct tok lsa_opaque_te_link_tlv_subtlv_values
[] = {
156 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
, "Link Type" },
157 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
, "Link ID" },
158 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
, "Local Interface IP address" },
159 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
, "Remote Interface IP address" },
160 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
, "Traffic Engineering Metric" },
161 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
, "Maximum Bandwidth" },
162 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
, "Maximum Reservable Bandwidth" },
163 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
, "Unreserved Bandwidth" },
164 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
, "Administrative Group" },
165 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
, "Link Local/Remote Identifier" },
166 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
, "Link Protection Type" },
167 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
, "Interface Switching Capability" },
168 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
, "Shared Risk Link Group" },
169 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
, "Bandwidth Constraints" },
173 static const struct tok lsa_opaque_grace_tlv_values
[] = {
174 { LS_OPAQUE_GRACE_TLV_PERIOD
, "Grace Period" },
175 { LS_OPAQUE_GRACE_TLV_REASON
, "Graceful restart Reason" },
176 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS
, "IPv4 interface address" },
180 static const struct tok lsa_opaque_grace_tlv_reason_values
[] = {
181 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN
, "Unknown" },
182 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART
, "Software Restart" },
183 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE
, "Software Reload/Upgrade" },
184 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH
, "Control Processor Switch" },
188 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
189 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
190 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
194 static const struct tok lsa_opaque_ri_tlv_values
[] = {
195 { LS_OPAQUE_RI_TLV_CAP
, "Router Capabilities" },
196 { LS_OPAQUE_RI_TLV_SR_ALGO
, "SR-Algorithm" },
197 { LS_OPAQUE_RI_TLV_HOSTNAME
, "Hostname" },
198 { LS_OPAQUE_RI_TLV_SID_LABEL_RANGE
, "SID/Label Range" },
199 { LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK
, "SR Local Block" },
200 { LS_OPAQUE_RI_TLV_SRMS_PREFERENCE
, "SRMS Preference" },
204 static const struct tok lsa_opaque_ri_tlv_cap_values
[] = {
209 { 16, "graceful restart capable" },
210 { 32, "graceful restart helper" },
211 { 64, "Stub router support" },
212 { 128, "Traffic engineering" },
213 { 256, "p2p over LAN" },
214 { 512, "path computation server" },
218 static const struct tok lsa_opaque_ri_tlv_sr_algos
[] = {
219 { 0, "Shortest Path First" },
220 { 1, "Strict Shortest Path First" },
224 static const struct tok ospf_lls_tlv_values
[] = {
225 { OSPF_LLS_EO
, "Extended Options" },
226 { OSPF_LLS_MD5
, "MD5 Authentication" },
230 static const struct tok ospf_lls_eo_options
[] = {
231 { OSPF_LLS_EO_LR
, "LSDB resync" },
232 { OSPF_LLS_EO_RS
, "Restart" },
237 ospf_grace_lsa_print(netdissect_options
*ndo
,
238 const u_char
*tptr
, u_int ls_length
)
240 u_int tlv_type
, tlv_length
;
243 while (ls_length
!= 0) {
246 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length
);
249 tlv_type
= GET_BE_U_2(tptr
);
250 tlv_length
= GET_BE_U_2(tptr
+ 2);
254 ND_PRINT("\n\t %s TLV (%u), length %u, value: ",
255 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
259 if (tlv_length
> ls_length
) {
260 ND_PRINT("\n\t Bogus length %u > %u", tlv_length
,
265 /* Infinite loop protection. */
266 if (tlv_type
== 0 || tlv_length
==0) {
267 nd_print_invalid(ndo
);
271 ND_TCHECK_LEN(tptr
, tlv_length
);
274 case LS_OPAQUE_GRACE_TLV_PERIOD
:
275 if (tlv_length
!= 4) {
276 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
279 ND_PRINT("%us", GET_BE_U_4(tptr
));
282 case LS_OPAQUE_GRACE_TLV_REASON
:
283 if (tlv_length
!= 1) {
284 ND_PRINT("\n\t Bogus length %u != 1", tlv_length
);
288 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", GET_U_1(tptr
)),
292 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
293 if (tlv_length
!= 4) {
294 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
297 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
301 if (ndo
->ndo_vflag
<= 1) {
302 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
308 /* in OSPF everything has to be 32-bit aligned, including TLVs */
309 if (tlv_length
%4 != 0) {
310 tlv_length
+=4-(tlv_length
%4);
311 if (tlv_length
> ls_length
) {
312 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
317 ls_length
-=tlv_length
;
327 ospf_te_tlv_link_print(netdissect_options
*ndo
,
328 const u_char
*tptr
, u_int tlv_length
)
330 u_int subtlv_type
, subtlv_length
;
331 u_int priority_level
, te_class
, count_srlg
;
334 while (tlv_length
!= 0) {
335 if (tlv_length
< 4) {
336 ND_PRINT("\n\t Remaining TLV length %u < 4",
340 subtlv_type
= GET_BE_U_2(tptr
);
341 subtlv_length
= GET_BE_U_2(tptr
+ 2);
345 /* Infinite loop protection */
346 if (subtlv_type
== 0 || subtlv_length
== 0)
349 ND_PRINT("\n\t %s subTLV (%u), length: %u",
350 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
354 if (tlv_length
< subtlv_length
) {
355 ND_PRINT("\n\t Remaining TLV length %u < %u",
356 tlv_length
, subtlv_length
);
359 ND_TCHECK_LEN(tptr
, subtlv_length
);
360 switch(subtlv_type
) {
361 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
362 if (subtlv_length
!= 4) {
366 ND_PRINT(", 0x%08x", GET_BE_U_4(tptr
));
368 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
369 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
370 if (subtlv_length
!= 4 && subtlv_length
!= 8) {
371 ND_PRINT(" != 4 && != 8");
374 ND_PRINT(", %s (0x%08x)",
375 GET_IPADDR_STRING(tptr
),
377 if (subtlv_length
== 8) /* rfc4203 */
378 ND_PRINT(", %s (0x%08x)",
379 GET_IPADDR_STRING(tptr
+4),
380 GET_BE_U_4(tptr
+ 4));
382 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
383 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
384 if (subtlv_length
!= 4) {
388 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
390 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
391 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
392 if (subtlv_length
!= 4) {
396 bw
= GET_BE_F_4(tptr
);
397 ND_PRINT(", %.3f Mbps", bw
* 8 / 1000000);
399 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
400 if (subtlv_length
!= 32) {
404 for (te_class
= 0; te_class
< 8; te_class
++) {
405 bw
= GET_BE_F_4(tptr
+ te_class
* 4);
406 ND_PRINT("\n\t\tTE-Class %u: %.3f Mbps",
411 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
412 if (subtlv_length
< 4) {
416 /* BC Model Id (1 octet) + Reserved (3 octets) */
417 ND_PRINT("\n\t\tBandwidth Constraints Model ID: %s (%u)",
418 tok2str(diffserv_te_bc_values
, "unknown", GET_U_1(tptr
)),
420 if (subtlv_length
% 4 != 0) {
421 ND_PRINT("\n\t\tlength %u != N x 4", subtlv_length
);
424 if (subtlv_length
> 36) {
425 ND_PRINT("\n\t\tlength %u > 36", subtlv_length
);
428 /* decode BCs until the subTLV ends */
429 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
430 bw
= GET_BE_F_4(tptr
+ 4 + te_class
* 4);
431 ND_PRINT("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
436 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
437 if (subtlv_length
!= 4) {
441 ND_PRINT(", Metric %u", GET_BE_U_4(tptr
));
443 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
444 /* Protection Cap (1 octet) + Reserved ((3 octets) */
445 if (subtlv_length
!= 4) {
450 bittok2str(gmpls_link_prot_values
, "none", GET_U_1(tptr
)));
452 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
453 if (subtlv_length
< 36) {
457 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
458 ND_PRINT("\n\t\tInterface Switching Capability: %s",
459 tok2str(gmpls_switch_cap_values
, "Unknown", GET_U_1((tptr
))));
460 ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
461 tok2str(gmpls_encoding_values
, "Unknown", GET_U_1((tptr
+ 1))));
462 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
463 bw
= GET_BE_F_4(tptr
+ 4 + (priority_level
* 4));
464 ND_PRINT("\n\t\t priority level %u: %.3f Mbps",
469 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
470 if (subtlv_length
!= 1) {
474 ND_PRINT(", %s (%u)",
475 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",GET_U_1(tptr
)),
478 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
479 if (subtlv_length
% 4 != 0) {
480 ND_PRINT(" != N x 4");
483 count_srlg
= subtlv_length
/ 4;
485 ND_PRINT("\n\t\t Shared risk group: ");
486 while (count_srlg
> 0) {
487 ND_PRINT("%u", GET_BE_U_4(tptr
));
495 if (ndo
->ndo_vflag
<= 1) {
496 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
501 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
502 if (subtlv_length
%4 != 0) {
503 subtlv_length
+=4-(subtlv_length
%4);
505 if (tlv_length
< subtlv_length
) {
506 ND_PRINT("\n\t Remaining TLV length %u < %u",
507 tlv_length
, subtlv_length
);
511 tlv_length
-=subtlv_length
;
518 nd_print_invalid(ndo
);
523 ospf_te_lsa_print(netdissect_options
*ndo
,
524 const u_char
*tptr
, u_int ls_length
)
526 u_int tlv_type
, tlv_length
;
528 while (ls_length
!= 0) {
531 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length
);
534 tlv_type
= GET_BE_U_2(tptr
);
535 tlv_length
= GET_BE_U_2(tptr
+ 2);
539 ND_PRINT("\n\t %s TLV (%u), length: %u",
540 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
544 if (tlv_length
> ls_length
) {
545 ND_PRINT("\n\t Bogus length %u > %u", tlv_length
,
550 /* Infinite loop protection. */
551 if (tlv_type
== 0 || tlv_length
==0) {
552 nd_print_invalid(ndo
);
557 case LS_OPAQUE_TE_TLV_LINK
:
558 if (ospf_te_tlv_link_print(ndo
, tptr
, tlv_length
) == -1)
562 case LS_OPAQUE_TE_TLV_ROUTER
:
563 if (tlv_length
< 4) {
564 ND_PRINT("\n\t TLV length %u < 4", tlv_length
);
567 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
571 if (ndo
->ndo_vflag
<= 1) {
572 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
577 /* in OSPF everything has to be 32-bit aligned, including TLVs */
578 if (tlv_length
%4 != 0) {
579 tlv_length
+=4-(tlv_length
%4);
580 if (tlv_length
> ls_length
) {
581 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
586 ls_length
-=tlv_length
;
593 nd_print_invalid(ndo
);
598 ospf_print_lshdr(netdissect_options
*ndo
,
599 const struct lsa_hdr
*lshp
)
604 ls_length
= GET_BE_U_2(lshp
->ls_length
);
605 if (ls_length
< sizeof(struct lsa_hdr
)) {
606 ND_PRINT("\n\t Bogus length %u < header (%zu)", ls_length
,
607 sizeof(struct lsa_hdr
));
610 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %zu",
611 GET_IPADDR_STRING(lshp
->ls_router
),
612 GET_BE_U_4(lshp
->ls_seq
),
613 GET_BE_U_2(lshp
->ls_age
),
614 ls_length
- sizeof(struct lsa_hdr
));
615 ls_type
= GET_U_1(lshp
->ls_type
);
617 /* the LSA header for opaque LSAs was slightly changed */
618 case LS_TYPE_OPAQUE_LL
:
619 case LS_TYPE_OPAQUE_AL
:
620 case LS_TYPE_OPAQUE_DW
:
621 ND_PRINT("\n\t %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u",
622 tok2str(lsa_values
,"unknown",ls_type
),
625 tok2str(lsa_opaque_values
,
627 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
628 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
),
629 GET_BE_U_3(lshp
->un_lsa_id
.opaque_field
.opaque_id
)
634 /* all other LSA types use regular style LSA headers */
636 ND_PRINT("\n\t %s LSA (%u), LSA-ID: %s",
637 tok2str(lsa_values
,"unknown",ls_type
),
639 GET_IPADDR_STRING(lshp
->un_lsa_id
.lsa_id
));
642 ND_PRINT("\n\t Options: [%s]",
643 bittok2str(ospf_option_values
, "none", GET_U_1(lshp
->ls_options
)));
648 /* draft-ietf-ospf-mt-09 */
649 static const struct tok ospf_topology_values
[] = {
657 * Print all the per-topology metrics.
660 ospf_print_tos_metrics(netdissect_options
*ndo
,
661 const union un_tos
*tos
)
667 toscount
= GET_U_1(tos
->link
.link_tos_count
)+1;
671 * All but the first metric contain a valid topology id.
673 while (toscount
!= 0) {
674 tos_type
= GET_U_1(tos
->metrics
.tos_type
);
675 ND_PRINT("\n\t\ttopology %s (%u), metric %u",
676 tok2str(ospf_topology_values
, "Unknown",
677 metric_count
? tos_type
: 0),
678 metric_count
? tos_type
: 0,
679 GET_BE_U_2(tos
->metrics
.tos_metric
));
687 * The SID/Label Range TLV
688 * https://datatracker.ietf.org/doc/html/rfc8665#section-3.2
689 * and the SR Local Block TLV
690 * https://datatracker.ietf.org/doc/html/rfc8665#section-3.3
691 * have the same contents, so this function is used to
695 ospf_print_ri_lsa_sid_label_range_tlv(netdissect_options
*ndo
, const uint8_t *tptr
,
698 u_int subtlv_type
, subtlv_length
;
700 while (tlv_length
>= 4) {
702 subtlv_type
= GET_BE_U_2(tptr
);
703 subtlv_length
= GET_BE_U_2(tptr
+2);
707 /* Infinite loop protection. */
708 if (subtlv_type
== 0 || subtlv_length
== 0) {
709 nd_print_invalid(ndo
);
713 ND_PRINT("\n\t %s subTLV (%u), length: %u, value: ",
714 tok2str(lsa_opaque_ri_sid_subtlv_values
,"unknown",subtlv_type
),
718 if (tlv_length
< subtlv_length
) {
719 ND_PRINT("\n\t Remaining TLV length %u < %u",
720 tlv_length
, subtlv_length
);
724 switch (subtlv_type
) {
725 case LS_OPAQUE_RI_SUBTLV_SID_LABEL
:
726 if (subtlv_length
== 3) {
727 ND_PRINT("\n\t\tLabel: %u", GET_BE_U_3(tptr
));
728 } else if (subtlv_length
== 4) {
729 ND_PRINT("\n\t\tSID: %u", GET_BE_U_4(tptr
));
731 ND_PRINT("\n\t\tBogus subTLV length %u", subtlv_length
);
736 if (ndo
->ndo_vflag
<= 1) {
737 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
742 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
743 if (subtlv_length
% 4) {
744 subtlv_length
+= (4 - (subtlv_length
% 4));
745 if (tlv_length
< subtlv_length
) {
746 ND_PRINT("\n\t Remaining TLV length %u < %u",
747 tlv_length
, subtlv_length
);
752 tlv_length
-=subtlv_length
;
758 ospf_print_ep_lsa_extd_prefix_tlv(netdissect_options
*ndo
, const uint8_t *tptr
,
761 u_int subtlv_type
, subtlv_length
;
762 uint8_t flags
, mt_id
, algo
;
764 while (tlv_length
>= 4) {
765 subtlv_type
= GET_BE_U_2(tptr
);
766 subtlv_length
= GET_BE_U_2(tptr
+2);
770 /* Infinite loop protection. */
771 if (subtlv_type
== 0 || subtlv_length
== 0) {
772 nd_print_invalid(ndo
);
776 ND_PRINT("\n\t\t%s subTLV (%u), length: %u, value: ",
777 tok2str(lsa_opaque_ep_extd_prefix_subtlv_values
,"unknown",subtlv_type
),
781 if (tlv_length
< subtlv_length
) {
782 ND_PRINT("\n\t Remaining TLV length %u < %u",
783 tlv_length
, subtlv_length
);
787 switch (subtlv_type
) {
788 case LS_OPAQUE_EP_SUBTLV_PREFIX_SID
:
789 flags
= GET_U_1(tptr
);
790 mt_id
= GET_U_1(tptr
+2);
791 algo
= GET_U_1(tptr
+3);
793 if (subtlv_length
== 7) {
794 ND_PRINT("\n\t\t Label: %u", GET_BE_U_3(tptr
+4));
795 } else if (subtlv_length
== 8) {
796 ND_PRINT("\n\t\t Index: %u", GET_BE_U_4(tptr
+4));
798 ND_PRINT("\n\t\tBogus subTLV length %u", subtlv_length
);
801 ND_PRINT( ", MT-ID: %u, Algorithm: %s (%u), Flags [%s]",
802 mt_id
, tok2str(lsa_opaque_ri_tlv_sr_algos
, "Unknown", algo
), algo
,
803 bittok2str(ep_range_tlv_prefix_sid_subtlv_flag_values
, "none", flags
));
807 if (ndo
->ndo_vflag
<= 1) {
808 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
813 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
814 if (subtlv_length
% 4) {
815 subtlv_length
+= (4 - (subtlv_length
% 4));
816 if (tlv_length
< subtlv_length
) {
817 ND_PRINT("\n\t Remaining TLV length %u < %u",
818 tlv_length
, subtlv_length
);
823 tlv_length
-=subtlv_length
;
829 ospf_ep_lsa_print(netdissect_options
*ndo
, const uint8_t *tptr
, u_int lsa_length
)
831 u_int tlv_type
, tlv_length
;
833 uint8_t af
, prefix_length
, route_type
, flags
;
835 while (lsa_length
>= 4) {
837 tlv_type
= GET_BE_U_2(tptr
);
838 tlv_length
= GET_BE_U_2(tptr
+2);
842 /* Infinite loop protection. */
843 if (tlv_type
== 0 || tlv_length
== 0) {
844 nd_print_invalid(ndo
);
848 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
849 tok2str(lsa_opaque_ep_tlv_values
,"unknown",tlv_type
),
853 if (tlv_length
> lsa_length
) {
854 ND_PRINT("\n\t Bogus length %u > %u",
855 tlv_length
, lsa_length
);
860 case LS_OPAQUE_EP_EXTD_PREFIX_TLV
:
861 prefix_length
= GET_U_1(tptr
+1);
862 af
= GET_U_1(tptr
+2);
863 route_type
= GET_U_1(tptr
);
864 flags
= GET_U_1(tptr
+3);
867 ND_PRINT("\n\t Bogus AF %u", af
);
871 if (prefix_length
> 32) {
872 ND_PRINT("\n\t IPv4 prefix: bad bit length %u", prefix_length
);
876 ND_PRINT("\n\t IPv4 prefix: %15s/%u, Route Type: %s, Flags [%s]",
877 GET_IPADDR_STRING(tptr
+4), prefix_length
,
878 tok2str(lsa_opaque_ep_route_type_values
, "Unknown", route_type
),
879 bittok2str(ep_tlv_flag_values
, "none", flags
));
881 /* subTLVs present ? */
882 if (tlv_length
> 12) {
883 if (ospf_print_ep_lsa_extd_prefix_tlv(ndo
, tptr
+8, tlv_length
-8) == -1) {
889 case LS_OPAQUE_EP_EXTD_PREFIX_RANGE_TLV
:
890 prefix_length
= GET_U_1(tptr
);
891 af
= GET_U_1(tptr
+1);
892 range_size
= GET_BE_U_2(tptr
+2);
893 flags
= GET_U_1(tptr
+4);
896 ND_PRINT("\n\t Bogus AF %u", af
);
900 if (prefix_length
> 32) {
901 ND_PRINT("\n\t IPv4 prefix: bad bit length %u", prefix_length
);
905 ND_PRINT("\n\t IPv4 prefix: %15s/%u, Range size: %u, Flags [%s]",
906 GET_IPADDR_STRING(tptr
+8), prefix_length
,
908 bittok2str(ep_tlv_flag_values
, "none", flags
));
910 /* subTLVs present ? */
911 if (tlv_length
> 12) {
912 if (ospf_print_ep_lsa_extd_prefix_tlv(ndo
, tptr
+12, tlv_length
-12) == -1) {
919 if (ndo
->ndo_vflag
<= 1) {
920 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", tlv_length
))
925 /* in OSPF everything has to be 32-bit aligned, including TLVs */
926 if (tlv_length
% 4) {
927 tlv_length
+= (4 - (tlv_length
% 4));
928 if (tlv_length
> lsa_length
) {
929 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
935 lsa_length
-=tlv_length
;
941 * Print a single link state advertisement. If truncated or if LSA length
942 * field is less than the length of the LSA header, return NULl, else
943 * return pointer to data past end of LSA.
945 static const uint8_t *
946 ospf_print_lsa(netdissect_options
*ndo
,
947 const struct lsa
*lsap
)
949 const uint8_t *ls_end
;
950 const struct rlalink
*rlp
;
952 const struct aslametric
*almp
;
953 const struct mcla
*mcp
;
955 u_int tlv_type
, tlv_length
, rla_count
, topology
, num_tlv
;
956 int ospf_print_lshdr_ret
;
960 tptr
= (const uint8_t *)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
961 ospf_print_lshdr_ret
= ospf_print_lshdr(ndo
, &lsap
->ls_hdr
);
962 if (ospf_print_lshdr_ret
< 0)
964 ls_length
= (u_int
)ospf_print_lshdr_ret
;
965 ls_end
= (const uint8_t *)lsap
+ ls_length
;
967 * ospf_print_lshdr() returns -1 if the length is too short,
968 * so we know ls_length is >= sizeof(struct lsa_hdr).
970 ls_length
-= sizeof(struct lsa_hdr
);
972 switch (GET_U_1(lsap
->ls_hdr
.ls_type
)) {
975 ND_PRINT("\n\t Router LSA Options: [%s]",
976 bittok2str(ospf_rla_flag_values
, "none", GET_U_1(lsap
->lsa_un
.un_rla
.rla_flags
)));
978 rla_count
= GET_BE_U_2(lsap
->lsa_un
.un_rla
.rla_count
);
979 ND_TCHECK_SIZE(lsap
->lsa_un
.un_rla
.rla_link
);
980 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
981 for (u_int i
= rla_count
; i
!= 0; i
--) {
983 switch (GET_U_1(rlp
->un_tos
.link
.link_type
)) {
985 case RLA_TYPE_VIRTUAL
:
986 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
987 GET_IPADDR_STRING(rlp
->link_id
),
988 GET_IPADDR_STRING(rlp
->link_data
));
991 case RLA_TYPE_ROUTER
:
992 ND_PRINT("\n\t Neighbor Router-ID: %s, Interface Address: %s",
993 GET_IPADDR_STRING(rlp
->link_id
),
994 GET_IPADDR_STRING(rlp
->link_data
));
997 case RLA_TYPE_TRANSIT
:
998 ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s",
999 GET_IPADDR_STRING(rlp
->link_id
),
1000 GET_IPADDR_STRING(rlp
->link_data
));
1004 ND_PRINT("\n\t Stub Network: %s, Mask: %s",
1005 GET_IPADDR_STRING(rlp
->link_id
),
1006 GET_IPADDR_STRING(rlp
->link_data
));
1010 ND_PRINT("\n\t Unknown Router Link Type (%u)",
1011 GET_U_1(rlp
->un_tos
.link
.link_type
));
1015 ospf_print_tos_metrics(ndo
, &rlp
->un_tos
);
1017 rlp
= (const struct rlalink
*)((const u_char
*)(rlp
+ 1) +
1018 (GET_U_1(rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
1022 case LS_TYPE_NETWORK
:
1023 ND_PRINT("\n\t Mask %s\n\t Connected Routers:",
1024 GET_IPADDR_STRING(lsap
->lsa_un
.un_nla
.nla_mask
));
1025 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
1026 while ((const u_char
*)ap
< ls_end
) {
1027 ND_PRINT("\n\t %s", GET_IPADDR_STRING(ap
));
1032 case LS_TYPE_SUM_IP
:
1033 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
1034 ND_PRINT("\n\t Mask %s",
1035 GET_IPADDR_STRING(lsap
->lsa_un
.un_sla
.sla_mask
));
1036 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
1037 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
1038 while (lp
< ls_end
) {
1041 ul
= GET_BE_U_4(lp
);
1042 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
1043 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
1044 tok2str(ospf_topology_values
, "Unknown", topology
),
1046 ul
& SLA_MASK_METRIC
);
1051 case LS_TYPE_SUM_ABR
:
1052 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
1053 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
1054 while (lp
< ls_end
) {
1057 ul
= GET_BE_U_4(lp
);
1058 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
1059 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
1060 tok2str(ospf_topology_values
, "Unknown", topology
),
1062 ul
& SLA_MASK_METRIC
);
1068 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
1069 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
1070 ND_PRINT("\n\t Mask %s",
1071 GET_IPADDR_STRING(lsap
->lsa_un
.un_asla
.asla_mask
));
1073 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
1074 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
1075 while ((const u_char
*)almp
< ls_end
) {
1078 ul
= GET_BE_U_4(almp
->asla_tosmetric
);
1079 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
1080 ND_PRINT("\n\t\ttopology %s (%u), type %u, metric",
1081 tok2str(ospf_topology_values
, "Unknown", topology
),
1083 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1);
1084 if ((ul
& ASLA_MASK_METRIC
) == 0xffffff)
1085 ND_PRINT(" infinite");
1087 ND_PRINT(" %u", (ul
& ASLA_MASK_METRIC
));
1089 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_forward
) != 0) {
1090 ND_PRINT(", forward %s", GET_IPADDR_STRING(almp
->asla_forward
));
1092 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_tag
) != 0) {
1093 ND_PRINT(", tag %s", GET_IPADDR_STRING(almp
->asla_tag
));
1100 /* Multicast extensions as of 23 July 1991 */
1101 mcp
= lsap
->lsa_un
.un_mcla
;
1102 while ((const u_char
*)mcp
< ls_end
) {
1103 switch (GET_BE_U_4(mcp
->mcla_vtype
)) {
1105 case MCLA_VERTEX_ROUTER
:
1106 ND_PRINT("\n\t Router Router-ID %s",
1107 GET_IPADDR_STRING(mcp
->mcla_vid
));
1110 case MCLA_VERTEX_NETWORK
:
1111 ND_PRINT("\n\t Network Designated Router %s",
1112 GET_IPADDR_STRING(mcp
->mcla_vid
));
1116 ND_PRINT("\n\t unknown VertexType (%u)",
1117 GET_BE_U_4(mcp
->mcla_vtype
));
1124 case LS_TYPE_OPAQUE_LL
: /* fall through */
1125 case LS_TYPE_OPAQUE_AL
:
1126 case LS_TYPE_OPAQUE_DW
:
1128 switch (GET_U_1(lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
1129 case LS_OPAQUE_TYPE_RI
:
1130 tptr
= (const uint8_t *)(lsap
->lsa_un
.un_ri_tlv
);
1132 u_int ls_length_remaining
= ls_length
;
1133 while (ls_length_remaining
!= 0) {
1135 if (ls_length_remaining
< 4) {
1136 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length_remaining
);
1139 tlv_type
= GET_BE_U_2(tptr
);
1140 tlv_length
= GET_BE_U_2(tptr
+ 2);
1142 ls_length_remaining
-=4;
1144 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
1145 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
1149 if (tlv_length
> ls_length_remaining
) {
1150 ND_PRINT("\n\t Bogus length %u > remaining LS length %u", tlv_length
,
1151 ls_length_remaining
);
1154 ND_TCHECK_LEN(tptr
, tlv_length
);
1157 case LS_OPAQUE_RI_TLV_CAP
:
1158 if (tlv_length
!= 4) {
1159 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
1162 ND_PRINT("Capabilities: %s",
1163 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", GET_BE_U_4(tptr
)));
1166 case LS_OPAQUE_RI_TLV_HOSTNAME
:
1167 ND_PRINT("\n\t Hostname: ");
1168 nd_printjnp(ndo
, tptr
, tlv_length
);
1171 case LS_OPAQUE_RI_TLV_SR_ALGO
:
1172 num_tlv
= tlv_length
;
1173 while (num_tlv
>= 1) {
1174 ND_PRINT("\n\t %s (%u)",
1175 tok2str(lsa_opaque_ri_tlv_sr_algos
, "Unknown", GET_U_1(tptr
+tlv_length
-num_tlv
)), GET_U_1(tptr
+tlv_length
-num_tlv
));
1180 case LS_OPAQUE_RI_TLV_SID_LABEL_RANGE
:
1181 case LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK
:
1183 ND_PRINT("\n\t Range size: %u", GET_BE_U_3(tptr
));
1184 if (ospf_print_ri_lsa_sid_label_range_tlv(ndo
, tptr
+4, tlv_length
-4) == -1) {
1189 case LS_OPAQUE_RI_TLV_SRMS_PREFERENCE
:
1190 if (tlv_length
!= 4) {
1191 ND_PRINT("\n\t Bogus SRMS Preference TLV length %u != 4", tlv_length
);
1194 ND_PRINT("\n\t SRMS Preference: %u", GET_U_1(tptr
));
1198 if (ndo
->ndo_vflag
<= 1) {
1199 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
1206 /* in OSPF everything has to be 32-bit aligned, including TLVs */
1207 if (tlv_length
% 4) {
1208 tlv_length
+= (4 - (tlv_length
% 4));
1209 if (tlv_length
> ls_length_remaining
) {
1210 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
1211 ls_length_remaining
);
1216 ls_length_remaining
-=tlv_length
;
1220 case LS_OPAQUE_TYPE_GRACE
:
1221 if (ospf_grace_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_grace_tlv
),
1227 case LS_OPAQUE_TYPE_TE
:
1228 if (ospf_te_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_te_lsa_tlv
),
1234 case LS_OPAQUE_TYPE_EP
:
1235 if (ospf_ep_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_ep_tlv
),
1242 if (ndo
->ndo_vflag
<= 1) {
1243 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
1244 "\n\t ", ls_length
))
1251 /* do we want to see an additionally hexdump ? */
1252 if (ndo
->ndo_vflag
> 1)
1253 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
1254 "\n\t ", ls_length
)) {
1264 ospf_decode_lls(netdissect_options
*ndo
,
1265 const struct ospfhdr
*op
, u_int length
)
1268 const u_char
*dataend
;
1270 uint16_t lls_type
, lls_len
;
1273 switch (GET_U_1(op
->ospf_type
)) {
1275 case OSPF_TYPE_HELLO
:
1276 if (!(GET_U_1(op
->ospf_hello
.hello_options
) & OSPF_OPTION_L
))
1281 if (!(GET_U_1(op
->ospf_db
.db_options
) & OSPF_OPTION_L
))
1289 /* dig deeper if LLS data is available; see RFC4813 */
1290 length2
= GET_BE_U_2(op
->ospf_len
);
1291 dptr
= (const u_char
*)op
+ length2
;
1292 dataend
= (const u_char
*)op
+ length
;
1294 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1295 dptr
= dptr
+ GET_U_1(op
->ospf_authdata
+ 3);
1296 length2
+= GET_U_1(op
->ospf_authdata
+ 3);
1298 if (length2
>= length
) {
1299 ND_PRINT("\n\t[LLS truncated]");
1302 ND_PRINT("\n\t LLS: checksum: 0x%04x", (u_int
) GET_BE_U_2(dptr
));
1305 length2
= GET_BE_U_2(dptr
);
1306 ND_PRINT(", length: %u", length2
);
1309 while (dptr
< dataend
) {
1310 lls_type
= GET_BE_U_2(dptr
);
1311 ND_PRINT("\n\t %s (%u)",
1312 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
1315 lls_len
= GET_BE_U_2(dptr
);
1316 ND_PRINT(", length: %u", lls_len
);
1322 ND_PRINT(" [should be 4]");
1325 lls_flags
= GET_BE_U_4(dptr
);
1326 ND_PRINT("\n\t Options: 0x%08x [%s]", lls_flags
,
1327 bittok2str(ospf_lls_eo_options
, "?", lls_flags
));
1332 if (lls_len
!= 20) {
1333 ND_PRINT(" [should be 20]");
1336 ND_PRINT("\n\t Sequence number: 0x%08x", GET_BE_U_4(dptr
));
1345 ospf_decode_v2(netdissect_options
*ndo
,
1346 const struct ospfhdr
*op
, const u_char
*dataend
)
1349 const struct lsr
*lsrp
;
1350 const struct lsa_hdr
*lshp
;
1351 const struct lsa
*lsap
;
1352 uint32_t lsa_count
,lsa_count_max
;
1354 switch (GET_U_1(op
->ospf_type
)) {
1356 case OSPF_TYPE_HELLO
:
1357 ND_PRINT("\n\tOptions [%s]",
1358 bittok2str(ospf_option_values
,"none",GET_U_1(op
->ospf_hello
.hello_options
)));
1360 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1361 GET_BE_U_2(op
->ospf_hello
.hello_helloint
),
1362 GET_BE_U_4(op
->ospf_hello
.hello_deadint
),
1363 GET_IPADDR_STRING(op
->ospf_hello
.hello_mask
),
1364 GET_U_1(op
->ospf_hello
.hello_priority
));
1366 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_dr
) != 0)
1367 ND_PRINT("\n\t Designated Router %s",
1368 GET_IPADDR_STRING(op
->ospf_hello
.hello_dr
));
1370 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_bdr
) != 0)
1371 ND_PRINT(", Backup Designated Router %s",
1372 GET_IPADDR_STRING(op
->ospf_hello
.hello_bdr
));
1374 ap
= op
->ospf_hello
.hello_neighbor
;
1375 if ((const u_char
*)ap
< dataend
)
1376 ND_PRINT("\n\t Neighbor List:");
1377 while ((const u_char
*)ap
< dataend
) {
1378 ND_PRINT("\n\t %s", GET_IPADDR_STRING(ap
));
1384 ND_PRINT("\n\tOptions [%s]",
1385 bittok2str(ospf_option_values
, "none", GET_U_1(op
->ospf_db
.db_options
)));
1386 ND_PRINT(", DD Flags [%s]",
1387 bittok2str(ospf_dd_flag_values
, "none", GET_U_1(op
->ospf_db
.db_flags
)));
1388 if (GET_BE_U_2(op
->ospf_db
.db_ifmtu
)) {
1389 ND_PRINT(", MTU: %u",
1390 GET_BE_U_2(op
->ospf_db
.db_ifmtu
));
1392 ND_PRINT(", Sequence: 0x%08x", GET_BE_U_4(op
->ospf_db
.db_seq
));
1394 /* Print all the LS adv's */
1395 lshp
= op
->ospf_db
.db_lshdr
;
1396 while (((const u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
1401 case OSPF_TYPE_LS_REQ
:
1402 lsrp
= op
->ospf_lsr
;
1403 while ((const u_char
*)lsrp
< dataend
) {
1404 ND_TCHECK_SIZE(lsrp
);
1406 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1407 GET_IPADDR_STRING(lsrp
->ls_router
),
1408 tok2str(lsa_values
,"unknown",GET_BE_U_4(lsrp
->ls_type
)),
1409 GET_BE_U_4(lsrp
->ls_type
));
1411 switch (GET_BE_U_4(lsrp
->ls_type
)) {
1412 /* the LSA header for opaque LSAs was slightly changed */
1413 case LS_TYPE_OPAQUE_LL
:
1414 case LS_TYPE_OPAQUE_AL
:
1415 case LS_TYPE_OPAQUE_DW
:
1416 ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1417 tok2str(lsa_opaque_values
, "unknown",GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
)),
1418 GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1419 GET_BE_U_3(lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
1422 ND_PRINT(", LSA-ID: %s",
1423 GET_IPADDR_STRING(lsrp
->un_ls_stateid
.ls_stateid
));
1431 case OSPF_TYPE_LS_UPDATE
:
1432 lsap
= op
->ospf_lsu
.lsu_lsa
;
1433 lsa_count_max
= GET_BE_U_4(op
->ospf_lsu
.lsu_count
);
1434 ND_PRINT(", %u LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
));
1435 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1436 ND_PRINT("\n\t LSA #%u", lsa_count
);
1437 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1443 case OSPF_TYPE_LS_ACK
:
1444 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1445 while ((const u_char
*)lshp
< dataend
) {
1446 ospf_print_lshdr(ndo
, lshp
);
1460 ospf_print(netdissect_options
*ndo
,
1461 const u_char
*bp
, u_int length
,
1462 const u_char
*bp2 _U_
)
1464 const struct ospfhdr
*op
;
1465 const u_char
*dataend
;
1468 ndo
->ndo_protocol
= "ospf2";
1469 op
= (const struct ospfhdr
*)bp
;
1471 /* XXX Before we do anything else, strip off the MD5 trailer */
1472 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1473 length
-= OSPF_AUTH_MD5_LEN
;
1474 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1477 /* If the type is valid translate it, or just print the type */
1478 /* value. If it's not valid, say so and return */
1479 cp
= tok2str(type2str
, "unknown LS-type %u", GET_U_1(op
->ospf_type
));
1480 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op
->ospf_version
), cp
,
1485 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1489 if (length
!= GET_BE_U_2(op
->ospf_len
)) {
1490 ND_PRINT(" [len %u]", GET_BE_U_2(op
->ospf_len
));
1493 if (length
> GET_BE_U_2(op
->ospf_len
)) {
1494 dataend
= bp
+ GET_BE_U_2(op
->ospf_len
);
1496 dataend
= bp
+ length
;
1499 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op
->ospf_routerid
));
1501 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_areaid
) != 0)
1502 ND_PRINT(", Area %s", GET_IPADDR_STRING(op
->ospf_areaid
));
1504 ND_PRINT(", Backbone Area");
1506 if (ndo
->ndo_vflag
) {
1507 /* Print authentication data (should we really do this?) */
1508 ND_TCHECK_LEN(op
->ospf_authdata
, sizeof(op
->ospf_authdata
));
1510 ND_PRINT(", Authentication Type: %s (%u)",
1511 tok2str(ospf_authtype_values
, "unknown", GET_BE_U_2(op
->ospf_authtype
)),
1512 GET_BE_U_2(op
->ospf_authtype
));
1514 switch (GET_BE_U_2(op
->ospf_authtype
)) {
1516 case OSPF_AUTH_NONE
:
1519 case OSPF_AUTH_SIMPLE
:
1520 ND_PRINT("\n\tSimple text password: ");
1521 nd_printjnp(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1525 ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1526 GET_U_1(op
->ospf_authdata
+ 2),
1527 GET_U_1(op
->ospf_authdata
+ 3),
1528 GET_BE_U_4((op
->ospf_authdata
) + 4));
1535 /* Do rest according to version. */
1536 switch (GET_U_1(op
->ospf_version
)) {
1539 /* ospf version 2 */
1540 if (ospf_decode_v2(ndo
, op
, dataend
))
1542 if (length
> GET_BE_U_2(op
->ospf_len
))
1543 ospf_decode_lls(ndo
, op
, length
);
1547 ND_PRINT(" ospf [version %u]", GET_U_1(op
->ospf_version
));
1549 } /* end switch on version */
1553 nd_trunc_longjmp(ndo
);