X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/f9b3c51da6c9454af79601666b5afe705901c126..de0c7fc746c37eb83e15a6890d30dc6f608e9d76:/print-mpcp.c diff --git a/print-mpcp.c b/print-mpcp.c index a61e0531..4dc92bbc 100644 --- a/print-mpcp.c +++ b/print-mpcp.c @@ -12,16 +12,16 @@ * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * - * support for the IEEE MPCP protocol as per 802.3ah - * - * Original code by Hannes Gredler (hannes@juniper.net) + * Original code by Hannes Gredler (hannes@gredler.at) */ +/* \summary: IEEE 802.3ah Multi-Point Control Protocol (MPCP) printer */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include "netdissect.h" #include "extract.h" @@ -30,8 +30,8 @@ #define MPCP_TIMESTAMP_DURATION_LEN 2 struct mpcp_common_header_t { - u_int8_t opcode[2]; - u_int8_t timestamp[MPCP_TIMESTAMP_LEN]; + uint8_t opcode[2]; + uint8_t timestamp[MPCP_TIMESTAMP_LEN]; }; #define MPCP_OPCODE_PAUSE 0x0001 @@ -63,13 +63,13 @@ static const struct tok mpcp_grant_flag_values[] = { }; struct mpcp_grant_t { - u_int8_t starttime[MPCP_TIMESTAMP_LEN]; - u_int8_t duration[MPCP_TIMESTAMP_DURATION_LEN]; + uint8_t starttime[MPCP_TIMESTAMP_LEN]; + uint8_t duration[MPCP_TIMESTAMP_DURATION_LEN]; }; struct mpcp_reg_req_t { - u_int8_t flags; - u_int8_t pending_grants; + uint8_t flags; + uint8_t pending_grants; }; @@ -80,10 +80,10 @@ static const struct tok mpcp_reg_req_flag_values[] = { }; struct mpcp_reg_t { - u_int8_t assigned_port[2]; - u_int8_t flags; - u_int8_t sync_time[MPCP_TIMESTAMP_DURATION_LEN]; - u_int8_t echoed_pending_grants; + uint8_t assigned_port[2]; + uint8_t flags; + uint8_t sync_time[MPCP_TIMESTAMP_DURATION_LEN]; + uint8_t echoed_pending_grants; }; static const struct tok mpcp_reg_flag_values[] = { @@ -109,9 +109,9 @@ static const struct tok mpcp_report_bitmap_values[] = { }; struct mpcp_reg_ack_t { - u_int8_t flags; - u_int8_t echoed_assigned_port[2]; - u_int8_t echoed_sync_time[MPCP_TIMESTAMP_DURATION_LEN]; + uint8_t flags; + uint8_t echoed_assigned_port[2]; + uint8_t echoed_sync_time[MPCP_TIMESTAMP_DURATION_LEN]; }; static const struct tok mpcp_reg_ack_flag_values[] = { @@ -121,8 +121,8 @@ static const struct tok mpcp_reg_ack_flag_values[] = { }; void -mpcp_print(netdissect_options *ndo, register const u_char *pptr, register u_int length) { - +mpcp_print(netdissect_options *ndo, register const u_char *pptr, register u_int length) +{ union { const struct mpcp_common_header_t *common_header; const struct mpcp_grant_t *grant; @@ -133,69 +133,63 @@ mpcp_print(netdissect_options *ndo, register const u_char *pptr, register u_int const u_char *tptr; - u_int16_t opcode; - u_int8_t grant_numbers, grant; - u_int8_t queue_sets, queue_set, report_bitmap, report; + uint16_t opcode; + uint8_t grant_numbers, grant; + uint8_t queue_sets, queue_set, report_bitmap, report; tptr=pptr; mpcp.common_header = (const struct mpcp_common_header_t *)pptr; - if (!ND_TTEST2(*tptr, sizeof(const struct mpcp_common_header_t))) - goto trunc; - opcode = EXTRACT_16BITS(mpcp.common_header->opcode); + ND_TCHECK2(*tptr, sizeof(struct mpcp_common_header_t)); + opcode = EXTRACT_BE_U_2(mpcp.common_header->opcode); ND_PRINT((ndo, "MPCP, Opcode %s", tok2str(mpcp_opcode_values, "Unknown (%u)", opcode))); if (opcode != MPCP_OPCODE_PAUSE) { - ND_PRINT((ndo, ", Timestamp %u ticks", EXTRACT_32BITS(mpcp.common_header->timestamp))); + ND_PRINT((ndo, ", Timestamp %u ticks", EXTRACT_BE_U_4(mpcp.common_header->timestamp))); } ND_PRINT((ndo, ", length %u", length)); if (!ndo->ndo_vflag) return; - tptr += sizeof(const struct mpcp_common_header_t); + tptr += sizeof(struct mpcp_common_header_t); switch (opcode) { case MPCP_OPCODE_PAUSE: break; case MPCP_OPCODE_GATE: - if (!ND_TTEST2(*tptr, MPCP_GRANT_NUMBER_LEN)) - goto trunc; - grant_numbers = *tptr & MPCP_GRANT_NUMBER_MASK; + ND_TCHECK2(*tptr, MPCP_GRANT_NUMBER_LEN); + grant_numbers = EXTRACT_U_1(tptr) & MPCP_GRANT_NUMBER_MASK; ND_PRINT((ndo, "\n\tGrant Numbers %u, Flags [ %s ]", grant_numbers, bittok2str(mpcp_grant_flag_values, "?", - *tptr &~ MPCP_GRANT_NUMBER_MASK))); + EXTRACT_U_1(tptr) & ~MPCP_GRANT_NUMBER_MASK))); tptr++; for (grant = 1; grant <= grant_numbers; grant++) { - if (!ND_TTEST2(*tptr, sizeof(const struct mpcp_grant_t))) - goto trunc; + ND_TCHECK2(*tptr, sizeof(struct mpcp_grant_t)); mpcp.grant = (const struct mpcp_grant_t *)tptr; ND_PRINT((ndo, "\n\tGrant #%u, Start-Time %u ticks, duration %u ticks", grant, - EXTRACT_32BITS(mpcp.grant->starttime), - EXTRACT_16BITS(mpcp.grant->duration))); - tptr += sizeof(const struct mpcp_grant_t); + EXTRACT_BE_U_4(mpcp.grant->starttime), + EXTRACT_BE_U_2(mpcp.grant->duration))); + tptr += sizeof(struct mpcp_grant_t); } - if (!ND_TTEST2(*tptr, MPCP_TIMESTAMP_DURATION_LEN)) - goto trunc; - ND_PRINT((ndo, "\n\tSync-Time %u ticks", EXTRACT_16BITS(tptr))); + ND_TCHECK2(*tptr, MPCP_TIMESTAMP_DURATION_LEN); + ND_PRINT((ndo, "\n\tSync-Time %u ticks", EXTRACT_BE_U_2(tptr))); break; case MPCP_OPCODE_REPORT: - if (!ND_TTEST2(*tptr, MPCP_REPORT_QUEUESETS_LEN)) - goto trunc; + ND_TCHECK2(*tptr, MPCP_REPORT_QUEUESETS_LEN); queue_sets = *tptr; tptr+=MPCP_REPORT_QUEUESETS_LEN; ND_PRINT((ndo, "\n\tTotal Queue-Sets %u", queue_sets)); for (queue_set = 1; queue_set < queue_sets; queue_set++) { - if (!ND_TTEST2(*tptr, MPCP_REPORT_REPORTBITMAP_LEN)) - goto trunc; + ND_TCHECK2(*tptr, MPCP_REPORT_REPORTBITMAP_LEN); report_bitmap = *(tptr); ND_PRINT((ndo, "\n\t Queue-Set #%u, Report-Bitmap [ %s ]", queue_sets, @@ -205,11 +199,10 @@ mpcp_print(netdissect_options *ndo, register const u_char *pptr, register u_int report=1; while (report_bitmap != 0) { if (report_bitmap & 1) { - if (!ND_TTEST2(*tptr, MPCP_TIMESTAMP_DURATION_LEN)) - goto trunc; + ND_TCHECK2(*tptr, MPCP_TIMESTAMP_DURATION_LEN); ND_PRINT((ndo, "\n\t Q%u Report, Duration %u ticks", report, - EXTRACT_16BITS(tptr))); + EXTRACT_BE_U_2(tptr))); tptr+=MPCP_TIMESTAMP_DURATION_LEN; } report++; @@ -219,8 +212,7 @@ mpcp_print(netdissect_options *ndo, register const u_char *pptr, register u_int break; case MPCP_OPCODE_REG_REQ: - if (!ND_TTEST2(*tptr, sizeof(const struct mpcp_reg_req_t))) - goto trunc; + ND_TCHECK2(*tptr, sizeof(struct mpcp_reg_req_t)); mpcp.reg_req = (const struct mpcp_reg_req_t *)tptr; ND_PRINT((ndo, "\n\tFlags [ %s ], Pending-Grants %u", bittok2str(mpcp_reg_req_flag_values, "Reserved", mpcp.reg_req->flags), @@ -228,26 +220,24 @@ mpcp_print(netdissect_options *ndo, register const u_char *pptr, register u_int break; case MPCP_OPCODE_REG: - if (!ND_TTEST2(*tptr, sizeof(const struct mpcp_reg_t))) - goto trunc; + ND_TCHECK2(*tptr, sizeof(struct mpcp_reg_t)); mpcp.reg = (const struct mpcp_reg_t *)tptr; ND_PRINT((ndo, "\n\tAssigned-Port %u, Flags [ %s ]" \ "\n\tSync-Time %u ticks, Echoed-Pending-Grants %u", - EXTRACT_16BITS(mpcp.reg->assigned_port), + EXTRACT_BE_U_2(mpcp.reg->assigned_port), bittok2str(mpcp_reg_flag_values, "Reserved", mpcp.reg->flags), - EXTRACT_16BITS(mpcp.reg->sync_time), + EXTRACT_BE_U_2(mpcp.reg->sync_time), mpcp.reg->echoed_pending_grants)); break; case MPCP_OPCODE_REG_ACK: - if (!ND_TTEST2(*tptr, sizeof(const struct mpcp_reg_ack_t))) - goto trunc; + ND_TCHECK2(*tptr, sizeof(struct mpcp_reg_ack_t)); mpcp.reg_ack = (const struct mpcp_reg_ack_t *)tptr; ND_PRINT((ndo, "\n\tEchoed-Assigned-Port %u, Flags [ %s ]" \ "\n\tEchoed-Sync-Time %u ticks", - EXTRACT_16BITS(mpcp.reg_ack->echoed_assigned_port), + EXTRACT_BE_U_2(mpcp.reg_ack->echoed_assigned_port), bittok2str(mpcp_reg_ack_flag_values, "Reserved", mpcp.reg_ack->flags), - EXTRACT_16BITS(mpcp.reg_ack->echoed_sync_time))); + EXTRACT_BE_U_2(mpcp.reg_ack->echoed_sync_time))); break; default: