tap: use in->buf_size rather than sizeof(pkt_buf)

buf_size is set to sizeof(pkt_buf) by default. And it seems more correct
to provide the actual size of the buffer.

Later a buf_size of 0 will allow vhost-user mode to detect
guest memory buffers.

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Laurent Vivier 2024-06-13 14:36:55 +02:00 committed by Stefano Brivio
parent 7290335b14
commit 4070bac7a4

10
tap.c
View file

@ -602,7 +602,7 @@ resume:
if (!eh) if (!eh)
continue; continue;
if (ntohs(eh->h_proto) == ETH_P_ARP) { if (ntohs(eh->h_proto) == ETH_P_ARP) {
PACKET_POOL_P(pkt, 1, in->buf, sizeof(pkt_buf)); PACKET_POOL_P(pkt, 1, in->buf, in->buf_size);
packet_add(pkt, l2len, (char *)eh); packet_add(pkt, l2len, (char *)eh);
arp(c, pkt); arp(c, pkt);
@ -642,7 +642,7 @@ resume:
continue; continue;
if (iph->protocol == IPPROTO_ICMP) { if (iph->protocol == IPPROTO_ICMP) {
PACKET_POOL_P(pkt, 1, in->buf, sizeof(pkt_buf)); PACKET_POOL_P(pkt, 1, in->buf, in->buf_size);
if (c->no_icmp) if (c->no_icmp)
continue; continue;
@ -661,7 +661,7 @@ resume:
continue; continue;
if (iph->protocol == IPPROTO_UDP) { if (iph->protocol == IPPROTO_UDP) {
PACKET_POOL_P(pkt, 1, in->buf, sizeof(pkt_buf)); PACKET_POOL_P(pkt, 1, in->buf, in->buf_size);
packet_add(pkt, l2len, (char *)eh); packet_add(pkt, l2len, (char *)eh);
if (dhcp(c, pkt)) if (dhcp(c, pkt))
@ -810,7 +810,7 @@ resume:
} }
if (proto == IPPROTO_ICMPV6) { if (proto == IPPROTO_ICMPV6) {
PACKET_POOL_P(pkt, 1, in->buf, sizeof(pkt_buf)); PACKET_POOL_P(pkt, 1, in->buf, in->buf_size);
if (c->no_icmp) if (c->no_icmp)
continue; continue;
@ -834,7 +834,7 @@ resume:
uh = (struct udphdr *)l4h; uh = (struct udphdr *)l4h;
if (proto == IPPROTO_UDP) { if (proto == IPPROTO_UDP) {
PACKET_POOL_P(pkt, 1, in->buf, sizeof(pkt_buf)); PACKET_POOL_P(pkt, 1, in->buf, in->buf_size);
packet_add(pkt, l4len, l4h); packet_add(pkt, l4len, l4h);