]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-lspping.c
Use more the EXTRACT_U_1() macro (40/n)
[tcpdump] / print-lspping.c
index 7e629dbcd60226c51dadf74e057f8b1993c99450..89edc1dd8f8e940353b3e40769e5ce72c7c08e54 100644 (file)
@@ -10,7 +10,7 @@
  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  * FOR A PARTICULAR PURPOSE.
  *
- * Original code by Hannes Gredler (hannes@juniper.net)
+ * Original code by Hannes Gredler (hannes@gredler.at)
  */
 
 /* \summary: MPLS LSP PING printer */
@@ -104,6 +104,7 @@ static const struct tok lspping_return_code_values[] = {
     { 11, "No label entry at stack-depth"},
     { 12, "Protocol not associated with interface at FEC stack depth"},
     { 13, "Premature termination of ping due to label stack shrinking to a single label"},
+    { 0,  NULL},
 };
 
 
@@ -522,25 +523,25 @@ lspping_print(netdissect_options *ndo,
 
     tptr=pptr;
     lspping_com_header = (const struct lspping_common_header *)pptr;
-    if (len < sizeof(const struct lspping_common_header))
+    if (len < sizeof(struct lspping_common_header))
         goto tooshort;
     ND_TCHECK(*lspping_com_header);
 
     /*
      * Sanity checking of the header.
      */
-    if (EXTRACT_16BITS(&lspping_com_header->version[0]) != LSPPING_VERSION) {
+    if (EXTRACT_BE_U_2(&lspping_com_header->version[0]) != LSPPING_VERSION) {
        ND_PRINT((ndo, "LSP-PING version %u packet not supported",
-               EXTRACT_16BITS(&lspping_com_header->version[0])));
+               EXTRACT_BE_U_2(&lspping_com_header->version[0])));
        return;
     }
 
     /* in non-verbose mode just lets print the basic Message Type*/
     if (ndo->ndo_vflag < 1) {
         ND_PRINT((ndo, "LSP-PINGv%u, %s, seq %u, length: %u",
-               EXTRACT_16BITS(&lspping_com_header->version[0]),
+               EXTRACT_BE_U_2(&lspping_com_header->version[0]),
                tok2str(lspping_msg_type_values, "unknown (%u)",lspping_com_header->msg_type),
-               EXTRACT_32BITS(lspping_com_header->seq_number),
+               EXTRACT_BE_U_4(lspping_com_header->seq_number),
                len));
         return;
     }
@@ -550,7 +551,7 @@ lspping_print(netdissect_options *ndo,
     tlen=len;
 
     ND_PRINT((ndo, "\n\tLSP-PINGv%u, msg-type: %s (%u), length: %u\n\t  reply-mode: %s (%u)",
-           EXTRACT_16BITS(&lspping_com_header->version[0]),
+           EXTRACT_BE_U_2(&lspping_com_header->version[0]),
            tok2str(lspping_msg_type_values, "unknown",lspping_com_header->msg_type),
            lspping_com_header->msg_type,
            len,
@@ -579,24 +580,24 @@ lspping_print(netdissect_options *ndo,
                lspping_com_header->return_subcode));
 
     ND_PRINT((ndo, "\n\t  Sender Handle: 0x%08x, Sequence: %u",
-           EXTRACT_32BITS(lspping_com_header->sender_handle),
-           EXTRACT_32BITS(lspping_com_header->seq_number)));
+           EXTRACT_BE_U_4(lspping_com_header->sender_handle),
+           EXTRACT_BE_U_4(lspping_com_header->seq_number)));
 
-    timestamp.tv_sec=EXTRACT_32BITS(lspping_com_header->ts_sent_sec);
-    timestamp.tv_usec=EXTRACT_32BITS(lspping_com_header->ts_sent_usec);
+    timestamp.tv_sec=EXTRACT_BE_U_4(lspping_com_header->ts_sent_sec);
+    timestamp.tv_usec=EXTRACT_BE_U_4(lspping_com_header->ts_sent_usec);
     ND_PRINT((ndo, "\n\t  Sender Timestamp: "));
     ts_print(ndo, &timestamp);
 
-    timestamp.tv_sec=EXTRACT_32BITS(lspping_com_header->ts_rcvd_sec);
-    timestamp.tv_usec=EXTRACT_32BITS(lspping_com_header->ts_rcvd_usec);
+    timestamp.tv_sec=EXTRACT_BE_U_4(lspping_com_header->ts_rcvd_sec);
+    timestamp.tv_usec=EXTRACT_BE_U_4(lspping_com_header->ts_rcvd_usec);
     ND_PRINT((ndo, "Receiver Timestamp: "));
     if ((timestamp.tv_sec != 0) && (timestamp.tv_usec != 0))
         ts_print(ndo, &timestamp);
     else
         ND_PRINT((ndo, "no timestamp"));
 
