Merge fd_set_recv_ecn to create_quic_server_socket and handle errors

This commit is contained in:
Tatsuhiro Tsujikawa 2021-11-06 17:19:02 +09:00
parent 68b2295f4e
commit 2aed077761
3 changed files with 18 additions and 27 deletions

View File

@ -834,6 +834,15 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) {
continue;
}
if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVTCLASS, &val,
static_cast<socklen_t>(sizeof(val))) == -1) {
auto error = errno;
LOG(WARN) << "Failed to set IPV6_RECVTCLASS option to listener socket: "
<< xsi_strerror(error, errbuf.data(), errbuf.size());
close(fd);
continue;
}
# if defined(IPV6_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
int mtu_disc = IP_PMTUDISC_DO;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, &mtu_disc,
@ -856,6 +865,15 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) {
continue;
}
if (setsockopt(fd, IPPROTO_IP, IP_RECVTOS, &val,
static_cast<socklen_t>(sizeof(val))) == -1) {
auto error = errno;
LOG(WARN) << "Failed to set IP_RECVTOS option to listener socket: "
<< xsi_strerror(error, errbuf.data(), errbuf.size());
close(fd);
continue;
}
# if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
int mtu_disc = IP_PMTUDISC_DO;
if (setsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER, &mtu_disc,
@ -869,8 +887,6 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) {
# endif // defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
}
util::fd_set_recv_ecn(fd, faddr.family);
if (bind(fd, rp->ai_addr, rp->ai_addrlen) == -1) {
auto error = errno;
LOG(WARN) << "bind() syscall failed: "

View File

@ -1748,29 +1748,6 @@ unsigned int msghdr_get_ecn(msghdr *msg, int family) {
return 0;
}
int fd_set_recv_ecn(int fd, int family) {
unsigned int tos = 1;
switch (family) {
case AF_INET:
if (setsockopt(fd, IPPROTO_IP, IP_RECVTOS, &tos,
static_cast<socklen_t>(sizeof(tos))) == -1) {
return -1;
}
return 0;
case AF_INET6:
if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVTCLASS, &tos,
static_cast<socklen_t>(sizeof(tos))) == -1) {
return -1;
}
return 0;
}
return -1;
}
int fd_set_send_ecn(int fd, int family, unsigned int ecn) {
switch (family) {
case AF_INET:

View File

@ -921,8 +921,6 @@ int msghdr_get_local_addr(Address &dest, msghdr *msg, int family);
unsigned int msghdr_get_ecn(msghdr *msg, int family);
int fd_set_recv_ecn(int fd, int family);
int fd_set_send_ecn(int fd, int family, unsigned int ecn);
#endif // ENABLE_HTTP3