]> The Tcpdump Group git mirrors - tcpdump/commitdiff
OSPF: Add SR-Algo, Local Block, and SRMS Preference TLV parsers.
authorRachid Tak Tak <[email protected]>
Fri, 10 Nov 2023 11:43:06 +0000 (03:43 -0800)
committerfxlb <[email protected]>
Tue, 6 Feb 2024 09:46:15 +0000 (09:46 +0000)
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.

CREDITS
ospf.h
print-ospf.c
tests/TESTLIST
tests/ospf-sr-ri-sid-v.out [new file with mode: 0644]
tests/ospf-sr-ri-sid.pcap [new file with mode: 0644]
tests/ospf-sr-v.out
tests/ospf-sr2-v.out

diff --git a/CREDITS b/CREDITS
index b6862ccba5a8b0bd63cf90053753a9927afcdbe5..ab5b318443739694cca7c1515b1e4b3e0308a0a9 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -265,6 +265,7 @@ Additional people who have contributed patches (in alphabetical order):
     Phil Wood                     <cpw at lanl dot gov>
     Pier Carlo Chiodi             <pierky at pierky dot com>
     Quentin Armitage              <quentin at armitage dot org dot uk>
+    Rachid Tak Tak                <rachidtt at arista dot com>
     Rafal Maszkowski              <rzm at icm dot edu dot pl>
     Randy Sofia                   <rsofia at users dot sourceforge dot net>
     Raphael Raimbault             <raphael dot raimbault at netasq dot com>
diff --git a/ospf.h b/ospf.h
index 24ff2e98405611d18ec80f3893072fdbab0d402c..9b274fafc032285b250fb47e92078afa073914eb 100644 (file)
--- 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 */
 #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 */
index d0cf573c0676a5fb133ce13fa45f2af93304e103..7191087b08a970da962ad1f1f420cd65ac841b64 100644 (file)
@@ -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))
index 12310b048623d5a4ef01ae44b46ea5b0d1df1f0a..f03e2250fcdeaf4aee1d39570e90c99cc312a9ba 100644 (file)
@@ -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 (file)
index 0000000..6ec22a7
--- /dev/null
@@ -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 (file)
index 0000000..2bcbc62
Binary files /dev/null and b/tests/ospf-sr-ri-sid.pcap differ
index b93298a3b31eb8cff2fc1feaf2ca3e365f3244ab..f2d1c549a39d423092ed2a7b9de1eab0906b0b87 100644 (file)
@@ -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
index 43ee93c2bb4b6fa01b1960f8debd3341caca716a..fe83170b258e95e9090ccc5f7c256dc6e848c138 100644 (file)
@@ -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