mirror of
https://passt.top/passt
synced 2025-05-28 20:35:33 +02:00
udp: Merge vhost-user and "buf" listening socket paths
udp_buf_listen_sock_data() and udp_vu_listen_sock_data() now have effectively identical structure. The forwarding functions used for flow specific sockets (udp_buf_sock_to_tap(), udp_vu_sock_to_tap() and udp_sock_to_sock()) also now take a number of datagrams. This means we can re-use them for the listening socket path, just passing '1' so they handle a single datagram at a time. This allows us to merge both the vhost-user and flow specific paths into a single, simpler udp_listen_sock_data(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
0304dd9c34
commit
fc6ee68ad3
3 changed files with 10 additions and 80 deletions
27
udp.c
27
udp.c
|
@ -629,7 +629,7 @@ static int udp_sock_errs(const struct ctx *c, union epoll_ref ref)
|
|||
*
|
||||
* Return: 0 on success, -1 otherwise
|
||||
*/
|
||||
int udp_peek_addr(int s, union sockaddr_inany *src)
|
||||
static int udp_peek_addr(int s, union sockaddr_inany *src)
|
||||
{
|
||||
struct msghdr msg = {
|
||||
.msg_name = src,
|
||||
|
@ -714,12 +714,12 @@ static void udp_buf_sock_to_tap(const struct ctx *c, int s, int n,
|
|||
}
|
||||
|
||||
/**
|
||||
* udp_buf_listen_sock_data() - Handle new data from socket
|
||||
* udp_listen_sock_data() - Handle new data from listening socket
|
||||
* @c: Execution context
|
||||
* @ref: epoll reference
|
||||
* @now: Current timestamp
|
||||
*/
|
||||
static void udp_buf_listen_sock_data(const struct ctx *c, union epoll_ref ref,
|
||||
static void udp_listen_sock_data(const struct ctx *c, union epoll_ref ref,
|
||||
const struct timespec *now)
|
||||
{
|
||||
union sockaddr_inany src;
|
||||
|
@ -728,16 +728,13 @@ static void udp_buf_listen_sock_data(const struct ctx *c, union epoll_ref ref,
|
|||
flow_sidx_t tosidx = udp_flow_from_sock(c, ref, &src, now);
|
||||
uint8_t topif = pif_at_sidx(tosidx);
|
||||
|
||||
if (udp_sock_recv(c, ref.fd, udp_mh_recv, 1) <= 0)
|
||||
break;
|
||||
|
||||
if (pif_is_socket(topif)) {
|
||||
udp_splice_prepare(udp_mh_recv, 0);
|
||||
udp_splice_send(c, 0, 1, tosidx);
|
||||
udp_sock_to_sock(c, ref.fd, 1, tosidx);
|
||||
} else if (topif == PIF_TAP) {
|
||||
udp_tap_prepare(udp_mh_recv, 0, flowside_at_sidx(tosidx),
|
||||
false);
|
||||
tap_send_frames(c, &udp_l2_iov[0][0], UDP_NUM_IOVS, 1);
|
||||
if (c->mode == MODE_VU)
|
||||
udp_vu_sock_to_tap(c, ref.fd, 1, tosidx);
|
||||
else
|
||||
udp_buf_sock_to_tap(c, ref.fd, 1, tosidx);
|
||||
} else if (flow_sidx_valid(tosidx)) {
|
||||
flow_sidx_t fromsidx = flow_sidx_opposite(tosidx);
|
||||
struct udp_flow *uflow = udp_at_sidx(tosidx);
|
||||
|
@ -772,12 +769,8 @@ void udp_listen_sock_handler(const struct ctx *c,
|
|||
}
|
||||
}
|
||||
|
||||
if (events & EPOLLIN) {
|
||||
if (c->mode == MODE_VU)
|
||||
udp_vu_listen_sock_data(c, ref, now);
|
||||
else
|
||||
udp_buf_listen_sock_data(c, ref, now);
|
||||
}
|
||||
if (events & EPOLLIN)
|
||||
udp_listen_sock_data(c, ref, now);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,6 +30,5 @@ size_t udp_update_hdr4(struct iphdr *ip4h, struct udp_payload_t *bp,
|
|||
size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t *bp,
|
||||
const struct flowside *toside, size_t dlen,
|
||||
bool no_udp_csum);
|
||||
int udp_peek_addr(int s, union sockaddr_inany *src);
|
||||
|
||||
#endif /* UDP_INTERNAL_H */
|
||||
|
|
62
udp_vu.c
62
udp_vu.c
|
@ -191,68 +191,6 @@ static void udp_vu_csum(const struct flowside *toside, int iov_used)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* udp_vu_listen_sock_data() - Handle new data from socket
|
||||
* @c: Execution context
|
||||
* @ref: epoll reference
|
||||
* @now: Current timestamp
|
||||
*/
|
||||
void udp_vu_listen_sock_data(const struct ctx *c, union epoll_ref ref,
|
||||
const struct timespec *now)
|
||||
{
|
||||
struct vu_dev *vdev = c->vdev;
|
||||
struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < UDP_MAX_FRAMES; i++) {
|
||||
const struct flowside *toside;
|
||||
union sockaddr_inany s_in;
|
||||
flow_sidx_t sidx;
|
||||
uint8_t pif;
|
||||
ssize_t dlen;
|
||||
int iov_used;
|
||||
bool v6;
|
||||
|
||||
if (udp_peek_addr(ref.fd, &s_in) < 0)
|
||||
break;
|
||||
|
||||
sidx = udp_flow_from_sock(c, ref, &s_in, now);
|
||||
pif = pif_at_sidx(sidx);
|
||||
|
||||
if (pif != PIF_TAP) {
|
||||
if (flow_sidx_valid(sidx)) {
|
||||
flow_sidx_t fromsidx = flow_sidx_opposite(sidx);
|
||||
struct udp_flow *uflow = udp_at_sidx(sidx);
|
||||
|
||||
flow_err(uflow,
|
||||
"No support for forwarding UDP from %s to %s",
|
||||
pif_name(pif_at_sidx(fromsidx)),
|
||||
pif_name(pif));
|
||||
} else {
|
||||
debug("Discarding 1 datagram without flow");
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
toside = flowside_at_sidx(sidx);
|
||||
|
||||
v6 = !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr));
|
||||
|
||||
iov_used = udp_vu_sock_recv(c, ref.fd, v6, &dlen);
|
||||
if (iov_used <= 0)
|
||||
break;
|
||||
|
||||
udp_vu_prepare(c, toside, dlen);
|
||||
if (*c->pcap) {
|
||||
udp_vu_csum(toside, iov_used);
|
||||
pcap_iov(iov_vu, iov_used,
|
||||
sizeof(struct virtio_net_hdr_mrg_rxbuf));
|
||||
}
|
||||
vu_flush(vdev, vq, elem, iov_used);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* udp_vu_sock_to_tap() - Forward datagrams from socket to tap
|
||||
* @c: Execution context
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue