]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-pgm.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-pgm.c
index 6926be2348ad43ba86e124066942cb9a4a8dd199..d9c1e2c2fe143e2f91f4ab14b26c6d9bc5296502 100644 (file)
 
 /* \summary: Pragmatic General Multicast (PGM) printer */
 
-#ifdef HAVE_CONFIG_H
+/* specification: RFC 3208
+
+   Plus https://dl.acm.org/doi/pdf/10.1145/347057.347390 for PGMCC,
+   whence the ACK packet type comes; there are some I-Ds for PGMCC,
+   draft-ietf-rmt-bb-pgmcc-00 through draft-ietf-rmt-bb-pgmcc-03,
+   but none of them give any description of the packet-level
+   changes to PGM, unlike the paper in question, which merely gives
+   an *insufficient* description of said changes.  In particular,
+   it doesn't indicate what the packet type code for ACK is.
+
+   Luigi Rizzo's PGMCC code for FreeBSD, at
+
+      https://web.archive.org/web/20020302084503/http://info.iet.unipi.it/~luigi/pgm-code/
+
+   uses 0x0b (11) for ACK.
+
+   A capture file attached to
+
+      https://gitlab.com/wireshark/wireshark/-/issues/4798
+
+   has packets that use 0x0d for ACK, as does the Wireshark dissector
+   for PGM, and as does OpenPGM at https://github.com/steve-o/openpgm.
+   It may be that some proprietary PGMCC implementations, such as
+   SmartPGM, do so as well.
+
+   We use *both*, treating *either one* as a PGMCC ACK, pending
+   more information, such as an answer to
+
+      https://github.com/steve-o/openpgm/issues/75.
+
+   */
+
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
@@ -95,17 +126,17 @@ struct pgm_data {
 };
 
 typedef enum _pgm_type {
-    PGM_SPM = 0,               /* source path message */
-    PGM_POLL = 1,              /* POLL Request */
-    PGM_POLR = 2,              /* POLL Response */
-    PGM_ODATA = 4,             /* original data */
-    PGM_RDATA = 5,             /* repair data */
-    PGM_NAK = 8,               /* NAK */
-    PGM_NULLNAK = 9,           /* Null NAK */
-    PGM_NCF = 10,              /* NAK Confirmation */
-    PGM_ACK = 11,              /* ACK for congestion control */
-    PGM_SPMR = 12,             /* SPM request */
-    PGM_MAX = 255
+    PGM_SPM = 0x00,            /* source path message */
+    PGM_POLL = 0x01,           /* POLL Request */
+    PGM_POLR = 0x02,           /* POLL Response */
+    PGM_ODATA = 0x04,          /* original data */
+    PGM_RDATA = 0x05,          /* repair data */
+    PGM_NAK = 0x08,            /* NAK */
+    PGM_NULLNAK = 0x09,                /* Null NAK */
+    PGM_NCF = 0x0a,            /* NAK Confirmation */
+    PGM_ACK = 0x0b,            /* ACK for congestion control? */
+    PGM_SPMR = 0x0c,           /* SPM request */
+    PGM_ACK2 = 0x0d,           /* Also ACK for congestion control? */
 } pgm_type;
 
 #define PGM_OPT_BIT_PRESENT    0x01
