]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-pim.c
Fix spaces
[tcpdump] / print-pim.c
index 5b1d61bce24c0517cf2419aa282a6b8f026f757c..b18933d464f47bdeafc6dbbf9b43b08fe6e222ca 100644 (file)
@@ -118,6 +118,23 @@ static const struct tok pimv2_register_flag_values[] = {
     { 0, NULL}
 };
 
+#define PIMV2_DF_ELECTION_OFFER                  1
+#define PIMV2_DF_ELECTION_WINNER                 2
+#define PIMV2_DF_ELECTION_BACKOFF                3
+#define PIMV2_DF_ELECTION_PASS                   4
+
+static const struct tok pimv2_df_election_flag_values[] = {
+    { PIMV2_DF_ELECTION_OFFER, "Offer" },
+    { PIMV2_DF_ELECTION_WINNER, "Winner" },
+    { PIMV2_DF_ELECTION_BACKOFF, "Backoff" },
+    { PIMV2_DF_ELECTION_PASS, "Pass" },
+    { 0, NULL}
+};
+
+#define PIMV2_DF_ELECTION_PASS_BACKOFF_STR(x)   ( \
+      x == PIMV2_DF_ELECTION_BACKOFF ? "offer" : "new winner" )
+
+
 /*
  * XXX: We consider a case where IPv6 is not ready yet for portability,
  * but PIM dependent defintions should be independent of IPv6...
@@ -133,7 +150,8 @@ struct pim {
                         */
 #define PIM_VER(x)     (((x) & 0xf0) >> 4)
 #define PIM_TYPE(x)    ((x) & 0x0f)
-       nd_uint8_t      pim_rsv;        /* Reserved in v1, address length in v2 */
+       nd_uint8_t      pim_rsv;        /* Reserved in v1, subtype+address length in v2 */
+#define PIM_SUBTYPE(x)  (((x) & 0xf0) >> 4)
        nd_uint16_t     pim_cksum;      /* IP style check sum */
 };
 
@@ -151,17 +169,17 @@ pimv1_join_prune_print(netdissect_options *ndo,
            ((njoin = GET_BE_U_2(bp + 20)) + GET_BE_U_2(bp + 22)) == 1) {
                u_int hold;
 
-               ND_PRINT(" RPF %s ", ipaddr_string(ndo, bp));
+               ND_PRINT(" RPF %s ", GET_IPADDR_STRING(bp));
                hold = GET_BE_U_2(bp + 6);
                if (hold != 180) {
                        ND_PRINT("Hold ");
                        unsigned_relts_print(ndo, hold);
                }
                ND_PRINT("%s (%s/%u, %s", njoin ? "Join" : "Prune",
-               ipaddr_string(ndo, bp + 26), GET_U_1(bp + 25) & 0x3f,
-               ipaddr_string(ndo, bp + 12));
+               GET_IPADDR_STRING(bp + 26), GET_U_1(bp + 25) & 0x3f,
+               GET_IPADDR_STRING(bp + 12));
                if (GET_BE_U_4(bp + 16) != 0xffffffff)
