]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-lspping.c
Translate UDP/1700 as RADIUS
[tcpdump] / print-lspping.c
index 6ecac82315e092588b6e5d12744eeb826e50537e..3e48504963e096f70208787e18f62616cc8aa685 100644 (file)
  * Original code by Hannes Gredler ([email protected])
  */
 
-#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <tcpdump-stdinc.h>
+#include <netdissect-stdinc.h>
 
-#include "interface.h"
+#include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
 
  */
 
 struct lspping_common_header {
-    u_int8_t version[2];
-    u_int8_t reserved[2];
-    u_int8_t msg_type;
-    u_int8_t reply_mode;
-    u_int8_t return_code;
-    u_int8_t return_subcode;
-    u_int8_t sender_handle[4];
-    u_int8_t seq_number[4];
-    u_int8_t ts_sent_sec[4];
-    u_int8_t ts_sent_usec[4];
-    u_int8_t ts_rcvd_sec[4];
-    u_int8_t ts_rcvd_usec[4];
+    uint8_t version[2];
+    uint8_t reserved[2];
+    uint8_t msg_type;
+    uint8_t reply_mode;
+    uint8_t return_code;
+    uint8_t return_subcode;
+    uint8_t sender_handle[4];
+    uint8_t seq_number[4];
+    uint8_t ts_sent_sec[4];
+    uint8_t ts_sent_usec[4];
+    uint8_t ts_rcvd_sec[4];
+    uint8_t ts_rcvd_usec[4];
 };
 
 #define LSPPING_VERSION            1