@@ -167,15 +198,14 @@ pgm_print(netdissect_options *ndo,
        if (!ND_TTEST_2(pgm->pgm_dport)) {
                if (ip6) {
                        ND_PRINT("%s > %s:",
-                               ip6addr_string(ndo, ip6->ip6_src),
-                               ip6addr_string(ndo, ip6->ip6_dst));
+                               GET_IP6ADDR_STRING(ip6->ip6_src),
+                               GET_IP6ADDR_STRING(ip6->ip6_dst));
                } else {
                        ND_PRINT("%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));
                }
-               nd_print_trunc(ndo);
-               return;
+               nd_trunc_longjmp(ndo);
        }
 
        sport = GET_BE_U_2(pgm->pgm_sport);
@@ -184,9 +214,9 @@ pgm_print(netdissect_options *ndo,
        if (ip6) {
                if (GET_U_1(ip6->ip6_nxt) == IPPROTO_PGM) {
                        ND_PRINT("%s.%s > %s.%s: ",
-                               ip6addr_string(ndo, ip6->ip6_src),
+                               GET_IP6ADDR_STRING(ip6->ip6_src),
                                tcpport_string(ndo, sport),
-                               ip6addr_string(ndo, ip6->ip6_dst),
+                               GET_IP6ADDR_STRING(ip6->ip6_dst),
                                tcpport_string(ndo, dport));
                } else {
                        ND_PRINT("%s > %s: ",
@@ -195,9 +225,9 @@ pgm_print(netdissect_options *ndo,
        } else {
                if (GET_U_1(ip->ip_p) == IPPROTO_PGM) {
                        ND_PRINT("%s.%s > %s.%s: ",
-                               ipaddr_string(ndo, ip->ip_src),
+                               GET_IPADDR_STRING(ip->ip_src),
                                tcpport_string(ndo, sport),
-                               ipaddr_string(ndo, ip->ip_dst),
+                               GET_IPADDR_STRING(ip->ip_dst),
                                tcpport_string(ndo, dport));
                } else {
                        ND_PRINT("%s > %s: ",
@@ -220,28 +250,28 @@ pgm_print(netdissect_options *ndo,
                     pgm->pgm_gsid[3],
                      pgm->pgm_gsid[4],
                      pgm->pgm_gsid[5]);
+       bp += sizeof(struct pgm_header);
        switch (pgm_type_val) {
        case PGM_SPM: {
            const struct pgm_spm *spm;
 
-           spm = (const struct pgm_spm *)(pgm + 1);
+           spm = (const struct pgm_spm *)bp;
            ND_TCHECK_SIZE(spm);
-           bp = (const u_char *) (spm + 1);
+           bp += sizeof(struct pgm_spm);
 
            switch (GET_BE_U_2(spm->pgms_nla_afi)) {
-           case AFNUM_INET:
+           case AFNUM_IP:
                ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
                addrtostr(bp, nla_buf, sizeof(nla_buf));
                bp += sizeof(nd_ipv4);
                break;
-           case AFNUM_INET6:
+           case AFNUM_IP6:
                ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
                addrtostr6(bp, nla_buf, sizeof(nla_buf));
                bp += sizeof(nd_ipv6);
                break;
            default:
-               goto trunc;
-               break;
+               goto invalid;
            }
 
            ND_PRINT("SPM seq %u trail %u lead %u nla %s",
@@ -256,35 +286,31 @@ pgm_print(netdissect_options *ndo,
            const struct pgm_poll *pgm_poll;
            uint32_t ivl, rnd, mask;
 
-           pgm_poll = (const struct pgm_poll *)(pgm + 1);
+           pgm_poll = (const struct pgm_poll *)bp;
            ND_TCHECK_SIZE(pgm_poll);
-           bp = (const u_char *) (pgm_poll + 1);
+           bp += sizeof(struct pgm_poll);
 
            switch (GET_BE_U_2(pgm_poll->pgmp_nla_afi)) {
-           case AFNUM_INET:
+           case AFNUM_IP:
                ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
                addrtostr(bp, nla_buf, sizeof(nla_buf));
                bp += sizeof(nd_ipv4);
                break;
-           case AFNUM_INET6:
+           case AFNUM_IP6:
                ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
                addrtostr6(bp, nla_buf, sizeof(nla_buf));
                bp += sizeof(nd_ipv6);
                break;
            default:
-               goto trunc;
-               break;
+               goto invalid;
            }
 
-           ND_TCHECK_LEN(bp, sizeof(uint32_t));
            ivl = GET_BE_U_4(bp);
            bp += sizeof(uint32_t);
 
-           ND_TCHECK_LEN(bp, sizeof(uint32_t));
            rnd = GET_BE_U_4(bp);
            bp += sizeof(uint32_t);
 
-           ND_TCHECK_LEN(bp, sizeof(uint32_t));
            mask = GET_BE_U_4(bp);
            bp += sizeof(uint32_t);
 
@@ -297,35 +323,33 @@ pgm_print(netdissect_options *ndo,
        case PGM_POLR: {
            const struct pgm_polr *polr_msg;
 
-           polr_msg = (const struct pgm_polr *)(pgm + 1);
+           polr_msg = (const struct pgm_polr *)bp;
            ND_TCHECK_SIZE(polr_msg);
            ND_PRINT("POLR seq %u round %u",
                         GET_BE_U_4(polr_msg->pgmp_seq),
                         GET_BE_U_2(polr_msg->pgmp_round));
-           bp = (const u_char *) (polr_msg + 1);
+           bp += sizeof(struct pgm_polr);
            break;
        }
        case PGM_ODATA: {
            const struct pgm_data *odata;
 
-           odata = (const struct pgm_data *)(pgm + 1);
-           ND_TCHECK_SIZE(odata);
+           odata = (const struct pgm_data *)bp;
            ND_PRINT("ODATA trail %u seq %u",
                         GET_BE_U_4(odata->pgmd_trailseq),
                         GET_BE_U_4(odata->pgmd_seq));
-           bp = (const u_char *) (odata + 1);
+           bp += sizeof(struct pgm_data);
            break;
        }
 
        case PGM_RDATA: {
            const struct pgm_data *rdata;
 
-           rdata = (const struct pgm_data *)(pgm + 1);
-           ND_TCHECK_SIZE(rdata);
+           rdata = (const struct pgm_data *)bp;
            ND_PRINT("RDATA trail %u seq %u",
                         GET_BE_U_4(rdata->pgmd_trailseq),
                         GET_BE_U_4(rdata->pgmd_seq));
-           bp = (const u_char *) (rdata + 1);
+           bp += sizeof(struct pgm_data);
            break;
        }
 
@@ -335,28 +359,27 @@ pgm_print(netdissect_options *ndo,
            const struct pgm_nak *nak;
            char source_buf[INET6_ADDRSTRLEN], group_buf[INET6_ADDRSTRLEN];
 
-           nak = (const struct pgm_nak *)(pgm + 1);
+           nak = (const struct pgm_nak *)bp;
            ND_TCHECK_SIZE(nak);
-           bp = (const u_char *) (nak + 1);
+           bp += sizeof(struct pgm_nak);
 
            /*
             * Skip past the source, saving info along the way
             * and stopping if we don't have enough.
             */
            switch (GET_BE_U_2(nak->pgmn_source_afi)) {
-           case AFNUM_INET:
+           case AFNUM_IP:
                ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
                addrtostr(bp, source_buf, sizeof(source_buf));
                bp += sizeof(nd_ipv4);
                break;
-           case AFNUM_INET6:
+           case AFNUM_IP6:
                ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
                addrtostr6(bp, source_buf, sizeof(source_buf));
                bp += sizeof(nd_ipv6);
                break;
            default:
-               goto trunc;
-               break;
+               goto invalid;
            }
 
            /*
@@ -364,21 +387,19 @@ pgm_print(netdissect_options *ndo,
             * and stopping if we don't have enough.
             */
            bp += (2 * sizeof(uint16_t));
-           ND_TCHECK_2(bp);
            switch (GET_BE_U_2(bp)) {
-           case AFNUM_INET:
+           case AFNUM_IP:
                ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
                addrtostr(bp, group_buf, sizeof(group_buf));
                bp += sizeof(nd_ipv4);
                break;
-           case AFNUM_INET6:
+           case AFNUM_IP6:
                ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
                addrtostr6(bp, group_buf, sizeof(group_buf));
                bp += sizeof(nd_ipv6);
                break;
            default:
-               goto trunc;
-               break;
+               goto invalid;
            }
 
            /*
@@ -402,14 +423,15 @@ pgm_print(netdissect_options *ndo,
            break;
        }
 
-       case PGM_ACK: {
+       case PGM_ACK:
+       case PGM_ACK2: {
            const struct pgm_ack *ack;
 
-           ack = (const struct pgm_ack *)(pgm + 1);
+           ack = (const struct pgm_ack *)bp;
            ND_TCHECK_SIZE(ack);
            ND_PRINT("ACK seq %u",
                         GET_BE_U_4(ack->pgma_rx_max_seq));
-           bp = (const u_char *) (ack + 1);
+           bp += sizeof(struct pgm_ack);
            break;
        }
 
@@ -459,7 +481,6 @@ pgm_print(netdissect_options *ndo,
                    ND_PRINT("[Total option length leaves no room for final option]");
                    return;
                }
-               ND_TCHECK_2(bp);
                opt_type = GET_U_1(bp);
                bp++;
                opt_len = GET_U_1(bp);
@@ -515,7 +536,6 @@ pgm_print(netdissect_options *ndo,
                            ND_PRINT("[Option length not a multiple of 4]");
                            return;
                        }
-                       ND_TCHECK_4(bp);
                        ND_PRINT(" %u", GET_BE_U_4(bp));
                        bp += 4;
                        opt_len -= 4;
@@ -580,7 +600,7 @@ pgm_print(netdissect_options *ndo,
                    nla_afnum = GET_BE_U_2(bp);
                    bp += 2+2;
                    switch (nla_afnum) {
-                   case AFNUM_INET:
+                   case AFNUM_IP:
                        if (opt_len != PGM_OPT_REDIRECT_FIXED_LEN + sizeof(nd_ipv4)) {
                            ND_PRINT("[Bad OPT_REDIRECT option, length %u != %u + address size]",
                                opt_len, PGM_OPT_REDIRECT_FIXED_LEN);
@@ -591,10 +611,10 @@ pgm_print(netdissect_options *ndo,
                        bp += sizeof(nd_ipv4);
                        opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(nd_ipv4);
                        break;
-                   case AFNUM_INET6:
+                   case AFNUM_IP6:
                        if (opt_len != PGM_OPT_REDIRECT_FIXED_LEN + sizeof(nd_ipv6)) {
                            ND_PRINT("[Bad OPT_REDIRECT option, length %u != %u + address size]",
-                               PGM_OPT_REDIRECT_FIXED_LEN, opt_len);
+                               opt_len, PGM_OPT_REDIRECT_FIXED_LEN);
                            return;
                        }
                        ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
@@ -603,8 +623,7 @@ pgm_print(netdissect_options *ndo,
                        opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(nd_ipv6);
                        break;
                    default:
-                       goto trunc;
-                       break;
+                       goto invalid;
                    }
 
                    ND_PRINT(" REDIRECT %s",  nla_buf);
@@ -666,7 +685,7 @@ pgm_print(netdissect_options *ndo,
 
                case PGM_OPT_PATH_NLA:
                    ND_PRINT(" PATH_NLA [%u]", opt_len);
-                   bp += opt_len;
+                   bp += opt_len - 2;
                    opts_len -= opt_len;
                    break;
 
@@ -708,7 +727,7 @@ pgm_print(netdissect_options *ndo,
 
                case PGM_OPT_CR:
                    ND_PRINT(" CR");
-                   bp += opt_len;
+                   bp += opt_len - 2;
                    opts_len -= opt_len;
                    break;
 
@@ -737,7 +756,7 @@ pgm_print(netdissect_options *ndo,
                    nla_afnum = GET_BE_U_2(bp);
                    bp += 2+2;
                    switch (nla_afnum) {
-                   case AFNUM_INET:
+                   case AFNUM_IP:
                        if (opt_len != PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(nd_ipv4)) {
                            ND_PRINT("[Bad OPT_PGMCC_DATA option, length %u != %u + address size]",
                                opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN);
@@ -748,7 +767,7 @@ pgm_print(netdissect_options *ndo,
                        bp += sizeof(nd_ipv4);
                        opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(nd_ipv4);
                        break;
-                   case AFNUM_INET6:
+                   case AFNUM_IP6:
                        if (opt_len != PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(nd_ipv6)) {
                            ND_PRINT("[Bad OPT_PGMCC_DATA option, length %u != %u + address size]",
                                opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN);
@@ -760,8 +779,7 @@ pgm_print(netdissect_options *ndo,
                        opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(nd_ipv6);
                        break;
                    default:
-                       goto trunc;
-                       break;
+                       goto invalid;
                    }
 
                    ND_PRINT(" PGMCC DATA %u %s", offset, nla_buf);
@@ -780,7 +798,7 @@ pgm_print(netdissect_options *ndo,
                    nla_afnum = GET_BE_U_2(bp);
                    bp += 2+2;
                    switch (nla_afnum) {
-                   case AFNUM_INET:
+                   case AFNUM_IP:
                        if (opt_len != PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(nd_ipv4)) {
                            ND_PRINT("[Bad OPT_PGMCC_FEEDBACK option, length %u != %u + address size]",
                                opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN);
@@ -791,7 +809,7 @@ pgm_print(netdissect_options *ndo,
                        bp += sizeof(nd_ipv4);
                        opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(nd_ipv4);
                        break;
-                   case AFNUM_INET6:
+                   case AFNUM_IP6:
                        if (opt_len != PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(nd_ipv6)) {
                            ND_PRINT("[Bad OPT_PGMCC_FEEDBACK option, length %u != %u + address size]",
                                opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN);
@@ -803,8 +821,7 @@ pgm_print(netdissect_options *ndo,
                        opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(nd_ipv6);
                        break;
                    default:
-                       goto trunc;
-                       break;
+                       goto invalid;
                    }
 
                    ND_PRINT(" PGMCC FEEDBACK %u %s", offset, nla_buf);
@@ -812,7 +829,7 @@ pgm_print(netdissect_options *ndo,
 
                default:
                    ND_PRINT(" OPT_%02X [%u] ", opt_type, opt_len);
-                   bp += opt_len;
+                   bp += opt_len - 2;
                    opts_len -= opt_len;
                    break;
                }
@@ -829,7 +846,6 @@ pgm_print(netdissect_options *ndo,
                                     GET_BE_U_2(pgm->pgm_length));
 
        return;
-
-trunc:
-       nd_print_trunc(ndo);
+invalid:
+       nd_print_invalid(ndo);
 }