From: Rachid Tak Tak Date: Fri, 10 Nov 2023 11:43:06 +0000 (-0800) Subject: OSPF: Add SR-Algo, Local Block, and SRMS Preference TLV parsers. X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/922fcadc882f2bc08b0bf86aea3239a7c6a62306 OSPF: Add SR-Algo, Local Block, and SRMS Preference TLV parsers. Display additional TLVs and their sub-TLVs from RFC8665: - SR-Algorithm TLV - SR Local Block TLV and its sub-TLVs - SRMS Preference TLV It also uses the SR-Algorithm names when printing the Prefix-SID Sub-TLV. --- diff --git a/CREDITS b/CREDITS index b6862ccb..ab5b3184 100644 --- a/CREDITS +++ b/CREDITS @@ -265,6 +265,7 @@ Additional people who have contributed patches (in alphabetical order): Phil Wood Pier Carlo Chiodi Quentin Armitage + Rachid Tak Tak Rafal Maszkowski Randy Sofia Raphael Raimbault diff --git a/ospf.h b/ospf.h index 24ff2e98..9b274faf 100644 --- a/ospf.h +++ b/ospf.h @@ -71,8 +71,9 @@ #define LS_OPAQUE_TYPE_TE 1 /* rfc3630 */ #define LS_OPAQUE_TYPE_GRACE 3 /* rfc3623 */ -#define LS_OPAQUE_TYPE_RI 4 /* draft-ietf-ospf-cap-03 */ +#define LS_OPAQUE_TYPE_RI 4 /* rfc7770 */ #define LS_OPAQUE_TYPE_EP 7 /* rfc7684 */ +#define LS_OPAQUE_TYPE_EL 8 /* rfc7684 */ #define LS_OPAQUE_TE_TLV_ROUTER 1 /* rfc3630 */ #define LS_OPAQUE_TE_TLV_LINK 2 /* rfc3630 */ @@ -110,9 +111,12 @@ #define LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE 2 /* rfc3623 */ #define LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH 3 /* rfc3623 */ -#define LS_OPAQUE_RI_TLV_CAP 1 /* draft-ietf-ospf-cap-03 */ -#define LS_OPAQUE_RI_TLV_HOSTNAME 7 /* rfc5642 */ -#define LS_OPAQUE_RI_TLV_SID_LABEL_RANGE 9 /* rfc8665 */ +#define LS_OPAQUE_RI_TLV_CAP 1 /* rfc7770 */ +#define LS_OPAQUE_RI_TLV_HOSTNAME 7 /* rfc5642 */ +#define LS_OPAQUE_RI_TLV_SR_ALGO 8 /* rfc8865 */ +#define LS_OPAQUE_RI_TLV_SID_LABEL_RANGE 9 /* rfc8865 */ +#define LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK 14 /* rfc8865 */ +#define LS_OPAQUE_RI_TLV_SRMS_PREFERENCE 15 /* rfc8865 */ /* rla_link.link_type */ #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */ diff --git a/print-ospf.c b/print-ospf.c index d0cf573c..7191087b 100644 --- a/print-ospf.c +++ b/print-ospf.c @@ -102,6 +102,7 @@ static const struct tok lsa_opaque_values[] = { { LS_OPAQUE_TYPE_GRACE, "Graceful restart" }, { LS_OPAQUE_TYPE_RI, "Router Information" }, { LS_OPAQUE_TYPE_EP, "Extended Prefix" }, + { LS_OPAQUE_TYPE_EL, "Extended Link" }, { 0, NULL } }; @@ -192,8 +193,11 @@ static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = { static const struct tok lsa_opaque_ri_tlv_values[] = { { LS_OPAQUE_RI_TLV_CAP, "Router Capabilities" }, + { LS_OPAQUE_RI_TLV_SR_ALGO, "SR-Algorithm" }, { LS_OPAQUE_RI_TLV_HOSTNAME, "Hostname" }, { LS_OPAQUE_RI_TLV_SID_LABEL_RANGE, "SID/Label Range" }, + { LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK, "SR Local Block" }, + { LS_OPAQUE_RI_TLV_SRMS_PREFERENCE, "SRMS Preference" }, { 0, NULL } }; @@ -211,6 +215,12 @@ static const struct tok lsa_opaque_ri_tlv_cap_values[] = { { 0, NULL } }; +static const struct tok lsa_opaque_ri_tlv_sr_algos[] = { + { 0, "Shortest Path First" }, + { 1, "Strict Shortest Path First" }, + { 0, NULL } +}; + static const struct tok ospf_lls_tlv_values[] = { { OSPF_LLS_EO, "Extended Options" }, { OSPF_LLS_MD5, "MD5 Authentication" }, @@ -656,6 +666,14 @@ ospf_print_tos_metrics(netdissect_options *ndo, } } +/* + * The SID/Label Range TLV + * https://datatracker.ietf.org/doc/html/rfc8665#section-3.2 + * and the SR Local Block TLV + * https://datatracker.ietf.org/doc/html/rfc8665#section-3.3 + * have the same contents, so this function is used to + * print both. + */ static int ospf_print_ri_lsa_sid_label_range_tlv(netdissect_options *ndo, const uint8_t *tptr, u_int tlv_length) @@ -739,15 +757,16 @@ ospf_print_ep_lsa_extd_prefix_tlv(netdissect_options *ndo, const uint8_t *tptr, algo = GET_U_1(tptr+3); if (subtlv_length == 7) { - ND_PRINT("\n\t\t Label: %u, MT-ID: %u, Algorithm: %u", - GET_BE_U_3(tptr+4), mt_id, algo); + ND_PRINT("\n\t\t Label: %u", GET_BE_U_3(tptr+4)); } else if (subtlv_length == 8) { - ND_PRINT("\n\t\t Index: %u, MT-ID: %u, Algorithm: %u, Flags [%s]", - GET_BE_U_4(tptr+4), mt_id, algo, - bittok2str(ep_range_tlv_prefix_sid_subtlv_flag_values, "none", flags)); + ND_PRINT("\n\t\t Index: %u", GET_BE_U_4(tptr+4)); } else { ND_PRINT("\n\t\tBogus subTLV length %u", subtlv_length); + break; } + ND_PRINT( ", MT-ID: %u, Algorithm: %s (%u), Flags [%s]", + mt_id, tok2str(lsa_opaque_ri_tlv_sr_algos, "Unknown", algo), algo, + bittok2str(ep_range_tlv_prefix_sid_subtlv_flag_values, "none", flags)); break; default: @@ -883,7 +902,7 @@ ospf_print_lsa(netdissect_options *ndo, const struct aslametric *almp; const struct mcla *mcp; const uint8_t *lp; - u_int tlv_type, tlv_length, rla_count, topology; + u_int tlv_type, tlv_length, rla_count, topology, num_tlv; int ospf_print_lshdr_ret; u_int ls_length; const uint8_t *tptr; @@ -1099,7 +1118,17 @@ ospf_print_lsa(netdissect_options *ndo, nd_printjnp(ndo, tptr, tlv_length); break; + case LS_OPAQUE_RI_TLV_SR_ALGO: + num_tlv = tlv_length; + while (num_tlv >= 1) { + ND_PRINT("\n\t %s (%u)", + tok2str(lsa_opaque_ri_tlv_sr_algos, "Unknown", GET_U_1(tptr+tlv_length-num_tlv)), GET_U_1(tptr+tlv_length-num_tlv)); + num_tlv--; + } + break; + case LS_OPAQUE_RI_TLV_SID_LABEL_RANGE: + case LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK: ND_TCHECK_4(tptr); ND_PRINT("\n\t Range size: %u", GET_BE_U_3(tptr)); if (ospf_print_ri_lsa_sid_label_range_tlv(ndo, tptr+4, tlv_length-4) == -1) { @@ -1107,6 +1136,14 @@ ospf_print_lsa(netdissect_options *ndo, } break; + case LS_OPAQUE_RI_TLV_SRMS_PREFERENCE: + if (tlv_length != 4) { + ND_PRINT("\n\t Bogus SRMS Preference TLV length %u != 4", tlv_length); + return(ls_end); + } + ND_PRINT("\n\t SRMS Preference: %u", GET_U_1(tptr)); + break; + default: if (ndo->ndo_vflag <= 1) { if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length)) diff --git a/tests/TESTLIST b/tests/TESTLIST index 12310b04..f03e2250 100644 --- a/tests/TESTLIST +++ b/tests/TESTLIST @@ -134,6 +134,7 @@ ospf-nssa-bitnt ospf-nssa-bitnt.pcap ospf-nssa-bitnt.out -v ospf-ack ospf-ack.pcap ospf-ack.out -v ospf-sr ospf-sr.pcapng ospf-sr-v.out -v ospf-sr2 ospf-sr2.pcapng ospf-sr2-v.out -v +ospf-sr-ri-sid ospf-sr-ri-sid.pcap ospf-sr-ri-sid-v.out -v ospf3_ah-vv OSPFv3_with_AH.pcap ospf3_ah-vv.out -v -v ospf3_auth-vv ospf3_auth.pcapng ospf3_auth-vv.out -v -v ospf3_bc-vv OSPFv3_broadcast_adjacency.pcap ospf3_bc-vv.out -v -v diff --git a/tests/ospf-sr-ri-sid-v.out b/tests/ospf-sr-ri-sid-v.out new file mode 100644 index 00000000..6ec22a7b --- /dev/null +++ b/tests/ospf-sr-ri-sid-v.out @@ -0,0 +1,27 @@ + 1 22:11:10.755260 IP (tos 0x0, ttl 1, id 1, offset 0, flags [none], proto OSPF (89), length 148, bad cksum d831 (->d809)!) + 1.0.0.2 > 224.0.0.5: OSPFv2, LS-Update, length 128 + Router-ID 2.2.2.2, Backbone Area, Authentication Type: none (0), 1 LSA + LSA #1 + Advertising Router 2.2.2.2, seq 0x80000001, age 3600s, length 80 + Area Local Opaque LSA (10), Opaque-Type Router Information LSA (4), Opaque-ID 0 + Options: [none] + SR-Algorithm TLV (8), length: 1, value: + Shortest Path First (0) + SID/Label Range TLV (9), length: 12, value: + Range size: 100 + SID/Label subTLV (1), length: 3, value: + Label: 100 + SID/Label Range TLV (9), length: 12, value: + Range size: 100 + SID/Label subTLV (1), length: 3, value: + Label: 1000 + SR Local Block TLV (14), length: 12, value: + Range size: 4242 + SID/Label subTLV (1), length: 3, value: + Label: 4321 + SR Local Block TLV (14), length: 12, value: + Range size: 4242 + SID/Label subTLV (1), length: 4, value: + SID: 24680 + SRMS Preference TLV (15), length: 4, value: + SRMS Preference: 99 diff --git a/tests/ospf-sr-ri-sid.pcap b/tests/ospf-sr-ri-sid.pcap new file mode 100644 index 00000000..2bcbc627 Binary files /dev/null and b/tests/ospf-sr-ri-sid.pcap differ diff --git a/tests/ospf-sr-v.out b/tests/ospf-sr-v.out index b93298a3..f2d1c549 100644 --- a/tests/ospf-sr-v.out +++ b/tests/ospf-sr-v.out @@ -18,7 +18,7 @@ Extended Prefix Range TLV (2), length: 24, value: IPv4 prefix: 192.168.0.0/32, Range size: 1, Flags [none] Prefix-SID subTLV (2), length: 8, value: - Index: 4, MT-ID: 0, Algorithm: 0, Flags [none] + Index: 4, MT-ID: 0, Algorithm: Shortest Path First (0), Flags [none] LSA #3 Advertising Router 192.168.0.4, seq 0x8000001e, age 1s, length 112 Router LSA (1), LSA-ID: 192.168.0.4 diff --git a/tests/ospf-sr2-v.out b/tests/ospf-sr2-v.out index 43ee93c2..fe83170b 100644 --- a/tests/ospf-sr2-v.out +++ b/tests/ospf-sr2-v.out @@ -18,7 +18,7 @@ Extended Prefix TLV (1), length: 20, value: IPv4 prefix: 192.168.0.0/32, Route Type: Intra-Area, Flags [none] Prefix-SID subTLV (2), length: 8, value: - Index: 0, MT-ID: 0, Algorithm: 0, Flags [none] + Index: 0, MT-ID: 0, Algorithm: Shortest Path First (0), Flags [none] LSA #3 Advertising Router 192.168.0.0, seq 0x80000009, age 1s, length 112 Router LSA (1), LSA-ID: 192.168.0.0