]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ospf.c
CHANGES: Add/move change(s) backported to 4.99
[tcpdump] / print-ospf.c
index a0474a39157b33e3c781c25ee008fd3c012c9aae..eae546d9c296a216b3553d81e003ca581f0a8168 100644 (file)
@@ -23,9 +23,7 @@
 
 /* \summary: Open Shortest Path First (OSPF) printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
 
 
 static const struct tok ospf_option_values[] = {
-        { OSPF_OPTION_T,       "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
+       { OSPF_OPTION_MT,       "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
        { OSPF_OPTION_E,        "External" },
        { OSPF_OPTION_MC,       "Multicast" },
        { OSPF_OPTION_NP,       "NSSA" },
-        { OSPF_OPTION_L,        "LLS" },
+       { OSPF_OPTION_L,        "LLS" },
        { OSPF_OPTION_DC,       "Demand Circuit" },
        { OSPF_OPTION_O,        "Opaque" },
        { OSPF_OPTION_DN,       "Up/Down" },
@@ -59,8 +57,10 @@ static const struct tok ospf_authtype_values[] = {
 static const struct tok ospf_rla_flag_values[] = {
        { RLA_FLAG_B,           "ABR" },
        { RLA_FLAG_E,           "ASBR" },
-       { RLA_FLAG_W1,          "Virtual" },
-       { RLA_FLAG_W2,          "W2" },
+       { RLA_FLAG_V,           "Virtual" },
+       { RLA_FLAG_W,           "Wildcard" },
+       { RLA_FLAG_NT,          "Nt" },
+       { RLA_FLAG_H,           "Host" },
        { 0,                    NULL }
 };
 
@@ -491,7 +491,6 @@ ospf_te_lsa_print(netdissect_options *ndo,
                 ND_PRINT("\n\t    TLV length %u < 4", tlv_length);
                 return -1;
             }
-            ND_TCHECK_4(tptr);
             ND_PRINT(", %s", GET_IPADDR_STRING(tptr));
             break;
 
@@ -534,11 +533,11 @@ ospf_print_lshdr(netdissect_options *ndo,
                     sizeof(struct lsa_hdr));
                 return(-1);
         }
-        ND_PRINT("\n\t  Advertising Router %s, seq 0x%08x, age %us, length %u",
+        ND_PRINT("\n\t  Advertising Router %s, seq 0x%08x, age %us, length %zu",
                   GET_IPADDR_STRING(lshp->ls_router),
                   GET_BE_U_4(lshp->ls_seq),
                   GET_BE_U_2(lshp->ls_age),
-                  ls_length - (u_int)sizeof(struct lsa_hdr));
+                  ls_length - sizeof(struct lsa_hdr));
         ls_type = GET_U_1(lshp->ls_type);
         switch (ls_type) {
         /* the LSA header for opaque LSAs was slightly changed */
