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_lsa_print(netdissect_options
*ndo
,
328 const u_char
*tptr
, u_int ls_length
)
330 u_int tlv_type
, tlv_length
, subtlv_type
, subtlv_length
;
331 u_int priority_level
, te_class
, count_srlg
;
334 while (ls_length
!= 0) {
337 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length
);
340 tlv_type
= GET_BE_U_2(tptr
);
341 tlv_length
= GET_BE_U_2(tptr
+ 2);
345 ND_PRINT("\n\t %s TLV (%u), length: %u",
346 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
350 if (tlv_length
> ls_length
) {
351 ND_PRINT("\n\t Bogus length %u > %u", tlv_length
,
356 /* Infinite loop protection. */
357 if (tlv_type
== 0 || tlv_length
==0) {
358 nd_print_invalid(ndo
);
363 case LS_OPAQUE_TE_TLV_LINK
:
364 while (tlv_length
!= 0) {
365 if (tlv_length
< 4) {
366 ND_PRINT("\n\t Remaining TLV length %u < 4",
370 subtlv_type
= GET_BE_U_2(tptr
);
371 subtlv_length
= GET_BE_U_2(tptr
+ 2);
375 /* Infinite loop protection */
376 if (subtlv_type
== 0 || subtlv_length
== 0)
379 ND_PRINT("\n\t %s subTLV (%u), length: %u",
380 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
384 if (tlv_length
< subtlv_length
) {
385 ND_PRINT("\n\t Remaining TLV length %u < %u",
386 tlv_length
, subtlv_length
);
389 ND_TCHECK_LEN(tptr
, subtlv_length
);
390 switch(subtlv_type
) {
391 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
392 if (subtlv_length
!= 4) {
396 ND_PRINT(", 0x%08x", GET_BE_U_4(tptr
));
398 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
399 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
400 if (subtlv_length
!= 4 && subtlv_length
!= 8) {
401 ND_PRINT(" != 4 && != 8");
404 ND_PRINT(", %s (0x%08x)",
405 GET_IPADDR_STRING(tptr
),
407 if (subtlv_length
== 8) /* rfc4203 */
408 ND_PRINT(", %s (0x%08x)",
409 GET_IPADDR_STRING(tptr
+4),
410 GET_BE_U_4(tptr
+ 4));
412 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
413 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
414 if (subtlv_length
!= 4) {
418 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
420 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
421 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
422 if (subtlv_length
!= 4) {
426 bw
= GET_BE_F_4(tptr
);
427 ND_PRINT(", %.3f Mbps", bw
* 8 / 1000000);
429 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
430 if (subtlv_length
!= 32) {
434 for (te_class
= 0; te_class
< 8; te_class
++) {
435 bw
= GET_BE_F_4(tptr
+ te_class
* 4);
436 ND_PRINT("\n\t\tTE-Class %u: %.3f Mbps",
441 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
442 if (subtlv_length
< 4) {
446 /* BC Model Id (1 octet) + Reserved (3 octets) */
447 ND_PRINT("\n\t\tBandwidth Constraints Model ID: %s (%u)",
448 tok2str(diffserv_te_bc_values
, "unknown", GET_U_1(tptr
)),
450 if (subtlv_length
% 4 != 0) {
451 ND_PRINT("\n\t\tlength %u != N x 4", subtlv_length
);
454 if (subtlv_length
> 36) {
455 ND_PRINT("\n\t\tlength %u > 36", subtlv_length
);
458 /* decode BCs until the subTLV ends */
459 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
460 bw
= GET_BE_F_4(tptr
+ 4 + te_class
* 4);
461 ND_PRINT("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
466 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
467 if (subtlv_length
!= 4) {
471 ND_PRINT(", Metric %u", GET_BE_U_4(tptr
));
473 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
474 /* Protection Cap (1 octet) + Reserved ((3 octets) */
475 if (subtlv_length
!= 4) {
480 bittok2str(gmpls_link_prot_values
, "none", GET_U_1(tptr
)));
482 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
483 if (subtlv_length
< 36) {
487 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
488 ND_PRINT("\n\t\tInterface Switching Capability: %s",
489 tok2str(gmpls_switch_cap_values
, "Unknown", GET_U_1((tptr
))));
490 ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
491 tok2str(gmpls_encoding_values
, "Unknown", GET_U_1((tptr
+ 1))));
492 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
493 bw
= GET_BE_F_4(tptr
+ 4 + (priority_level
* 4));
494 ND_PRINT("\n\t\t priority level %u: %.3f Mbps",
499 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
500 if (subtlv_length
!= 1) {
504 ND_PRINT(", %s (%u)",
505 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",GET_U_1(tptr
)),
509 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
510 if (subtlv_length
% 4 != 0) {
511 ND_PRINT(" != N x 4");
514 count_srlg
= subtlv_length
/ 4;
516 ND_PRINT("\n\t\t Shared risk group: ");
517 while (count_srlg
> 0) {
518 ND_PRINT("%u", GET_BE_U_4(tptr
));
527 if (ndo
->ndo_vflag
<= 1) {
528 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
533 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
534 if (subtlv_length
%4 != 0) {
535 subtlv_length
+=4-(subtlv_length
%4);
537 if (tlv_length
< subtlv_length
) {
538 ND_PRINT("\n\t Remaining TLV length %u < %u",
539 tlv_length
, subtlv_length
);
543 tlv_length
-=subtlv_length
;
549 case LS_OPAQUE_TE_TLV_ROUTER
:
550 if (tlv_length
< 4) {
551 ND_PRINT("\n\t TLV length %u < 4", tlv_length
);
554 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
558 if (ndo
->ndo_vflag
<= 1) {
559 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
564 /* in OSPF everything has to be 32-bit aligned, including TLVs */
565 if (tlv_length
%4 != 0) {
566 tlv_length
+=4-(tlv_length
%4);
567 if (tlv_length
> ls_length
) {
568 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
573 ls_length
-=tlv_length
;
580 nd_print_invalid(ndo
);
585 ospf_print_lshdr(netdissect_options
*ndo
,
586 const struct lsa_hdr
*lshp
)
591 ls_length
= GET_BE_U_2(lshp
->ls_length
);
592 if (ls_length
< sizeof(struct lsa_hdr
)) {
593 ND_PRINT("\n\t Bogus length %u < header (%zu)", ls_length
,
594 sizeof(struct lsa_hdr
));
597 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %zu",
598 GET_IPADDR_STRING(lshp
->ls_router
),
599 GET_BE_U_4(lshp
->ls_seq
),
600 GET_BE_U_2(lshp
->ls_age
),
601 ls_length
- sizeof(struct lsa_hdr
));
602 ls_type
= GET_U_1(lshp
->ls_type
);
604 /* the LSA header for opaque LSAs was slightly changed */
605 case LS_TYPE_OPAQUE_LL
:
606 case LS_TYPE_OPAQUE_AL
:
607 case LS_TYPE_OPAQUE_DW
:
608 ND_PRINT("\n\t %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u",
609 tok2str(lsa_values
,"unknown",ls_type
),
612 tok2str(lsa_opaque_values
,
614 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
615 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
),
616 GET_BE_U_3(lshp
->un_lsa_id
.opaque_field
.opaque_id
)
621 /* all other LSA types use regular style LSA headers */
623 ND_PRINT("\n\t %s LSA (%u), LSA-ID: %s",
624 tok2str(lsa_values
,"unknown",ls_type
),
626 GET_IPADDR_STRING(lshp
->un_lsa_id
.lsa_id
));
629 ND_PRINT("\n\t Options: [%s]",
630 bittok2str(ospf_option_values
, "none", GET_U_1(lshp
->ls_options
)));
635 /* draft-ietf-ospf-mt-09 */
636 static const struct tok ospf_topology_values
[] = {
644 * Print all the per-topology metrics.
647 ospf_print_tos_metrics(netdissect_options
*ndo
,
648 const union un_tos
*tos
)
654 toscount
= GET_U_1(tos
->link
.link_tos_count
)+1;
658 * All but the first metric contain a valid topology id.
660 while (toscount
!= 0) {
661 tos_type
= GET_U_1(tos
->metrics
.tos_type
);
662 ND_PRINT("\n\t\ttopology %s (%u), metric %u",
663 tok2str(ospf_topology_values
, "Unknown",
664 metric_count
? tos_type
: 0),
665 metric_count
? tos_type
: 0,
666 GET_BE_U_2(tos
->metrics
.tos_metric
));
674 * The SID/Label Range TLV
675 * https://datatracker.ietf.org/doc/html/rfc8665#section-3.2
676 * and the SR Local Block TLV
677 * https://datatracker.ietf.org/doc/html/rfc8665#section-3.3
678 * have the same contents, so this function is used to
682 ospf_print_ri_lsa_sid_label_range_tlv(netdissect_options
*ndo
, const uint8_t *tptr
,
685 u_int subtlv_type
, subtlv_length
;
687 while (tlv_length
>= 4) {
689 subtlv_type
= GET_BE_U_2(tptr
);
690 subtlv_length
= GET_BE_U_2(tptr
+2);
694 /* Infinite loop protection. */
695 if (subtlv_type
== 0 || subtlv_length
== 0) {
696 nd_print_invalid(ndo
);
700 ND_PRINT("\n\t %s subTLV (%u), length: %u, value: ",
701 tok2str(lsa_opaque_ri_sid_subtlv_values
,"unknown",subtlv_type
),
705 if (tlv_length
< subtlv_length
) {
706 ND_PRINT("\n\t Remaining TLV length %u < %u",
707 tlv_length
, subtlv_length
);
711 switch (subtlv_type
) {
712 case LS_OPAQUE_RI_SUBTLV_SID_LABEL
:
713 if (subtlv_length
== 3) {
714 ND_PRINT("\n\t\tLabel: %u", GET_BE_U_3(tptr
));
715 } else if (subtlv_length
== 4) {
716 ND_PRINT("\n\t\tSID: %u", GET_BE_U_4(tptr
));
718 ND_PRINT("\n\t\tBogus subTLV length %u", subtlv_length
);
723 if (ndo
->ndo_vflag
<= 1) {
724 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
729 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
730 if (subtlv_length
% 4) {
731 subtlv_length
+= (4 - (subtlv_length
% 4));
732 if (tlv_length
< subtlv_length
) {
733 ND_PRINT("\n\t Remaining TLV length %u < %u",
734 tlv_length
, subtlv_length
);
739 tlv_length
-=subtlv_length
;
745 ospf_print_ep_lsa_extd_prefix_tlv(netdissect_options
*ndo
, const uint8_t *tptr
,
748 u_int subtlv_type
, subtlv_length
;
749 uint8_t flags
, mt_id
, algo
;
751 while (tlv_length
>= 4) {
752 subtlv_type
= GET_BE_U_2(tptr
);
753 subtlv_length
= GET_BE_U_2(tptr
+2);
757 /* Infinite loop protection. */
758 if (subtlv_type
== 0 || subtlv_length
== 0) {
759 nd_print_invalid(ndo
);
763 ND_PRINT("\n\t\t%s subTLV (%u), length: %u, value: ",
764 tok2str(lsa_opaque_ep_extd_prefix_subtlv_values
,"unknown",subtlv_type
),
768 if (tlv_length
< subtlv_length
) {
769 ND_PRINT("\n\t Remaining TLV length %u < %u",
770 tlv_length
, subtlv_length
);
774 switch (subtlv_type
) {
775 case LS_OPAQUE_EP_SUBTLV_PREFIX_SID
:
776 flags
= GET_U_1(tptr
);
777 mt_id
= GET_U_1(tptr
+2);
778 algo
= GET_U_1(tptr
+3);
780 if (subtlv_length
== 7) {
781 ND_PRINT("\n\t\t Label: %u", GET_BE_U_3(tptr
+4));
782 } else if (subtlv_length
== 8) {
783 ND_PRINT("\n\t\t Index: %u", GET_BE_U_4(tptr
+4));
785 ND_PRINT("\n\t\tBogus subTLV length %u", subtlv_length
);
788 ND_PRINT( ", MT-ID: %u, Algorithm: %s (%u), Flags [%s]",
789 mt_id
, tok2str(lsa_opaque_ri_tlv_sr_algos
, "Unknown", algo
), algo
,
790 bittok2str(ep_range_tlv_prefix_sid_subtlv_flag_values
, "none", flags
));
794 if (ndo
->ndo_vflag
<= 1) {
795 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
800 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
801 if (subtlv_length
% 4) {
802 subtlv_length
+= (4 - (subtlv_length
% 4));
803 if (tlv_length
< subtlv_length
) {
804 ND_PRINT("\n\t Remaining TLV length %u < %u",
805 tlv_length
, subtlv_length
);
810 tlv_length
-=subtlv_length
;
816 ospf_ep_lsa_print(netdissect_options
*ndo
, const uint8_t *tptr
, u_int lsa_length
)
818 u_int tlv_type
, tlv_length
;
820 uint8_t af
, prefix_length
, route_type
, flags
;
822 while (lsa_length
>= 4) {
824 tlv_type
= GET_BE_U_2(tptr
);
825 tlv_length
= GET_BE_U_2(tptr
+2);
829 /* Infinite loop protection. */
830 if (tlv_type
== 0 || tlv_length
== 0) {
831 nd_print_invalid(ndo
);
835 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
836 tok2str(lsa_opaque_ep_tlv_values
,"unknown",tlv_type
),
840 if (tlv_length
> lsa_length
) {
841 ND_PRINT("\n\t Bogus length %u > %u",
842 tlv_length
, lsa_length
);
847 case LS_OPAQUE_EP_EXTD_PREFIX_TLV
:
848 prefix_length
= GET_U_1(tptr
+1);
849 af
= GET_U_1(tptr
+2);
850 route_type
= GET_U_1(tptr
);
851 flags
= GET_U_1(tptr
+3);
854 ND_PRINT("\n\t Bogus AF %u", af
);
858 if (prefix_length
> 32) {
859 ND_PRINT("\n\t IPv4 prefix: bad bit length %u", prefix_length
);
863 ND_PRINT("\n\t IPv4 prefix: %15s/%u, Route Type: %s, Flags [%s]",
864 GET_IPADDR_STRING(tptr
+4), prefix_length
,
865 tok2str(lsa_opaque_ep_route_type_values
, "Unknown", route_type
),
866 bittok2str(ep_tlv_flag_values
, "none", flags
));
868 /* subTLVs present ? */
869 if (tlv_length
> 12) {
870 if (ospf_print_ep_lsa_extd_prefix_tlv(ndo
, tptr
+8, tlv_length
-8) == -1) {
876 case LS_OPAQUE_EP_EXTD_PREFIX_RANGE_TLV
:
877 prefix_length
= GET_U_1(tptr
);
878 af
= GET_U_1(tptr
+1);
879 range_size
= GET_BE_U_2(tptr
+2);
880 flags
= GET_U_1(tptr
+4);
883 ND_PRINT("\n\t Bogus AF %u", af
);
887 if (prefix_length
> 32) {
888 ND_PRINT("\n\t IPv4 prefix: bad bit length %u", prefix_length
);
892 ND_PRINT("\n\t IPv4 prefix: %15s/%u, Range size: %u, Flags [%s]",
893 GET_IPADDR_STRING(tptr
+8), prefix_length
,
895 bittok2str(ep_tlv_flag_values
, "none", flags
));
897 /* subTLVs present ? */
898 if (tlv_length
> 12) {
899 if (ospf_print_ep_lsa_extd_prefix_tlv(ndo
, tptr
+12, tlv_length
-12) == -1) {
906 if (ndo
->ndo_vflag
<= 1) {
907 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", tlv_length
))
912 /* in OSPF everything has to be 32-bit aligned, including TLVs */
913 if (tlv_length
% 4) {
914 tlv_length
+= (4 - (tlv_length
% 4));
915 if (tlv_length
> lsa_length
) {
916 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
922 lsa_length
-=tlv_length
;
928 * Print a single link state advertisement. If truncated or if LSA length
929 * field is less than the length of the LSA header, return NULl, else
930 * return pointer to data past end of LSA.
932 static const uint8_t *
933 ospf_print_lsa(netdissect_options
*ndo
,
934 const struct lsa
*lsap
)
936 const uint8_t *ls_end
;
937 const struct rlalink
*rlp
;
939 const struct aslametric
*almp
;
940 const struct mcla
*mcp
;
942 u_int tlv_type
, tlv_length
, rla_count
, topology
, num_tlv
;
943 int ospf_print_lshdr_ret
;
947 tptr
= (const uint8_t *)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
948 ospf_print_lshdr_ret
= ospf_print_lshdr(ndo
, &lsap
->ls_hdr
);
949 if (ospf_print_lshdr_ret
< 0)
951 ls_length
= (u_int
)ospf_print_lshdr_ret
;
952 ls_end
= (const uint8_t *)lsap
+ ls_length
;
954 * ospf_print_lshdr() returns -1 if the length is too short,
955 * so we know ls_length is >= sizeof(struct lsa_hdr).
957 ls_length
-= sizeof(struct lsa_hdr
);
959 switch (GET_U_1(lsap
->ls_hdr
.ls_type
)) {
962 ND_PRINT("\n\t Router LSA Options: [%s]",
963 bittok2str(ospf_rla_flag_values
, "none", GET_U_1(lsap
->lsa_un
.un_rla
.rla_flags
)));
965 rla_count
= GET_BE_U_2(lsap
->lsa_un
.un_rla
.rla_count
);
966 ND_TCHECK_SIZE(lsap
->lsa_un
.un_rla
.rla_link
);
967 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
968 for (u_int i
= rla_count
; i
!= 0; i
--) {
970 switch (GET_U_1(rlp
->un_tos
.link
.link_type
)) {
972 case RLA_TYPE_VIRTUAL
:
973 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
974 GET_IPADDR_STRING(rlp
->link_id
),
975 GET_IPADDR_STRING(rlp
->link_data
));
978 case RLA_TYPE_ROUTER
:
979 ND_PRINT("\n\t 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_TRANSIT
:
985 ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s",
986 GET_IPADDR_STRING(rlp
->link_id
),
987 GET_IPADDR_STRING(rlp
->link_data
));
991 ND_PRINT("\n\t Stub Network: %s, Mask: %s",
992 GET_IPADDR_STRING(rlp
->link_id
),
993 GET_IPADDR_STRING(rlp
->link_data
));
997 ND_PRINT("\n\t Unknown Router Link Type (%u)",
998 GET_U_1(rlp
->un_tos
.link
.link_type
));
1002 ospf_print_tos_metrics(ndo
, &rlp
->un_tos
);
1004 rlp
= (const struct rlalink
*)((const u_char
*)(rlp
+ 1) +
1005 (GET_U_1(rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
1009 case LS_TYPE_NETWORK
:
1010 ND_PRINT("\n\t Mask %s\n\t Connected Routers:",
1011 GET_IPADDR_STRING(lsap
->lsa_un
.un_nla
.nla_mask
));
1012 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
1013 while ((const u_char
*)ap
< ls_end
) {
1014 ND_PRINT("\n\t %s", GET_IPADDR_STRING(ap
));
1019 case LS_TYPE_SUM_IP
:
1020 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
1021 ND_PRINT("\n\t Mask %s",
1022 GET_IPADDR_STRING(lsap
->lsa_un
.un_sla
.sla_mask
));
1023 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
1024 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
1025 while (lp
< ls_end
) {
1028 ul
= GET_BE_U_4(lp
);
1029 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
1030 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
1031 tok2str(ospf_topology_values
, "Unknown", topology
),
1033 ul
& SLA_MASK_METRIC
);
1038 case LS_TYPE_SUM_ABR
:
1039 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
1040 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
1041 while (lp
< ls_end
) {
1044 ul
= GET_BE_U_4(lp
);
1045 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
1046 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
1047 tok2str(ospf_topology_values
, "Unknown", topology
),
1049 ul
& SLA_MASK_METRIC
);
1055 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
1056 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
1057 ND_PRINT("\n\t Mask %s",
1058 GET_IPADDR_STRING(lsap
->lsa_un
.un_asla
.asla_mask
));
1060 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
1061 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
1062 while ((const u_char
*)almp
< ls_end
) {
1065 ul
= GET_BE_U_4(almp
->asla_tosmetric
);
1066 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
1067 ND_PRINT("\n\t\ttopology %s (%u), type %u, metric",
1068 tok2str(ospf_topology_values
, "Unknown", topology
),
1070 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1);
1071 if ((ul
& ASLA_MASK_METRIC
) == 0xffffff)
1072 ND_PRINT(" infinite");
1074 ND_PRINT(" %u", (ul
& ASLA_MASK_METRIC
));
1076 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_forward
) != 0) {
1077 ND_PRINT(", forward %s", GET_IPADDR_STRING(almp
->asla_forward
));
1079 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_tag
) != 0) {
1080 ND_PRINT(", tag %s", GET_IPADDR_STRING(almp
->asla_tag
));
1087 /* Multicast extensions as of 23 July 1991 */
1088 mcp
= lsap
->lsa_un
.un_mcla
;
1089 while ((const u_char
*)mcp
< ls_end
) {
1090 switch (GET_BE_U_4(mcp
->mcla_vtype
)) {
1092 case MCLA_VERTEX_ROUTER
:
1093 ND_PRINT("\n\t Router Router-ID %s",
1094 GET_IPADDR_STRING(mcp
->mcla_vid
));
1097 case MCLA_VERTEX_NETWORK
:
1098 ND_PRINT("\n\t Network Designated Router %s",
1099 GET_IPADDR_STRING(mcp
->mcla_vid
));
1103 ND_PRINT("\n\t unknown VertexType (%u)",
1104 GET_BE_U_4(mcp
->mcla_vtype
));
1111 case LS_TYPE_OPAQUE_LL
: /* fall through */
1112 case LS_TYPE_OPAQUE_AL
:
1113 case LS_TYPE_OPAQUE_DW
:
1115 switch (GET_U_1(lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
1116 case LS_OPAQUE_TYPE_RI
:
1117 tptr
= (const uint8_t *)(lsap
->lsa_un
.un_ri_tlv
);
1119 u_int ls_length_remaining
= ls_length
;
1120 while (ls_length_remaining
!= 0) {
1122 if (ls_length_remaining
< 4) {
1123 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length_remaining
);
1126 tlv_type
= GET_BE_U_2(tptr
);
1127 tlv_length
= GET_BE_U_2(tptr
+ 2);
1129 ls_length_remaining
-=4;
1131 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
1132 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
1136 if (tlv_length
> ls_length_remaining
) {
1137 ND_PRINT("\n\t Bogus length %u > remaining LS length %u", tlv_length
,
1138 ls_length_remaining
);
1141 ND_TCHECK_LEN(tptr
, tlv_length
);
1144 case LS_OPAQUE_RI_TLV_CAP
:
1145 if (tlv_length
!= 4) {
1146 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
1149 ND_PRINT("Capabilities: %s",
1150 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", GET_BE_U_4(tptr
)));
1153 case LS_OPAQUE_RI_TLV_HOSTNAME
:
1154 ND_PRINT("\n\t Hostname: ");
1155 nd_printjnp(ndo
, tptr
, tlv_length
);
1158 case LS_OPAQUE_RI_TLV_SR_ALGO
:
1159 num_tlv
= tlv_length
;
1160 while (num_tlv
>= 1) {
1161 ND_PRINT("\n\t %s (%u)",
1162 tok2str(lsa_opaque_ri_tlv_sr_algos
, "Unknown", GET_U_1(tptr
+tlv_length
-num_tlv
)), GET_U_1(tptr
+tlv_length
-num_tlv
));
1167 case LS_OPAQUE_RI_TLV_SID_LABEL_RANGE
:
1168 case LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK
:
1170 ND_PRINT("\n\t Range size: %u", GET_BE_U_3(tptr
));
1171 if (ospf_print_ri_lsa_sid_label_range_tlv(ndo
, tptr
+4, tlv_length
-4) == -1) {
1176 case LS_OPAQUE_RI_TLV_SRMS_PREFERENCE
:
1177 if (tlv_length
!= 4) {
1178 ND_PRINT("\n\t Bogus SRMS Preference TLV length %u != 4", tlv_length
);
1181 ND_PRINT("\n\t SRMS Preference: %u", GET_U_1(tptr
));
1185 if (ndo
->ndo_vflag
<= 1) {
1186 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
1193 /* in OSPF everything has to be 32-bit aligned, including TLVs */
1194 if (tlv_length
% 4) {
1195 tlv_length
+= (4 - (tlv_length
% 4));
1196 if (tlv_length
> ls_length_remaining
) {
1197 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
1198 ls_length_remaining
);
1203 ls_length_remaining
-=tlv_length
;
1207 case LS_OPAQUE_TYPE_GRACE
:
1208 if (ospf_grace_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_grace_tlv
),
1214 case LS_OPAQUE_TYPE_TE
:
1215 if (ospf_te_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_te_lsa_tlv
),
1221 case LS_OPAQUE_TYPE_EP
:
1222 if (ospf_ep_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_ep_tlv
),
1229 if (ndo
->ndo_vflag
<= 1) {
1230 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
1231 "\n\t ", ls_length
))
1238 /* do we want to see an additionally hexdump ? */
1239 if (ndo
->ndo_vflag
> 1)
1240 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
1241 "\n\t ", ls_length
)) {
1251 ospf_decode_lls(netdissect_options
*ndo
,
1252 const struct ospfhdr
*op
, u_int length
)
1255 const u_char
*dataend
;
1257 uint16_t lls_type
, lls_len
;
1260 switch (GET_U_1(op
->ospf_type
)) {
1262 case OSPF_TYPE_HELLO
:
1263 if (!(GET_U_1(op
->ospf_hello
.hello_options
) & OSPF_OPTION_L
))
1268 if (!(GET_U_1(op
->ospf_db
.db_options
) & OSPF_OPTION_L
))
1276 /* dig deeper if LLS data is available; see RFC4813 */
1277 length2
= GET_BE_U_2(op
->ospf_len
);
1278 dptr
= (const u_char
*)op
+ length2
;
1279 dataend
= (const u_char
*)op
+ length
;
1281 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1282 dptr
= dptr
+ GET_U_1(op
->ospf_authdata
+ 3);
1283 length2
+= GET_U_1(op
->ospf_authdata
+ 3);
1285 if (length2
>= length
) {
1286 ND_PRINT("\n\t[LLS truncated]");
1289 ND_PRINT("\n\t LLS: checksum: 0x%04x", (u_int
) GET_BE_U_2(dptr
));
1292 length2
= GET_BE_U_2(dptr
);
1293 ND_PRINT(", length: %u", length2
);
1296 while (dptr
< dataend
) {
1297 lls_type
= GET_BE_U_2(dptr
);
1298 ND_PRINT("\n\t %s (%u)",
1299 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
1302 lls_len
= GET_BE_U_2(dptr
);
1303 ND_PRINT(", length: %u", lls_len
);
1309 ND_PRINT(" [should be 4]");
1312 lls_flags
= GET_BE_U_4(dptr
);
1313 ND_PRINT("\n\t Options: 0x%08x [%s]", lls_flags
,
1314 bittok2str(ospf_lls_eo_options
, "?", lls_flags
));
1319 if (lls_len
!= 20) {
1320 ND_PRINT(" [should be 20]");
1323 ND_PRINT("\n\t Sequence number: 0x%08x", GET_BE_U_4(dptr
));
1332 ospf_decode_v2(netdissect_options
*ndo
,
1333 const struct ospfhdr
*op
, const u_char
*dataend
)
1336 const struct lsr
*lsrp
;
1337 const struct lsa_hdr
*lshp
;
1338 const struct lsa
*lsap
;
1339 uint32_t lsa_count
,lsa_count_max
;
1341 switch (GET_U_1(op
->ospf_type
)) {
1343 case OSPF_TYPE_HELLO
:
1344 ND_PRINT("\n\tOptions [%s]",
1345 bittok2str(ospf_option_values
,"none",GET_U_1(op
->ospf_hello
.hello_options
)));
1347 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1348 GET_BE_U_2(op
->ospf_hello
.hello_helloint
),
1349 GET_BE_U_4(op
->ospf_hello
.hello_deadint
),
1350 GET_IPADDR_STRING(op
->ospf_hello
.hello_mask
),
1351 GET_U_1(op
->ospf_hello
.hello_priority
));
1353 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_dr
) != 0)
1354 ND_PRINT("\n\t Designated Router %s",
1355 GET_IPADDR_STRING(op
->ospf_hello
.hello_dr
));
1357 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_bdr
) != 0)
1358 ND_PRINT(", Backup Designated Router %s",
1359 GET_IPADDR_STRING(op
->ospf_hello
.hello_bdr
));
1361 ap
= op
->ospf_hello
.hello_neighbor
;
1362 if ((const u_char
*)ap
< dataend
)
1363 ND_PRINT("\n\t Neighbor List:");
1364 while ((const u_char
*)ap
< dataend
) {
1365 ND_PRINT("\n\t %s", GET_IPADDR_STRING(ap
));
1371 ND_PRINT("\n\tOptions [%s]",
1372 bittok2str(ospf_option_values
, "none", GET_U_1(op
->ospf_db
.db_options
)));
1373 ND_PRINT(", DD Flags [%s]",
1374 bittok2str(ospf_dd_flag_values
, "none", GET_U_1(op
->ospf_db
.db_flags
)));
1375 if (GET_BE_U_2(op
->ospf_db
.db_ifmtu
)) {
1376 ND_PRINT(", MTU: %u",
1377 GET_BE_U_2(op
->ospf_db
.db_ifmtu
));
1379 ND_PRINT(", Sequence: 0x%08x", GET_BE_U_4(op
->ospf_db
.db_seq
));
1381 /* Print all the LS adv's */
1382 lshp
= op
->ospf_db
.db_lshdr
;
1383 while (((const u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
1388 case OSPF_TYPE_LS_REQ
:
1389 lsrp
= op
->ospf_lsr
;
1390 while ((const u_char
*)lsrp
< dataend
) {
1391 ND_TCHECK_SIZE(lsrp
);
1393 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1394 GET_IPADDR_STRING(lsrp
->ls_router
),
1395 tok2str(lsa_values
,"unknown",GET_BE_U_4(lsrp
->ls_type
)),
1396 GET_BE_U_4(lsrp
->ls_type
));
1398 switch (GET_BE_U_4(lsrp
->ls_type
)) {
1399 /* the LSA header for opaque LSAs was slightly changed */
1400 case LS_TYPE_OPAQUE_LL
:
1401 case LS_TYPE_OPAQUE_AL
:
1402 case LS_TYPE_OPAQUE_DW
:
1403 ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1404 tok2str(lsa_opaque_values
, "unknown",GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
)),
1405 GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1406 GET_BE_U_3(lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
1409 ND_PRINT(", LSA-ID: %s",
1410 GET_IPADDR_STRING(lsrp
->un_ls_stateid
.ls_stateid
));
1418 case OSPF_TYPE_LS_UPDATE
:
1419 lsap
= op
->ospf_lsu
.lsu_lsa
;
1420 lsa_count_max
= GET_BE_U_4(op
->ospf_lsu
.lsu_count
);
1421 ND_PRINT(", %u LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
));
1422 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1423 ND_PRINT("\n\t LSA #%u", lsa_count
);
1424 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1430 case OSPF_TYPE_LS_ACK
:
1431 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1432 while ((const u_char
*)lshp
< dataend
) {
1433 ospf_print_lshdr(ndo
, lshp
);
1447 ospf_print(netdissect_options
*ndo
,
1448 const u_char
*bp
, u_int length
,
1449 const u_char
*bp2 _U_
)
1451 const struct ospfhdr
*op
;
1452 const u_char
*dataend
;
1455 ndo
->ndo_protocol
= "ospf2";
1456 op
= (const struct ospfhdr
*)bp
;
1458 /* XXX Before we do anything else, strip off the MD5 trailer */
1459 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1460 length
-= OSPF_AUTH_MD5_LEN
;
1461 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1464 /* If the type is valid translate it, or just print the type */
1465 /* value. If it's not valid, say so and return */
1466 cp
= tok2str(type2str
, "unknown LS-type %u", GET_U_1(op
->ospf_type
));
1467 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op
->ospf_version
), cp
,
1472 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1476 if (length
!= GET_BE_U_2(op
->ospf_len
)) {
1477 ND_PRINT(" [len %u]", GET_BE_U_2(op
->ospf_len
));
1480 if (length
> GET_BE_U_2(op
->ospf_len
)) {
1481 dataend
= bp
+ GET_BE_U_2(op
->ospf_len
);
1483 dataend
= bp
+ length
;
1486 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op
->ospf_routerid
));
1488 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_areaid
) != 0)
1489 ND_PRINT(", Area %s", GET_IPADDR_STRING(op
->ospf_areaid
));
1491 ND_PRINT(", Backbone Area");
1493 if (ndo
->ndo_vflag
) {
1494 /* Print authentication data (should we really do this?) */
1495 ND_TCHECK_LEN(op
->ospf_authdata
, sizeof(op
->ospf_authdata
));
1497 ND_PRINT(", Authentication Type: %s (%u)",
1498 tok2str(ospf_authtype_values
, "unknown", GET_BE_U_2(op
->ospf_authtype
)),
1499 GET_BE_U_2(op
->ospf_authtype
));
1501 switch (GET_BE_U_2(op
->ospf_authtype
)) {
1503 case OSPF_AUTH_NONE
:
1506 case OSPF_AUTH_SIMPLE
:
1507 ND_PRINT("\n\tSimple text password: ");
1508 nd_printjnp(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1512 ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1513 GET_U_1(op
->ospf_authdata
+ 2),
1514 GET_U_1(op
->ospf_authdata
+ 3),
1515 GET_BE_U_4((op
->ospf_authdata
) + 4));
1522 /* Do rest according to version. */
1523 switch (GET_U_1(op
->ospf_version
)) {
1526 /* ospf version 2 */
1527 if (ospf_decode_v2(ndo
, op
, dataend
))
1529 if (length
> GET_BE_U_2(op
->ospf_len
))
1530 ospf_decode_lls(ndo
, op
, length
);
1534 ND_PRINT(" ospf [version %u]", GET_U_1(op
->ospf_version
));
1536 } /* end switch on version */
1540 nd_trunc_longjmp(ndo
);