-    tptr+=sizeof(const struct lspping_common_header);
-    tlen-=sizeof(const struct lspping_common_header);
+    tptr+=sizeof(struct lspping_common_header);
+    tlen-=sizeof(struct lspping_common_header);
 
     while (tlen != 0) {
         /* Does the TLV go past the end of the packet? */
@@ -607,8 +608,8 @@ lspping_print(netdissect_options *ndo,
         ND_TCHECK2(*tptr, sizeof(struct lspping_tlv_header));
 
         lspping_tlv_header = (const struct lspping_tlv_header *)tptr;
-        lspping_tlv_type=EXTRACT_16BITS(lspping_tlv_header->type);
-        lspping_tlv_len=EXTRACT_16BITS(lspping_tlv_header->length);
+        lspping_tlv_type=EXTRACT_BE_U_2(lspping_tlv_header->type);
+        lspping_tlv_len=EXTRACT_BE_U_2(lspping_tlv_header->length);
 
         ND_PRINT((ndo, "\n\t  %s TLV (%u), length: %u",
                tok2str(lspping_tlv_values,
@@ -637,24 +638,26 @@ lspping_print(netdissect_options *ndo,
         switch(lspping_tlv_type) {
         case LSPPING_TLV_TARGET_FEC_STACK:
             while (tlv_tlen != 0) {
-                /* Does the subTLV go past the end of the TLV? */
+                /* Does the subTLV header go past the end of the TLV? */
                 if (tlv_tlen < sizeof(struct lspping_tlv_header)) {
-                    subtlv_hexdump = TRUE;
-                    goto subtlv_too_short;
+                    ND_PRINT((ndo, "\n\t      TLV is too short"));
+                    tlv_hexdump = TRUE;
+                    goto tlv_tooshort;
                 }
                 /* did we capture enough for fully decoding the subtlv header ? */
                 ND_TCHECK2(*tlv_tptr, sizeof(struct lspping_tlv_header));
                 subtlv_hexdump=FALSE;
 
                 lspping_subtlv_header = (const struct lspping_tlv_header *)tlv_tptr;
-                lspping_subtlv_type=EXTRACT_16BITS(lspping_subtlv_header->type);
-                lspping_subtlv_len=EXTRACT_16BITS(lspping_subtlv_header->length);
+                lspping_subtlv_type=EXTRACT_BE_U_2(lspping_subtlv_header->type);
+                lspping_subtlv_len=EXTRACT_BE_U_2(lspping_subtlv_header->length);
                 subtlv_tptr=tlv_tptr+sizeof(struct lspping_tlv_header);
 
                 /* Does the subTLV go past the end of the TLV? */
                 if (tlv_tlen < lspping_subtlv_len+sizeof(struct lspping_tlv_header)) {
-                    subtlv_hexdump = TRUE;
-                    goto subtlv_too_short;
+                    ND_PRINT((ndo, "\n\t      TLV is too short"));
+                    tlv_hexdump = TRUE;
+                    goto tlv_tooshort;
                 }
 
                 /* Did we capture enough for fully decoding the subTLV? */
@@ -737,8 +740,8 @@ lspping_print(netdissect_options *ndo,
                                "\n\t      tunnel-id 0x%04x, extended tunnel-id %s",
                                ipaddr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_endpoint),
                                ipaddr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_sender),
-                               EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->lsp_id),
-                               EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_id),
+                               EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->lsp_id),
+                               EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_id),
                                ipaddr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->extended_tunnel_id)));
                     }
                     break;
@@ -755,8 +758,8 @@ lspping_print(netdissect_options *ndo,
                                "\n\t      tunnel-id 0x%04x, extended tunnel-id %s",
                                ip6addr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_endpoint),
                                ip6addr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_sender),
-                               EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->lsp_id),
-                               EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_id),
+                               EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->lsp_id),
+                               EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_id),
                                ip6addr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->extended_tunnel_id)));
                     }
                     break;
@@ -802,12 +805,12 @@ lspping_print(netdissect_options *ndo,
                         ND_PRINT((ndo, "\n\t      RD: %s, Sender VE ID: %u, Receiver VE ID: %u" \
                                "\n\t      Encapsulation Type: %s (%u)",
                                bgp_vpn_rd_print(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->rd),
-                               EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->sender_ve_id),
-                               EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->receiver_ve_id),
+                               EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->sender_ve_id),
+                               EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->receiver_ve_id),
                                tok2str(mpls_pw_types_values,
                                        "unknown",
-                                       EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation)),
-                               EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation)));
+                                       EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation)),
+                               EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation)));
                     }
                     break;
 
