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 */
28 #include "netdissect-stdinc.h"
30 #include "netdissect.h"
31 #include "addrtoname.h"
37 static const struct tok ospf_option_values
[] = {
38 { OSPF_OPTION_MT
, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
39 { OSPF_OPTION_E
, "External" },
40 { OSPF_OPTION_MC
, "Multicast" },
41 { OSPF_OPTION_NP
, "NSSA" },
42 { OSPF_OPTION_L
, "LLS" },
43 { OSPF_OPTION_DC
, "Demand Circuit" },
44 { OSPF_OPTION_O
, "Opaque" },
45 { OSPF_OPTION_DN
, "Up/Down" },
49 static const struct tok ospf_authtype_values
[] = {
50 { OSPF_AUTH_NONE
, "none" },
51 { OSPF_AUTH_SIMPLE
, "simple" },
52 { OSPF_AUTH_MD5
, "MD5" },
56 static const struct tok ospf_rla_flag_values
[] = {
57 { RLA_FLAG_B
, "ABR" },
58 { RLA_FLAG_E
, "ASBR" },
59 { RLA_FLAG_V
, "Virtual" },
60 { RLA_FLAG_W
, "Wildcard" },
61 { RLA_FLAG_NT
, "Nt" },
62 { RLA_FLAG_H
, "Host" },
66 static const struct tok type2str
[] = {
67 { OSPF_TYPE_HELLO
, "Hello" },
68 { OSPF_TYPE_DD
, "Database Description" },
69 { OSPF_TYPE_LS_REQ
, "LS-Request" },
70 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
71 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
75 static const struct tok lsa_values
[] = {
76 { LS_TYPE_ROUTER
, "Router" },
77 { LS_TYPE_NETWORK
, "Network" },
78 { LS_TYPE_SUM_IP
, "Summary" },
79 { LS_TYPE_SUM_ABR
, "ASBR Summary" },
80 { LS_TYPE_ASE
, "External" },
81 { LS_TYPE_GROUP
, "Multicast Group" },
82 { LS_TYPE_NSSA
, "NSSA" },
83 { LS_TYPE_OPAQUE_LL
, "Link Local Opaque" },
84 { LS_TYPE_OPAQUE_AL
, "Area Local Opaque" },
85 { LS_TYPE_OPAQUE_DW
, "Domain Wide Opaque" },
89 static const struct tok ospf_dd_flag_values
[] = {
90 { OSPF_DB_INIT
, "Init" },
91 { OSPF_DB_MORE
, "More" },
92 { OSPF_DB_MASTER
, "Master" },
93 { OSPF_DB_RESYNC
, "OOBResync" },
97 static const struct tok lsa_opaque_values
[] = {
98 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
99 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
100 { LS_OPAQUE_TYPE_RI
, "Router Information" },
101 { LS_OPAQUE_TYPE_EP
, "Extended Prefix" },
102 { LS_OPAQUE_TYPE_EL
, "Extended Link" },
106 static const struct tok lsa_opaque_ri_sid_subtlv_values
[] = {
107 { LS_OPAQUE_RI_SUBTLV_SID_LABEL
, "SID/Label" },
111 static const struct tok lsa_opaque_te_tlv_values
[] = {
112 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
113 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
117 static const struct tok lsa_opaque_ep_extd_prefix_subtlv_values
[] = {
118 { LS_OPAQUE_EP_SUBTLV_PREFIX_SID
, "Prefix-SID" },
122 static const struct tok ep_range_tlv_prefix_sid_subtlv_flag_values
[] = {
124 { 0x20, "Mapping-Server"},
125 { 0x10, "Explicit-NULL"},
131 static const struct tok lsa_opaque_ep_route_type_values
[] = {
132 { 0, "Unspecified" },
135 { 5, "AS External" },
136 { 7, "NSSA External" },
140 static const struct tok lsa_opaque_ep_tlv_values
[] = {
141 { LS_OPAQUE_EP_EXTD_PREFIX_TLV
, "Extended Prefix" },
142 { LS_OPAQUE_EP_EXTD_PREFIX_RANGE_TLV
, "Extended Prefix Range" },
146 static const struct tok ep_tlv_flag_values
[] = {
147 { 0x80, "Inter-Area"},
151 static const struct tok lsa_opaque_te_link_tlv_subtlv_values
[] = {
152 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
, "Link Type" },
153 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
, "Link ID" },
154 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
, "Local Interface IP address" },
155 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
, "Remote Interface IP address" },
156 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
, "Traffic Engineering Metric" },
157 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
, "Maximum Bandwidth" },
158 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
, "Maximum Reservable Bandwidth" },
159 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
, "Unreserved Bandwidth" },
160 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
, "Administrative Group" },
161 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
, "Link Local/Remote Identifier" },
162 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
, "Link Protection Type" },
163 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
, "Interface Switching Capability" },
164 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
, "Shared Risk Link Group" },
165 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
, "Bandwidth Constraints" },
169 static const struct tok lsa_opaque_grace_tlv_values
[] = {
170 { LS_OPAQUE_GRACE_TLV_PERIOD
, "Grace Period" },
171 { LS_OPAQUE_GRACE_TLV_REASON
, "Graceful restart Reason" },
172 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS
, "IPv4 interface address" },
176 static const struct tok lsa_opaque_grace_tlv_reason_values
[] = {
177 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN
, "Unknown" },
178 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART
, "Software Restart" },
179 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE
, "Software Reload/Upgrade" },
180 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH
, "Control Processor Switch" },
184 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
185 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
186 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
190 static const struct tok lsa_opaque_ri_tlv_values
[] = {
191 { LS_OPAQUE_RI_TLV_CAP
, "Router Capabilities" },
192 { LS_OPAQUE_RI_TLV_SR_ALGO
, "SR-Algorithm" },
193 { LS_OPAQUE_RI_TLV_HOSTNAME
, "Hostname" },
194 { LS_OPAQUE_RI_TLV_SID_LABEL_RANGE
, "SID/Label Range" },
195 { LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK
, "SR Local Block" },
196 { LS_OPAQUE_RI_TLV_SRMS_PREFERENCE
, "SRMS Preference" },
200 static const struct tok lsa_opaque_ri_tlv_cap_values
[] = {
205 { 16, "graceful restart capable" },
206 { 32, "graceful restart helper" },
207 { 64, "Stub router support" },
208 { 128, "Traffic engineering" },
209 { 256, "p2p over LAN" },
210 { 512, "path computation server" },
214 static const struct tok lsa_opaque_ri_tlv_sr_algos
[] = {
215 { 0, "Shortest Path First" },
216 { 1, "Strict Shortest Path First" },
220 static const struct tok ospf_lls_tlv_values
[] = {
221 { OSPF_LLS_EO
, "Extended Options" },
222 { OSPF_LLS_MD5
, "MD5 Authentication" },
226 static const struct tok ospf_lls_eo_options
[] = {
227 { OSPF_LLS_EO_LR
, "LSDB resync" },
228 { OSPF_LLS_EO_RS
, "Restart" },
233 ospf_grace_lsa_print(netdissect_options
*ndo
,
234 const u_char
*tptr
, u_int ls_length
)
236 u_int tlv_type
, tlv_length
;
238 while (ls_length
!= 0) {
241 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length
);
244 tlv_type
= GET_BE_U_2(tptr
);
245 tlv_length
= GET_BE_U_2(tptr
+ 2);
249 ND_PRINT("\n\t %s TLV (%u), length %u, value: ",
250 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
254 if (tlv_length
> ls_length
) {
255 ND_PRINT("\n\t Bogus length %u > %u", tlv_length
,
260 /* Infinite loop protection. */
261 if (tlv_type
== 0 || tlv_length
==0) {
262 nd_print_invalid(ndo
);
266 ND_TCHECK_LEN(tptr
, tlv_length
);
269 case LS_OPAQUE_GRACE_TLV_PERIOD
:
270 if (tlv_length
!= 4) {
271 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
274 ND_PRINT("%us", GET_BE_U_4(tptr
));
277 case LS_OPAQUE_GRACE_TLV_REASON
:
278 if (tlv_length
!= 1) {
279 ND_PRINT("\n\t Bogus length %u != 1", tlv_length
);
283 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", GET_U_1(tptr
)),
287 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
288 if (tlv_length
!= 4) {
289 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
292 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
296 if (ndo
->ndo_vflag
<= 1) {
297 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
303 /* in OSPF everything has to be 32-bit aligned, including TLVs */
304 if (tlv_length
%4 != 0) {
305 tlv_length
+=4-(tlv_length
%4);
306 if (tlv_length
> ls_length
) {
307 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
312 ls_length
-=tlv_length
;
323 ospf_te_tlv_link_print(netdissect_options
*ndo
,
324 const u_char
*tptr
, u_int tlv_length
)
326 u_int subtlv_type
, subtlv_length
;
327 u_int priority_level
, te_class
, count_srlg
;
329 while (tlv_length
!= 0) {
330 if (tlv_length
< 4) {
331 ND_PRINT("\n\t Remaining TLV length %u < 4",
335 subtlv_type
= GET_BE_U_2(tptr
);
336 subtlv_length
= GET_BE_U_2(tptr
+ 2);
340 /* Infinite loop protection */
341 if (subtlv_type
== 0 || subtlv_length
== 0)
344 ND_PRINT("\n\t %s subTLV (%u), length: %u",
345 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
349 if (tlv_length
< subtlv_length
) {
350 ND_PRINT("\n\t Remaining TLV length %u < %u",
351 tlv_length
, subtlv_length
);
354 ND_TCHECK_LEN(tptr
, subtlv_length
);
355 switch(subtlv_type
) {
356 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
357 if (subtlv_length
!= 4) {
361 ND_PRINT(", 0x%08x", GET_BE_U_4(tptr
));
363 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
364 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
365 if (subtlv_length
!= 4 && subtlv_length
!= 8) {
366 ND_PRINT(" != 4 && != 8");
369 ND_PRINT(", %s (0x%08x)",
370 GET_IPADDR_STRING(tptr
),
372 if (subtlv_length
== 8) /* rfc4203 */
373 ND_PRINT(", %s (0x%08x)",
374 GET_IPADDR_STRING(tptr
+4),
375 GET_BE_U_4(tptr
+ 4));
377 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
378 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
379 if (subtlv_length
!= 4) {
383 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
385 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
386 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
387 if (subtlv_length
!= 4) {
391 ND_PRINT(", %.3f Mbps", GET_BE_F_4(tptr
) * 8 / 1000000);
393 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
394 if (subtlv_length
!= 32) {
398 for (te_class
= 0; te_class
< 8; te_class
++) {
399 ND_PRINT("\n\t\tTE-Class %u: %.3f Mbps",
401 GET_BE_F_4(tptr
+ te_class
* 4) * 8 / 1000000);
404 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
405 if (subtlv_length
< 4) {
409 /* BC Model Id (1 octet) + Reserved (3 octets) */
410 ND_PRINT("\n\t\tBandwidth Constraints Model ID: %s (%u)",
411 tok2str(diffserv_te_bc_values
, "unknown", GET_U_1(tptr
)),
413 if (subtlv_length
% 4 != 0) {
414 ND_PRINT("\n\t\tlength %u != N x 4", subtlv_length
);
417 if (subtlv_length
> 36) {
418 ND_PRINT("\n\t\tlength %u > 36", subtlv_length
);
421 /* decode BCs until the subTLV ends */
422 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
423 ND_PRINT("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
425 GET_BE_F_4(tptr
+ 4 + te_class
* 4) * 8 / 1000000);
428 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
429 if (subtlv_length
!= 4) {
433 ND_PRINT(", Metric %u", GET_BE_U_4(tptr
));
435 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
436 /* Protection Cap (1 octet) + Reserved ((3 octets) */
437 if (subtlv_length
!= 4) {
442 bittok2str(gmpls_link_prot_values
, "none", GET_U_1(tptr
)));
444 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
445 if (subtlv_length
< 36) {
449 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
450 ND_PRINT("\n\t\tInterface Switching Capability: %s",
451 tok2str(gmpls_switch_cap_values
, "Unknown", GET_U_1((tptr
))));
452 ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
453 tok2str(gmpls_encoding_values
, "Unknown", GET_U_1((tptr
+ 1))));
454 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
455 ND_PRINT("\n\t\t priority level %u: %.3f Mbps",
457 GET_BE_F_4(tptr
+ 4 + (priority_level
* 4)) * 8 / 1000000);
460 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
461 if (subtlv_length
!= 1) {
465 ND_PRINT(", %s (%u)",
466 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",GET_U_1(tptr
)),
469 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
470 if (subtlv_length
% 4 != 0) {
471 ND_PRINT(" != N x 4");
474 count_srlg
= subtlv_length
/ 4;
476 ND_PRINT("\n\t\t Shared risk group: ");
477 while (count_srlg
!= 0) {
478 ND_PRINT("%u", GET_BE_U_4(tptr
));
486 if (ndo
->ndo_vflag
<= 1) {
487 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
492 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
493 if (subtlv_length
%4 != 0) {
494 subtlv_length
+=4-(subtlv_length
%4);
496 if (tlv_length
< subtlv_length
) {
497 ND_PRINT("\n\t Remaining TLV length %u < %u",
498 tlv_length
, subtlv_length
);
502 tlv_length
-=subtlv_length
;
510 nd_print_invalid(ndo
);
515 ospf_te_lsa_print(netdissect_options
*ndo
,
516 const u_char
*tptr
, u_int ls_length
)
518 u_int tlv_type
, tlv_length
;
520 while (ls_length
!= 0) {
523 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length
);
526 tlv_type
= GET_BE_U_2(tptr
);
527 tlv_length
= GET_BE_U_2(tptr
+ 2);
531 ND_PRINT("\n\t %s TLV (%u), length: %u",
532 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
536 if (tlv_length
> ls_length
) {
537 ND_PRINT("\n\t Bogus length %u > %u", tlv_length
,
542 /* Infinite loop protection. */
543 if (tlv_type
== 0 || tlv_length
==0) {
544 nd_print_invalid(ndo
);
549 case LS_OPAQUE_TE_TLV_LINK
:
550 if (ospf_te_tlv_link_print(ndo
, tptr
, tlv_length
) == -1)
554 case LS_OPAQUE_TE_TLV_ROUTER
:
555 if (tlv_length
< 4) {
556 ND_PRINT("\n\t TLV length %u < 4", tlv_length
);
559 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
563 if (ndo
->ndo_vflag
<= 1) {
564 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
569 /* in OSPF everything has to be 32-bit aligned, including TLVs */
570 if (tlv_length
%4 != 0) {
571 tlv_length
+=4-(tlv_length
%4);
572 if (tlv_length
> ls_length
) {
573 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
578 ls_length
-=tlv_length
;
586 nd_print_invalid(ndo
);
591 ospf_print_lshdr(netdissect_options
*ndo
,
592 const struct lsa_hdr
*lshp
)
597 ls_length
= GET_BE_U_2(lshp
->ls_length
);
598 if (ls_length
< sizeof(struct lsa_hdr
)) {
599 ND_PRINT("\n\t Bogus length %u < header (%zu)", ls_length
,
600 sizeof(struct lsa_hdr
));
603 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %zu",
604 GET_IPADDR_STRING(lshp
->ls_router
),
605 GET_BE_U_4(lshp
->ls_seq
),
606 GET_BE_U_2(lshp
->ls_age
),
607 ls_length
- sizeof(struct lsa_hdr
));
608 ls_type
= GET_U_1(lshp
->ls_type
);
610 /* the LSA header for opaque LSAs was slightly changed */
611 case LS_TYPE_OPAQUE_LL
:
612 case LS_TYPE_OPAQUE_AL
:
613 case LS_TYPE_OPAQUE_DW
:
614 ND_PRINT("\n\t %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u",
615 tok2str(lsa_values
,"unknown",ls_type
),
618 tok2str(lsa_opaque_values
,
620 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
621 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
),
622 GET_BE_U_3(lshp
->un_lsa_id
.opaque_field
.opaque_id
)
627 /* all other LSA types use regular style LSA headers */
629 ND_PRINT("\n\t %s LSA (%u), LSA-ID: %s",
630 tok2str(lsa_values
,"unknown",ls_type
),
632 GET_IPADDR_STRING(lshp
->un_lsa_id
.lsa_id
));
635 ND_PRINT("\n\t Options: [%s]",
636 bittok2str(ospf_option_values
, "none", GET_U_1(lshp
->ls_options
)));
641 /* draft-ietf-ospf-mt-09 */
642 static const struct tok ospf_topology_values
[] = {
650 * Print all the per-topology metrics.
653 ospf_print_tos_metrics(netdissect_options
*ndo
,
654 const union un_tos
*tos
)
660 toscount
= GET_U_1(tos
->link
.link_tos_count
)+1;
664 * All but the first metric contain a valid topology id.
666 while (toscount
!= 0) {
667 tos_type
= GET_U_1(tos
->metrics
.tos_type
);
668 ND_PRINT("\n\t\ttopology %s (%u), metric %u",
669 tok2str(ospf_topology_values
, "Unknown",
670 metric_count
? tos_type
: 0),
671 metric_count
? tos_type
: 0,
672 GET_BE_U_2(tos
->metrics
.tos_metric
));
680 * The SID/Label Range TLV
681 * https://datatracker.ietf.org/doc/html/rfc8665#section-3.2
682 * and the SR Local Block TLV
683 * https://datatracker.ietf.org/doc/html/rfc8665#section-3.3
684 * have the same contents, so this function is used to
688 ospf_print_ri_lsa_sid_label_range_tlv(netdissect_options
*ndo
, const uint8_t *tptr
,
691 u_int subtlv_type
, subtlv_length
;
693 while (tlv_length
>= 4) {
695 subtlv_type
= GET_BE_U_2(tptr
);
696 subtlv_length
= GET_BE_U_2(tptr
+2);
700 /* Infinite loop protection. */
701 if (subtlv_type
== 0 || subtlv_length
== 0) {
702 nd_print_invalid(ndo
);
706 ND_PRINT("\n\t %s subTLV (%u), length: %u, value: ",
707 tok2str(lsa_opaque_ri_sid_subtlv_values
,"unknown",subtlv_type
),
711 if (tlv_length
< subtlv_length
) {
712 ND_PRINT("\n\t Remaining TLV length %u < %u",
713 tlv_length
, subtlv_length
);
717 switch (subtlv_type
) {
718 case LS_OPAQUE_RI_SUBTLV_SID_LABEL
:
719 if (subtlv_length
== 3) {
720 ND_PRINT("\n\t\tLabel: %u", GET_BE_U_3(tptr
));
721 } else if (subtlv_length
== 4) {
722 ND_PRINT("\n\t\tSID: %u", GET_BE_U_4(tptr
));
724 ND_PRINT("\n\t\tBogus subTLV length %u", subtlv_length
);
729 if (ndo
->ndo_vflag
<= 1) {
730 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
735 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
736 if (subtlv_length
% 4) {
737 subtlv_length
+= (4 - (subtlv_length
% 4));
738 if (tlv_length
< subtlv_length
) {
739 ND_PRINT("\n\t Remaining TLV length %u < %u",
740 tlv_length
, subtlv_length
);
745 tlv_length
-=subtlv_length
;
751 ospf_print_ep_lsa_extd_prefix_tlv(netdissect_options
*ndo
, const uint8_t *tptr
,
754 u_int subtlv_type
, subtlv_length
;
755 uint8_t flags
, mt_id
, algo
;
757 while (tlv_length
>= 4) {
758 subtlv_type
= GET_BE_U_2(tptr
);
759 subtlv_length
= GET_BE_U_2(tptr
+2);
763 /* Infinite loop protection. */
764 if (subtlv_type
== 0 || subtlv_length
== 0) {
765 nd_print_invalid(ndo
);
769 ND_PRINT("\n\t\t%s subTLV (%u), length: %u, value: ",
770 tok2str(lsa_opaque_ep_extd_prefix_subtlv_values
,"unknown",subtlv_type
),
774 if (tlv_length
< subtlv_length
) {
775 ND_PRINT("\n\t Remaining TLV length %u < %u",
776 tlv_length
, subtlv_length
);
780 switch (subtlv_type
) {
781 case LS_OPAQUE_EP_SUBTLV_PREFIX_SID
:
782 flags
= GET_U_1(tptr
);
783 mt_id
= GET_U_1(tptr
+2);
784 algo
= GET_U_1(tptr
+3);
786 if (subtlv_length
== 7) {
787 ND_PRINT("\n\t\t Label: %u", GET_BE_U_3(tptr
+4));
788 } else if (subtlv_length
== 8) {
789 ND_PRINT("\n\t\t Index: %u", GET_BE_U_4(tptr
+4));
791 ND_PRINT("\n\t\tBogus subTLV length %u", subtlv_length
);
794 ND_PRINT( ", MT-ID: %u, Algorithm: %s (%u), Flags [%s]",
795 mt_id
, tok2str(lsa_opaque_ri_tlv_sr_algos
, "Unknown", algo
), algo
,
796 bittok2str(ep_range_tlv_prefix_sid_subtlv_flag_values
, "none", flags
));
800 if (ndo
->ndo_vflag
<= 1) {
801 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
806 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
807 if (subtlv_length
% 4) {
808 subtlv_length
+= (4 - (subtlv_length
% 4));
809 if (tlv_length
< subtlv_length
) {
810 ND_PRINT("\n\t Remaining TLV length %u < %u",
811 tlv_length
, subtlv_length
);
816 tlv_length
-=subtlv_length
;
822 ospf_ep_lsa_print(netdissect_options
*ndo
, const uint8_t *tptr
, u_int lsa_length
)
824 u_int tlv_type
, tlv_length
;
826 uint8_t af
, prefix_length
, route_type
, flags
;
828 while (lsa_length
>= 4) {
830 tlv_type
= GET_BE_U_2(tptr
);
831 tlv_length
= GET_BE_U_2(tptr
+2);
835 /* Infinite loop protection. */
836 if (tlv_type
== 0 || tlv_length
== 0) {
837 nd_print_invalid(ndo
);
841 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
842 tok2str(lsa_opaque_ep_tlv_values
,"unknown",tlv_type
),
846 if (tlv_length
> lsa_length
) {
847 ND_PRINT("\n\t Bogus length %u > %u",
848 tlv_length
, lsa_length
);
853 case LS_OPAQUE_EP_EXTD_PREFIX_TLV
:
854 prefix_length
= GET_U_1(tptr
+1);
855 af
= GET_U_1(tptr
+2);
856 route_type
= GET_U_1(tptr
);
857 flags
= GET_U_1(tptr
+3);
860 ND_PRINT("\n\t Bogus AF %u", af
);
864 if (prefix_length
> 32) {
865 ND_PRINT("\n\t IPv4 prefix: bad bit length %u", prefix_length
);
869 ND_PRINT("\n\t IPv4 prefix: %15s/%u, Route Type: %s, Flags [%s]",
870 GET_IPADDR_STRING(tptr
+4), prefix_length
,
871 tok2str(lsa_opaque_ep_route_type_values
, "Unknown", route_type
),
872 bittok2str(ep_tlv_flag_values
, "none", flags
));
874 /* subTLVs present ? */
875 if (tlv_length
> 12) {
876 if (ospf_print_ep_lsa_extd_prefix_tlv(ndo
, tptr
+8, tlv_length
-8) == -1) {
882 case LS_OPAQUE_EP_EXTD_PREFIX_RANGE_TLV
:
883 prefix_length
= GET_U_1(tptr
);
884 af
= GET_U_1(tptr
+1);
885 range_size
= GET_BE_U_2(tptr
+2);
886 flags
= GET_U_1(tptr
+4);
889 ND_PRINT("\n\t Bogus AF %u", af
);
893 if (prefix_length
> 32) {
894 ND_PRINT("\n\t IPv4 prefix: bad bit length %u", prefix_length
);
898 ND_PRINT("\n\t IPv4 prefix: %15s/%u, Range size: %u, Flags [%s]",
899 GET_IPADDR_STRING(tptr
+8), prefix_length
,
901 bittok2str(ep_tlv_flag_values
, "none", flags
));
903 /* subTLVs present ? */
904 if (tlv_length
> 12) {
905 if (ospf_print_ep_lsa_extd_prefix_tlv(ndo
, tptr
+12, tlv_length
-12) == -1) {
912 if (ndo
->ndo_vflag
<= 1) {
913 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", tlv_length
))
918 /* in OSPF everything has to be 32-bit aligned, including TLVs */
919 if (tlv_length
% 4) {
920 tlv_length
+= (4 - (tlv_length
% 4));
921 if (tlv_length
> lsa_length
) {
922 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
928 lsa_length
-=tlv_length
;
934 * Print a single link state advertisement. If truncated or if LSA length
935 * field is less than the length of the LSA header, return NULl, else
936 * return pointer to data past end of LSA.
938 static const uint8_t *
939 ospf_print_lsa(netdissect_options
*ndo
,
940 const struct lsa
*lsap
)
942 const uint8_t *ls_end
;
943 const struct rlalink
*rlp
;
945 const struct aslametric
*almp
;
946 const struct mcla
*mcp
;
948 u_int tlv_type
, tlv_length
, rla_count
, topology
, num_tlv
;
949 int ospf_print_lshdr_ret
;
953 tptr
= (const uint8_t *)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
954 ospf_print_lshdr_ret
= ospf_print_lshdr(ndo
, &lsap
->ls_hdr
);
955 if (ospf_print_lshdr_ret
< 0)
957 ls_length
= (u_int
)ospf_print_lshdr_ret
;
958 ls_end
= (const uint8_t *)lsap
+ ls_length
;
960 * ospf_print_lshdr() returns -1 if the length is too short,
961 * so we know ls_length is >= sizeof(struct lsa_hdr).
963 ls_length
-= sizeof(struct lsa_hdr
);
965 switch (GET_U_1(lsap
->ls_hdr
.ls_type
)) {
968 ND_PRINT("\n\t Router LSA Options: [%s]",
969 bittok2str(ospf_rla_flag_values
, "none", GET_U_1(lsap
->lsa_un
.un_rla
.rla_flags
)));
971 rla_count
= GET_BE_U_2(lsap
->lsa_un
.un_rla
.rla_count
);
972 ND_TCHECK_SIZE(lsap
->lsa_un
.un_rla
.rla_link
);
973 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
974 for (u_int i
= rla_count
; i
!= 0; i
--) {
976 switch (GET_U_1(rlp
->un_tos
.link
.link_type
)) {
978 case RLA_TYPE_VIRTUAL
:
979 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
980 GET_IPADDR_STRING(rlp
->link_id
),
981 GET_IPADDR_STRING(rlp
->link_data
));
984 case RLA_TYPE_ROUTER
:
985 ND_PRINT("\n\t Neighbor Router-ID: %s, Interface Address: %s",
986 GET_IPADDR_STRING(rlp
->link_id
),
987 GET_IPADDR_STRING(rlp
->link_data
));
990 case RLA_TYPE_TRANSIT
:
991 ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s",
992 GET_IPADDR_STRING(rlp
->link_id
),
993 GET_IPADDR_STRING(rlp
->link_data
));
997 ND_PRINT("\n\t Stub Network: %s, Mask: %s",
998 GET_IPADDR_STRING(rlp
->link_id
),
999 GET_IPADDR_STRING(rlp
->link_data
));
1003 ND_PRINT("\n\t Unknown Router Link Type (%u)",
1004 GET_U_1(rlp
->un_tos
.link
.link_type
));
1008 ospf_print_tos_metrics(ndo
, &rlp
->un_tos
);
1010 rlp
= (const struct rlalink
*)((const u_char
*)(rlp
+ 1) +
1011 (GET_U_1(rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
1015 case LS_TYPE_NETWORK
:
1016 ND_PRINT("\n\t Mask %s\n\t Connected Routers:",
1017 GET_IPADDR_STRING(lsap
->lsa_un
.un_nla
.nla_mask
));
1018 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
1019 while ((const u_char
*)ap
< ls_end
) {
1020 ND_PRINT("\n\t %s", GET_IPADDR_STRING(ap
));
1025 case LS_TYPE_SUM_IP
:
1026 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
1027 ND_PRINT("\n\t Mask %s",
1028 GET_IPADDR_STRING(lsap
->lsa_un
.un_sla
.sla_mask
));
1029 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
1030 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
1031 while (lp
< ls_end
) {
1034 ul
= GET_BE_U_4(lp
);
1035 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
1036 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
1037 tok2str(ospf_topology_values
, "Unknown", topology
),
1039 ul
& SLA_MASK_METRIC
);
1044 case LS_TYPE_SUM_ABR
:
1045 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
1046 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
1047 while (lp
< ls_end
) {
1050 ul
= GET_BE_U_4(lp
);
1051 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
1052 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
1053 tok2str(ospf_topology_values
, "Unknown", topology
),
1055 ul
& SLA_MASK_METRIC
);
1061 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
1062 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
1063 ND_PRINT("\n\t Mask %s",
1064 GET_IPADDR_STRING(lsap
->lsa_un
.un_asla
.asla_mask
));
1066 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
1067 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
1068 while ((const u_char
*)almp
< ls_end
) {
1071 ul
= GET_BE_U_4(almp
->asla_tosmetric
);
1072 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
1073 ND_PRINT("\n\t\ttopology %s (%u), type %u, metric",
1074 tok2str(ospf_topology_values
, "Unknown", topology
),
1076 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1);
1077 if ((ul
& ASLA_MASK_METRIC
) == 0xffffff)
1078 ND_PRINT(" infinite");
1080 ND_PRINT(" %u", (ul
& ASLA_MASK_METRIC
));
1082 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_forward
) != 0) {
1083 ND_PRINT(", forward %s", GET_IPADDR_STRING(almp
->asla_forward
));
1085 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_tag
) != 0) {
1086 ND_PRINT(", tag %s", GET_IPADDR_STRING(almp
->asla_tag
));
1093 /* Multicast extensions as of 23 July 1991 */
1094 mcp
= lsap
->lsa_un
.un_mcla
;
1095 while ((const u_char
*)mcp
< ls_end
) {
1096 switch (GET_BE_U_4(mcp
->mcla_vtype
)) {
1098 case MCLA_VERTEX_ROUTER
:
1099 ND_PRINT("\n\t Router Router-ID %s",
1100 GET_IPADDR_STRING(mcp
->mcla_vid
));
1103 case MCLA_VERTEX_NETWORK
:
1104 ND_PRINT("\n\t Network Designated Router %s",
1105 GET_IPADDR_STRING(mcp
->mcla_vid
));
1109 ND_PRINT("\n\t unknown VertexType (%u)",
1110 GET_BE_U_4(mcp
->mcla_vtype
));
1117 case LS_TYPE_OPAQUE_LL
: /* fall through */
1118 case LS_TYPE_OPAQUE_AL
:
1119 case LS_TYPE_OPAQUE_DW
:
1121 switch (GET_U_1(lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
1122 case LS_OPAQUE_TYPE_RI
:
1123 tptr
= (const uint8_t *)(lsap
->lsa_un
.un_ri_tlv
);
1125 u_int ls_length_remaining
= ls_length
;
1126 while (ls_length_remaining
!= 0) {
1128 if (ls_length_remaining
< 4) {
1129 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length_remaining
);
1132 tlv_type
= GET_BE_U_2(tptr
);
1133 tlv_length
= GET_BE_U_2(tptr
+ 2);
1135 ls_length_remaining
-=4;
1137 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
1138 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
1142 if (tlv_length
> ls_length_remaining
) {
1143 ND_PRINT("\n\t Bogus length %u > remaining LS length %u", tlv_length
,
1144 ls_length_remaining
);
1147 ND_TCHECK_LEN(tptr
, tlv_length
);
1150 case LS_OPAQUE_RI_TLV_CAP
:
1151 if (tlv_length
!= 4) {
1152 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
1155 ND_PRINT("Capabilities: %s",
1156 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", GET_BE_U_4(tptr
)));
1159 case LS_OPAQUE_RI_TLV_HOSTNAME
:
1160 ND_PRINT("\n\t Hostname: ");
1161 nd_printjnp(ndo
, tptr
, tlv_length
);
1164 case LS_OPAQUE_RI_TLV_SR_ALGO
:
1165 num_tlv
= tlv_length
;
1166 while (num_tlv
>= 1) {
1167 ND_PRINT("\n\t %s (%u)",
1168 tok2str(lsa_opaque_ri_tlv_sr_algos
, "Unknown", GET_U_1(tptr
+tlv_length
-num_tlv
)), GET_U_1(tptr
+tlv_length
-num_tlv
));
1173 case LS_OPAQUE_RI_TLV_SID_LABEL_RANGE
:
1174 case LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK
:
1176 ND_PRINT("\n\t Range size: %u", GET_BE_U_3(tptr
));
1177 if (ospf_print_ri_lsa_sid_label_range_tlv(ndo
, tptr
+4, tlv_length
-4) == -1) {
1182 case LS_OPAQUE_RI_TLV_SRMS_PREFERENCE
:
1183 if (tlv_length
!= 4) {
1184 ND_PRINT("\n\t Bogus SRMS Preference TLV length %u != 4", tlv_length
);
1187 ND_PRINT("\n\t SRMS Preference: %u", GET_U_1(tptr
));
1191 if (ndo
->ndo_vflag
<= 1) {
1192 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
1199 /* in OSPF everything has to be 32-bit aligned, including TLVs */
1200 if (tlv_length
% 4) {
1201 tlv_length
+= (4 - (tlv_length
% 4));
1202 if (tlv_length
> ls_length_remaining
) {
1203 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
1204 ls_length_remaining
);
1209 ls_length_remaining
-=tlv_length
;
1213 case LS_OPAQUE_TYPE_GRACE
:
1214 if (ospf_grace_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_grace_tlv
),
1220 case LS_OPAQUE_TYPE_TE
:
1221 if (ospf_te_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_te_lsa_tlv
),
1227 case LS_OPAQUE_TYPE_EP
:
1228 if (ospf_ep_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_ep_tlv
),
1235 if (ndo
->ndo_vflag
<= 1) {
1236 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
1237 "\n\t ", ls_length
))
1244 /* do we want to see an additionally hexdump ? */
1245 if (ndo
->ndo_vflag
> 1)
1246 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
1247 "\n\t ", ls_length
)) {
1253 nd_print_trunc(ndo
);
1258 ospf_decode_lls(netdissect_options
*ndo
,
1259 const struct ospfhdr
*op
, u_int length
)
1262 const u_char
*dataend
;
1264 uint16_t lls_type
, lls_len
;
1267 switch (GET_U_1(op
->ospf_type
)) {
1269 case OSPF_TYPE_HELLO
:
1270 if (!(GET_U_1(op
->ospf_hello
.hello_options
) & OSPF_OPTION_L
))
1275 if (!(GET_U_1(op
->ospf_db
.db_options
) & OSPF_OPTION_L
))
1283 /* dig deeper if LLS data is available; see RFC4813 */
1284 length2
= GET_BE_U_2(op
->ospf_len
);
1285 dptr
= (const u_char
*)op
+ length2
;
1286 dataend
= (const u_char
*)op
+ length
;
1288 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1289 dptr
= dptr
+ GET_U_1(op
->ospf_authdata
+ 3);
1290 length2
+= GET_U_1(op
->ospf_authdata
+ 3);
1292 if (length2
>= length
) {
1293 ND_PRINT("\n\t[LLS truncated]");
1296 ND_PRINT("\n\t LLS: checksum: 0x%04x", (u_int
) GET_BE_U_2(dptr
));
1299 length2
= GET_BE_U_2(dptr
);
1300 ND_PRINT(", length: %u", length2
);
1303 while (dptr
< dataend
) {
1304 lls_type
= GET_BE_U_2(dptr
);
1305 ND_PRINT("\n\t %s (%u)",
1306 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
1309 lls_len
= GET_BE_U_2(dptr
);
1310 ND_PRINT(", length: %u", lls_len
);
1316 ND_PRINT(" [should be 4]");
1319 lls_flags
= GET_BE_U_4(dptr
);
1320 ND_PRINT("\n\t Options: 0x%08x [%s]", lls_flags
,
1321 bittok2str(ospf_lls_eo_options
, "?", lls_flags
));
1326 if (lls_len
!= 20) {
1327 ND_PRINT(" [should be 20]");
1330 ND_PRINT("\n\t Sequence number: 0x%08x", GET_BE_U_4(dptr
));
1339 ospf_decode_v2(netdissect_options
*ndo
,
1340 const struct ospfhdr
*op
, const u_char
*dataend
)
1343 const struct lsr
*lsrp
;
1344 const struct lsa_hdr
*lshp
;
1345 const struct lsa
*lsap
;
1346 uint32_t lsa_count
,lsa_count_max
;
1348 switch (GET_U_1(op
->ospf_type
)) {
1350 case OSPF_TYPE_HELLO
:
1351 ND_PRINT("\n\tOptions [%s]",
1352 bittok2str(ospf_option_values
,"none",GET_U_1(op
->ospf_hello
.hello_options
)));
1354 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1355 GET_BE_U_2(op
->ospf_hello
.hello_helloint
),
1356 GET_BE_U_4(op
->ospf_hello
.hello_deadint
),
1357 GET_IPADDR_STRING(op
->ospf_hello
.hello_mask
),
1358 GET_U_1(op
->ospf_hello
.hello_priority
));
1360 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_dr
) != 0)
1361 ND_PRINT("\n\t Designated Router %s",
1362 GET_IPADDR_STRING(op
->ospf_hello
.hello_dr
));
1364 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_bdr
) != 0)
1365 ND_PRINT(", Backup Designated Router %s",
1366 GET_IPADDR_STRING(op
->ospf_hello
.hello_bdr
));
1368 ap
= op
->ospf_hello
.hello_neighbor
;
1369 if ((const u_char
*)ap
< dataend
)
1370 ND_PRINT("\n\t Neighbor List:");
1371 while ((const u_char
*)ap
< dataend
) {
1372 ND_PRINT("\n\t %s", GET_IPADDR_STRING(ap
));
1378 ND_PRINT("\n\tOptions [%s]",
1379 bittok2str(ospf_option_values
, "none", GET_U_1(op
->ospf_db
.db_options
)));
1380 ND_PRINT(", DD Flags [%s]",
1381 bittok2str(ospf_dd_flag_values
, "none", GET_U_1(op
->ospf_db
.db_flags
)));
1382 if (GET_BE_U_2(op
->ospf_db
.db_ifmtu
)) {
1383 ND_PRINT(", MTU: %u",
1384 GET_BE_U_2(op
->ospf_db
.db_ifmtu
));
1386 ND_PRINT(", Sequence: 0x%08x", GET_BE_U_4(op
->ospf_db
.db_seq
));
1388 /* Print all the LS adv's */
1389 lshp
= op
->ospf_db
.db_lshdr
;
1390 while (((const u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
1395 case OSPF_TYPE_LS_REQ
:
1396 lsrp
= op
->ospf_lsr
;
1397 while ((const u_char
*)lsrp
< dataend
) {
1398 ND_TCHECK_SIZE(lsrp
);
1400 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1401 GET_IPADDR_STRING(lsrp
->ls_router
),
1402 tok2str(lsa_values
,"unknown",GET_BE_U_4(lsrp
->ls_type
)),
1403 GET_BE_U_4(lsrp
->ls_type
));
1405 switch (GET_BE_U_4(lsrp
->ls_type
)) {
1406 /* the LSA header for opaque LSAs was slightly changed */
1407 case LS_TYPE_OPAQUE_LL
:
1408 case LS_TYPE_OPAQUE_AL
:
1409 case LS_TYPE_OPAQUE_DW
:
1410 ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1411 tok2str(lsa_opaque_values
, "unknown",GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
)),
1412 GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1413 GET_BE_U_3(lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
1416 ND_PRINT(", LSA-ID: %s",
1417 GET_IPADDR_STRING(lsrp
->un_ls_stateid
.ls_stateid
));
1425 case OSPF_TYPE_LS_UPDATE
:
1426 lsap
= op
->ospf_lsu
.lsu_lsa
;
1427 lsa_count_max
= GET_BE_U_4(op
->ospf_lsu
.lsu_count
);
1428 ND_PRINT(", %u LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
));
1429 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1430 ND_PRINT("\n\t LSA #%u", lsa_count
);
1431 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1437 case OSPF_TYPE_LS_ACK
:
1438 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1439 while ((const u_char
*)lshp
< dataend
) {
1440 ospf_print_lshdr(ndo
, lshp
);
1454 ospf_print(netdissect_options
*ndo
,
1455 const u_char
*bp
, u_int length
,
1456 const u_char
*bp2 _U_
)
1458 const struct ospfhdr
*op
;
1459 const u_char
*dataend
;
1462 ndo
->ndo_protocol
= "ospf2";
1463 op
= (const struct ospfhdr
*)bp
;
1465 /* XXX Before we do anything else, strip off the MD5 trailer */
1466 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1467 length
-= OSPF_AUTH_MD5_LEN
;
1468 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1471 /* If the type is valid translate it, or just print the type */
1472 /* value. If it's not valid, say so and return */
1473 cp
= tok2str(type2str
, "unknown LS-type %u", GET_U_1(op
->ospf_type
));
1474 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op
->ospf_version
), cp
,
1479 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1483 if (length
!= GET_BE_U_2(op
->ospf_len
)) {
1484 ND_PRINT(" [len %u]", GET_BE_U_2(op
->ospf_len
));
1487 if (length
> GET_BE_U_2(op
->ospf_len
)) {
1488 dataend
= bp
+ GET_BE_U_2(op
->ospf_len
);
1490 dataend
= bp
+ length
;
1493 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op
->ospf_routerid
));
1495 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_areaid
) != 0)
1496 ND_PRINT(", Area %s", GET_IPADDR_STRING(op
->ospf_areaid
));
1498 ND_PRINT(", Backbone Area");
1500 if (ndo
->ndo_vflag
) {
1501 /* Print authentication data (should we really do this?) */
1502 ND_TCHECK_LEN(op
->ospf_authdata
, sizeof(op
->ospf_authdata
));
1504 ND_PRINT(", Authentication Type: %s (%u)",
1505 tok2str(ospf_authtype_values
, "unknown", GET_BE_U_2(op
->ospf_authtype
)),
1506 GET_BE_U_2(op
->ospf_authtype
));
1508 switch (GET_BE_U_2(op
->ospf_authtype
)) {
1510 case OSPF_AUTH_NONE
:
1513 case OSPF_AUTH_SIMPLE
:
1514 ND_PRINT("\n\tSimple text password: ");
1515 nd_printjnp(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1519 ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1520 GET_U_1(op
->ospf_authdata
+ 2),
1521 GET_U_1(op
->ospf_authdata
+ 3),
1522 GET_BE_U_4((op
->ospf_authdata
) + 4));
1529 /* Do rest according to version. */
1530 switch (GET_U_1(op
->ospf_version
)) {
1533 /* ospf version 2 */
1534 if (ospf_decode_v2(ndo
, op
, dataend
))
1536 if (length
> GET_BE_U_2(op
->ospf_len
))
1537 ospf_decode_lls(ndo
, op
, length
);
1541 ND_PRINT(" ospf [version %u]", GET_U_1(op
->ospf_version
));
1543 } /* end switch on version */
1547 nd_trunc_longjmp(ndo
);