@@ -583,7 +582,7 @@ static const struct tok ospf_topology_values[] = {
 /*
  * Print all the per-topology metrics.
  */
-static int
+static void
 ospf_print_tos_metrics(netdissect_options *ndo,
                        const union un_tos *tos)
 {
@@ -598,7 +597,6 @@ ospf_print_tos_metrics(netdissect_options *ndo,
      * All but the first metric contain a valid topology id.
      */
     while (toscount != 0) {
-        ND_TCHECK_SIZE(tos);
         tos_type = GET_U_1(tos->metrics.tos_type);
         ND_PRINT("\n\t\ttopology %s (%u), metric %u",
                tok2str(ospf_topology_values, "Unknown",
@@ -609,9 +607,6 @@ ospf_print_tos_metrics(netdissect_options *ndo,
         tos++;
         toscount--;
     }
-    return 0;
-trunc:
-    return 1;
 }
 
 /*
@@ -689,8 +684,7 @@ ospf_print_lsa(netdissect_options *ndo,
                                return (ls_end);
                        }
 
-                       if (ospf_print_tos_metrics(ndo, &rlp->un_tos))
-                               goto trunc;
+                       ospf_print_tos_metrics(ndo, &rlp->un_tos);
 
                        rlp = (const struct rlalink *)((const u_char *)(rlp + 1) +
                            (GET_U_1(rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
@@ -698,13 +692,11 @@ ospf_print_lsa(netdissect_options *ndo,
                break;
 
        case LS_TYPE_NETWORK:
-               ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
                ND_PRINT("\n\t    Mask %s\n\t    Connected Routers:",
                    GET_IPADDR_STRING(lsap->lsa_un.un_nla.nla_mask));
                ap = lsap->lsa_un.un_nla.nla_router;
                while ((const u_char *)ap < ls_end) {
-                       ND_TCHECK_SIZE(ap);
-                       ND_PRINT("\n\t      %s", GET_IPADDR_STRING(*ap));
+                       ND_PRINT("\n\t      %s", GET_IPADDR_STRING(ap));
                        ++ap;
                }
                break;
@@ -766,11 +758,9 @@ ospf_print_lsa(netdissect_options *ndo,
                        else
                                ND_PRINT(" %u", (ul & ASLA_MASK_METRIC));
 
-                       ND_TCHECK_4(almp->asla_forward);
                        if (GET_IPV4_TO_NETWORK_ORDER(almp->asla_forward) != 0) {
                                ND_PRINT(", forward %s", GET_IPADDR_STRING(almp->asla_forward));
                        }
-                       ND_TCHECK_4(almp->asla_tag);
                        if (GET_IPV4_TO_NETWORK_ORDER(almp->asla_tag) != 0) {
                                ND_PRINT(", tag %s", GET_IPADDR_STRING(almp->asla_tag));
                        }
@@ -782,7 +772,6 @@ ospf_print_lsa(netdissect_options *ndo,
                /* Multicast extensions as of 23 July 1991 */
                mcp = lsap->lsa_un.un_mcla;
                while ((const u_char *)mcp < ls_end) {
-                       ND_TCHECK_4(mcp->mcla_vid);
                        switch (GET_BE_U_4(mcp->mcla_vtype)) {
 
                        case MCLA_VERTEX_ROUTER:
@@ -853,6 +842,11 @@ ospf_print_lsa(netdissect_options *ndo,
                         break;
 
                     }
+
+                    /* in OSPF everything has to be 32-bit aligned, including TLVs */
+                    if (tlv_length % 4) {
+                        tlv_length += (4 - (tlv_length % 4));
+                    }
                     tptr+=tlv_length;
                     ls_length_remaining-=tlv_length;
                 }
@@ -894,7 +888,7 @@ trunc:
        return (NULL);
 }
 
-static int
+static void
 ospf_decode_lls(netdissect_options *ndo,
                 const struct ospfhdr *op, u_int length)
 {
@@ -908,16 +902,16 @@ ospf_decode_lls(netdissect_options *ndo,
 
     case OSPF_TYPE_HELLO:
         if (!(GET_U_1(op->ospf_hello.hello_options) & OSPF_OPTION_L))
-            return (0);
+            return;
         break;
 
     case OSPF_TYPE_DD:
         if (!(GET_U_1(op->ospf_db.db_options) & OSPF_OPTION_L))
-            return (0);
+            return;
         break;
 
     default:
-        return (0);
+        return;
     }
 
     /* dig deeper if LLS data is available; see RFC4813 */
@@ -926,12 +920,12 @@ ospf_decode_lls(netdissect_options *ndo,
     dataend = (const u_char *)op + length;
 
     if (GET_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) {
-        dptr = dptr + op->ospf_authdata[3];
-        length2 += op->ospf_authdata[3];
+        dptr = dptr + GET_U_1(op->ospf_authdata + 3);
+        length2 += GET_U_1(op->ospf_authdata + 3);
     }
     if (length2 >= length) {
         ND_PRINT("\n\t[LLS truncated]");
-        return (1);
+        return;
     }
     ND_PRINT("\n\t  LLS: checksum: 0x%04x", (u_int) GET_BE_U_2(dptr));
 
@@ -973,8 +967,6 @@ ospf_decode_lls(netdissect_options *ndo,
 
         dptr += lls_len;
     }
-
-    return (0);
 }
 
 static int
@@ -999,12 +991,10 @@ ospf_decode_v2(netdissect_options *ndo,
                          GET_IPADDR_STRING(op->ospf_hello.hello_mask),
                          GET_U_1(op->ospf_hello.hello_priority));
 
-               ND_TCHECK_4(op->ospf_hello.hello_dr);
                if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_dr) != 0)
                        ND_PRINT("\n\t  Designated Router %s",
                            GET_IPADDR_STRING(op->ospf_hello.hello_dr));
 
-               ND_TCHECK_4(op->ospf_hello.hello_bdr);
                if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_bdr) != 0)
                        ND_PRINT(", Backup Designated Router %s",
                                  GET_IPADDR_STRING(op->ospf_hello.hello_bdr));
@@ -1013,8 +1003,7 @@ ospf_decode_v2(netdissect_options *ndo,
                if ((const u_char *)ap < dataend)
                        ND_PRINT("\n\t  Neighbor List:");
                while ((const u_char *)ap < dataend) {
-                       ND_TCHECK_SIZE(ap);
-                       ND_PRINT("\n\t    %s", GET_IPADDR_STRING(*ap));
+                       ND_PRINT("\n\t    %s", GET_IPADDR_STRING(ap));
                        ++ap;
                }
                break;  /* HELLO */
@@ -1081,7 +1070,8 @@ ospf_decode_v2(netdissect_options *ndo,
 
        case OSPF_TYPE_LS_ACK:
                 lshp = op->ospf_lsa.lsa_lshdr;
-                while (ospf_print_lshdr(ndo, lshp) != -1) {
+                while ((const u_char *)lshp < dataend) {
+                    ospf_print_lshdr(ndo, lshp);
                     ++lshp;
                 }
                 break;
@@ -1134,10 +1124,8 @@ ospf_print(netdissect_options *ndo,
                dataend = bp + length;
        }
 
-       ND_TCHECK_4(op->ospf_routerid);
        ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op->ospf_routerid));
 
-       ND_TCHECK_4(op->ospf_areaid);
        if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_areaid) != 0)
                ND_PRINT(", Area %s", GET_IPADDR_STRING(op->ospf_areaid));
        else
@@ -1158,13 +1146,13 @@ ospf_print(netdissect_options *ndo,
 
                case OSPF_AUTH_SIMPLE:
                        ND_PRINT("\n\tSimple text password: ");
-                       (void)nd_printzp(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN, NULL);
+                       nd_printjnp(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN);
                        break;
 
                case OSPF_AUTH_MD5:
                        ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
-                                 *((op->ospf_authdata) + 2),
-                                 *((op->ospf_authdata) + 3),
+                                 GET_U_1(op->ospf_authdata + 2),
+                                 GET_U_1(op->ospf_authdata + 3),
                                  GET_BE_U_4((op->ospf_authdata) + 4));
                        break;
 
@@ -1179,10 +1167,8 @@ ospf_print(netdissect_options *ndo,
                /* ospf version 2 */
                if (ospf_decode_v2(ndo, op, dataend))
                        goto trunc;
-               if (length > GET_BE_U_2(op->ospf_len)) {
-                       if (ospf_decode_lls(ndo, op, length))
-                               goto trunc;
-               }
+               if (length > GET_BE_U_2(op->ospf_len))
+                       ospf_decode_lls(ndo, op, length);
                break;
 
        default:
@@ -1192,5 +1178,5 @@ ospf_print(netdissect_options *ndo,
 
        return;
 trunc:
-       nd_print_trunc(ndo);
+       nd_trunc_longjmp(ndo);
 }