@@ -119,8 +118,8 @@ static const struct tok lspping_return_code_values[] = {
  */
 
 struct lspping_tlv_header {
-    u_int8_t type[2];
-    u_int8_t length[2];
+    uint8_t type[2];
+    uint8_t length[2];
 };
 
 #define        LSPPING_TLV_TARGET_FEC_STACK      1
@@ -186,8 +185,8 @@ static const struct tok lspping_tlvtargetfec_subtlv_values[] = {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t {
-    u_int8_t prefix [4];
-    u_int8_t prefix_len;
+    uint8_t prefix [4];
+    uint8_t prefix_len;
 };
 
 /*
@@ -203,8 +202,8 @@ struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t {
-    u_int8_t prefix [16];
-    u_int8_t prefix_len;
+    uint8_t prefix [16];
+    uint8_t prefix_len;
 };
 
 /*
@@ -218,9 +217,9 @@ struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t {
-    u_int8_t sender_id [4];
-    u_int8_t prefix [4];
-    u_int8_t prefix_len;
+    uint8_t sender_id [4];
+    uint8_t prefix [4];
+    uint8_t prefix_len;
 };
 
 /*
@@ -240,9 +239,9 @@ struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t {
-    u_int8_t sender_id [16];
-    u_int8_t prefix [16];
-    u_int8_t prefix_len;
+    uint8_t sender_id [16];
+    uint8_t prefix [16];
+    uint8_t prefix_len;
 };
 
 /*
@@ -261,13 +260,13 @@ struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t {
-    u_int8_t tunnel_endpoint [4];
-    u_int8_t res[2];
-    u_int8_t tunnel_id[2];
-    u_int8_t extended_tunnel_id[4];
-    u_int8_t tunnel_sender [4];
-    u_int8_t res2[2];
-    u_int8_t lsp_id [2];
+    uint8_t tunnel_endpoint [4];
+    uint8_t res[2];
+    uint8_t tunnel_id[2];
+    uint8_t extended_tunnel_id[4];
+    uint8_t tunnel_sender [4];
+    uint8_t res2[2];
+    uint8_t lsp_id [2];
 };
 
 /*
@@ -295,13 +294,13 @@ struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t {
-    u_int8_t tunnel_endpoint [16];
-    u_int8_t res[2];
-    u_int8_t tunnel_id[2];
-    u_int8_t extended_tunnel_id[16];
-    u_int8_t tunnel_sender [16];
-    u_int8_t res2[2];
-    u_int8_t lsp_id [2];
+    uint8_t tunnel_endpoint [16];
+    uint8_t res[2];
+    uint8_t tunnel_id[2];
+    uint8_t extended_tunnel_id[16];
+    uint8_t tunnel_sender [16];
+    uint8_t res2[2];
+    uint8_t lsp_id [2];
 };
 
 /*
@@ -317,9 +316,9 @@ struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t {
-    u_int8_t rd [8];
-    u_int8_t prefix [4];
-    u_int8_t prefix_len;
+    uint8_t rd [8];
+    uint8_t prefix [4];
+    uint8_t prefix_len;
 };
 
 /*
@@ -338,9 +337,9 @@ struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t {
-    u_int8_t rd [8];
-    u_int8_t prefix [16];
-    u_int8_t prefix_len;
+    uint8_t rd [8];
+    uint8_t prefix [16];
+    uint8_t prefix_len;
 };
 
 /*
@@ -357,10 +356,10 @@ struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t {
  *  0                   1                   2                   3
  */
 struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t {
-    u_int8_t rd [8];
-    u_int8_t sender_ce_id [2];
-    u_int8_t receiver_ce_id [2];
-    u_int8_t encapsulation[2];
+    uint8_t rd [8];
+    uint8_t sender_ce_id [2];
+    uint8_t receiver_ce_id [2];
+    uint8_t encapsulation[2];
 };
 
 /*
@@ -374,9 +373,9 @@ struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_old_t {
-    u_int8_t remote_pe_address [4];
-    u_int8_t vc_id [4];
-    u_int8_t encapsulation[2];
+    uint8_t remote_pe_address [4];
+    uint8_t vc_id [4];
+    uint8_t encapsulation[2];
 };
 
 /*
@@ -392,10 +391,10 @@ struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_old_t {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t {
-    u_int8_t sender_pe_address [4];
-    u_int8_t remote_pe_address [4];
-    u_int8_t vc_id [4];
-    u_int8_t encapsulation[2];
+    uint8_t sender_pe_address [4];
+    uint8_t remote_pe_address [4];
+    uint8_t vc_id [4];
+    uint8_t encapsulation[2];
 };
 
 /*
@@ -424,25 +423,25 @@ struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t {
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 struct lspping_tlv_downstream_map_ipv4_t {
-    u_int8_t mtu [2];
-    u_int8_t address_type;
-    u_int8_t res;
-    u_int8_t downstream_ip[4];
-    u_int8_t downstream_interface[4];
+    uint8_t mtu [2];
+    uint8_t address_type;
+    uint8_t res;
+    uint8_t downstream_ip[4];
+    uint8_t downstream_interface[4];
 };
 
 struct lspping_tlv_downstream_map_ipv6_t {
-    u_int8_t mtu [2];
-    u_int8_t address_type;
-    u_int8_t res;
-    u_int8_t downstream_ip[16];
-    u_int8_t downstream_interface[16];
+    uint8_t mtu [2];
+    uint8_t address_type;
+    uint8_t res;
+    uint8_t downstream_ip[16];
+    uint8_t downstream_interface[16];
 };
 
 struct lspping_tlv_downstream_map_info_t {
-    u_int8_t hash_key_type;
-    u_int8_t depth_limit;
-    u_int8_t multipath_length [2];
+    uint8_t hash_key_type;
+    uint8_t depth_limit;
+    uint8_t multipath_length [2];
 };
 
 #define LSPPING_AFI_IPV4 1
@@ -458,8 +457,8 @@ static const struct tok lspping_tlv_downstream_addr_values[] = {
 
 void
 lspping_print(netdissect_options *ndo,
-              register const u_char *pptr, register u_int len) {
-
+              register const u_char *pptr, register u_int len)
+{
     const struct lspping_common_header *lspping_com_header;
     const struct lspping_tlv_header *lspping_tlv_header;
     const struct lspping_tlv_header *lspping_subtlv_header;
@@ -568,8 +567,7 @@ lspping_print(netdissect_options *ndo,
     while(tlen>(int)sizeof(struct lspping_tlv_header)) {
 
         /* did we capture enough for fully decoding the tlv header ? */
-        if (!ND_TTEST2(*tptr, sizeof(struct lspping_tlv_header)))
-            goto trunc;
+        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);
@@ -595,8 +593,7 @@ lspping_print(netdissect_options *ndo,
         tlv_tlen=lspping_tlv_len; /* header not included -> no adjustment */
 
         /* did we capture enough for fully decoding the tlv ? */
-        if (!ND_TTEST2(*tptr, lspping_tlv_len))
-            goto trunc;
+        ND_TCHECK2(*tptr, lspping_tlv_len);
         tlv_hexdump=FALSE;
 
         switch(lspping_tlv_type) {
@@ -604,8 +601,7 @@ lspping_print(netdissect_options *ndo,
             while(tlv_tlen>(int)sizeof(struct lspping_tlv_header)) {
 
                 /* did we capture enough for fully decoding the subtlv header ? */
-                if (!ND_TTEST2(*tptr, sizeof(struct lspping_tlv_header)))
-                    goto trunc;
+                ND_TCHECK2(*tptr, sizeof(struct lspping_tlv_header));
                 subtlv_hexdump=FALSE;
 
                 lspping_subtlv_header = (const struct lspping_tlv_header *)tlv_tptr;
@@ -633,7 +629,6 @@ lspping_print(netdissect_options *ndo,
                            subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix_len));
                     break;
 
-#ifdef INET6
                 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6:
                     subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6 = \
                         (const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *)subtlv_tptr;
@@ -641,7 +636,6 @@ lspping_print(netdissect_options *ndo,
                            ip6addr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix),
                            subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix_len));
                     break;
-#endif
 
                 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4:
                     subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4 = \
@@ -652,7 +646,6 @@ lspping_print(netdissect_options *ndo,
                            ipaddr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->sender_id)));
                     break;
 
