X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/9d046ee0503d4c8cbfcb200c88986de876f6cae7..b51a0dafc7861eb31d21524ec067d7c529a664b8:/print-vsock.c?ds=sidebyside diff --git a/print-vsock.c b/print-vsock.c index 5f0209b2..bb18c92b 100644 --- a/print-vsock.c +++ b/print-vsock.c @@ -148,12 +148,15 @@ vsock_virtio_hdr_print(netdissect_options *ndo, const struct virtio_vsock_hdr *h ND_PRINT(", fwd_cnt %u", u32_v); } -static size_t +/* + * This size had better fit in a u_int. + */ +static u_int vsock_transport_hdr_size(uint16_t transport) { switch (transport) { case AF_VSOCK_TRANSPORT_VIRTIO: - return sizeof(struct virtio_vsock_hdr); + return (u_int)sizeof(struct virtio_vsock_hdr); default: return 0; } @@ -162,12 +165,12 @@ vsock_transport_hdr_size(uint16_t transport) /* Returns 0 on success, -1 on truncation */ static int vsock_transport_hdr_print(netdissect_options *ndo, uint16_t transport, - const u_char *p, const u_int len) + const u_char *p, const u_int caplen) { - size_t transport_size = vsock_transport_hdr_size(transport); + u_int transport_size = vsock_transport_hdr_size(transport); const void *hdr; - if (len < sizeof(struct af_vsockmon_hdr) + transport_size) { + if (caplen < sizeof(struct af_vsockmon_hdr) + transport_size) { return -1; } @@ -185,13 +188,13 @@ vsock_transport_hdr_print(netdissect_options *ndo, uint16_t transport, } static void -vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len) +vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int caplen) { const struct af_vsockmon_hdr *hdr = (const struct af_vsockmon_hdr *)p; uint16_t hdr_transport, hdr_op; uint32_t hdr_src_port, hdr_dst_port; uint64_t hdr_src_cid, hdr_dst_cid; - size_t total_hdr_size; + u_int total_hdr_size; int ret = 0; hdr_transport = GET_LE_U_2(hdr->transport); @@ -201,7 +204,7 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len) /* If verbose level is more than 0 print transport details */ if (ndo->ndo_vflag) { - ret = vsock_transport_hdr_print(ndo, hdr_transport, p, len); + ret = vsock_transport_hdr_print(ndo, hdr_transport, p, caplen); if (ret == 0) ND_PRINT("\n\t"); } else @@ -216,21 +219,22 @@ vsock_hdr_print(netdissect_options *ndo, const u_char *p, const u_int len) hdr_src_cid, hdr_src_port, hdr_dst_cid, hdr_dst_port, tok2str(vsock_op, " invalid op (%u)", hdr_op), - len); + caplen); if (ret < 0) goto trunc; /* If debug level is more than 1 print payload contents */ - total_hdr_size = sizeof(struct af_vsockmon_hdr) + + /* This size had better fit in a u_int */ + total_hdr_size = (u_int)sizeof(struct af_vsockmon_hdr) + vsock_transport_hdr_size(hdr_transport); if (ndo->ndo_vflag > 1 && hdr_op == AF_VSOCK_OP_PAYLOAD) { - if (len > total_hdr_size) { + if (caplen > total_hdr_size) { const u_char *payload = p + total_hdr_size; ND_PRINT("\n"); print_unknown_data(ndo, payload, "\t", - len - total_hdr_size); + caplen - total_hdr_size); } else goto trunc; } @@ -240,18 +244,19 @@ trunc: nd_print_trunc(ndo); } -u_int +void vsock_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *cp) { - u_int len = h->caplen; + u_int caplen = h->caplen; ndo->ndo_protocol = "vsock"; - if (len < sizeof(struct af_vsockmon_hdr)) + if (caplen < sizeof(struct af_vsockmon_hdr)) { nd_print_trunc(ndo); - else - vsock_hdr_print(ndo, cp, len); - - return len; + ndo->ndo_ll_hdr_len += caplen; + return; + } + ndo->ndo_ll_hdr_len += sizeof(struct af_vsockmon_hdr); + vsock_hdr_print(ndo, cp, caplen); }