-                       ND_PRINT("/%s", ipaddr_string(ndo, bp + 16));
+                       ND_PRINT("/%s", GET_IPADDR_STRING(bp + 16));
                ND_PRINT(") %s%s %s",
                    (GET_U_1(bp + 24) & 0x01) ? "Sparse" : "Dense",
                    (GET_U_1(bp + 25) & 0x80) ? " WC" : "",
@@ -174,7 +192,7 @@ pimv1_join_prune_print(netdissect_options *ndo,
        ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
        if (ndo->ndo_vflag > 1)
                ND_PRINT("\n");
-       ND_PRINT(" Upstream Nbr: %s", ipaddr_string(ndo, bp));
+       ND_PRINT(" Upstream Nbr: %s", GET_IPADDR_STRING(bp));
        bp += 4;
        len -= 4;
        if (len < 4)
@@ -203,14 +221,14 @@ pimv1_join_prune_print(netdissect_options *ndo,
                if (len < 4)
                        goto trunc;
                ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
-               ND_PRINT("\n\tGroup: %s", ipaddr_string(ndo, bp));
+               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", ipaddr_string(ndo, bp));
+                       ND_PRINT("/%s", GET_IPADDR_STRING(bp));
                bp += 4;
                len -= 4;
                if (len < 4)
@@ -235,7 +253,7 @@ pimv1_join_prune_print(netdissect_options *ndo,
                            (GET_U_1(bp) & 0x01) ? "Sparse " : "Dense ",
                            (GET_U_1(bp + 1) & 0x80) ? "WC " : "",
                            (GET_U_1(bp + 1) & 0x40) ? "RP " : "SPT ",
-                           ipaddr_string(ndo, bp + 2),
+                           GET_IPADDR_STRING(bp + 2),
                            GET_U_1(bp + 1) & 0x3f);
                        bp += 6;
                        len -= 6;
@@ -287,30 +305,30 @@ pimv1_print(netdissect_options *ndo,
 
        case PIMV1_TYPE_REGISTER:
                ND_TCHECK_LEN(bp + 8, 20);                      /* ip header */
-               ND_PRINT(" for %s > %s", ipaddr_string(ndo, bp + 20),
-                         ipaddr_string(ndo, bp + 24));
+               ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 20),
+                         GET_IPADDR_STRING(bp + 24));
                break;
        case PIMV1_TYPE_REGISTER_STOP:
                ND_TCHECK_LEN(bp + 12, sizeof(nd_ipv4));
-               ND_PRINT(" for %s > %s", ipaddr_string(ndo, bp + 8),
-                         ipaddr_string(ndo, bp + 12));
+               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", ipaddr_string(ndo, bp + 8));
+                       ND_PRINT(" group %s", GET_IPADDR_STRING(bp + 8));
                        if (GET_BE_U_4(bp + 12) != 0xffffffff)
-                               ND_PRINT("/%s", ipaddr_string(ndo, bp + 12));
-                       ND_PRINT(" RP %s hold ", ipaddr_string(ndo, bp + 16));
+                               ND_PRINT("/%s", GET_IPADDR_STRING(bp + 12));
+                       ND_PRINT(" RP %s hold ", GET_IPADDR_STRING(bp + 16));
                        unsigned_relts_print(ndo, GET_BE_U_2(bp + 22));
                }
                break;
        case PIMV1_TYPE_ASSERT:
                ND_TCHECK_LEN(bp + 16, sizeof(nd_ipv4));
-               ND_PRINT(" for %s > %s", ipaddr_string(ndo, bp + 16),
-                         ipaddr_string(ndo, bp + 8));
+               ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 16),
+                         GET_IPADDR_STRING(bp + 8));
                if (GET_BE_U_4(bp + 12) != 0xffffffff)
-                       ND_PRINT("/%s", ipaddr_string(ndo, bp + 12));
+                       ND_PRINT("/%s", GET_IPADDR_STRING(bp + 12));
                ND_TCHECK_4(bp + 24);
                ND_PRINT(" %s pref %u metric %u",
                    (GET_U_1(bp + 20) & 0x80) ? "RP-tree" : "SPT",
@@ -404,7 +422,7 @@ cisco_autorp_print(netdissect_options *ndo,
                if (len < 4)
                        goto trunc;
                ND_TCHECK_4(bp);
-               ND_PRINT(" RP %s", ipaddr_string(ndo, bp));
+               ND_PRINT(" RP %s", GET_IPADDR_STRING(bp));
                bp += 4;
                len -= 4;
                if (len < 1)
@@ -436,7 +454,7 @@ cisco_autorp_print(netdissect_options *ndo,
                                goto trunc;
                        ND_TCHECK_6(bp);
                        ND_PRINT("%c%s%s/%u", s, GET_U_1(bp) & 1 ? "!" : "",
-                                 ipaddr_string(ndo, bp + 2), GET_U_1(bp + 1));
+                                 GET_IPADDR_STRING(bp + 2), GET_U_1(bp + 1));
                        if (GET_U_1(bp) & 0x02) {
                                ND_PRINT(" bidir");
                        }
@@ -614,11 +632,11 @@ pimv2_addr_print(netdissect_options *ndo,
                ND_TCHECK_LEN(bp, addr_len);
                if (af == AF_INET) {
                        if (!silent)
-                               ND_PRINT("%s", ipaddr_string(ndo, bp));
+                               ND_PRINT("%s", GET_IPADDR_STRING(bp));
                }
                else if (af == AF_INET6) {
                        if (!silent)
-                               ND_PRINT("%s", ip6addr_string(ndo, bp));
+                               ND_PRINT("%s", GET_IP6ADDR_STRING(bp));
                }
                return hdrlen + addr_len;
        case pimv2_group:
@@ -628,14 +646,14 @@ pimv2_addr_print(netdissect_options *ndo,
                ND_TCHECK_LEN(bp, addr_len + 2);
                if (af == AF_INET) {
                        if (!silent) {
-                               ND_PRINT("%s", ipaddr_string(ndo, bp + 2));
+                               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) {
                        if (!silent) {
-                               ND_PRINT("%s", ip6addr_string(ndo, bp + 2));
+                               ND_PRINT("%s", GET_IP6ADDR_STRING(bp + 2));
                                if (GET_U_1(bp + 1) != 128)
                                        ND_PRINT("/%u", GET_U_1(bp + 1));
                        }
@@ -705,21 +723,29 @@ pimv2_print(netdissect_options *ndo,
 {
        const struct pim *pim = (const struct pim *)bp;
        int advance;
+       int subtype;
        enum checksum_status cksum_status;
        u_int pim_typever;
        u_int pimv2_addr_len;
 
        ndo->ndo_protocol = "pimv2";
-       if (len < 2)
-               goto trunc;
+       if (len < 2) {
+               ND_PRINT("[length %u < 2]", len);
+               nd_print_invalid(ndo);
+               return;
+       }
        ND_TCHECK_1(pim->pim_rsv);
        pim_typever = GET_U_1(pim->pim_typever);
-       pimv2_addr_len = GET_U_1(pim->pim_rsv);
+       /* RFC5015 allocates the high 4 bits of pim_rsv for "subtype". */
+       pimv2_addr_len = GET_U_1(pim->pim_rsv) & 0x0f;
        if (pimv2_addr_len != 0)
                ND_PRINT(", RFC2117-encoding");
 
-       if (len < 4)
-               goto trunc;
+       if (len < 4) {
+               ND_PRINT("[length %u < 4]", len);
+               nd_print_invalid(ndo);
+               return;
+       }
        ND_TCHECK_2(pim->pim_cksum);
        ND_PRINT(", cksum 0x%04x ", GET_BE_U_2(pim->pim_cksum));
        if (GET_BE_U_2(pim->pim_cksum) == 0) {
@@ -787,7 +813,9 @@ pimv2_print(netdissect_options *ndo,
                        switch (otype) {
                        case PIMV2_HELLO_OPTION_HOLDTIME:
                                if (olen != 2) {
-                                       ND_PRINT("ERROR: Option Length != 2 Bytes (%u)", olen);
+                                       ND_PRINT("[option length %u != 2]", olen);
+                                       nd_print_invalid(ndo);
+                                       return;
                                } else {
                                        unsigned_relts_print(ndo,
                                                             GET_BE_U_2(bp));
@@ -796,7 +824,9 @@ pimv2_print(netdissect_options *ndo,
 
                        case PIMV2_HELLO_OPTION_LANPRUNEDELAY:
                                if (olen != 4) {
-                                       ND_PRINT("ERROR: Option Length != 4 Bytes (%u)", olen);
+                                       ND_PRINT("[option length %u != 4]", olen);
+                                       nd_print_invalid(ndo);
+                                       return;
                                } else {
                                        char t_bit;
                                        uint16_t lan_delay, override_interval;
@@ -819,14 +849,18 @@ pimv2_print(netdissect_options *ndo,
                                        ND_PRINT("%u", GET_BE_U_4(bp));
                                        break;
                                default:
-                                       ND_PRINT("ERROR: Option Length != 4 Bytes (%u)", olen);
+                                       ND_PRINT("[option length %u != 4]", olen);
+                                       nd_print_invalid(ndo);
+                                       return;
                                        break;
                                }
                                break;
 
                        case PIMV2_HELLO_OPTION_GENID:
                                if (olen != 4) {
-                                       ND_PRINT("ERROR: Option Length != 4 Bytes (%u)", olen);
+                                       ND_PRINT("[option length %u != 4]", olen);
+                                       nd_print_invalid(ndo);
+                                       return;
                                } else {
                                        ND_PRINT("0x%08x", GET_BE_U_4(bp));
                                }
@@ -834,7 +868,9 @@ pimv2_print(netdissect_options *ndo,
 
                        case PIMV2_HELLO_OPTION_REFRESH_CAP:
                                if (olen != 4) {
-                                       ND_PRINT("ERROR: Option Length != 4 Bytes (%u)", olen);
+                                       ND_PRINT("[option length %u != 4]", olen);
+                                       nd_print_invalid(ndo);
+                                       return;
                                } else {
                                        ND_PRINT("v%u", GET_U_1(bp));
                                        if (GET_U_1(bp + 1) != 0) {
@@ -904,8 +940,8 @@ pimv2_print(netdissect_options *ndo,
                 case 0: /* Null header */
                        ND_TCHECK_4(ip->ip_dst);
                        ND_PRINT("IP-Null-header %s > %s",
-                                 ipaddr_string(ndo, ip->ip_src),
-                                 ipaddr_string(ndo, ip->ip_dst));
+                                 GET_IPADDR_STRING(ip->ip_src),
+                                 GET_IPADDR_STRING(ip->ip_dst));
                        break;
 
                case 4: /* IPv4 */
@@ -1192,6 +1228,48 @@ pimv2_print(netdissect_options *ndo,
                unsigned_relts_print(ndo, GET_BE_U_2(bp));
                break;
 
+       case PIMV2_TYPE_DF_ELECTION:
+               subtype = PIM_SUBTYPE(GET_U_1(pim->pim_rsv));
+               ND_PRINT("\n\t  %s,", tok2str( pimv2_df_election_flag_values,
+                        "Unknown", subtype) );
+
+               ND_PRINT(" rpa=");
+               if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) {
+                       goto trunc;
+               }
+               bp += advance;
+               len -= advance;
+               ND_PRINT(" sender pref=%u", GET_BE_U_4(bp) );
+               ND_PRINT(" sender metric=%u", GET_BE_U_4(bp + 4));
+
+               bp += 8;
+               len -= 8;
+
+               switch (subtype) {
+               case PIMV2_DF_ELECTION_BACKOFF:
+               case PIMV2_DF_ELECTION_PASS:
+                       ND_PRINT("\n\t  %s addr=", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype));
+                       if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) {
+                               goto trunc;
+                       }
+                       bp += advance;
+                       len -= advance;
+
+                       ND_PRINT(" %s pref=%u", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype), GET_BE_U_4(bp) );
+                       ND_PRINT(" %s metric=%u", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype), GET_BE_U_4(bp + 4));
+
+                       bp += 8;
+                       len -= 8;
+
+                       if (subtype == PIMV2_DF_ELECTION_BACKOFF) {
+                               ND_PRINT(" interval %dms", GET_BE_U_2(bp));
+                       }
+
+                       break;
+               default:
+                       break;
+               }
+               break;
 
         default:
                ND_PRINT(" [type %u]", PIM_TYPE(pim_typever));