X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/da20bc56d6100b5275d6f85c4a25bac1dab4e57e..a63600a1fc28dbc7ae7ce9f996829c49a25fb33c:/print-pgm.c diff --git a/print-pgm.c b/print-pgm.c index 723a074d..3b063ba7 100644 --- a/print-pgm.c +++ b/print-pgm.c @@ -16,11 +16,12 @@ /* \summary: Pragmatic General Multicast (PGM) printer */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif -#include +#include "netdissect-stdinc.h" +#define ND_LONGJMP_FROM_TCHECK #include "netdissect.h" #include "extract.h" #include "addrtoname.h" @@ -35,29 +36,29 @@ * PGM header (RFC 3208) */ struct pgm_header { - uint16_t pgm_sport; - uint16_t pgm_dport; - uint8_t pgm_type; - uint8_t pgm_options; - uint16_t pgm_sum; - uint8_t pgm_gsid[6]; - uint16_t pgm_length; + nd_uint16_t pgm_sport; + nd_uint16_t pgm_dport; + nd_uint8_t pgm_type; + nd_uint8_t pgm_options; + nd_uint16_t pgm_sum; + nd_byte pgm_gsid[6]; + nd_uint16_t pgm_length; }; struct pgm_spm { - uint32_t pgms_seq; - uint32_t pgms_trailseq; - uint32_t pgms_leadseq; - uint16_t pgms_nla_afi; - uint16_t pgms_reserved; + nd_uint32_t pgms_seq; + nd_uint32_t pgms_trailseq; + nd_uint32_t pgms_leadseq; + nd_uint16_t pgms_nla_afi; + nd_uint16_t pgms_reserved; /* ... uint8_t pgms_nla[0]; */ /* ... options */ }; struct pgm_nak { - uint32_t pgmn_seq; - uint16_t pgmn_source_afi; - uint16_t pgmn_reserved; + nd_uint32_t pgmn_seq; + nd_uint16_t pgmn_source_afi; + nd_uint16_t pgmn_reserved; /* ... uint8_t pgmn_source[0]; */ /* ... uint16_t pgmn_group_afi */ /* ... uint16_t pgmn_reserved2; */ @@ -66,31 +67,31 @@ struct pgm_nak { }; struct pgm_ack { - uint32_t pgma_rx_max_seq; - uint32_t pgma_bitmap; + nd_uint32_t pgma_rx_max_seq; + nd_uint32_t pgma_bitmap; /* ... options */ }; struct pgm_poll { - uint32_t pgmp_seq; - uint16_t pgmp_round; - uint16_t pgmp_reserved; + nd_uint32_t pgmp_seq; + nd_uint16_t pgmp_round; + nd_uint16_t pgmp_subtype; + nd_uint16_t pgmp_nla_afi; + nd_uint16_t pgmp_reserved; + /* ... uint8_t pgmp_nla[0]; */ /* ... options */ }; struct pgm_polr { - uint32_t pgmp_seq; - uint16_t pgmp_round; - uint16_t pgmp_subtype; - uint16_t pgmp_nla_afi; - uint16_t pgmp_reserved; - /* ... uint8_t pgmp_nla[0]; */ + nd_uint32_t pgmp_seq; + nd_uint16_t pgmp_round; + nd_uint16_t pgmp_reserved; /* ... options */ }; struct pgm_data { - uint32_t pgmd_seq; - uint32_t pgmd_trailseq; + nd_uint32_t pgmd_seq; + nd_uint32_t pgmd_trailseq; /* ... options */ }; @@ -144,172 +145,170 @@ typedef enum _pgm_type { void pgm_print(netdissect_options *ndo, - register const u_char *bp, register u_int length, - register const u_char *bp2) + const u_char *bp, u_int length, + const u_char *bp2) { - register const struct pgm_header *pgm; - register const struct ip *ip; - register char ch; + const struct pgm_header *pgm; + const struct ip *ip; + uint8_t pgm_type_val; uint16_t sport, dport; u_int nla_afnum; char nla_buf[INET6_ADDRSTRLEN]; - register const struct ip6_hdr *ip6; + const struct ip6_hdr *ip6; uint8_t opt_type, opt_len; uint32_t seq, opts_len, len, offset; + ndo->ndo_protocol = "pgm"; pgm = (const struct pgm_header *)bp; ip = (const struct ip *)bp2; if (IP_V(ip) == 6) ip6 = (const struct ip6_hdr *)bp2; else ip6 = NULL; - ch = '\0'; - if (!ND_TTEST(pgm->pgm_dport)) { + if (!ND_TTEST_2(pgm->pgm_dport)) { if (ip6) { - ND_PRINT((ndo, "%s > %s: [|pgm]", - ip6addr_string(ndo, &ip6->ip6_src), - ip6addr_string(ndo, &ip6->ip6_dst))); + ND_PRINT("%s > %s:", + GET_IP6ADDR_STRING(ip6->ip6_src), + GET_IP6ADDR_STRING(ip6->ip6_dst)); } else { - ND_PRINT((ndo, "%s > %s: [|pgm]", - ipaddr_string(ndo, &ip->ip_src), - ipaddr_string(ndo, &ip->ip_dst))); + ND_PRINT("%s > %s:", + GET_IPADDR_STRING(ip->ip_src), + GET_IPADDR_STRING(ip->ip_dst)); } - return; + nd_trunc_longjmp(ndo); } - sport = EXTRACT_BE_U_2(&pgm->pgm_sport); - dport = EXTRACT_BE_U_2(&pgm->pgm_dport); + sport = GET_BE_U_2(pgm->pgm_sport); + dport = GET_BE_U_2(pgm->pgm_dport); if (ip6) { - if (ip6->ip6_nxt == IPPROTO_PGM) { - ND_PRINT((ndo, "%s.%s > %s.%s: ", - ip6addr_string(ndo, &ip6->ip6_src), + if (GET_U_1(ip6->ip6_nxt) == IPPROTO_PGM) { + ND_PRINT("%s.%s > %s.%s: ", + GET_IP6ADDR_STRING(ip6->ip6_src), tcpport_string(ndo, sport), - ip6addr_string(ndo, &ip6->ip6_dst), - tcpport_string(ndo, dport))); + GET_IP6ADDR_STRING(ip6->ip6_dst), + tcpport_string(ndo, dport)); } else { - ND_PRINT((ndo, "%s > %s: ", - tcpport_string(ndo, sport), tcpport_string(ndo, dport))); + ND_PRINT("%s > %s: ", + tcpport_string(ndo, sport), tcpport_string(ndo, dport)); } } else { - if (ip->ip_p == IPPROTO_PGM) { - ND_PRINT((ndo, "%s.%s > %s.%s: ", - ipaddr_string(ndo, &ip->ip_src), + if (GET_U_1(ip->ip_p) == IPPROTO_PGM) { + ND_PRINT("%s.%s > %s.%s: ", + GET_IPADDR_STRING(ip->ip_src), tcpport_string(ndo, sport), - ipaddr_string(ndo, &ip->ip_dst), - tcpport_string(ndo, dport))); + GET_IPADDR_STRING(ip->ip_dst), + tcpport_string(ndo, dport)); } else { - ND_PRINT((ndo, "%s > %s: ", - tcpport_string(ndo, sport), tcpport_string(ndo, dport))); + ND_PRINT("%s > %s: ", + tcpport_string(ndo, sport), tcpport_string(ndo, dport)); } } - ND_TCHECK(*pgm); + ND_TCHECK_SIZE(pgm); - ND_PRINT((ndo, "PGM, length %u", EXTRACT_BE_U_2(&pgm->pgm_length))); + ND_PRINT("PGM, length %u", GET_BE_U_2(pgm->pgm_length)); if (!ndo->ndo_vflag) return; - ND_PRINT((ndo, " 0x%02x%02x%02x%02x%02x%02x ", + pgm_type_val = GET_U_1(pgm->pgm_type); + ND_PRINT(" 0x%02x%02x%02x%02x%02x%02x ", pgm->pgm_gsid[0], pgm->pgm_gsid[1], pgm->pgm_gsid[2], pgm->pgm_gsid[3], pgm->pgm_gsid[4], - pgm->pgm_gsid[5])); - switch (pgm->pgm_type) { + pgm->pgm_gsid[5]); + switch (pgm_type_val) { case PGM_SPM: { const struct pgm_spm *spm; spm = (const struct pgm_spm *)(pgm + 1); - ND_TCHECK(*spm); + ND_TCHECK_SIZE(spm); bp = (const u_char *) (spm + 1); - switch (EXTRACT_BE_U_2(&spm->pgms_nla_afi)) { - case AFNUM_INET: - ND_TCHECK2(*bp, sizeof(struct in_addr)); + switch (GET_BE_U_2(spm->pgms_nla_afi)) { + case AFNUM_IP: + ND_TCHECK_LEN(bp, sizeof(nd_ipv4)); addrtostr(bp, nla_buf, sizeof(nla_buf)); - bp += sizeof(struct in_addr); + bp += sizeof(nd_ipv4); break; - case AFNUM_INET6: - ND_TCHECK2(*bp, sizeof(struct in6_addr)); + case AFNUM_IP6: + ND_TCHECK_LEN(bp, sizeof(nd_ipv6)); addrtostr6(bp, nla_buf, sizeof(nla_buf)); - bp += sizeof(struct in6_addr); + bp += sizeof(nd_ipv6); break; default: - goto trunc; + goto invalid; break; } - ND_PRINT((ndo, "SPM seq %u trail %u lead %u nla %s", - EXTRACT_BE_U_4(&spm->pgms_seq), - EXTRACT_BE_U_4(&spm->pgms_trailseq), - EXTRACT_BE_U_4(&spm->pgms_leadseq), - nla_buf)); + ND_PRINT("SPM seq %u trail %u lead %u nla %s", + GET_BE_U_4(spm->pgms_seq), + GET_BE_U_4(spm->pgms_trailseq), + GET_BE_U_4(spm->pgms_leadseq), + nla_buf); break; } case PGM_POLL: { - const struct pgm_poll *poll_msg; - - poll_msg = (const struct pgm_poll *)(pgm + 1); - ND_TCHECK(*poll_msg); - ND_PRINT((ndo, "POLL seq %u round %u", - EXTRACT_BE_U_4(&poll_msg->pgmp_seq), - EXTRACT_BE_U_2(&poll_msg->pgmp_round))); - bp = (const u_char *) (poll_msg + 1); - break; - } - case PGM_POLR: { - const struct pgm_polr *polr; + const struct pgm_poll *pgm_poll; uint32_t ivl, rnd, mask; - polr = (const struct pgm_polr *)(pgm + 1); - ND_TCHECK(*polr); - bp = (const u_char *) (polr + 1); + pgm_poll = (const struct pgm_poll *)(pgm + 1); + ND_TCHECK_SIZE(pgm_poll); + bp = (const u_char *) (pgm_poll + 1); - switch (EXTRACT_BE_U_2(&polr->pgmp_nla_afi)) { - case AFNUM_INET: - ND_TCHECK2(*bp, sizeof(struct in_addr)); + switch (GET_BE_U_2(pgm_poll->pgmp_nla_afi)) { + case AFNUM_IP: + ND_TCHECK_LEN(bp, sizeof(nd_ipv4)); addrtostr(bp, nla_buf, sizeof(nla_buf)); - bp += sizeof(struct in_addr); + bp += sizeof(nd_ipv4); break; - case AFNUM_INET6: - ND_TCHECK2(*bp, sizeof(struct in6_addr)); + case AFNUM_IP6: + ND_TCHECK_LEN(bp, sizeof(nd_ipv6)); addrtostr6(bp, nla_buf, sizeof(nla_buf)); - bp += sizeof(struct in6_addr); + bp += sizeof(nd_ipv6); break; default: - goto trunc; + goto invalid; break; } - ND_TCHECK2(*bp, sizeof(uint32_t)); - ivl = EXTRACT_BE_U_4(bp); + ivl = GET_BE_U_4(bp); bp += sizeof(uint32_t); - ND_TCHECK2(*bp, sizeof(uint32_t)); - rnd = EXTRACT_BE_U_4(bp); + rnd = GET_BE_U_4(bp); bp += sizeof(uint32_t); - ND_TCHECK2(*bp, sizeof(uint32_t)); - mask = EXTRACT_BE_U_4(bp); + mask = GET_BE_U_4(bp); bp += sizeof(uint32_t); - ND_PRINT((ndo, "POLR seq %u round %u nla %s ivl %u rnd 0x%08x " - "mask 0x%08x", EXTRACT_BE_U_4(&polr->pgmp_seq), - EXTRACT_BE_U_2(&polr->pgmp_round), nla_buf, ivl, rnd, mask)); + ND_PRINT("POLL seq %u round %u nla %s ivl %u rnd 0x%08x " + "mask 0x%08x", GET_BE_U_4(pgm_poll->pgmp_seq), + GET_BE_U_2(pgm_poll->pgmp_round), nla_buf, ivl, rnd, + mask); + break; + } + case PGM_POLR: { + const struct pgm_polr *polr_msg; + + polr_msg = (const struct pgm_polr *)(pgm + 1); + 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); break; } case PGM_ODATA: { const struct pgm_data *odata; odata = (const struct pgm_data *)(pgm + 1); - ND_TCHECK(*odata); - ND_PRINT((ndo, "ODATA trail %u seq %u", - EXTRACT_BE_U_4(&odata->pgmd_trailseq), - EXTRACT_BE_U_4(&odata->pgmd_seq))); + 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); break; } @@ -318,10 +317,9 @@ pgm_print(netdissect_options *ndo, const struct pgm_data *rdata; rdata = (const struct pgm_data *)(pgm + 1); - ND_TCHECK(*rdata); - ND_PRINT((ndo, "RDATA trail %u seq %u", - EXTRACT_BE_U_4(&rdata->pgmd_trailseq), - EXTRACT_BE_U_4(&rdata->pgmd_seq))); + 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); break; } @@ -333,26 +331,26 @@ pgm_print(netdissect_options *ndo, char source_buf[INET6_ADDRSTRLEN], group_buf[INET6_ADDRSTRLEN]; nak = (const struct pgm_nak *)(pgm + 1); - ND_TCHECK(*nak); + ND_TCHECK_SIZE(nak); bp = (const u_char *) (nak + 1); /* * Skip past the source, saving info along the way * and stopping if we don't have enough. */ - switch (EXTRACT_BE_U_2(&nak->pgmn_source_afi)) { - case AFNUM_INET: - ND_TCHECK2(*bp, sizeof(struct in_addr)); + switch (GET_BE_U_2(nak->pgmn_source_afi)) { + case AFNUM_IP: + ND_TCHECK_LEN(bp, sizeof(nd_ipv4)); addrtostr(bp, source_buf, sizeof(source_buf)); - bp += sizeof(struct in_addr); + bp += sizeof(nd_ipv4); break; - case AFNUM_INET6: - ND_TCHECK2(*bp, sizeof(struct in6_addr)); + case AFNUM_IP6: + ND_TCHECK_LEN(bp, sizeof(nd_ipv6)); addrtostr6(bp, source_buf, sizeof(source_buf)); - bp += sizeof(struct in6_addr); + bp += sizeof(nd_ipv6); break; default: - goto trunc; + goto invalid; break; } @@ -361,41 +359,40 @@ pgm_print(netdissect_options *ndo, * and stopping if we don't have enough. */ bp += (2 * sizeof(uint16_t)); - ND_TCHECK_2(bp); - switch (EXTRACT_BE_U_2(bp)) { - case AFNUM_INET: - ND_TCHECK2(*bp, sizeof(struct in_addr)); + switch (GET_BE_U_2(bp)) { + case AFNUM_IP: + ND_TCHECK_LEN(bp, sizeof(nd_ipv4)); addrtostr(bp, group_buf, sizeof(group_buf)); - bp += sizeof(struct in_addr); + bp += sizeof(nd_ipv4); break; - case AFNUM_INET6: - ND_TCHECK2(*bp, sizeof(struct in6_addr)); + case AFNUM_IP6: + ND_TCHECK_LEN(bp, sizeof(nd_ipv6)); addrtostr6(bp, group_buf, sizeof(group_buf)); - bp += sizeof(struct in6_addr); + bp += sizeof(nd_ipv6); break; default: - goto trunc; + goto invalid; break; } /* * Options decoding can go here. */ - switch (pgm->pgm_type) { + switch (pgm_type_val) { case PGM_NAK: - ND_PRINT((ndo, "NAK ")); + ND_PRINT("NAK "); break; case PGM_NULLNAK: - ND_PRINT((ndo, "NNAK ")); + ND_PRINT("NNAK "); break; case PGM_NCF: - ND_PRINT((ndo, "NCF ")); + ND_PRINT("NCF "); break; default: break; } - ND_PRINT((ndo, "(%s -> %s), seq %u", - source_buf, group_buf, EXTRACT_BE_U_4(&nak->pgmn_seq))); + ND_PRINT("(%s -> %s), seq %u", + source_buf, group_buf, GET_BE_U_4(nak->pgmn_seq)); break; } @@ -403,93 +400,83 @@ pgm_print(netdissect_options *ndo, const struct pgm_ack *ack; ack = (const struct pgm_ack *)(pgm + 1); - ND_TCHECK(*ack); - ND_PRINT((ndo, "ACK seq %u", - EXTRACT_BE_U_4(&ack->pgma_rx_max_seq))); + ND_TCHECK_SIZE(ack); + ND_PRINT("ACK seq %u", + GET_BE_U_4(ack->pgma_rx_max_seq)); bp = (const u_char *) (ack + 1); break; } case PGM_SPMR: - ND_PRINT((ndo, "SPMR")); + ND_PRINT("SPMR"); break; default: - ND_PRINT((ndo, "UNKNOWN type 0x%02x", pgm->pgm_type)); + ND_PRINT("UNKNOWN type 0x%02x", pgm_type_val); break; } - if (pgm->pgm_options & PGM_OPT_BIT_PRESENT) { + if (GET_U_1(pgm->pgm_options) & PGM_OPT_BIT_PRESENT) { /* * make sure there's enough for the first option header */ - if (!ND_TTEST2(*bp, PGM_MIN_OPT_LEN)) { - ND_PRINT((ndo, "[|OPT]")); - return; - } + ND_TCHECK_LEN(bp, PGM_MIN_OPT_LEN); /* * That option header MUST be an OPT_LENGTH option * (see the first paragraph of section 9.1 in RFC 3208). */ - opt_type = EXTRACT_U_1(bp); + opt_type = GET_U_1(bp); bp++; if ((opt_type & PGM_OPT_MASK) != PGM_OPT_LENGTH) { - ND_PRINT((ndo, "[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type & PGM_OPT_MASK)); + ND_PRINT("[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type & PGM_OPT_MASK); return; } - opt_len = EXTRACT_U_1(bp); + opt_len = GET_U_1(bp); bp++; if (opt_len != 4) { - ND_PRINT((ndo, "[Bad OPT_LENGTH option, length %u != 4]", opt_len)); + ND_PRINT("[Bad OPT_LENGTH option, length %u != 4]", opt_len); return; } - opts_len = EXTRACT_BE_U_2(bp); + opts_len = GET_BE_U_2(bp); + bp += sizeof(uint16_t); if (opts_len < 4) { - ND_PRINT((ndo, "[Bad total option length %u < 4]", opts_len)); + ND_PRINT("[Bad total option length %u < 4]", opts_len); return; } - bp += sizeof(uint16_t); - ND_PRINT((ndo, " OPTS LEN %d", opts_len)); + ND_PRINT(" OPTS LEN %u", opts_len); opts_len -= 4; while (opts_len) { if (opts_len < PGM_MIN_OPT_LEN) { - ND_PRINT((ndo, "[Total option length leaves no room for final option]")); + ND_PRINT("[Total option length leaves no room for final option]"); return; } - if (!ND_TTEST2(*bp, 2)) { - ND_PRINT((ndo, " [|OPT]")); - return; - } - opt_type = EXTRACT_U_1(bp); + opt_type = GET_U_1(bp); bp++; - opt_len = EXTRACT_U_1(bp); + opt_len = GET_U_1(bp); bp++; if (opt_len < PGM_MIN_OPT_LEN) { - ND_PRINT((ndo, "[Bad option, length %u < %u]", opt_len, - PGM_MIN_OPT_LEN)); + ND_PRINT("[Bad option, length %u < %u]", opt_len, + PGM_MIN_OPT_LEN); break; } if (opts_len < opt_len) { - ND_PRINT((ndo, "[Total option length leaves no room for final option]")); - return; - } - if (!ND_TTEST2(*bp, opt_len - 2)) { - ND_PRINT((ndo, " [|OPT]")); + ND_PRINT("[Total option length leaves no room for final option]"); return; } + ND_TCHECK_LEN(bp, opt_len - 2); switch (opt_type & PGM_OPT_MASK) { case PGM_OPT_LENGTH: #define PGM_OPT_LENGTH_LEN (2+2) if (opt_len != PGM_OPT_LENGTH_LEN) { - ND_PRINT((ndo, "[Bad OPT_LENGTH option, length %u != %u]", - opt_len, PGM_OPT_LENGTH_LEN)); + ND_PRINT("[Bad OPT_LENGTH option, length %u != %u]", + opt_len, PGM_OPT_LENGTH_LEN); return; } - ND_PRINT((ndo, " OPTS LEN (extra?) %d", EXTRACT_BE_U_2(bp))); + ND_PRINT(" OPTS LEN (extra?) %u", GET_BE_U_2(bp)); bp += 2; opts_len -= PGM_OPT_LENGTH_LEN; break; @@ -497,32 +484,31 @@ pgm_print(netdissect_options *ndo, case PGM_OPT_FRAGMENT: #define PGM_OPT_FRAGMENT_LEN (2+2+4+4+4) if (opt_len != PGM_OPT_FRAGMENT_LEN) { - ND_PRINT((ndo, "[Bad OPT_FRAGMENT option, length %u != %u]", - opt_len, PGM_OPT_FRAGMENT_LEN)); + ND_PRINT("[Bad OPT_FRAGMENT option, length %u != %u]", + opt_len, PGM_OPT_FRAGMENT_LEN); return; } bp += 2; - seq = EXTRACT_BE_U_4(bp); + seq = GET_BE_U_4(bp); bp += 4; - offset = EXTRACT_BE_U_4(bp); + offset = GET_BE_U_4(bp); bp += 4; - len = EXTRACT_BE_U_4(bp); + len = GET_BE_U_4(bp); bp += 4; - ND_PRINT((ndo, " FRAG seq %u off %u len %u", seq, offset, len)); + ND_PRINT(" FRAG seq %u off %u len %u", seq, offset, len); opts_len -= PGM_OPT_FRAGMENT_LEN; break; case PGM_OPT_NAK_LIST: bp += 2; opt_len -= 4; /* option header */ - ND_PRINT((ndo, " NAK LIST")); + ND_PRINT(" NAK LIST"); while (opt_len) { if (opt_len < 4) { - ND_PRINT((ndo, "[Option length not a multiple of 4]")); + ND_PRINT("[Option length not a multiple of 4]"); return; } - ND_TCHECK2(*bp, 4); - ND_PRINT((ndo, " %u", EXTRACT_BE_U_4(bp))); + ND_PRINT(" %u", GET_BE_U_4(bp)); bp += 4; opt_len -= 4; opts_len -= 4; @@ -532,146 +518,146 @@ pgm_print(netdissect_options *ndo, case PGM_OPT_JOIN: #define PGM_OPT_JOIN_LEN (2+2+4) if (opt_len != PGM_OPT_JOIN_LEN) { - ND_PRINT((ndo, "[Bad OPT_JOIN option, length %u != %u]", - opt_len, PGM_OPT_JOIN_LEN)); + ND_PRINT("[Bad OPT_JOIN option, length %u != %u]", + opt_len, PGM_OPT_JOIN_LEN); return; } bp += 2; - seq = EXTRACT_BE_U_4(bp); + seq = GET_BE_U_4(bp); bp += 4; - ND_PRINT((ndo, " JOIN %u", seq)); + ND_PRINT(" JOIN %u", seq); opts_len -= PGM_OPT_JOIN_LEN; break; case PGM_OPT_NAK_BO_IVL: #define PGM_OPT_NAK_BO_IVL_LEN (2+2+4+4) if (opt_len != PGM_OPT_NAK_BO_IVL_LEN) { - ND_PRINT((ndo, "[Bad OPT_NAK_BO_IVL option, length %u != %u]", - opt_len, PGM_OPT_NAK_BO_IVL_LEN)); + ND_PRINT("[Bad OPT_NAK_BO_IVL option, length %u != %u]", + opt_len, PGM_OPT_NAK_BO_IVL_LEN); return; } bp += 2; - offset = EXTRACT_BE_U_4(bp); + offset = GET_BE_U_4(bp); bp += 4; - seq = EXTRACT_BE_U_4(bp); + seq = GET_BE_U_4(bp); bp += 4; - ND_PRINT((ndo, " BACKOFF ivl %u ivlseq %u", offset, seq)); + ND_PRINT(" BACKOFF ivl %u ivlseq %u", offset, seq); opts_len -= PGM_OPT_NAK_BO_IVL_LEN; break; case PGM_OPT_NAK_BO_RNG: #define PGM_OPT_NAK_BO_RNG_LEN (2+2+4+4) if (opt_len != PGM_OPT_NAK_BO_RNG_LEN) { - ND_PRINT((ndo, "[Bad OPT_NAK_BO_RNG option, length %u != %u]", - opt_len, PGM_OPT_NAK_BO_RNG_LEN)); + ND_PRINT("[Bad OPT_NAK_BO_RNG option, length %u != %u]", + opt_len, PGM_OPT_NAK_BO_RNG_LEN); return; } bp += 2; - offset = EXTRACT_BE_U_4(bp); + offset = GET_BE_U_4(bp); bp += 4; - seq = EXTRACT_BE_U_4(bp); + seq = GET_BE_U_4(bp); bp += 4; - ND_PRINT((ndo, " BACKOFF max %u min %u", offset, seq)); + ND_PRINT(" BACKOFF max %u min %u", offset, seq); opts_len -= PGM_OPT_NAK_BO_RNG_LEN; break; case PGM_OPT_REDIRECT: #define PGM_OPT_REDIRECT_FIXED_LEN (2+2+2+2) if (opt_len < PGM_OPT_REDIRECT_FIXED_LEN) { - ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u < %u]", - opt_len, PGM_OPT_REDIRECT_FIXED_LEN)); + ND_PRINT("[Bad OPT_REDIRECT option, length %u < %u]", + opt_len, PGM_OPT_REDIRECT_FIXED_LEN); return; } bp += 2; - nla_afnum = EXTRACT_BE_U_2(bp); + nla_afnum = GET_BE_U_2(bp); bp += 2+2; switch (nla_afnum) { - case AFNUM_INET: - if (opt_len != PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in_addr)) { - ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != %u + address size]", - opt_len, PGM_OPT_REDIRECT_FIXED_LEN)); + 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); return; } - ND_TCHECK2(*bp, sizeof(struct in_addr)); + ND_TCHECK_LEN(bp, sizeof(nd_ipv4)); addrtostr(bp, nla_buf, sizeof(nla_buf)); - bp += sizeof(struct in_addr); - opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in_addr); + bp += sizeof(nd_ipv4); + opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(nd_ipv4); break; - case AFNUM_INET6: - if (opt_len != PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in6_addr)) { - ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != %u + address size]", - PGM_OPT_REDIRECT_FIXED_LEN, opt_len)); + 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]", + opt_len, PGM_OPT_REDIRECT_FIXED_LEN); return; } - ND_TCHECK2(*bp, sizeof(struct in6_addr)); + ND_TCHECK_LEN(bp, sizeof(nd_ipv6)); addrtostr6(bp, nla_buf, sizeof(nla_buf)); - bp += sizeof(struct in6_addr); - opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in6_addr); + bp += sizeof(nd_ipv6); + opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(nd_ipv6); break; default: - goto trunc; + goto invalid; break; } - ND_PRINT((ndo, " REDIRECT %s", nla_buf)); + ND_PRINT(" REDIRECT %s", nla_buf); break; case PGM_OPT_PARITY_PRM: #define PGM_OPT_PARITY_PRM_LEN (2+2+4) if (opt_len != PGM_OPT_PARITY_PRM_LEN) { - ND_PRINT((ndo, "[Bad OPT_PARITY_PRM option, length %u != %u]", - opt_len, PGM_OPT_PARITY_PRM_LEN)); + ND_PRINT("[Bad OPT_PARITY_PRM option, length %u != %u]", + opt_len, PGM_OPT_PARITY_PRM_LEN); return; } bp += 2; - len = EXTRACT_BE_U_4(bp); + len = GET_BE_U_4(bp); bp += 4; - ND_PRINT((ndo, " PARITY MAXTGS %u", len)); + ND_PRINT(" PARITY MAXTGS %u", len); opts_len -= PGM_OPT_PARITY_PRM_LEN; break; case PGM_OPT_PARITY_GRP: #define PGM_OPT_PARITY_GRP_LEN (2+2+4) if (opt_len != PGM_OPT_PARITY_GRP_LEN) { - ND_PRINT((ndo, "[Bad OPT_PARITY_GRP option, length %u != %u]", - opt_len, PGM_OPT_PARITY_GRP_LEN)); + ND_PRINT("[Bad OPT_PARITY_GRP option, length %u != %u]", + opt_len, PGM_OPT_PARITY_GRP_LEN); return; } bp += 2; - seq = EXTRACT_BE_U_4(bp); + seq = GET_BE_U_4(bp); bp += 4; - ND_PRINT((ndo, " PARITY GROUP %u", seq)); + ND_PRINT(" PARITY GROUP %u", seq); opts_len -= PGM_OPT_PARITY_GRP_LEN; break; case PGM_OPT_CURR_TGSIZE: #define PGM_OPT_CURR_TGSIZE_LEN (2+2+4) if (opt_len != PGM_OPT_CURR_TGSIZE_LEN) { - ND_PRINT((ndo, "[Bad OPT_CURR_TGSIZE option, length %u != %u]", - opt_len, PGM_OPT_CURR_TGSIZE_LEN)); + ND_PRINT("[Bad OPT_CURR_TGSIZE option, length %u != %u]", + opt_len, PGM_OPT_CURR_TGSIZE_LEN); return; } bp += 2; - len = EXTRACT_BE_U_4(bp); + len = GET_BE_U_4(bp); bp += 4; - ND_PRINT((ndo, " PARITY ATGS %u", len)); + ND_PRINT(" PARITY ATGS %u", len); opts_len -= PGM_OPT_CURR_TGSIZE_LEN; break; case PGM_OPT_NBR_UNREACH: #define PGM_OPT_NBR_UNREACH_LEN (2+2) if (opt_len != PGM_OPT_NBR_UNREACH_LEN) { - ND_PRINT((ndo, "[Bad OPT_NBR_UNREACH option, length %u != %u]", - opt_len, PGM_OPT_NBR_UNREACH_LEN)); + ND_PRINT("[Bad OPT_NBR_UNREACH option, length %u != %u]", + opt_len, PGM_OPT_NBR_UNREACH_LEN); return; } bp += 2; - ND_PRINT((ndo, " NBR_UNREACH")); + ND_PRINT(" NBR_UNREACH"); opts_len -= PGM_OPT_NBR_UNREACH_LEN; break; case PGM_OPT_PATH_NLA: - ND_PRINT((ndo, " PATH_NLA [%d]", opt_len)); + ND_PRINT(" PATH_NLA [%u]", opt_len); bp += opt_len; opts_len -= opt_len; break; @@ -679,41 +665,41 @@ pgm_print(netdissect_options *ndo, case PGM_OPT_SYN: #define PGM_OPT_SYN_LEN (2+2) if (opt_len != PGM_OPT_SYN_LEN) { - ND_PRINT((ndo, "[Bad OPT_SYN option, length %u != %u]", - opt_len, PGM_OPT_SYN_LEN)); + ND_PRINT("[Bad OPT_SYN option, length %u != %u]", + opt_len, PGM_OPT_SYN_LEN); return; } bp += 2; - ND_PRINT((ndo, " SYN")); + ND_PRINT(" SYN"); opts_len -= PGM_OPT_SYN_LEN; break; case PGM_OPT_FIN: #define PGM_OPT_FIN_LEN (2+2) if (opt_len != PGM_OPT_FIN_LEN) { - ND_PRINT((ndo, "[Bad OPT_FIN option, length %u != %u]", - opt_len, PGM_OPT_FIN_LEN)); + ND_PRINT("[Bad OPT_FIN option, length %u != %u]", + opt_len, PGM_OPT_FIN_LEN); return; } bp += 2; - ND_PRINT((ndo, " FIN")); + ND_PRINT(" FIN"); opts_len -= PGM_OPT_FIN_LEN; break; case PGM_OPT_RST: #define PGM_OPT_RST_LEN (2+2) if (opt_len != PGM_OPT_RST_LEN) { - ND_PRINT((ndo, "[Bad OPT_RST option, length %u != %u]", - opt_len, PGM_OPT_RST_LEN)); + ND_PRINT("[Bad OPT_RST option, length %u != %u]", + opt_len, PGM_OPT_RST_LEN); return; } bp += 2; - ND_PRINT((ndo, " RST")); + ND_PRINT(" RST"); opts_len -= PGM_OPT_RST_LEN; break; case PGM_OPT_CR: - ND_PRINT((ndo, " CR")); + ND_PRINT(" CR"); bp += opt_len; opts_len -= opt_len; break; @@ -721,103 +707,103 @@ pgm_print(netdissect_options *ndo, case PGM_OPT_CRQST: #define PGM_OPT_CRQST_LEN (2+2) if (opt_len != PGM_OPT_CRQST_LEN) { - ND_PRINT((ndo, "[Bad OPT_CRQST option, length %u != %u]", - opt_len, PGM_OPT_CRQST_LEN)); + ND_PRINT("[Bad OPT_CRQST option, length %u != %u]", + opt_len, PGM_OPT_CRQST_LEN); return; } bp += 2; - ND_PRINT((ndo, " CRQST")); + ND_PRINT(" CRQST"); opts_len -= PGM_OPT_CRQST_LEN; break; case PGM_OPT_PGMCC_DATA: #define PGM_OPT_PGMCC_DATA_FIXED_LEN (2+2+4+2+2) if (opt_len < PGM_OPT_PGMCC_DATA_FIXED_LEN) { - ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u < %u]", - opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN)); + ND_PRINT("[Bad OPT_PGMCC_DATA option, length %u < %u]", + opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN); return; } bp += 2; - offset = EXTRACT_BE_U_4(bp); + offset = GET_BE_U_4(bp); bp += 4; - nla_afnum = EXTRACT_BE_U_2(bp); + nla_afnum = GET_BE_U_2(bp); bp += 2+2; switch (nla_afnum) { - case AFNUM_INET: - if (opt_len != PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in_addr)) { - ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != %u + address size]", - opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN)); + 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); return; } - ND_TCHECK2(*bp, sizeof(struct in_addr)); + ND_TCHECK_LEN(bp, sizeof(nd_ipv4)); addrtostr(bp, nla_buf, sizeof(nla_buf)); - bp += sizeof(struct in_addr); - opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in_addr); + bp += sizeof(nd_ipv4); + opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(nd_ipv4); break; - case AFNUM_INET6: - if (opt_len != PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in6_addr)) { - ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != %u + address size]", - opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN)); + 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); return; } - ND_TCHECK2(*bp, sizeof(struct in6_addr)); + ND_TCHECK_LEN(bp, sizeof(nd_ipv6)); addrtostr6(bp, nla_buf, sizeof(nla_buf)); - bp += sizeof(struct in6_addr); - opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in6_addr); + bp += sizeof(nd_ipv6); + opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(nd_ipv6); break; default: - goto trunc; + goto invalid; break; } - ND_PRINT((ndo, " PGMCC DATA %u %s", offset, nla_buf)); + ND_PRINT(" PGMCC DATA %u %s", offset, nla_buf); break; case PGM_OPT_PGMCC_FEEDBACK: #define PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN (2+2+4+2+2) if (opt_len < PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN) { - ND_PRINT((ndo, "[Bad PGM_OPT_PGMCC_FEEDBACK option, length %u < %u]", - opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN)); + ND_PRINT("[Bad PGM_OPT_PGMCC_FEEDBACK option, length %u < %u]", + opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN); return; } bp += 2; - offset = EXTRACT_BE_U_4(bp); + offset = GET_BE_U_4(bp); bp += 4; - nla_afnum = EXTRACT_BE_U_2(bp); + nla_afnum = GET_BE_U_2(bp); bp += 2+2; switch (nla_afnum) { - case AFNUM_INET: - if (opt_len != PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in_addr)) { - ND_PRINT((ndo, "[Bad OPT_PGMCC_FEEDBACK option, length %u != %u + address size]", - opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN)); + 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); return; } - ND_TCHECK2(*bp, sizeof(struct in_addr)); + ND_TCHECK_LEN(bp, sizeof(nd_ipv4)); addrtostr(bp, nla_buf, sizeof(nla_buf)); - bp += sizeof(struct in_addr); - opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in_addr); + bp += sizeof(nd_ipv4); + opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(nd_ipv4); break; - case AFNUM_INET6: - if (opt_len != PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in6_addr)) { - ND_PRINT((ndo, "[Bad OPT_PGMCC_FEEDBACK option, length %u != %u + address size]", - opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN)); + 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); return; } - ND_TCHECK2(*bp, sizeof(struct in6_addr)); + ND_TCHECK_LEN(bp, sizeof(nd_ipv6)); addrtostr6(bp, nla_buf, sizeof(nla_buf)); - bp += sizeof(struct in6_addr); - opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in6_addr); + bp += sizeof(nd_ipv6); + opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(nd_ipv6); break; default: - goto trunc; + goto invalid; break; } - ND_PRINT((ndo, " PGMCC FEEDBACK %u %s", offset, nla_buf)); + ND_PRINT(" PGMCC FEEDBACK %u %s", offset, nla_buf); break; default: - ND_PRINT((ndo, " OPT_%02X [%d] ", opt_type, opt_len)); + ND_PRINT(" OPT_%02X [%u] ", opt_type, opt_len); bp += opt_len; opts_len -= opt_len; break; @@ -828,16 +814,13 @@ pgm_print(netdissect_options *ndo, } } - ND_PRINT((ndo, " [%u]", length)); + ND_PRINT(" [%u]", length); if (ndo->ndo_packettype == PT_PGM_ZMTP1 && - (pgm->pgm_type == PGM_ODATA || pgm->pgm_type == PGM_RDATA)) + (pgm_type_val == PGM_ODATA || pgm_type_val == PGM_RDATA)) zmtp1_datagram_print(ndo, bp, - EXTRACT_BE_U_2(&pgm->pgm_length)); + GET_BE_U_2(pgm->pgm_length)); return; - -trunc: - ND_PRINT((ndo, "[|pgm]")); - if (ch != '\0') - ND_PRINT((ndo, ">")); +invalid: + nd_print_invalid(ndo); }