aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2025-04-15 17:16:23 +1000
committerStefano Brivio <sbrivio@redhat.com>2025-04-15 19:49:06 +0200
commitcfc0ee145a5cdd29b6e584171085dac6539b86c0 (patch)
treeb1a40b11d6289b2d8b92b9f4425c40c43a175126
parentf107a86cc05c83c5755861b00b85cdf0eb5c9534 (diff)
downloadpasst-cfc0ee145a5cdd29b6e584171085dac6539b86c0.tar
passt-cfc0ee145a5cdd29b6e584171085dac6539b86c0.tar.gz
passt-cfc0ee145a5cdd29b6e584171085dac6539b86c0.tar.bz2
passt-cfc0ee145a5cdd29b6e584171085dac6539b86c0.tar.lz
passt-cfc0ee145a5cdd29b6e584171085dac6539b86c0.tar.xz
passt-cfc0ee145a5cdd29b6e584171085dac6539b86c0.tar.zst
passt-cfc0ee145a5cdd29b6e584171085dac6539b86c0.zip
udp: Minor re-organisation of udp_sock_recverr()
Usually we work with the "exit early" flow style, where we return early on "error" conditions in functions. We don't currently do this in udp_sock_recverr() for the case where we don't have a flow to associate the error with. Reorganise to use the "exit early" style, which will make some subsequent changes less awkward. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--udp.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/udp.c b/udp.c
index 97034f6..e8240fe 100644
--- a/udp.c
+++ b/udp.c
@@ -530,6 +530,9 @@ static int udp_sock_recverr(const struct ctx *c, int s, flow_sidx_t sidx)
.msg_control = buf,
.msg_controllen = sizeof(buf),
};
+ const struct flowside *toside;
+ flow_sidx_t tosidx;
+ size_t dlen;
ssize_t rc;
rc = recvmsg(s, &mh, MSG_ERRQUEUE);
@@ -560,29 +563,32 @@ static int udp_sock_recverr(const struct ctx *c, int s, flow_sidx_t sidx)
}
eh = (const struct errhdr *)CMSG_DATA(hdr);
- if (flow_sidx_valid(sidx)) {
- flow_sidx_t tosidx = flow_sidx_opposite(sidx);
- const struct flowside *toside = flowside_at_sidx(tosidx);
- size_t dlen = rc;
-
- if (pif_is_socket(pif_at_sidx(tosidx))) {
- /* XXX Is there any way to propagate ICMPs from socket
- * to socket? */
- } else if (hdr->cmsg_level == IPPROTO_IP) {
- dlen = MIN(dlen, ICMP4_MAX_DLEN);
- udp_send_tap_icmp4(c, &eh->ee, toside,
- eh->saddr.sa4.sin_addr, data, dlen);
- } else if (hdr->cmsg_level == IPPROTO_IPV6) {
- udp_send_tap_icmp6(c, &eh->ee, toside,
- &eh->saddr.sa6.sin6_addr, data,
- dlen, sidx.flowi);
- }
- } else {
- trace("Ignoring received IP_RECVERR cmsg on listener socket");
- }
+
debug("%s error on UDP socket %i: %s",
str_ee_origin(&eh->ee), s, strerror_(eh->ee.ee_errno));
+ if (!flow_sidx_valid(sidx)) {
+ trace("Ignoring received IP_RECVERR cmsg on listener socket");
+ return 1;
+ }
+
+ tosidx = flow_sidx_opposite(sidx);
+ toside = flowside_at_sidx(tosidx);
+ dlen = rc;
+
+ if (pif_is_socket(pif_at_sidx(tosidx))) {
+ /* XXX Is there any way to propagate ICMPs from socket to
+ * socket? */
+ } else if (hdr->cmsg_level == IPPROTO_IP) {
+ dlen = MIN(dlen, ICMP4_MAX_DLEN);
+ udp_send_tap_icmp4(c, &eh->ee, toside,
+ eh->saddr.sa4.sin_addr, data, dlen);
+ } else if (hdr->cmsg_level == IPPROTO_IPV6) {
+ udp_send_tap_icmp6(c, &eh->ee, toside,
+ &eh->saddr.sa6.sin6_addr, data,
+ dlen, sidx.flowi);
+ }
+
return 1;
}