From 2aed077761aa96f4a7891e0736e6463d2c9f2050 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 6 Nov 2021 17:19:02 +0900 Subject: [PATCH] Merge fd_set_recv_ecn to create_quic_server_socket and handle errors --- src/shrpx_worker.cc | 20 ++++++++++++++++++-- src/util.cc | 23 ----------------------- src/util.h | 2 -- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc index c0169066..04bae7ed 100644 --- a/src/shrpx_worker.cc +++ b/src/shrpx_worker.cc @@ -834,6 +834,15 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) { continue; } + if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVTCLASS, &val, + static_cast(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(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: " diff --git a/src/util.cc b/src/util.cc index bb6e5e47..7ee5acf9 100644 --- a/src/util.cc +++ b/src/util.cc @@ -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(sizeof(tos))) == -1) { - return -1; - } - - return 0; - case AF_INET6: - if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVTCLASS, &tos, - static_cast(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: diff --git a/src/util.h b/src/util.h index 359e785f..e7a07242 100644 --- a/src/util.h +++ b/src/util.h @@ -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