]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-pim.c
RADIUS: Rename a test with an invalid length
[tcpdump] / print-pim.c
index 4eacd04df35eed60c0e204a0e7ca1b0c1d18977f..2a33c1ffb6796eeb390eb93d2457cab198d16593 100644 (file)
@@ -34,6 +34,7 @@
 #include "ip.h"
 #include "ip6.h"
 #include "ipproto.h"
+#include "af.h"
 
 #define PIMV1_TYPE_QUERY           0
 #define PIMV1_TYPE_REGISTER        1
@@ -137,7 +138,7 @@ static const struct tok pimv2_df_election_flag_values[] = {
 
 /*
  * XXX: We consider a case where IPv6 is not ready yet for portability,
- * but PIM dependent defintions should be independent of IPv6...
+ * but PIM dependent definitions should be independent of IPv6...
  */
 
 struct pim {
@@ -189,7 +190,6 @@ pimv1_join_prune_print(netdissect_options *ndo,
 
        if (len < sizeof(nd_ipv4))
                goto trunc;
-       ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
        if (ndo->ndo_vflag > 1)
                ND_PRINT("\n");
        ND_PRINT(" Upstream Nbr: %s", GET_IPADDR_STRING(bp));
@@ -197,7 +197,6 @@ pimv1_join_prune_print(netdissect_options *ndo,
        len -= 4;
        if (len < 4)
                goto trunc;
-       ND_TCHECK_2(bp + 2);
        if (ndo->ndo_vflag > 1)
                ND_PRINT("\n");
        ND_PRINT(" Hold time: ");
@@ -209,7 +208,6 @@ pimv1_join_prune_print(netdissect_options *ndo,
 
        if (len < 4)
                goto trunc;
-       ND_TCHECK_4(bp);
        ngroups = GET_U_1(bp + 3);
        bp += 4;
        len -= 4;
@@ -220,20 +218,17 @@ pimv1_join_prune_print(netdissect_options *ndo,
                 */
                if (len < 4)
                        goto trunc;
-               ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
                ND_PRINT("\n\tGroup: %s", GET_IPADDR_STRING(bp));
                bp += 4;
                len -= 4;
                if (len < 4)
                        goto trunc;
-               ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
                if (GET_BE_U_4(bp) != 0xffffffff)
                        ND_PRINT("/%s", GET_IPADDR_STRING(bp));
                bp += 4;
                len -= 4;
                if (len < 4)
                        goto trunc;
-               ND_TCHECK_4(bp);
                njoin = GET_BE_U_2(bp);
                nprune = GET_BE_U_2(bp + 2);
                ND_PRINT(" joined: %u pruned: %u", njoin, nprune);
@@ -248,7 +243,6 @@ pimv1_join_prune_print(netdissect_options *ndo,
                                type = "Prune";
                        if (len < 6)
                                goto trunc;
-                       ND_TCHECK_6(bp);
                        ND_PRINT("\n\t%s %s%s%s%s/%u", type,
                            (GET_U_1(bp) & 0x01) ? "Sparse " : "Dense ",
                            (GET_U_1(bp + 1) & 0x80) ? "WC " : "",
@@ -263,7 +257,6 @@ pimv1_join_prune_print(netdissect_options *ndo,
        return;
 trunc:
        nd_print_trunc(ndo);
-       return;
 }
 
 void
@@ -307,13 +300,11 @@ pimv1_print(netdissect_options *ndo,
                          GET_IPADDR_STRING(bp + 24));
                break;
        case PIMV1_TYPE_REGISTER_STOP:
-               ND_TCHECK_LEN(bp + 12, sizeof(nd_ipv4));
                ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 8),
                          GET_IPADDR_STRING(bp + 12));
                break;
        case PIMV1_TYPE_RP_REACHABILITY:
                if (ndo->ndo_vflag) {
-                       ND_TCHECK_2(bp + 22);
                        ND_PRINT(" group %s", GET_IPADDR_STRING(bp + 8));
                        if (GET_BE_U_4(bp + 12) != 0xffffffff)
                                ND_PRINT("/%s", GET_IPADDR_STRING(bp + 12));
@@ -322,7 +313,6 @@ pimv1_print(netdissect_options *ndo,
                }
                break;
        case PIMV1_TYPE_ASSERT:
-               ND_TCHECK_LEN(bp + 16, sizeof(nd_ipv4));
                ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 16),
                          GET_IPADDR_STRING(bp + 8));
                if (GET_BE_U_4(bp + 12) != 0xffffffff)
@@ -348,7 +338,6 @@ pimv1_print(netdissect_options *ndo,
 
 trunc:
        nd_print_trunc(ndo);
-       return;
 }
 
 /*
@@ -414,7 +403,6 @@ cisco_autorp_print(netdissect_options *ndo,
 
                if (len < 4)
                        goto trunc;
-               ND_TCHECK_4(bp);
                ND_PRINT(" RP %s", GET_IPADDR_STRING(bp));
                bp += 4;
                len -= 4;
@@ -443,7 +431,6 @@ cisco_autorp_print(netdissect_options *ndo,
                while (nentries != 0) {
                        if (len < 6)
                                goto trunc;
-                       ND_TCHECK_6(bp);
                        ND_PRINT("%c%s%s/%u", s, GET_U_1(bp) & 1 ? "!" : "",
                                  GET_IPADDR_STRING(bp + 2), GET_U_1(bp + 1));
                        if (GET_U_1(bp) & 0x02) {
@@ -462,7 +449,6 @@ cisco_autorp_print(netdissect_options *ndo,
 
 trunc:
        nd_print_trunc(ndo);
-       return;
 }
 
 void
@@ -473,9 +459,6 @@ pim_print(netdissect_options *ndo,
        uint8_t pim_typever;
 
        ndo->ndo_protocol = "pim";
-#ifdef notyet                  /* currently we see only version and type */
-       ND_TCHECK_1(pim->pim_rsv);
-#endif
 
        pim_typever = GET_U_1(pim->pim_typever);
        switch (PIM_VER(pim_typever)) {
@@ -577,14 +560,12 @@ pimv2_addr_print(netdissect_options *ndo,
        if (addr_len == 0) {
                if (len < 2)
                        goto trunc;
-               ND_TCHECK_1(bp + 1);
-               switch (GET_U_1(bp)) {
-               case 1:
-                       af = AF_INET;
+               af = GET_U_1(bp);
+               switch (af) {
+               case AFNUM_IP:
                        addr_len = (u_int)sizeof(nd_ipv4);
                        break;
-               case 2:
-                       af = AF_INET6;
+               case AFNUM_IP6:
                        addr_len = (u_int)sizeof(nd_ipv6);
                        break;
                default:
@@ -596,10 +577,10 @@ pimv2_addr_print(netdissect_options *ndo,
        } else {
                switch (addr_len) {
                case sizeof(nd_ipv4):
-                       af = AF_INET;
+                       af = AFNUM_IP;
                        break;
                case sizeof(nd_ipv6):
-                       af = AF_INET6;
+                       af = AFNUM_IP6;
                        break;
                default:
                        return -1;
@@ -615,11 +596,10 @@ pimv2_addr_print(netdissect_options *ndo,
                if (len < addr_len)
                        goto trunc;
                ND_TCHECK_LEN(bp, addr_len);
-               if (af == AF_INET) {
+               if (af == AFNUM_IP) {
                        if (!silent)
                                ND_PRINT("%s", GET_IPADDR_STRING(bp));
-               }
-               else if (af == AF_INET6) {
+               } else if (af == AFNUM_IP6) {
                        if (!silent)
                                ND_PRINT("%s", GET_IP6ADDR_STRING(bp));
                }
@@ -629,14 +609,13 @@ pimv2_addr_print(netdissect_options *ndo,
                if (len < addr_len + 2)
                        goto trunc;
                ND_TCHECK_LEN(bp, addr_len + 2);
-               if (af == AF_INET) {
+               if (af == AFNUM_IP) {
                        if (!silent) {
                                ND_PRINT("%s", GET_IPADDR_STRING(bp + 2));
                                if (GET_U_1(bp + 1) != 32)
                                        ND_PRINT("/%u", GET_U_1(bp + 1));
                        }
-               }
-               else if (af == AF_INET6) {
+               } else if (af == AFNUM_IP6) {
                        if (!silent) {
                                ND_PRINT("%s", GET_IP6ADDR_STRING(bp + 2));
                                if (GET_U_1(bp + 1) != 128)
@@ -719,7 +698,6 @@ pimv2_print(netdissect_options *ndo,
                nd_print_invalid(ndo);
                return;
        }
-       ND_TCHECK_1(pim->pim_rsv);
        pim_typever = GET_U_1(pim->pim_typever);
        /* RFC5015 allocates the high 4 bits of pim_rsv for "subtype". */
        pimv2_addr_len = GET_U_1(pim->pim_rsv) & 0x0f;
@@ -781,7 +759,6 @@ pimv2_print(netdissect_options *ndo,
                while (len > 0) {
                        if (len < 4)
                                goto trunc;
-                       ND_TCHECK_4(bp);
                        otype = GET_BE_U_2(bp);
                        olen = GET_BE_U_2(bp + 2);
                        ND_PRINT("\n\t  %s Option (%u), length %u, Value: ",
@@ -919,10 +896,8 @@ pimv2_print(netdissect_options *ndo,
                if (len == 0)
                        goto trunc;
                ip = (const struct ip *)bp;
-               ND_TCHECK_1(ip->ip_vhl);
                switch (IP_V(ip)) {
                 case 0: /* Null header */
-                       ND_TCHECK_4(ip->ip_dst);
                        ND_PRINT("IP-Null-header %s > %s",
                                  GET_IPADDR_STRING(ip->ip_src),
                                  GET_IPADDR_STRING(ip->ip_dst));
@@ -1110,7 +1085,6 @@ pimv2_print(netdissect_options *ndo,
 
                                if (len < 2)
                                        goto trunc;
-                               ND_TCHECK_2(bp);
                                ND_PRINT(",holdtime=");
                                unsigned_relts_print(ndo,
                                                     GET_BE_U_2(bp));