mirror of
https://passt.top/passt
synced 2025-06-20 05:55:33 +02:00
udp: Fix breakage of UDP error handling by PKTINFO support
We recently enabled the IP_PKTINFO / IPV6_RECVPKTINFO socket options on our
UDP sockets. This lets us obtain and properly handle the specific local
address used when we're "listening" with a socket on 0.0.0.0 or ::.
However, the PKTINFO cmsgs this option generates appear on error queue
messages as well as regular datagrams. udp_sock_recverr() doesn't expect
this and so flags an unrecoverable error when it can't parse the control
message.
Correct this by adding space in udp_sock_recverr()s control buffer for the
additional PKTINFO data, and scan through all cmsgs for the RECVERR, rather
than only looking at the first one.
Link: https://bugs.passt.top/show_bug.cgi?id=99
Fixes: f4b0dd8b06
("udp: Use PKTINFO cmsgs to get destination address for received datagrams")
Reported-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
50249086a9
commit
baf049f8e0
1 changed files with 17 additions and 13 deletions
30
udp.c
30
udp.c
|
@ -155,6 +155,10 @@ __attribute__ ((aligned(32)))
|
||||||
#endif
|
#endif
|
||||||
udp_meta[UDP_MAX_FRAMES];
|
udp_meta[UDP_MAX_FRAMES];
|
||||||
|
|
||||||
|
#define PKTINFO_SPACE \
|
||||||
|
MAX(CMSG_SPACE(sizeof(struct in_pktinfo)), \
|
||||||
|
CMSG_SPACE(sizeof(struct in6_pktinfo)))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enum udp_iov_idx - Indices for the buffers making up a single UDP frame
|
* enum udp_iov_idx - Indices for the buffers making up a single UDP frame
|
||||||
* @UDP_IOV_TAP tap specific header
|
* @UDP_IOV_TAP tap specific header
|
||||||
|
@ -476,10 +480,10 @@ static int udp_sock_recverr(const struct ctx *c, union epoll_ref ref)
|
||||||
struct sock_extended_err ee;
|
struct sock_extended_err ee;
|
||||||
union sockaddr_inany saddr;
|
union sockaddr_inany saddr;
|
||||||
};
|
};
|
||||||
const struct errhdr *eh;
|
char buf[PKTINFO_SPACE + CMSG_SPACE(sizeof(struct errhdr))];
|
||||||
const struct cmsghdr *hdr;
|
|
||||||
char buf[CMSG_SPACE(sizeof(struct errhdr))];
|
|
||||||
char data[ICMP6_MAX_DLEN];
|
char data[ICMP6_MAX_DLEN];
|
||||||
|
const struct errhdr *eh;
|
||||||
|
struct cmsghdr *hdr;
|
||||||
int s = ref.fd;
|
int s = ref.fd;
|
||||||
struct iovec iov = {
|
struct iovec iov = {
|
||||||
.iov_base = data,
|
.iov_base = data,
|
||||||
|
@ -507,12 +511,16 @@ static int udp_sock_recverr(const struct ctx *c, union epoll_ref ref)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hdr = CMSG_FIRSTHDR(&mh);
|
for (hdr = CMSG_FIRSTHDR(&mh); hdr; hdr = CMSG_NXTHDR(&mh, hdr)) {
|
||||||
if (!((hdr->cmsg_level == IPPROTO_IP &&
|
if ((hdr->cmsg_level == IPPROTO_IP &&
|
||||||
hdr->cmsg_type == IP_RECVERR) ||
|
hdr->cmsg_type == IP_RECVERR) ||
|
||||||
(hdr->cmsg_level == IPPROTO_IPV6 &&
|
(hdr->cmsg_level == IPPROTO_IPV6 &&
|
||||||
hdr->cmsg_type == IPV6_RECVERR))) {
|
hdr->cmsg_type == IPV6_RECVERR))
|
||||||
err("Unexpected cmsg reading error queue");
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hdr) {
|
||||||
|
err("Missing RECVERR cmsg in error queue");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,10 +595,6 @@ static int udp_sock_errs(const struct ctx *c, union epoll_ref ref)
|
||||||
return n_err;
|
return n_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PKTINFO_SPACE \
|
|
||||||
MAX(CMSG_SPACE(sizeof(struct in_pktinfo)), \
|
|
||||||
CMSG_SPACE(sizeof(struct in6_pktinfo)))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* udp_peek_addr() - Get source address for next packet
|
* udp_peek_addr() - Get source address for next packet
|
||||||
* @s: Socket to get information from
|
* @s: Socket to get information from
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue