aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/iomgr
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-03-28 22:53:34 -0700
committerGravatar Craig Tiller <ctiller@google.com>2016-03-28 22:53:34 -0700
commitc2011586fae18c7b247686428a2469198589a1f9 (patch)
treedfcd31dd1d881e6c2bda9b565f853cb0d6ccb7d3 /src/core/lib/iomgr
parent3bd96959398d0671fee3785d4b2aee6042649b15 (diff)
parentc91504ed57c93d30f654d9f3a0fee62c1236fad8 (diff)
Merge github.com:grpc/grpc into idempotent
Diffstat (limited to 'src/core/lib/iomgr')
-rw-r--r--src/core/lib/iomgr/socket_utils_common_posix.c22
-rw-r--r--src/core/lib/iomgr/socket_utils_posix.h10
-rw-r--r--src/core/lib/iomgr/udp_server.c13
3 files changed, 35 insertions, 10 deletions
diff --git a/src/core/lib/iomgr/socket_utils_common_posix.c b/src/core/lib/iomgr/socket_utils_common_posix.c
index 9dbc2784e4..b433aee7fa 100644
--- a/src/core/lib/iomgr/socket_utils_common_posix.c
+++ b/src/core/lib/iomgr/socket_utils_common_posix.c
@@ -89,6 +89,28 @@ int grpc_set_socket_no_sigpipe_if_possible(int fd) {
#endif
}
+int grpc_set_socket_ip_pktinfo_if_possible(int fd) {
+#ifdef GPR_HAVE_IP_PKTINFO
+ int get_local_ip = 1;
+ return 0 == setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &get_local_ip,
+ sizeof(get_local_ip));
+#else
+ (void)fd;
+ return 1;
+#endif
+}
+
+int grpc_set_socket_ipv6_recvpktinfo_if_possible(int fd) {
+#ifdef GPR_HAVE_IPV6_RECVPKTINFO
+ int get_local_ip = 1;
+ return 0 == setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &get_local_ip,
+ sizeof(get_local_ip));
+#else
+ (void)fd;
+ return 1;
+#endif
+}
+
/* set a socket to close on exec */
int grpc_set_socket_cloexec(int fd, int close_on_exec) {
int oldflags = fcntl(fd, F_GETFD, 0);
diff --git a/src/core/lib/iomgr/socket_utils_posix.h b/src/core/lib/iomgr/socket_utils_posix.h
index 063f298d72..f73ad6317d 100644
--- a/src/core/lib/iomgr/socket_utils_posix.h
+++ b/src/core/lib/iomgr/socket_utils_posix.h
@@ -68,6 +68,16 @@ int grpc_ipv6_loopback_available(void);
If SO_NO_SIGPIPE is not available, returns 1. */
int grpc_set_socket_no_sigpipe_if_possible(int fd);
+/* Tries to set IP_PKTINFO if available on this platform.
+ Returns 1 on success, 0 on failure.
+ If IP_PKTINFO is not available, returns 1. */
+int grpc_set_socket_ip_pktinfo_if_possible(int fd);
+
+/* Tries to set IPV6_RECVPKTINFO if available on this platform.
+ Returns 1 on success, 0 on failure.
+ If IPV6_RECVPKTINFO is not available, returns 1. */
+int grpc_set_socket_ipv6_recvpktinfo_if_possible(int fd);
+
/* An enum to keep track of IPv4/IPv6 socket modes.
Currently, this information is only used when a socket is first created, but
diff --git a/src/core/lib/iomgr/udp_server.c b/src/core/lib/iomgr/udp_server.c
index 3d8bcc9c81..9068109c3a 100644
--- a/src/core/lib/iomgr/udp_server.c
+++ b/src/core/lib/iomgr/udp_server.c
@@ -208,8 +208,6 @@ static int prepare_socket(int fd, const struct sockaddr *addr,
size_t addr_len) {
struct sockaddr_storage sockname_temp;
socklen_t sockname_len;
- int get_local_ip;
- int rc;
if (fd < 0) {
goto error;
@@ -220,14 +218,9 @@ static int prepare_socket(int fd, const struct sockaddr *addr,
strerror(errno));
}
- get_local_ip = 1;
- rc = setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &get_local_ip,
- sizeof(get_local_ip));
- if (rc == 0 && addr->sa_family == AF_INET6) {
-#if !defined(__APPLE__)
- rc = setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &get_local_ip,
- sizeof(get_local_ip));
-#endif
+ if (grpc_set_socket_ip_pktinfo_if_possible(fd) &&
+ addr->sa_family == AF_INET6) {
+ grpc_set_socket_ipv6_recvpktinfo_if_possible(fd);
}
GPR_ASSERT(addr_len < ~(socklen_t)0);