1
0
mirror of https://passt.top/passt synced 2024-06-29 22:42:46 +00:00

udp: Don't pre-initialize msghdr array

In udp_tap_handler() the array of msghdr structures, mm[], is initialized
to zero.  Since UIO_MAXIOV is 1024, this can be quite a large zero, which
is expensive if we only end up using a few of its entries.  It also makes
it less obvious how we're setting all the control fields at the point we
actually invoke sendmmsg().

Rather than pre-initializing it, just initialize each element as we use it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2022-09-13 16:37:43 +10:00 committed by Stefano Brivio
parent 6f2db0e34b
commit 484652c632

6
udp.c
View File

@ -968,7 +968,7 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events,
int udp_tap_handler(struct ctx *c, int af, const void *addr,
const struct pool *p, const struct timespec *now)
{
struct mmsghdr mm[UIO_MAXIOV] = { 0 };
struct mmsghdr mm[UIO_MAXIOV];
struct iovec m[UIO_MAXIOV];
struct sockaddr_in6 s_in6;
struct sockaddr_in s_in;
@ -1087,6 +1087,10 @@ int udp_tap_handler(struct ctx *c, int af, const void *addr,
mm[i].msg_hdr.msg_iov = m + i;
mm[i].msg_hdr.msg_iovlen = 1;
mm[i].msg_hdr.msg_control = NULL;
mm[i].msg_hdr.msg_controllen = 0;
mm[i].msg_hdr.msg_flags = 0;
count++;
}