The vhost-user and non-vhost-user paths for both udp_listen_sock_handler() and udp_reply_sock_handler() are more or less completely separate. Both, however, start with essentially the same invocation of udp_sock_errs(), so that can be made common. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- udp.c | 37 ++++++++++++++++++++----------------- udp_internal.h | 2 +- udp_vu.c | 15 --------------- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/udp.c b/udp.c index 88128181..ca101fec 100644 --- a/udp.c +++ b/udp.c @@ -587,7 +587,8 @@ static int udp_sock_recverr(const struct ctx *c, union epoll_ref ref) * * Return: Number of errors handled, or < 0 if we have an unrecoverable error */ -int udp_sock_errs(const struct ctx *c, union epoll_ref ref, uint32_t events) +static int udp_sock_errs(const struct ctx *c, union epoll_ref ref, + uint32_t events) { unsigned n_err = 0; socklen_t errlen; @@ -680,13 +681,6 @@ static void udp_buf_listen_sock_handler(const struct ctx *c, const socklen_t sasize = sizeof(udp_meta[0].s_in); int n, i; - if (udp_sock_errs(c, ref, events) < 0) { - err("UDP: Unrecoverable error on listening socket:" - " (%s port %hu)", pif_name(ref.udp.pif), ref.udp.port); - /* FIXME: what now? close/re-open socket? */ - return; - } - if ((n = udp_sock_recv(c, ref.fd, events, udp_mh_recv)) <= 0) return; @@ -752,6 +746,13 @@ void udp_listen_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events, const struct timespec *now) { + if (udp_sock_errs(c, ref, events) < 0) { + err("UDP: Unrecoverable error on listening socket:" + " (%s port %hu)", pif_name(ref.udp.pif), ref.udp.port); + /* FIXME: what now? close/re-open socket? */ + return; + } + if (c->mode == MODE_VU) { udp_vu_listen_sock_handler(c, ref, events, now); return; @@ -779,17 +780,8 @@ static void udp_buf_reply_sock_handler(const struct ctx *c, union epoll_ref ref, uint8_t topif = pif_at_sidx(tosidx); int n, i, from_s; - ASSERT(!c->no_udp && uflow); - from_s = uflow->s[ref.flowside.sidei]; - if (udp_sock_errs(c, ref, events) < 0) { - flow_err(uflow, "Unrecoverable error on reply socket"); - flow_err_details(uflow); - udp_flow_close(c, uflow); - return; - } - if ((n = udp_sock_recv(c, from_s, events, udp_mh_recv)) <= 0) return; @@ -827,6 +819,17 @@ static void udp_buf_reply_sock_handler(const struct ctx *c, union epoll_ref ref, void udp_reply_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events, const struct timespec *now) { + struct udp_flow *uflow = udp_at_sidx(ref.flowside); + + ASSERT(!c->no_udp && uflow); + + if (udp_sock_errs(c, ref, events) < 0) { + flow_err(uflow, "Unrecoverable error on reply socket"); + flow_err_details(uflow); + udp_flow_close(c, uflow); + return; + } + if (c->mode == MODE_VU) { udp_vu_reply_sock_handler(c, ref, events, now); return; diff --git a/udp_internal.h b/udp_internal.h index 3b081f54..02724e59 100644 --- a/udp_internal.h +++ b/udp_internal.h @@ -30,5 +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_sock_errs(const struct ctx *c, union epoll_ref ref, uint32_t events); + #endif /* UDP_INTERNAL_H */ diff --git a/udp_vu.c b/udp_vu.c index c26a223d..84f52aff 100644 --- a/udp_vu.c +++ b/udp_vu.c @@ -227,12 +227,6 @@ void udp_vu_listen_sock_handler(const struct ctx *c, union epoll_ref ref, struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; int i; - if (udp_sock_errs(c, ref, events) < 0) { - err("UDP: Unrecoverable error on listening socket:" - " (%s port %hu)", pif_name(ref.udp.pif), ref.udp.port); - return; - } - for (i = 0; i < UDP_MAX_FRAMES; i++) { const struct flowside *toside; union sockaddr_inany s_in; @@ -300,15 +294,6 @@ void udp_vu_reply_sock_handler(const struct ctx *c, union epoll_ref ref, struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; int i; - ASSERT(!c->no_udp); - - if (udp_sock_errs(c, ref, events) < 0) { - flow_err(uflow, "Unrecoverable error on reply socket"); - flow_err_details(uflow); - udp_flow_close(c, uflow); - return; - } - for (i = 0; i < UDP_MAX_FRAMES; i++) { uint8_t topif = pif_at_sidx(tosidx); ssize_t dlen; -- 2.49.0