X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/fe1c2f0d7fb9221936b0d54a670b9f2eea2b72c4..66f29e001c608bf8ca3ed25f492fbd88e23e1b5e:/print-rx.c diff --git a/print-rx.c b/print-rx.c index 9783d55b..d4ca5094 100644 --- a/print-rx.c +++ b/print-rx.c @@ -112,15 +112,18 @@ struct rx_header { #define RX_MAXACKS 255 struct rx_ackPacket { - uint16_t bufferSpace; /* Number of packet buffers available */ - uint16_t maxSkew; /* Max diff between ack'd packet and */ + nd_uint16_t bufferSpace; /* Number of packet buffers available */ + nd_uint16_t maxSkew; /* Max diff between ack'd packet and */ /* highest packet received */ - uint32_t firstPacket; /* The first packet in ack list */ - uint32_t previousPacket; /* Previous packet recv'd (obsolete) */ - uint32_t serial; /* # of packet that prompted the ack */ - uint8_t reason; /* Reason for acknowledgement */ - uint8_t nAcks; /* Number of acknowledgements */ + nd_uint32_t firstPacket; /* The first packet in ack list */ + nd_uint32_t previousPacket; /* Previous packet recv'd (obsolete) */ + nd_uint32_t serial; /* # of packet that prompted the ack */ + nd_uint8_t reason; /* Reason for acknowledgement */ + nd_uint8_t nAcks; /* Number of acknowledgements */ + /* Followed by nAcks acknowledgments */ +#if 0 uint8_t acks[RX_MAXACKS]; /* Up to RX_MAXACKS acknowledgements */ +#endif }; /* @@ -523,44 +526,47 @@ static int is_ubik(uint32_t); void rx_print(netdissect_options *ndo, - register const u_char *bp, u_int length, u_int sport, u_int dport, + const u_char *bp, u_int length, u_int sport, u_int dport, const u_char *bp2) { - register const struct rx_header *rxh; + const struct rx_header *rxh; uint32_t i; + uint8_t type, flags; uint32_t opcode; - if (!ND_TTEST2(*bp, sizeof (struct rx_header))) { + if (!ND_TTEST_LEN(bp, sizeof(struct rx_header))) { ND_PRINT((ndo, " [|rx] (%u)", length)); return; } rxh = (const struct rx_header *) bp; - ND_PRINT((ndo, " rx %s", tok2str(rx_types, "type %u", rxh->type))); + type = EXTRACT_U_1(rxh->type); + ND_PRINT((ndo, " rx %s", tok2str(rx_types, "type %u", type))); + flags = EXTRACT_U_1(rxh->flags); if (ndo->ndo_vflag) { int firstflag = 0; if (ndo->ndo_vflag > 1) ND_PRINT((ndo, " cid %08x call# %u", - EXTRACT_BE_32BITS(&rxh->cid), - EXTRACT_BE_32BITS(&rxh->callNumber))); + EXTRACT_BE_U_4(rxh->cid), + EXTRACT_BE_U_4(rxh->callNumber))); ND_PRINT((ndo, " seq %u ser %u", - EXTRACT_BE_32BITS(&rxh->seq), - EXTRACT_BE_32BITS(&rxh->serial))); + EXTRACT_BE_U_4(rxh->seq), + EXTRACT_BE_U_4(rxh->serial))); if (ndo->ndo_vflag > 2) ND_PRINT((ndo, " secindex %u serviceid %hu", - rxh->securityIndex, - EXTRACT_BE_16BITS(&rxh->serviceId))); + EXTRACT_U_1(rxh->securityIndex), + EXTRACT_BE_U_2(rxh->serviceId))); if (ndo->ndo_vflag > 1) for (i = 0; i < NUM_RX_FLAGS; i++) { - if (rxh->flags & rx_flags[i].flag && + if (flags & rx_flags[i].flag && (!rx_flags[i].packetType || - rxh->type == rx_flags[i].packetType)) { + type == rx_flags[i].packetType)) { if (!firstflag) { firstflag = 1; ND_PRINT((ndo, " ")); @@ -581,9 +587,9 @@ rx_print(netdissect_options *ndo, * as well. */ - if (rxh->type == RX_PACKET_TYPE_DATA && - EXTRACT_BE_32BITS(&rxh->seq) == 1 && - rxh->flags & RX_CLIENT_INITIATED) { + if (type == RX_PACKET_TYPE_DATA && + EXTRACT_BE_U_4(rxh->seq) == 1 && + flags & RX_CLIENT_INITIATED) { /* * Insert this call into the call cache table, so we @@ -625,10 +631,10 @@ rx_print(netdissect_options *ndo, * because printing out the return code can be useful at times. */ - } else if (((rxh->type == RX_PACKET_TYPE_DATA && - EXTRACT_BE_32BITS(&rxh->seq) == 1) || - rxh->type == RX_PACKET_TYPE_ABORT) && - (rxh->flags & RX_CLIENT_INITIATED) == 0 && + } else if (((type == RX_PACKET_TYPE_DATA && + EXTRACT_BE_U_4(rxh->seq) == 1) || + type == RX_PACKET_TYPE_ABORT) && + (flags & RX_CLIENT_INITIATED) == 0 && rx_cache_find(rxh, (const struct ip *) bp2, sport, &opcode)) { @@ -664,7 +670,7 @@ rx_print(netdissect_options *ndo, * ack packet, so we can use one for all AFS services) */ - } else if (rxh->type == RX_PACKET_TYPE_ACK) + } else if (type == RX_PACKET_TYPE_ACK) rx_ack_print(ndo, bp, length); @@ -682,7 +688,7 @@ rx_cache_insert(netdissect_options *ndo, struct rx_cache_entry *rxent; const struct rx_header *rxh = (const struct rx_header *) bp; - if (!ND_TTEST_32BITS(bp + sizeof(struct rx_header))) + if (!ND_TTEST_4(bp + sizeof(struct rx_header))) return; rxent = &rx_cache[rx_cache_next]; @@ -690,12 +696,12 @@ rx_cache_insert(netdissect_options *ndo, if (++rx_cache_next >= RX_CACHE_SIZE) rx_cache_next = 0; - rxent->callnum = EXTRACT_BE_32BITS(&rxh->callNumber); + rxent->callnum = EXTRACT_BE_U_4(rxh->callNumber); UNALIGNED_MEMCPY(&rxent->client, &ip->ip_src, sizeof(uint32_t)); UNALIGNED_MEMCPY(&rxent->server, &ip->ip_dst, sizeof(uint32_t)); rxent->dport = dport; - rxent->serviceId = EXTRACT_BE_32BITS(&rxh->serviceId); - rxent->opcode = EXTRACT_BE_32BITS(bp + sizeof(struct rx_header)); + rxent->serviceId = EXTRACT_BE_U_4(rxh->serviceId); + rxent->opcode = EXTRACT_BE_U_4(bp + sizeof(struct rx_header)); } /* @@ -722,10 +728,10 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, u_int sport, i = rx_cache_hint; do { rxent = &rx_cache[i]; - if (rxent->callnum == EXTRACT_BE_32BITS(&rxh->callNumber) && + if (rxent->callnum == EXTRACT_BE_U_4(rxh->callNumber) && rxent->client.s_addr == clip && rxent->server.s_addr == sip && - rxent->serviceId == EXTRACT_BE_32BITS(&rxh->serviceId) && + rxent->serviceId == EXTRACT_BE_U_4(rxh->serviceId) && rxent->dport == sport) { /* We got a match! */ @@ -747,19 +753,19 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, u_int sport, */ #define FIDOUT() { uint32_t n1, n2, n3; \ - ND_TCHECK2(bp[0], sizeof(uint32_t) * 3); \ - n1 = EXTRACT_BE_32BITS(bp); \ + ND_TCHECK_LEN(bp, sizeof(uint32_t) * 3); \ + n1 = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ - n2 = EXTRACT_BE_32BITS(bp); \ + n2 = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ - n3 = EXTRACT_BE_32BITS(bp); \ + n3 = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ ND_PRINT((ndo, " fid %u/%u/%u", n1, n2, n3)); \ } #define STROUT(MAX) { uint32_t _i; \ - ND_TCHECK2(bp[0], sizeof(uint32_t)); \ - _i = EXTRACT_BE_32BITS(bp); \ + ND_TCHECK_LEN(bp, sizeof(uint32_t)); \ + _i = EXTRACT_BE_U_4(bp); \ if (_i > (MAX)) \ goto trunc; \ bp += sizeof(uint32_t); \ @@ -771,29 +777,29 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, u_int sport, } #define INTOUT() { int32_t _i; \ - ND_TCHECK_32BITS(bp); \ - _i = EXTRACT_BE_INT32(bp); \ + ND_TCHECK_4(bp); \ + _i = EXTRACT_BE_S_4(bp); \ bp += sizeof(int32_t); \ ND_PRINT((ndo, " %d", _i)); \ } #define UINTOUT() { uint32_t _i; \ - ND_TCHECK_32BITS(bp); \ - _i = EXTRACT_BE_32BITS(bp); \ + ND_TCHECK_4(bp); \ + _i = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ ND_PRINT((ndo, " %u", _i)); \ } #define UINT64OUT() { uint64_t _i; \ - ND_TCHECK2(bp[0], sizeof(uint64_t)); \ - _i = EXTRACT_BE_64BITS(bp); \ + ND_TCHECK_LEN(bp, sizeof(uint64_t)); \ + _i = EXTRACT_BE_U_8(bp); \ bp += sizeof(uint64_t); \ ND_PRINT((ndo, " %" PRIu64, _i)); \ } #define DATEOUT() { time_t _t; struct tm *tm; char str[256]; \ - ND_TCHECK_32BITS(bp); \ - _t = (time_t) EXTRACT_BE_INT32(bp); \ + ND_TCHECK_4(bp); \ + _t = (time_t) EXTRACT_BE_S_4(bp); \ bp += sizeof(int32_t); \ tm = localtime(&_t); \ strftime(str, 256, "%Y/%m/%d %H:%M:%S", tm); \ @@ -801,45 +807,45 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, u_int sport, } #define STOREATTROUT() { uint32_t mask, _i; \ - ND_TCHECK2(bp[0], (sizeof(uint32_t)*6)); \ - mask = EXTRACT_BE_32BITS(bp); bp += sizeof(uint32_t); \ + ND_TCHECK_LEN(bp, (sizeof(uint32_t) * 6)); \ + mask = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); \ if (mask) ND_PRINT((ndo, " StoreStatus")); \ if (mask & 1) { ND_PRINT((ndo, " date")); DATEOUT(); } \ else bp += sizeof(uint32_t); \ - _i = EXTRACT_BE_32BITS(bp); bp += sizeof(uint32_t); \ + _i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); \ if (mask & 2) ND_PRINT((ndo, " owner %u", _i)); \ - _i = EXTRACT_BE_32BITS(bp); bp += sizeof(uint32_t); \ + _i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); \ if (mask & 4) ND_PRINT((ndo, " group %u", _i)); \ - _i = EXTRACT_BE_32BITS(bp); bp += sizeof(uint32_t); \ + _i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); \ if (mask & 8) ND_PRINT((ndo, " mode %o", _i & 07777)); \ - _i = EXTRACT_BE_32BITS(bp); bp += sizeof(uint32_t); \ + _i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); \ if (mask & 16) ND_PRINT((ndo, " segsize %u", _i)); \ /* undocumented in 3.3 docu */ \ if (mask & 1024) ND_PRINT((ndo, " fsync")); \ } #define UBIK_VERSIONOUT() {uint32_t epoch; uint32_t counter; \ - ND_TCHECK2(bp[0], sizeof(uint32_t) * 2); \ - epoch = EXTRACT_BE_32BITS(bp); \ + ND_TCHECK_LEN(bp, sizeof(uint32_t) * 2); \ + epoch = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ - counter = EXTRACT_BE_32BITS(bp); \ + counter = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ ND_PRINT((ndo, " %u.%u", epoch, counter)); \ } #define AFSUUIDOUT() {uint32_t temp; int _i; \ - ND_TCHECK2(bp[0], 11*sizeof(uint32_t)); \ - temp = EXTRACT_BE_32BITS(bp); \ + ND_TCHECK_LEN(bp, 11 * sizeof(uint32_t)); \ + temp = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ ND_PRINT((ndo, " %08x", temp)); \ - temp = EXTRACT_BE_32BITS(bp); \ + temp = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ ND_PRINT((ndo, "%04x", temp)); \ - temp = EXTRACT_BE_32BITS(bp); \ + temp = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ ND_PRINT((ndo, "%04x", temp)); \ for (_i = 0; _i < 8; _i++) { \ - temp = EXTRACT_BE_32BITS(bp); \ + temp = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ ND_PRINT((ndo, "%02x", (unsigned char) temp)); \ } \ @@ -854,10 +860,10 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, u_int sport, uint32_t k; \ if ((MAX) + 1 > sizeof(s)) \ goto trunc; \ - ND_TCHECK2(bp[0], (MAX) * sizeof(uint32_t)); \ + ND_TCHECK_LEN(bp, (MAX) * sizeof(uint32_t)); \ sp = s; \ for (k = 0; k < (MAX); k++) { \ - *sp++ = (u_char) EXTRACT_BE_32BITS(bp); \ + *sp++ = (u_char) EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ } \ s[(MAX)] = '\0'; \ @@ -867,12 +873,12 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, u_int sport, } #define DESTSERVEROUT() { uint32_t n1, n2, n3; \ - ND_TCHECK2(bp[0], sizeof(uint32_t) * 3); \ - n1 = EXTRACT_BE_32BITS(bp); \ + ND_TCHECK_LEN(bp, sizeof(uint32_t) * 3); \ + n1 = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ - n2 = EXTRACT_BE_32BITS(bp); \ + n2 = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ - n3 = EXTRACT_BE_32BITS(bp); \ + n3 = EXTRACT_BE_U_4(bp); \ bp += sizeof(uint32_t); \ ND_PRINT((ndo, " server %u:%u:%u", n1, n2, n3)); \ } @@ -883,7 +889,7 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, u_int sport, static void fs_print(netdissect_options *ndo, - register const u_char *bp, u_int length) + const u_char *bp, u_int length) { uint32_t fs_op; uint32_t i; @@ -896,8 +902,8 @@ fs_print(netdissect_options *ndo, * gleaned from fsint/afsint.xg */ - ND_TCHECK_32BITS(bp + sizeof(struct rx_header)); - fs_op = EXTRACT_BE_32BITS(bp + sizeof(struct rx_header)); + ND_TCHECK_4(bp + sizeof(struct rx_header)); + fs_op = EXTRACT_BE_U_4(bp + sizeof(struct rx_header)); ND_PRINT((ndo, " fs call %s", tok2str(fs_req, "op#%u", fs_op))); @@ -948,10 +954,10 @@ fs_print(netdissect_options *ndo, { char a[AFSOPAQUEMAX+1]; FIDOUT(); - ND_TCHECK2(bp[0], 4); - i = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); - ND_TCHECK2(bp[0], i); + ND_TCHECK_LEN(bp, i); i = min(AFSOPAQUEMAX, i); strncpy(a, (const char *) bp, i); a[i] = '\0'; @@ -1005,8 +1011,8 @@ fs_print(netdissect_options *ndo, case 65536: /* Inline bulk stat */ { uint32_t j; - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); for (i = 0; i < j; i++) { @@ -1053,10 +1059,11 @@ trunc: static void fs_reply_print(netdissect_options *ndo, - register const u_char *bp, u_int length, uint32_t opcode) + const u_char *bp, u_int length, uint32_t opcode) { uint32_t i; const struct rx_header *rxh; + uint8_t type; if (length <= sizeof(struct rx_header)) return; @@ -1070,21 +1077,22 @@ fs_reply_print(netdissect_options *ndo, ND_PRINT((ndo, " fs reply %s", tok2str(fs_req, "op#%u", opcode))); + type = EXTRACT_U_1(rxh->type); bp += sizeof(struct rx_header); /* * If it was a data packet, interpret the response */ - if (rxh->type == RX_PACKET_TYPE_DATA) { + if (type == RX_PACKET_TYPE_DATA) { switch (opcode) { case 131: /* Fetch ACL */ { char a[AFSOPAQUEMAX+1]; - ND_TCHECK_32BITS(bp); - i = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); - ND_TCHECK2(bp[0], i); + ND_TCHECK_LEN(bp, i); i = min(AFSOPAQUEMAX, i); strncpy(a, (const char *) bp, i); a[i] = '\0'; @@ -1106,19 +1114,19 @@ fs_reply_print(netdissect_options *ndo, default: ; } - } else if (rxh->type == RX_PACKET_TYPE_ABORT) { + } else if (type == RX_PACKET_TYPE_ABORT) { /* * Otherwise, just print out the return code */ int32_t errcode; - ND_TCHECK_32BITS(bp); - errcode = EXTRACT_BE_INT32(bp); + ND_TCHECK_4(bp); + errcode = EXTRACT_BE_S_4(bp); bp += sizeof(int32_t); ND_PRINT((ndo, " error %s", tok2str(afs_fs_errors, "#%d", errcode))); } else { - ND_PRINT((ndo, " strange fs reply of type %u", rxh->type)); + ND_PRINT((ndo, " strange fs reply of type %u", type)); } return; @@ -1216,7 +1224,7 @@ finish: static void cb_print(netdissect_options *ndo, - register const u_char *bp, u_int length) + const u_char *bp, u_int length) { uint32_t cb_op; uint32_t i; @@ -1229,8 +1237,8 @@ cb_print(netdissect_options *ndo, * gleaned from fsint/afscbint.xg */ - ND_TCHECK_32BITS(bp + sizeof(struct rx_header)); - cb_op = EXTRACT_BE_32BITS(bp + sizeof(struct rx_header)); + ND_TCHECK_4(bp + sizeof(struct rx_header)); + cb_op = EXTRACT_BE_U_4(bp + sizeof(struct rx_header)); ND_PRINT((ndo, " cb call %s", tok2str(cb_req, "op#%u", cb_op))); @@ -1245,8 +1253,8 @@ cb_print(netdissect_options *ndo, case 204: /* Callback */ { uint32_t j, t; - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); for (i = 0; i < j; i++) { @@ -1258,8 +1266,8 @@ cb_print(netdissect_options *ndo, if (j == 0) ND_PRINT((ndo, " ")); - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); if (j != 0) @@ -1270,8 +1278,8 @@ cb_print(netdissect_options *ndo, INTOUT(); ND_PRINT((ndo, " expires")); DATEOUT(); - ND_TCHECK_32BITS(bp); - t = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + t = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); tok2str(cb_types, "type %u", t); } @@ -1297,9 +1305,10 @@ trunc: static void cb_reply_print(netdissect_options *ndo, - register const u_char *bp, u_int length, uint32_t opcode) + const u_char *bp, u_int length, uint32_t opcode) { const struct rx_header *rxh; + uint8_t type; if (length <= sizeof(struct rx_header)) return; @@ -1313,13 +1322,14 @@ cb_reply_print(netdissect_options *ndo, ND_PRINT((ndo, " cb reply %s", tok2str(cb_req, "op#%u", opcode))); + type = EXTRACT_U_1(rxh->type); bp += sizeof(struct rx_header); /* * If it was a data packet, interpret the response. */ - if (rxh->type == RX_PACKET_TYPE_DATA) + if (type == RX_PACKET_TYPE_DATA) switch (opcode) { case 213: /* InitCallBackState3 */ AFSUUIDOUT(); @@ -1347,7 +1357,7 @@ trunc: static void prot_print(netdissect_options *ndo, - register const u_char *bp, u_int length) + const u_char *bp, u_int length) { uint32_t i; uint32_t pt_op; @@ -1360,8 +1370,8 @@ prot_print(netdissect_options *ndo, * gleaned from ptserver/ptint.xg */ - ND_TCHECK_32BITS(bp + sizeof(struct rx_header)); - pt_op = EXTRACT_BE_32BITS(bp + sizeof(struct rx_header)); + ND_TCHECK_4(bp + sizeof(struct rx_header)); + pt_op = EXTRACT_BE_U_4(bp + sizeof(struct rx_header)); ND_PRINT((ndo, " pt")); @@ -1413,8 +1423,8 @@ prot_print(netdissect_options *ndo, case 504: /* Name to ID */ { uint32_t j; - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); /* @@ -1435,8 +1445,8 @@ prot_print(netdissect_options *ndo, { uint32_t j; ND_PRINT((ndo, " ids:")); - ND_TCHECK_32BITS(bp); - i = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); for (j = 0; j < i; j++) INTOUT(); @@ -1488,9 +1498,10 @@ trunc: static void prot_reply_print(netdissect_options *ndo, - register const u_char *bp, u_int length, uint32_t opcode) + const u_char *bp, u_int length, uint32_t opcode) { const struct rx_header *rxh; + uint8_t type; uint32_t i; if (length < sizeof(struct rx_header)) @@ -1513,20 +1524,21 @@ prot_reply_print(netdissect_options *ndo, ND_PRINT((ndo, " reply %s", tok2str(pt_req, "op#%u", opcode))); + type = EXTRACT_U_1(rxh->type); bp += sizeof(struct rx_header); /* * If it was a data packet, interpret the response */ - if (rxh->type == RX_PACKET_TYPE_DATA) + if (type == RX_PACKET_TYPE_DATA) switch (opcode) { case 504: /* Name to ID */ { uint32_t j; ND_PRINT((ndo, " ids:")); - ND_TCHECK_32BITS(bp); - i = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); for (j = 0; j < i; j++) INTOUT(); @@ -1537,8 +1549,8 @@ prot_reply_print(netdissect_options *ndo, case 505: /* ID to name */ { uint32_t j; - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); /* @@ -1562,8 +1574,8 @@ prot_reply_print(netdissect_options *ndo, case 519: /* Get host CPS */ { uint32_t j; - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); for (i = 0; i < j; i++) { INTOUT(); @@ -1601,7 +1613,7 @@ trunc: static void vldb_print(netdissect_options *ndo, - register const u_char *bp, u_int length) + const u_char *bp, u_int length) { uint32_t vldb_op; uint32_t i; @@ -1614,8 +1626,8 @@ vldb_print(netdissect_options *ndo, * gleaned from vlserver/vldbint.xg */ - ND_TCHECK_32BITS(bp + sizeof(struct rx_header)); - vldb_op = EXTRACT_BE_32BITS(bp + sizeof(struct rx_header)); + ND_TCHECK_4(bp + sizeof(struct rx_header)); + vldb_op = EXTRACT_BE_U_4(bp + sizeof(struct rx_header)); ND_PRINT((ndo, " vldb")); @@ -1644,8 +1656,8 @@ vldb_print(netdissect_options *ndo, case 518: /* Get entry by ID N */ ND_PRINT((ndo, " volid")); INTOUT(); - ND_TCHECK_32BITS(bp); - i = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); if (i <= 2) ND_PRINT((ndo, " type %s", voltype[i])); @@ -1664,8 +1676,8 @@ vldb_print(netdissect_options *ndo, case 520: /* Replace entry N */ ND_PRINT((ndo, " volid")); INTOUT(); - ND_TCHECK_32BITS(bp); - i = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); if (i <= 2) ND_PRINT((ndo, " type %s", voltype[i])); @@ -1692,9 +1704,10 @@ trunc: static void vldb_reply_print(netdissect_options *ndo, - register const u_char *bp, u_int length, uint32_t opcode) + const u_char *bp, u_int length, uint32_t opcode) { const struct rx_header *rxh; + uint8_t type; uint32_t i; if (length < sizeof(struct rx_header)) @@ -1717,13 +1730,14 @@ vldb_reply_print(netdissect_options *ndo, ND_PRINT((ndo, " reply %s", tok2str(vldb_req, "op#%u", opcode))); + type = EXTRACT_U_1(rxh->type); bp += sizeof(struct rx_header); /* * If it was a data packet, interpret the response */ - if (rxh->type == RX_PACKET_TYPE_DATA) + if (type == RX_PACKET_TYPE_DATA) switch (opcode) { case 510: /* List entry */ ND_PRINT((ndo, " count")); @@ -1734,16 +1748,16 @@ vldb_reply_print(netdissect_options *ndo, case 504: /* Get entry by name */ { uint32_t nservers, j; VECOUT(VLNAMEMAX); - ND_TCHECK_32BITS(bp); + ND_TCHECK_4(bp); bp += sizeof(uint32_t); ND_PRINT((ndo, " numservers")); - ND_TCHECK_32BITS(bp); - nservers = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + nservers = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); ND_PRINT((ndo, " %u", nservers)); ND_PRINT((ndo, " servers")); for (i = 0; i < 8; i++) { - ND_TCHECK_32BITS(bp); + ND_TCHECK_4(bp); if (i < nservers) ND_PRINT((ndo, " %s", intoa(((const struct in_addr *) bp)->s_addr))); @@ -1751,15 +1765,15 @@ vldb_reply_print(netdissect_options *ndo, } ND_PRINT((ndo, " partitions")); for (i = 0; i < 8; i++) { - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); if (i < nservers && j <= 26) ND_PRINT((ndo, " %c", 'a' + j)); else if (i < nservers) ND_PRINT((ndo, " %u", j)); bp += sizeof(uint32_t); } - ND_TCHECK2(bp[0], 8 * sizeof(uint32_t)); + ND_TCHECK_LEN(bp, 8 * sizeof(uint32_t)); bp += 8 * sizeof(uint32_t); ND_PRINT((ndo, " rwvol")); UINTOUT(); @@ -1784,13 +1798,13 @@ vldb_reply_print(netdissect_options *ndo, { uint32_t nservers, j; VECOUT(VLNAMEMAX); ND_PRINT((ndo, " numservers")); - ND_TCHECK_32BITS(bp); - nservers = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + nservers = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); ND_PRINT((ndo, " %u", nservers)); ND_PRINT((ndo, " servers")); for (i = 0; i < 13; i++) { - ND_TCHECK_32BITS(bp); + ND_TCHECK_4(bp); if (i < nservers) ND_PRINT((ndo, " %s", intoa(((const struct in_addr *) bp)->s_addr))); @@ -1798,15 +1812,15 @@ vldb_reply_print(netdissect_options *ndo, } ND_PRINT((ndo, " partitions")); for (i = 0; i < 13; i++) { - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); if (i < nservers && j <= 26) ND_PRINT((ndo, " %c", 'a' + j)); else if (i < nservers) ND_PRINT((ndo, " %u", j)); bp += sizeof(uint32_t); } - ND_TCHECK2(bp[0], 13 * sizeof(uint32_t)); + ND_TCHECK_LEN(bp, 13 * sizeof(uint32_t)); bp += 13 * sizeof(uint32_t); ND_PRINT((ndo, " rwvol")); UINTOUT(); @@ -1821,8 +1835,8 @@ vldb_reply_print(netdissect_options *ndo, { uint32_t nservers, j; VECOUT(VLNAMEMAX); ND_PRINT((ndo, " numservers")); - ND_TCHECK_32BITS(bp); - nservers = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + nservers = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); ND_PRINT((ndo, " %u", nservers)); ND_PRINT((ndo, " servers")); @@ -1831,23 +1845,23 @@ vldb_reply_print(netdissect_options *ndo, ND_PRINT((ndo, " afsuuid")); AFSUUIDOUT(); } else { - ND_TCHECK2(bp[0], 44); + ND_TCHECK_LEN(bp, 44); bp += 44; } } - ND_TCHECK2(bp[0], 4 * 13); + ND_TCHECK_LEN(bp, 4 * 13); bp += 4 * 13; ND_PRINT((ndo, " partitions")); for (i = 0; i < 13; i++) { - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); if (i < nservers && j <= 26) ND_PRINT((ndo, " %c", 'a' + j)); else if (i < nservers) ND_PRINT((ndo, " %u", j)); bp += sizeof(uint32_t); } - ND_TCHECK2(bp[0], 13 * sizeof(uint32_t)); + ND_TCHECK_LEN(bp, 13 * sizeof(uint32_t)); bp += 13 * sizeof(uint32_t); ND_PRINT((ndo, " rwvol")); UINTOUT(); @@ -1880,7 +1894,7 @@ trunc: static void kauth_print(netdissect_options *ndo, - register const u_char *bp, u_int length) + const u_char *bp, u_int length) { uint32_t kauth_op; @@ -1892,8 +1906,8 @@ kauth_print(netdissect_options *ndo, * gleaned from kauth/kauth.rg */ - ND_TCHECK_32BITS(bp + sizeof(struct rx_header)); - kauth_op = EXTRACT_BE_32BITS(bp + sizeof(struct rx_header)); + ND_TCHECK_4(bp + sizeof(struct rx_header)); + kauth_op = EXTRACT_BE_U_4(bp + sizeof(struct rx_header)); ND_PRINT((ndo, " kauth")); @@ -1934,10 +1948,10 @@ kauth_print(netdissect_options *ndo, INTOUT(); ND_PRINT((ndo, " domain")); STROUT(KANAMEMAX); - ND_TCHECK_32BITS(bp); - i = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + i = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); - ND_TCHECK2(bp[0], i); + ND_TCHECK_LEN(bp, i); bp += i; ND_PRINT((ndo, " principal")); STROUT(KANAMEMAX); @@ -1971,9 +1985,10 @@ trunc: static void kauth_reply_print(netdissect_options *ndo, - register const u_char *bp, u_int length, uint32_t opcode) + const u_char *bp, u_int length, uint32_t opcode) { const struct rx_header *rxh; + uint8_t type; if (length <= sizeof(struct rx_header)) return; @@ -1994,13 +2009,14 @@ kauth_reply_print(netdissect_options *ndo, ND_PRINT((ndo, " reply %s", tok2str(kauth_req, "op#%u", opcode))); + type = EXTRACT_U_1(rxh->type); bp += sizeof(struct rx_header); /* * If it was a data packet, interpret the response. */ - if (rxh->type == RX_PACKET_TYPE_DATA) + if (type == RX_PACKET_TYPE_DATA) /* Well, no, not really. Leave this for later */ ; else { @@ -2023,7 +2039,7 @@ trunc: static void vol_print(netdissect_options *ndo, - register const u_char *bp, u_int length) + const u_char *bp, u_int length) { uint32_t vol_op; @@ -2035,8 +2051,8 @@ vol_print(netdissect_options *ndo, * gleaned from volser/volint.xg */ - ND_TCHECK_32BITS(bp + sizeof(struct rx_header)); - vol_op = EXTRACT_BE_32BITS(bp + sizeof(struct rx_header)); + ND_TCHECK_4(bp + sizeof(struct rx_header)); + vol_op = EXTRACT_BE_U_4(bp + sizeof(struct rx_header)); ND_PRINT((ndo, " vol call %s", tok2str(vol_req, "op#%u", vol_op))); @@ -2187,8 +2203,8 @@ vol_print(netdissect_options *ndo, DATEOUT(); { uint32_t i, j; - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); for (i = 0; i < j; i++) { DESTSERVEROUT(); @@ -2222,9 +2238,10 @@ trunc: static void vol_reply_print(netdissect_options *ndo, - register const u_char *bp, u_int length, uint32_t opcode) + const u_char *bp, u_int length, uint32_t opcode) { const struct rx_header *rxh; + uint8_t type; if (length <= sizeof(struct rx_header)) return; @@ -2238,13 +2255,14 @@ vol_reply_print(netdissect_options *ndo, ND_PRINT((ndo, " vol reply %s", tok2str(vol_req, "op#%u", opcode))); + type = EXTRACT_U_1(rxh->type); bp += sizeof(struct rx_header); /* * If it was a data packet, interpret the response. */ - if (rxh->type == RX_PACKET_TYPE_DATA) { + if (type == RX_PACKET_TYPE_DATA) { switch (opcode) { case 100: /* Create volume */ ND_PRINT((ndo, " volid")); @@ -2315,8 +2333,8 @@ vol_reply_print(netdissect_options *ndo, case 121: /* List one volume */ { uint32_t i, j; - ND_TCHECK_32BITS(bp); - j = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + j = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); for (i = 0; i < j; i++) { ND_PRINT((ndo, " name")); @@ -2357,7 +2375,7 @@ trunc: static void bos_print(netdissect_options *ndo, - register const u_char *bp, u_int length) + const u_char *bp, u_int length) { uint32_t bos_op; @@ -2369,8 +2387,8 @@ bos_print(netdissect_options *ndo, * gleaned from bozo/bosint.xg */ - ND_TCHECK_32BITS(bp + sizeof(struct rx_header)); - bos_op = EXTRACT_BE_32BITS(bp + sizeof(struct rx_header)); + ND_TCHECK_4(bp + sizeof(struct rx_header)); + bos_op = EXTRACT_BE_U_4(bp + sizeof(struct rx_header)); ND_PRINT((ndo, " bos call %s", tok2str(bos_req, "op#%u", bos_op))); @@ -2446,9 +2464,10 @@ trunc: static void bos_reply_print(netdissect_options *ndo, - register const u_char *bp, u_int length, uint32_t opcode) + const u_char *bp, u_int length, uint32_t opcode) { const struct rx_header *rxh; + uint8_t type; if (length <= sizeof(struct rx_header)) return; @@ -2462,13 +2481,14 @@ bos_reply_print(netdissect_options *ndo, ND_PRINT((ndo, " bos reply %s", tok2str(bos_req, "op#%u", opcode))); + type = EXTRACT_U_1(rxh->type); bp += sizeof(struct rx_header); /* * If it was a data packet, interpret the response. */ - if (rxh->type == RX_PACKET_TYPE_DATA) + if (type == RX_PACKET_TYPE_DATA) /* Well, no, not really. Leave this for later */ ; else { @@ -2505,7 +2525,7 @@ is_ubik(uint32_t opcode) static void ubik_print(netdissect_options *ndo, - register const u_char *bp) + const u_char *bp) { uint32_t ubik_op; uint32_t temp; @@ -2519,7 +2539,7 @@ ubik_print(netdissect_options *ndo, * for (sizeof(rx_header) + 4) bytes, so long as it remains this way * the line below will not over-read. */ - ubik_op = EXTRACT_BE_32BITS(bp + sizeof(struct rx_header)); + ubik_op = EXTRACT_BE_U_4(bp + sizeof(struct rx_header)); ND_PRINT((ndo, " ubik call %s", tok2str(ubik_req, "op#%u", ubik_op))); @@ -2531,8 +2551,8 @@ ubik_print(netdissect_options *ndo, switch (ubik_op) { case 10000: /* Beacon */ - ND_TCHECK_32BITS(bp); - temp = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + temp = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); ND_PRINT((ndo, " syncsite %s", temp ? "yes" : "no")); ND_PRINT((ndo, " votestart")); @@ -2563,8 +2583,8 @@ ubik_print(netdissect_options *ndo, INTOUT(); ND_PRINT((ndo, " length")); INTOUT(); - ND_TCHECK_32BITS(bp); - temp = EXTRACT_BE_32BITS(bp); + ND_TCHECK_4(bp); + temp = EXTRACT_BE_U_4(bp); bp += sizeof(uint32_t); tok2str(ubik_lock_types, "type %u", temp); break; @@ -2620,9 +2640,10 @@ trunc: static void ubik_reply_print(netdissect_options *ndo, - register const u_char *bp, u_int length, uint32_t opcode) + const u_char *bp, u_int length, uint32_t opcode) { const struct rx_header *rxh; + uint8_t type; if (length < sizeof(struct rx_header)) return; @@ -2636,13 +2657,14 @@ ubik_reply_print(netdissect_options *ndo, ND_PRINT((ndo, " ubik reply %s", tok2str(ubik_req, "op#%u", opcode))); + type = EXTRACT_U_1(rxh->type); bp += sizeof(struct rx_header); /* * If it was a data packet, print out the arguments to the Ubik calls */ - if (rxh->type == RX_PACKET_TYPE_DATA) + if (type == RX_PACKET_TYPE_DATA) switch (opcode) { case 10000: /* Beacon */ ND_PRINT((ndo, " vote no")); @@ -2684,9 +2706,10 @@ trunc: static void rx_ack_print(netdissect_options *ndo, - register const u_char *bp, u_int length) + const u_char *bp, u_int length) { const struct rx_ackPacket *rxa; + uint8_t nAcks; int i, start, last; uint32_t firstPacket; @@ -2695,18 +2718,10 @@ rx_ack_print(netdissect_options *ndo, bp += sizeof(struct rx_header); - /* - * This may seem a little odd .... the rx_ackPacket structure - * contains an array of individual packet acknowledgements - * (used for selective ack/nack), but since it's variable in size, - * we don't want to truncate based on the size of the whole - * rx_ackPacket structure. - */ - - ND_TCHECK2(bp[0], sizeof(struct rx_ackPacket) - RX_MAXACKS); + ND_TCHECK_LEN(bp, sizeof(struct rx_ackPacket)); rxa = (const struct rx_ackPacket *) bp; - bp += (sizeof(struct rx_ackPacket) - RX_MAXACKS); + bp += sizeof(struct rx_ackPacket); /* * Print out a few useful things from the ack packet structure @@ -2714,13 +2729,13 @@ rx_ack_print(netdissect_options *ndo, if (ndo->ndo_vflag > 2) ND_PRINT((ndo, " bufspace %u maxskew %d", - EXTRACT_BE_16BITS(&rxa->bufferSpace), - EXTRACT_BE_16BITS(&rxa->maxSkew))); + EXTRACT_BE_U_2(rxa->bufferSpace), + EXTRACT_BE_U_2(rxa->maxSkew))); - firstPacket = EXTRACT_BE_32BITS(&rxa->firstPacket); + firstPacket = EXTRACT_BE_U_4(rxa->firstPacket); ND_PRINT((ndo, " first %u serial %u reason %s", - firstPacket, EXTRACT_BE_32BITS(&rxa->serial), - tok2str(rx_ack_reasons, "#%u", rxa->reason))); + firstPacket, EXTRACT_BE_U_4(rxa->serial), + tok2str(rx_ack_reasons, "#%u", EXTRACT_U_1(rxa->reason)))); /* * Okay, now we print out the ack array. The way _this_ works @@ -2741,17 +2756,18 @@ rx_ack_print(netdissect_options *ndo, * to bp after this, so bp ends up at the right spot. Go figure. */ - if (rxa->nAcks != 0) { + nAcks = EXTRACT_U_1(rxa->nAcks); + if (nAcks != 0) { - ND_TCHECK2(bp[0], rxa->nAcks); + ND_TCHECK_LEN(bp, nAcks); /* * Sigh, this is gross, but it seems to work to collapse * ranges correctly. */ - for (i = 0, start = last = -2; i < rxa->nAcks; i++) - if (rxa->acks[i] == RX_ACK_TYPE_ACK) { + for (i = 0, start = last = -2; i < nAcks; i++) + if (EXTRACT_U_1(bp + i) == RX_ACK_TYPE_ACK) { /* * I figured this deserved _some_ explanation. @@ -2821,8 +2837,8 @@ rx_ack_print(netdissect_options *ndo, * Same as above, just without comments */ - for (i = 0, start = last = -2; i < rxa->nAcks; i++) - if (rxa->acks[i] == RX_ACK_TYPE_NACK) { + for (i = 0, start = last = -2; i < nAcks; i++) + if (EXTRACT_U_1(bp + i) == RX_ACK_TYPE_NACK) { if (last == -2) { ND_PRINT((ndo, " nacked %u", firstPacket + i)); start = i; @@ -2837,9 +2853,11 @@ rx_ack_print(netdissect_options *ndo, if (last == i - 1 && start != last) ND_PRINT((ndo, "-%u", firstPacket + i - 1)); - bp += rxa->nAcks; + bp += nAcks; } + /* Padding. */ + bp += 3; /* * These are optional fields; depending on your version of AFS, @@ -2851,19 +2869,19 @@ rx_ack_print(netdissect_options *ndo, if (ndo->ndo_vflag > 1) { TRUNCRET(4); ND_PRINT((ndo, " ifmtu")); - INTOUT(); + UINTOUT(); TRUNCRET(4); ND_PRINT((ndo, " maxmtu")); - INTOUT(); + UINTOUT(); TRUNCRET(4); ND_PRINT((ndo, " rwind")); - INTOUT(); + UINTOUT(); TRUNCRET(4); ND_PRINT((ndo, " maxpackets")); - INTOUT(); + UINTOUT(); } return;