@@ -823,11 +826,11 @@ lspping_print(netdissect_options *ndo,
                         ND_PRINT((ndo, "\n\t      Remote PE: %s" \
                                "\n\t      PW ID: 0x%08x, PW Type: %s (%u)",
                                ipaddr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->remote_pe_address),
-                               EXTRACT_32BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_id),
+                               EXTRACT_BE_U_4(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_id),
                                tok2str(mpls_pw_types_values,
                                        "unknown",
-                                       EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_type)),
-                               EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_type)));
+                                       EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_type)),
+                               EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_type)));
                     }
                     break;
 
@@ -843,11 +846,11 @@ lspping_print(netdissect_options *ndo,
                                "\n\t      PW ID: 0x%08x, PW Type: %s (%u)",
                                ipaddr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->sender_pe_address),
                                ipaddr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->remote_pe_address),
-                               EXTRACT_32BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_id),
+                               EXTRACT_BE_U_4(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_id),
                                tok2str(mpls_pw_types_values,
                                        "unknown",
-                                       EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_type)),
-                               EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_type)));
+                                       EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_type)),
+                               EXTRACT_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_type)));
                     }
                     break;
 
@@ -856,7 +859,6 @@ lspping_print(netdissect_options *ndo,
                     break;
                 }
                 /* do we want to see an additionally subtlv hexdump ? */
-            subtlv_too_short:
                 if (ndo->ndo_vflag > 1 || subtlv_hexdump==TRUE)
                     print_unknown_data(ndo, tlv_tptr+sizeof(struct lspping_tlv_header), \
                                        "\n\t      ",
@@ -880,7 +882,8 @@ lspping_print(netdissect_options *ndo,
             /* Does the header go past the end of the TLV? */
             if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_t)) {
                 ND_PRINT((ndo, "\n\t      TLV is too short"));
-                goto map_tlv_tooshort;
+                tlv_hexdump = TRUE;
+                goto tlv_tooshort;
             }
             /* Did we capture enough to get the address family? */
             ND_TCHECK2(*tlv_tptr, sizeof(struct lspping_tlv_downstream_map_t));
@@ -893,7 +896,7 @@ lspping_print(netdissect_options *ndo,
              * we find the address-type, we recast the tlv_tptr and move on. */
 
             ND_PRINT((ndo, "\n\t    MTU: %u, Address-Type: %s (%u)",
-                   EXTRACT_16BITS(tlv_ptr.lspping_tlv_downstream_map->mtu),
+                   EXTRACT_BE_U_2(tlv_ptr.lspping_tlv_downstream_map->mtu),
                    tok2str(lspping_tlv_downstream_addr_values,
                            "unknown",
                            tlv_ptr.lspping_tlv_downstream_map->address_type),
@@ -905,7 +908,8 @@ lspping_print(netdissect_options *ndo,
                 /* Does the data go past the end of the TLV? */
                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv4_t)) {
                     ND_PRINT((ndo, "\n\t      TLV is too short"));
-                    goto map_tlv_tooshort;
+                    tlv_hexdump = TRUE;
+                    goto tlv_tooshort;
                 }
                 /* Did we capture enough for this part of the TLV? */
                 ND_TCHECK2(*tlv_tptr, sizeof(struct lspping_tlv_downstream_map_ipv4_t));
@@ -923,7 +927,8 @@ lspping_print(netdissect_options *ndo,
                 /* Does the data go past the end of the TLV? */
                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t)) {
                     ND_PRINT((ndo, "\n\t      TLV is too short"));
-                    goto map_tlv_tooshort;
+                    tlv_hexdump = TRUE;
+                    goto tlv_tooshort;
                 }
                 /* Did we capture enough for this part of the TLV? */
                 ND_TCHECK2(*tlv_tptr, sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t));
@@ -933,7 +938,7 @@ lspping_print(netdissect_options *ndo,
                 ND_PRINT((ndo, "\n\t    Downstream IP: %s" \
                        "\n\t    Downstream Interface Index: 0x%08x",
                        ipaddr_string(ndo, tlv_ptr.lspping_tlv_downstream_map_ipv4_unmb->downstream_ip),
-                       EXTRACT_32BITS(tlv_ptr.lspping_tlv_downstream_map_ipv4_unmb->downstream_interface)));
+                       EXTRACT_BE_U_4(tlv_ptr.lspping_tlv_downstream_map_ipv4_unmb->downstream_interface)));
                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t);
                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t);
                 break;
@@ -941,7 +946,8 @@ lspping_print(netdissect_options *ndo,
                 /* Does the data go past the end of the TLV? */
                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv6_t)) {
                     ND_PRINT((ndo, "\n\t      TLV is too short"));
-                    goto map_tlv_tooshort;
+                    tlv_hexdump = TRUE;
+                    goto tlv_tooshort;
                 }
                 /* Did we capture enough for this part of the TLV? */
                 ND_TCHECK2(*tlv_tptr, sizeof(struct lspping_tlv_downstream_map_ipv6_t));
@@ -959,7 +965,8 @@ lspping_print(netdissect_options *ndo,
                 /* Does the data go past the end of the TLV? */
                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t)) {
                     ND_PRINT((ndo, "\n\t      TLV is too short"));
-                    goto map_tlv_tooshort;
+                    tlv_hexdump = TRUE;
+                    goto tlv_tooshort;
                 }
                 /* Did we capture enough for this part of the TLV? */
                 ND_TCHECK2(*tlv_tptr, sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t));
@@ -969,7 +976,7 @@ lspping_print(netdissect_options *ndo,
                 ND_PRINT((ndo, "\n\t    Downstream IP: %s" \
                        "\n\t    Downstream Interface Index: 0x%08x",
                        ip6addr_string(ndo, tlv_ptr.lspping_tlv_downstream_map_ipv6_unmb->downstream_ip),
-                       EXTRACT_32BITS(tlv_ptr.lspping_tlv_downstream_map_ipv6_unmb->downstream_interface)));
+                       EXTRACT_BE_U_4(tlv_ptr.lspping_tlv_downstream_map_ipv6_unmb->downstream_interface)));
                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t);
                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t);
                 break;
@@ -982,7 +989,8 @@ lspping_print(netdissect_options *ndo,
             /* Does the data go past the end of the TLV? */
             if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_info_t)) {
                 ND_PRINT((ndo, "\n\t      TLV is too short"));
-                goto map_tlv_tooshort;
+                tlv_hexdump = TRUE;
+                goto tlv_tooshort;
             }
             /* Did we capture enough for this part of the TLV? */
             ND_TCHECK2(*tlv_tptr, sizeof(struct lspping_tlv_downstream_map_info_t));
@@ -997,7 +1005,6 @@ lspping_print(netdissect_options *ndo,
 
             /* FIXME print downstream labels */
 
-        map_tlv_tooshort:
             tlv_hexdump=TRUE; /* dump the TLV until code complete */
 
             break;
@@ -1005,9 +1012,11 @@ lspping_print(netdissect_options *ndo,
         case LSPPING_TLV_BFD_DISCRIMINATOR:
             if (tlv_tlen < LSPPING_TLV_BFD_DISCRIMINATOR_LEN) {
                 ND_PRINT((ndo, "\n\t      TLV is too short"));
+                tlv_hexdump = TRUE;
+                goto tlv_tooshort;
             } else {
                 ND_TCHECK2(*tptr, LSPPING_TLV_BFD_DISCRIMINATOR_LEN);
-                ND_PRINT((ndo, "\n\t    BFD Discriminator 0x%08x", EXTRACT_32BITS(tptr)));
+                ND_PRINT((ndo, "\n\t    BFD Discriminator 0x%08x", EXTRACT_BE_U_4(tptr)));
             }
             break;
 
@@ -1017,9 +1026,11 @@ lspping_print(netdissect_options *ndo,
 
             if (tlv_tlen < LSPPING_TLV_VENDOR_ENTERPRISE_LEN) {
                 ND_PRINT((ndo, "\n\t      TLV is too short"));
+                tlv_hexdump = TRUE;
+                goto tlv_tooshort;
             } else {
                 ND_TCHECK2(*tptr, LSPPING_TLV_VENDOR_ENTERPRISE_LEN);
-                vendor_id = EXTRACT_32BITS(tlv_tptr);
+                vendor_id = EXTRACT_BE_U_4(tlv_tptr);
                 ND_PRINT((ndo, "\n\t    Vendor: %s (0x%04x)",
                        tok2str(smi_values, "Unknown", vendor_id),
                        vendor_id));
@@ -1041,6 +1052,7 @@ lspping_print(netdissect_options *ndo,
             break;
         }
         /* do we want to see an additionally tlv hexdump ? */
+    tlv_tooshort:
         if (ndo->ndo_vflag > 1 || tlv_hexdump==TRUE)
             print_unknown_data(ndo, tptr+sizeof(struct lspping_tlv_header), "\n\t    ",
                                lspping_tlv_len);