udp: Combine initialisation of IPv4 and IPv6 iovs

We're going to introduce more sharing between the IPv4 and IPv6 buffer
structures.  Prepare for this by combinng the initialisation functions.
While we're at it remove the misleading "sock" from the name since these
initialise both tap side and sock side structures.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2024-05-01 18:31:06 +10:00 committed by Stefano Brivio
parent 3f9bd867b5
commit 6c4d26a364

28
udp.c
View file

@ -316,12 +316,13 @@ void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s)
}
/**
* udp_sock4_iov_init_one() - Initialise a scatter-gather L2 buffer for IPv4
* udp_iov_init_one() - Initialise scatter-gather lists for one buffer
* @c: Execution context
* @i: Index of buffer to initialize
*/
static void udp_sock4_iov_init_one(const struct ctx *c, size_t i)
static void udp_iov_init_one(const struct ctx *c, size_t i)
{
if (c->ifi4) {
struct msghdr *mh = &udp4_l2_mh_sock[i].msg_hdr;
struct udp4_l2_buf_t *buf = &udp4_l2_buf[i];
struct iovec *siov = &udp4_l2_iov_sock[i];
@ -345,13 +346,7 @@ static void udp_sock4_iov_init_one(const struct ctx *c, size_t i)
tiov[UDP_IOV_PAYLOAD].iov_base = &buf->uh;
}
/**
* udp_sock6_iov_init_one() - Initialise a scatter-gather L2 buffer for IPv6
* @c: Execution context
* @i: Index of buffer to initialize
*/
static void udp_sock6_iov_init_one(const struct ctx *c, size_t i)
{
if (c->ifi6) {
struct msghdr *mh = &udp6_l2_mh_sock[i].msg_hdr;
struct udp6_l2_buf_t *buf = &udp6_l2_buf[i];
struct iovec *siov = &udp6_l2_iov_sock[i];
@ -374,21 +369,18 @@ static void udp_sock6_iov_init_one(const struct ctx *c, size_t i)
tiov[UDP_IOV_IP] = IOV_OF_LVALUE(buf->ip6h);
tiov[UDP_IOV_PAYLOAD].iov_base = &buf->uh;
}
}
/**
* udp_sock_iov_init() - Initialise scatter-gather L2 buffers
* udp_iov_init() - Initialise scatter-gather L2 buffers
* @c: Execution context
*/
static void udp_sock_iov_init(const struct ctx *c)
static void udp_iov_init(const struct ctx *c)
{
size_t i;
for (i = 0; i < UDP_MAX_FRAMES; i++) {
if (c->ifi4)
udp_sock4_iov_init_one(c, i);
if (c->ifi6)
udp_sock6_iov_init_one(c, i);
}
for (i = 0; i < UDP_MAX_FRAMES; i++)
udp_iov_init_one(c, i);
}
/**
@ -1259,7 +1251,7 @@ v6:
*/
int udp_init(struct ctx *c)
{
udp_sock_iov_init(c);
udp_iov_init(c);
udp_invert_portmap(&c->udp.fwd_in);
udp_invert_portmap(&c->udp.fwd_out);