X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/c2a9094394193f1de9c968a1fc490e5a1f2a9a3d..c5a34f01b4d03a0c24f9abb57f0db45c502aceb5:/print-udp.c diff --git a/print-udp.c b/print-udp.c index 2bb5eac5..77bf330e 100644 --- a/print-udp.c +++ b/print-udp.c @@ -42,10 +42,6 @@ #include "nfs.h" -static const char vat_tstr[] = " [|vat]"; -static const char rtp_tstr[] = " [|rtp]"; -static const char rtcp_tstr[] = " [|rtcp]"; -static const char udp_tstr[] = " [|udp]"; struct rtcphdr { nd_uint16_t rh_flags; /* T:2 P:1 CNT:5 PT:8 */ @@ -102,12 +98,13 @@ vat_print(netdissect_options *ndo, const void *hdr, u_int length) /* vat/vt audio */ u_int ts; + ndo->ndo_protocol = "vat"; if (length < 2) { ND_PRINT("udp/va/vat, length %u < 2", length); return; } ND_TCHECK_2((const u_int *)hdr); - ts = EXTRACT_BE_U_2(hdr); + ts = GET_BE_U_2(hdr); if ((ts & 0xf060) != 0) { /* probably vt */ ND_PRINT("udp/vt %u %u / %u", @@ -122,9 +119,9 @@ vat_print(netdissect_options *ndo, const void *hdr, u_int length) return; } ND_TCHECK_4(&((const u_int *)hdr)[0]); - i0 = EXTRACT_BE_U_4(&((const u_int *)hdr)[0]); + i0 = GET_BE_U_4(&((const u_int *)hdr)[0]); ND_TCHECK_4(&((const u_int *)hdr)[1]); - i1 = EXTRACT_BE_U_4(&((const u_int *)hdr)[1]); + i1 = GET_BE_U_4(&((const u_int *)hdr)[1]); ND_PRINT("udp/vat %u c%u %u%s", length - 8, i0 & 0xffff, @@ -135,9 +132,10 @@ vat_print(netdissect_options *ndo, const void *hdr, u_int length) if (i0 & 0x3f000000) ND_PRINT(" s%u", (i0 >> 24) & 0x3f); } + return; trunc: - ND_PRINT("%s", vat_tstr); + nd_print_trunc(ndo); } static void @@ -149,14 +147,15 @@ rtp_print(netdissect_options *ndo, const void *hdr, u_int len) uint32_t i0, i1; const char * ptype; + ndo->ndo_protocol = "rtp"; if (len < 8) { ND_PRINT("udp/rtp, length %u < 8", len); return; } ND_TCHECK_4(&((const u_int *)hdr)[0]); - i0 = EXTRACT_BE_U_4(&((const u_int *)hdr)[0]); + i0 = GET_BE_U_4(&((const u_int *)hdr)[0]); ND_TCHECK_4(&((const u_int *)hdr)[1]); - i1 = EXTRACT_BE_U_4(&((const u_int *)hdr)[1]); + i1 = GET_BE_U_4(&((const u_int *)hdr)[1]); dlen = len - 8; ip += 2; len >>= 2; @@ -193,12 +192,12 @@ rtp_print(netdissect_options *ndo, const void *hdr, u_int len) i1); if (ndo->ndo_vflag) { ND_TCHECK_4(&((const u_int *)hdr)[2]); - ND_PRINT(" %u", EXTRACT_BE_U_4(&((const u_int *)hdr)[2])); + ND_PRINT(" %u", GET_BE_U_4(&((const u_int *)hdr)[2])); if (hasopt) { u_int i2, optlen; do { ND_TCHECK_4(ip); - i2 = EXTRACT_BE_U_4(ip); + i2 = GET_BE_U_4(ip); optlen = (i2 >> 16) & 0xff; if (optlen == 0 || optlen > len) { ND_PRINT(" !opt"); @@ -211,7 +210,7 @@ rtp_print(netdissect_options *ndo, const void *hdr, u_int len) if (hasext) { u_int i2, extlen; ND_TCHECK_4(ip); - i2 = EXTRACT_BE_U_4(ip); + i2 = GET_BE_U_4(ip); extlen = (i2 & 0xffff) + 1; if (extlen > len) { ND_PRINT(" !ext"); @@ -221,11 +220,12 @@ rtp_print(netdissect_options *ndo, const void *hdr, u_int len) } ND_TCHECK_4(ip); if (contype == 0x1f) /*XXX H.261 */ - ND_PRINT(" 0x%04x", EXTRACT_BE_U_4(ip) >> 16); + ND_PRINT(" 0x%04x", GET_BE_U_4(ip) >> 16); } + return; trunc: - ND_PRINT("%s", rtp_tstr); + nd_print_trunc(ndo); } static const u_char * @@ -239,11 +239,13 @@ rtcp_print(netdissect_options *ndo, const u_char *hdr, const u_char *ep) uint16_t flags; u_int cnt; double ts, dts; + + ndo->ndo_protocol = "rtcp"; if ((const u_char *)(rh + 1) > ep) goto trunc; ND_TCHECK_SIZE(rh); - len = (EXTRACT_BE_U_2(rh->rh_len) + 1) * 4; - flags = EXTRACT_BE_U_2(rh->rh_flags); + len = (GET_BE_U_2(rh->rh_len) + 1) * 4; + flags = GET_BE_U_2(rh->rh_flags); cnt = (flags >> 8) & 0x1f; switch (flags & 0xff) { case RTCP_PT_SR: @@ -252,15 +254,15 @@ rtcp_print(netdissect_options *ndo, const u_char *hdr, const u_char *ep) if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh)) ND_PRINT(" [%u]", len); if (ndo->ndo_vflag) - ND_PRINT(" %u", EXTRACT_BE_U_4(rh->rh_ssrc)); + ND_PRINT(" %u", GET_BE_U_4(rh->rh_ssrc)); if ((const u_char *)(sr + 1) > ep) goto trunc; ND_TCHECK_SIZE(sr); - ts = (double)(EXTRACT_BE_U_4(sr->sr_ntp.upper)) + - ((double)(EXTRACT_BE_U_4(sr->sr_ntp.lower)) / + ts = (double)(GET_BE_U_4(sr->sr_ntp.upper)) + + ((double)(GET_BE_U_4(sr->sr_ntp.lower)) / 4294967296.0); - ND_PRINT(" @%.2f %u %up %ub", ts, EXTRACT_BE_U_4(sr->sr_ts), - EXTRACT_BE_U_4(sr->sr_np), EXTRACT_BE_U_4(sr->sr_nb)); + ND_PRINT(" @%.2f %u %up %ub", ts, GET_BE_U_4(sr->sr_ts), + GET_BE_U_4(sr->sr_np), GET_BE_U_4(sr->sr_nb)); rr = (const struct rtcp_rr *)(sr + 1); break; case RTCP_PT_RR: @@ -269,18 +271,18 @@ rtcp_print(netdissect_options *ndo, const u_char *hdr, const u_char *ep) ND_PRINT(" [%u]", len); rr = (const struct rtcp_rr *)(rh + 1); if (ndo->ndo_vflag) - ND_PRINT(" %u", EXTRACT_BE_U_4(rh->rh_ssrc)); + ND_PRINT(" %u", GET_BE_U_4(rh->rh_ssrc)); break; case RTCP_PT_SDES: ND_PRINT(" sdes %u", len); if (ndo->ndo_vflag) - ND_PRINT(" %u", EXTRACT_BE_U_4(rh->rh_ssrc)); + ND_PRINT(" %u", GET_BE_U_4(rh->rh_ssrc)); cnt = 0; break; case RTCP_PT_BYE: ND_PRINT(" bye %u", len); if (ndo->ndo_vflag) - ND_PRINT(" %u", EXTRACT_BE_U_4(rh->rh_ssrc)); + ND_PRINT(" %u", GET_BE_U_4(rh->rh_ssrc)); cnt = 0; break; default: @@ -295,23 +297,23 @@ rtcp_print(netdissect_options *ndo, const u_char *hdr, const u_char *ep) goto trunc; ND_TCHECK_SIZE(rr); if (ndo->ndo_vflag) - ND_PRINT(" %u", EXTRACT_BE_U_4(rr->rr_srcid)); - ts = (double)(EXTRACT_BE_U_4(rr->rr_lsr)) / 65536.; - dts = (double)(EXTRACT_BE_U_4(rr->rr_dlsr)) / 65536.; + ND_PRINT(" %u", GET_BE_U_4(rr->rr_srcid)); + ts = (double)(GET_BE_U_4(rr->rr_lsr)) / 65536.; + dts = (double)(GET_BE_U_4(rr->rr_dlsr)) / 65536.; ND_PRINT(" %ul %us %uj @%.2f+%.2f", - EXTRACT_BE_U_4(rr->rr_nl) & 0x00ffffff, - EXTRACT_BE_U_4(rr->rr_ls), - EXTRACT_BE_U_4(rr->rr_dv), ts, dts); + GET_BE_U_4(rr->rr_nl) & 0x00ffffff, + GET_BE_U_4(rr->rr_ls), + GET_BE_U_4(rr->rr_dv), ts, dts); cnt--; } return (hdr + len); trunc: - ND_PRINT("%s", rtcp_tstr); + nd_print_trunc(ndo); return ep; } -static int udp_cksum(netdissect_options *ndo, const struct ip *ip, +static uint16_t udp_cksum(netdissect_options *ndo, const struct ip *ip, const struct udphdr *up, u_int len) { @@ -319,7 +321,7 @@ static int udp_cksum(netdissect_options *ndo, const struct ip *ip, IPPROTO_UDP); } -static int udp6_cksum(netdissect_options *ndo, const struct ip6_hdr *ip6, +static uint16_t udp6_cksum(netdissect_options *ndo, const struct ip6_hdr *ip6, const struct udphdr *up, u_int len) { return nextproto6_cksum(ndo, ip6, (const uint8_t *)(const void *)up, len, len, @@ -337,7 +339,7 @@ udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dpo ip6 = NULL; if (ip6) { - if (EXTRACT_U_1(ip6->ip6_nxt) == IPPROTO_UDP) { + if (GET_U_1(ip6->ip6_nxt) == IPPROTO_UDP) { if (sport == -1) { ND_PRINT("%s > %s: ", ip6addr_string(ndo, ip6->ip6_src), @@ -345,19 +347,19 @@ udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dpo } else { ND_PRINT("%s.%s > %s.%s: ", ip6addr_string(ndo, ip6->ip6_src), - udpport_string(ndo, sport), + udpport_string(ndo, (uint16_t)sport), ip6addr_string(ndo, ip6->ip6_dst), - udpport_string(ndo, dport)); + udpport_string(ndo, (uint16_t)dport)); } } else { if (sport != -1) { ND_PRINT("%s > %s: ", - udpport_string(ndo, sport), - udpport_string(ndo, dport)); + udpport_string(ndo, (uint16_t)sport), + udpport_string(ndo, (uint16_t)dport)); } } } else { - if (EXTRACT_U_1(ip->ip_p) == IPPROTO_UDP) { + if (GET_U_1(ip->ip_p) == IPPROTO_UDP) { if (sport == -1) { ND_PRINT("%s > %s: ", ipaddr_string(ndo, ip->ip_src), @@ -365,15 +367,15 @@ udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dpo } else { ND_PRINT("%s.%s > %s.%s: ", ipaddr_string(ndo, ip->ip_src), - udpport_string(ndo, sport), + udpport_string(ndo, (uint16_t)sport), ipaddr_string(ndo, ip->ip_dst), - udpport_string(ndo, dport)); + udpport_string(ndo, (uint16_t)dport)); } } else { if (sport != -1) { ND_PRINT("%s > %s: ", - udpport_string(ndo, sport), - udpport_string(ndo, dport)); + udpport_string(ndo, (uint16_t)sport), + udpport_string(ndo, (uint16_t)dport)); } } } @@ -381,17 +383,17 @@ udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dpo void udp_print(netdissect_options *ndo, const u_char *bp, u_int length, - const u_char *bp2, int fragmented) + const u_char *bp2, int fragmented, u_int ttl_hl) { const struct udphdr *up; const struct ip *ip; const u_char *cp; - const u_char *ep = bp + length; - uint16_t sport, dport, ulen; + const u_char *ep = ndo->ndo_snapend; + uint16_t sport, dport; + u_int ulen; const struct ip6_hdr *ip6; - if (ep > ndo->ndo_snapend) - ep = ndo->ndo_snapend; + ndo->ndo_protocol = "udp"; up = (const struct udphdr *)bp; ip = (const struct ip *)bp2; if (IP_V(ip) == 6) @@ -403,8 +405,8 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, goto trunc; } - sport = EXTRACT_BE_U_2(up->uh_sport); - dport = EXTRACT_BE_U_2(up->uh_dport); + sport = GET_BE_U_2(up->uh_sport); + dport = GET_BE_U_2(up->uh_dport); if (length < sizeof(struct udphdr)) { udpipaddr_print(ndo, ip, sport, dport); @@ -415,7 +417,14 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, udpipaddr_print(ndo, ip, sport, dport); goto trunc; } - ulen = EXTRACT_BE_U_2(up->uh_ulen); + ulen = GET_BE_U_2(up->uh_ulen); + /* + * IPv6 Jumbo Datagrams; see RFC 2675. + * If the length is zero, and the length provided to us is + * > 65535, use the provided length as the length. + */ + if (ulen == 0 && length > 65535) + ulen = length; if (ulen < sizeof(struct udphdr)) { udpipaddr_print(ndo, ip, sport, dport); ND_PRINT("truncated-udplength %u", ulen); @@ -450,7 +459,8 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, case PT_RPC: rp = (const struct sunrpc_msg *)(up + 1); - direction = (enum sunrpc_msg_type) EXTRACT_BE_U_4(rp->rm_direction); + ND_TCHECK_4(rp->rm_direction); + direction = (enum sunrpc_msg_type) GET_BE_U_4(rp->rm_direction); if (direction == SUNRPC_CALL) sunrpc_print(ndo, (const u_char *)rp, length, (const u_char *)ip); @@ -521,17 +531,17 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, rp = (const struct sunrpc_msg *)(up + 1); if (ND_TTEST_4(rp->rm_direction)) { - direction = (enum sunrpc_msg_type) EXTRACT_BE_U_4(rp->rm_direction); + direction = (enum sunrpc_msg_type) GET_BE_U_4(rp->rm_direction); if (dport == NFS_PORT && direction == SUNRPC_CALL) { ND_PRINT("NFS request xid %u ", - EXTRACT_BE_U_4(rp->rm_xid)); + GET_BE_U_4(rp->rm_xid)); nfsreq_noaddr_print(ndo, (const u_char *)rp, length, (const u_char *)ip); return; } if (sport == NFS_PORT && direction == SUNRPC_REPLY) { ND_PRINT("NFS reply xid %u ", - EXTRACT_BE_U_4(rp->rm_xid)); + GET_BE_U_4(rp->rm_xid)); nfsreply_noaddr_print(ndo, (const u_char *)rp, length, (const u_char *)ip); return; @@ -554,7 +564,8 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, * TCP does, and we do so for UDP-over-IPv6. */ if (IP_V(ip) == 4 && (ndo->ndo_vflag > 1)) { - udp_sum = EXTRACT_BE_U_2(up->uh_sum); + ND_TCHECK_2(up->uh_sum); + udp_sum = GET_BE_U_2(up->uh_sum); if (udp_sum == 0) { ND_PRINT("[no cksum] "); } else if (ND_TTEST_LEN(cp, length)) { @@ -568,11 +579,12 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, ND_PRINT("[udp sum ok] "); } } - else if (IP_V(ip) == 6 && ip6->ip6_plen) { + else if (IP_V(ip) == 6) { /* for IPv6, UDP checksum is mandatory */ if (ND_TTEST_LEN(cp, length)) { sum = udp6_cksum(ndo, ip6, up, length + sizeof(struct udphdr)); - udp_sum = EXTRACT_BE_U_2(up->uh_sum); + ND_TCHECK_2(up->uh_sum); + udp_sum = GET_BE_U_2(up->uh_sum); if (sum != 0) { ND_PRINT("[bad udp cksum 0x%04x -> 0x%04x!] ", @@ -603,7 +615,7 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT)) isakmp_print(ndo, (const u_char *)(up + 1), length, bp2); else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT_NATT)) - isakmp_rfc3948_print(ndo, (const u_char *)(up + 1), length, bp2); + isakmp_rfc3948_print(ndo, (const u_char *)(up + 1), length, bp2, IP_V(ip), fragmented, ttl_hl); else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT_USER1) || IS_SRC_OR_DST_PORT(ISAKMP_PORT_USER2)) isakmp_print(ndo, (const u_char *)(up + 1), length, bp2); else if (IS_SRC_OR_DST_PORT(SNMP_PORT) || IS_SRC_OR_DST_PORT(SNMPTRAP_PORT)) @@ -611,7 +623,7 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, else if (IS_SRC_OR_DST_PORT(NTP_PORT)) ntp_print(ndo, (const u_char *)(up + 1), length); else if (IS_SRC_OR_DST_PORT(KERBEROS_PORT) || IS_SRC_OR_DST_PORT(KERBEROS_SEC_PORT)) - krb_print(ndo, (const void *)(up + 1)); + krb_print(ndo, (const u_char *)(up + 1)); else if (IS_SRC_OR_DST_PORT(L2TP_PORT)) l2tp_print(ndo, (const u_char *)(up + 1), length); #ifdef ENABLE_SMB @@ -623,14 +635,14 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, else if (dport == VAT_PORT) vat_print(ndo, (const void *)(up + 1), length); else if (IS_SRC_OR_DST_PORT(ZEPHYR_SRV_PORT) || IS_SRC_OR_DST_PORT(ZEPHYR_CLT_PORT)) - zephyr_print(ndo, (const void *)(up + 1), length); + zephyr_print(ndo, (const u_char *)(up + 1), length); /* * Since there are 10 possible ports to check, I think * a <> test would be more efficient */ else if ((sport >= RX_PORT_LOW && sport <= RX_PORT_HIGH) || (dport >= RX_PORT_LOW && dport <= RX_PORT_HIGH)) - rx_print(ndo, (const void *)(up + 1), length, sport, dport, + rx_print(ndo, (const u_char *)(up + 1), length, sport, dport, (const u_char *) ip); else if (IS_SRC_OR_DST_PORT(RIPNG_PORT)) ripng_print(ndo, (const u_char *)(up + 1), length); @@ -648,7 +660,7 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, else if (dport == WB_PORT) wb_print(ndo, (const u_char *)(up + 1), length); else if (IS_SRC_OR_DST_PORT(CISCO_AUTORP_PORT)) - cisco_autorp_print(ndo, (const void *)(up + 1), length); + cisco_autorp_print(ndo, (const u_char *)(up + 1), length); else if (IS_SRC_OR_DST_PORT(RADIUS_PORT) || IS_SRC_OR_DST_PORT(RADIUS_NEW_PORT) || IS_SRC_OR_DST_PORT(RADIUS_ACCOUNTING_PORT) || @@ -668,6 +680,8 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, else if (IS_SRC_OR_DST_PORT(MPLS_LSP_PING_PORT)) lspping_print(ndo, (const u_char *)(up + 1), length); else if (dport == BFD_CONTROL_PORT || + dport == BFD_MULTIHOP_PORT || + dport == BFD_LAG_PORT || dport == BFD_ECHO_PORT ) bfd_print(ndo, (const u_char *)(up+1), length, dport); else if (IS_SRC_OR_DST_PORT(LMP_PORT)) @@ -696,8 +710,10 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, lisp_print(ndo, (const u_char *)(up + 1), length); else if (IS_SRC_OR_DST_PORT(VXLAN_GPE_PORT)) vxlan_gpe_print(ndo, (const u_char *)(up + 1), length); + else if (IS_SRC_OR_DST_PORT(ZEP_PORT)) + zep_print(ndo, (const u_char *)(up + 1), length); else if (ND_TTEST_1(((const struct LAP *)cp)->type) && - EXTRACT_U_1(((const struct LAP *)cp)->type) == lapDDP && + GET_U_1(((const struct LAP *)cp)->type) == lapDDP && (atalk_port(sport) || atalk_port(dport))) { if (ndo->ndo_vflag) ND_PRINT("kip "); @@ -719,13 +735,5 @@ udp_print(netdissect_options *ndo, const u_char *bp, u_int length, return; trunc: - ND_PRINT("%s", udp_tstr); + nd_print_trunc(ndo); } - - -/* - * Local Variables: - * c-style: whitesmith - * c-basic-offset: 8 - * End: - */