tap: Call tap_receive_iov() from tap_receive()

This will save duplicate logic found in both of tap_receive_iov() and
tap_receive().

Suggested-by: "Zhang, Chen" <chen.zhang@intel.com>
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
Akihiko Odaki 2024-04-28 16:00:48 +09:00 committed by Jason Wang
parent b9ad513e18
commit 336a058b26

View File

@ -133,39 +133,14 @@ static ssize_t tap_receive_iov(NetClientState *nc, const struct iovec *iov,
return tap_write_packet(s, iovp, iovcnt);
}
static ssize_t tap_receive_raw(NetClientState *nc, const uint8_t *buf, size_t size)
{
TAPState *s = DO_UPCAST(TAPState, nc, nc);
struct iovec iov[2];
int iovcnt = 0;
struct virtio_net_hdr_mrg_rxbuf hdr = { };
if (s->host_vnet_hdr_len) {
iov[iovcnt].iov_base = &hdr;
iov[iovcnt].iov_len = s->host_vnet_hdr_len;
iovcnt++;
}
iov[iovcnt].iov_base = (char *)buf;
iov[iovcnt].iov_len = size;
iovcnt++;
return tap_write_packet(s, iov, iovcnt);
}
static ssize_t tap_receive(NetClientState *nc, const uint8_t *buf, size_t size)
{
TAPState *s = DO_UPCAST(TAPState, nc, nc);
struct iovec iov[1];
struct iovec iov = {
.iov_base = (void *)buf,
.iov_len = size
};
if (s->host_vnet_hdr_len && !s->using_vnet_hdr) {
return tap_receive_raw(nc, buf, size);
}
iov[0].iov_base = (char *)buf;
iov[0].iov_len = size;
return tap_write_packet(s, iov, 1);
return tap_receive_iov(nc, &iov, 1);
}
#ifndef __sun__