1
0
Fork 0
mirror of https://passt.top/passt synced 2025-05-22 01:05:35 +02:00

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>
This commit is contained in:
David Gibson 2025-04-15 17:16:23 +10:00 committed by Stefano Brivio
parent f107a86cc0
commit cfc0ee145a

44
udp.c
View file

@ -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;
}