-#ifdef INET6
                 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6:
                     subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6 = \
                         (const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *)subtlv_tptr;
@@ -661,7 +654,6 @@ lspping_print(netdissect_options *ndo,
                            subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix_len,
                            ip6addr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->sender_id)));
                     break;
-#endif
 
                 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4:
                     subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4 = \
@@ -675,7 +667,6 @@ lspping_print(netdissect_options *ndo,
                            ipaddr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->extended_tunnel_id)));
                     break;
 
-#ifdef INET6
                 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6:
                     subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6 = \
                         (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *)subtlv_tptr;
@@ -687,7 +678,6 @@ lspping_print(netdissect_options *ndo,
                            EXTRACT_16BITS(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;
-#endif
 
                 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4:
                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4 = \
@@ -698,7 +688,6 @@ lspping_print(netdissect_options *ndo,
                            subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix_len));
                     break;
 
-#ifdef INET6
                 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6:
                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6 = \
                         (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *)subtlv_tptr;
@@ -707,7 +696,6 @@ lspping_print(netdissect_options *ndo,
                            ip6addr_string(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix),
                            subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix_len));
                     break;
-#endif
 
                 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT:
                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt = \
@@ -771,7 +759,7 @@ lspping_print(netdissect_options *ndo,
 
         case LSPPING_TLV_DOWNSTREAM_MAPPING:
             /* that strange thing with the downstream map TLV is that until now
-             * we do not know if its IPv4 or IPv6 , after we found the adress-type
+             * we do not know if its IPv4 or IPv6 , after we found the address-type
              * lets recast the tlv_tptr and move on */
 
             tlv_ptr.lspping_tlv_downstream_map_ipv4= \
@@ -795,7 +783,6 @@ lspping_print(netdissect_options *ndo,
                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
                 break;
-#ifdef INET6
              case LSPPING_AFI_IPV6:
                 ND_PRINT((ndo, "\n\t    Downstream IP: %s" \
                        "\n\t    Downstream Interface IP: %s",
@@ -804,7 +791,6 @@ lspping_print(netdissect_options *ndo,
                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv6_t);
                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv6_t);
                 break;
-#endif
             case LSPPING_AFI_UNMB:
                 ND_PRINT((ndo, "\n\t    Downstream IP: %s" \
                        "\n\t    Downstream Interface Index: 0x%08x",
@@ -837,17 +823,15 @@ lspping_print(netdissect_options *ndo,
 
         case LSPPING_TLV_BFD_DISCRIMINATOR:
             tptr += sizeof(struct lspping_tlv_header);
-            if (!ND_TTEST2(*tptr, LSPPING_TLV_BFD_DISCRIMINATOR_LEN))
-                goto trunc;
+            ND_TCHECK2(*tptr, LSPPING_TLV_BFD_DISCRIMINATOR_LEN);
             ND_PRINT((ndo, "\n\t    BFD Discriminator 0x%08x", EXTRACT_32BITS(tptr)));
             break;
 
         case  LSPPING_TLV_VENDOR_ENTERPRISE:
         {
-            u_int32_t vendor_id;
+            uint32_t vendor_id;
 
-            if (!ND_TTEST2(*tptr, LSPPING_TLV_VENDOR_ENTERPRISE_LEN))
-                goto trunc;
+            ND_TCHECK2(*tptr, LSPPING_TLV_VENDOR_ENTERPRISE_LEN);
             vendor_id = EXTRACT_32BITS(tlv_tptr);
             ND_PRINT((ndo, "\n\t    Vendor: %s (0x%04x)",
                    tok2str(smi_values, "Unknown", vendor_id),