aboutgitcodebugslistschat
path: root/udp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-05-01 18:31:06 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-05-02 16:13:41 +0200
commit6c4d26a3645b8cf58a62972f9e1b4e4af89971e0 (patch)
tree15e85fdc0a4960952c8aae85e50e6c53b7599fc9 /udp.c
parent3f9bd867b58513da50d79e039fb88c7fd332408e (diff)
downloadpasst-6c4d26a3645b8cf58a62972f9e1b4e4af89971e0.tar
passt-6c4d26a3645b8cf58a62972f9e1b4e4af89971e0.tar.gz
passt-6c4d26a3645b8cf58a62972f9e1b4e4af89971e0.tar.bz2
passt-6c4d26a3645b8cf58a62972f9e1b4e4af89971e0.tar.lz
passt-6c4d26a3645b8cf58a62972f9e1b4e4af89971e0.tar.xz
passt-6c4d26a3645b8cf58a62972f9e1b4e4af89971e0.tar.zst
passt-6c4d26a3645b8cf58a62972f9e1b4e4af89971e0.zip
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>
Diffstat (limited to 'udp.c')
-rw-r--r--udp.c114
1 files changed, 53 insertions, 61 deletions
diff --git a/udp.c b/udp.c
index d293bc5..bb7d161 100644
--- a/udp.c
+++ b/udp.c
@@ -316,79 +316,71 @@ 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)
{
- 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];
- struct iovec *tiov = udp4_l2_iov_tap[i];
-
- *buf = (struct udp4_l2_buf_t) {
- .eh = ETH_HDR_INIT(ETH_P_IP),
- .iph = L2_BUF_IP4_INIT(IPPROTO_UDP)
- };
-
- *siov = IOV_OF_LVALUE(buf->data);
-
- mh->msg_name = &buf->s_in;
- mh->msg_namelen = sizeof(buf->s_in);
- mh->msg_iov = siov;
- mh->msg_iovlen = 1;
-
- tiov[UDP_IOV_TAP] = tap_hdr_iov(c, &buf->taph);
- tiov[UDP_IOV_ETH] = IOV_OF_LVALUE(buf->eh);
- tiov[UDP_IOV_IP] = IOV_OF_LVALUE(buf->iph);
- tiov[UDP_IOV_PAYLOAD].iov_base = &buf->uh;
-}
+ 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];
+ struct iovec *tiov = udp4_l2_iov_tap[i];
+
+ *buf = (struct udp4_l2_buf_t) {
+ .eh = ETH_HDR_INIT(ETH_P_IP),
+ .iph = L2_BUF_IP4_INIT(IPPROTO_UDP)
+ };
-/**
- * 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)
-{
- 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];
- struct iovec *tiov = udp6_l2_iov_tap[i];
-
- *buf = (struct udp6_l2_buf_t) {
- .eh = ETH_HDR_INIT(ETH_P_IPV6),
- .ip6h = L2_BUF_IP6_INIT(IPPROTO_UDP)
- };
-
- *siov = IOV_OF_LVALUE(buf->data);
-
- mh->msg_name = &buf->s_in6;
- mh->msg_namelen = sizeof(buf->s_in6);
- mh->msg_iov = siov;
- mh->msg_iovlen = 1;
-
- tiov[UDP_IOV_TAP] = tap_hdr_iov(c, &buf->taph);
- tiov[UDP_IOV_ETH] = IOV_OF_LVALUE(buf->eh);
- tiov[UDP_IOV_IP] = IOV_OF_LVALUE(buf->ip6h);
- tiov[UDP_IOV_PAYLOAD].iov_base = &buf->uh;
+ *siov = IOV_OF_LVALUE(buf->data);
+
+ mh->msg_name = &buf->s_in;
+ mh->msg_namelen = sizeof(buf->s_in);
+ mh->msg_iov = siov;
+ mh->msg_iovlen = 1;
+
+ tiov[UDP_IOV_TAP] = tap_hdr_iov(c, &buf->taph);
+ tiov[UDP_IOV_ETH] = IOV_OF_LVALUE(buf->eh);
+ tiov[UDP_IOV_IP] = IOV_OF_LVALUE(buf->iph);
+ tiov[UDP_IOV_PAYLOAD].iov_base = &buf->uh;
+ }
+
+ 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];
+ struct iovec *tiov = udp6_l2_iov_tap[i];
+
+ *buf = (struct udp6_l2_buf_t) {
+ .eh = ETH_HDR_INIT(ETH_P_IPV6),
+ .ip6h = L2_BUF_IP6_INIT(IPPROTO_UDP)
+ };
+
+ *siov = IOV_OF_LVALUE(buf->data);
+
+ mh->msg_name = &buf->s_in6;
+ mh->msg_namelen = sizeof(buf->s_in6);
+ mh->msg_iov = siov;
+ mh->msg_iovlen = 1;
+
+ tiov[UDP_IOV_TAP] = tap_hdr_iov(c, &buf->taph);
+ tiov[UDP_IOV_ETH] = IOV_OF_LVALUE(buf->eh);
+ 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);