summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2009-11-18 17:48:30 +1100
committerDamien Miller <djm@mindrot.org>2009-11-18 17:48:30 +1100
commit04ee0f8f12ff3a1227439c5f67623547d7a5bd11 (patch)
treec434c075dc85b9eead1e2e8ac2a1046cf7c42417
parentdf6578bb4df17210f792c3bc98a72bed473e7e11 (diff)
- (djm) [channels.c misc.c misc.h sshd.c] add missing setsockopt() to
set IPV6_V6ONLY for local forwarding with GatwayPorts=yes. Unify setting IPV6_V6ONLY behind a new function misc.c:sock_set_v6only() report and fix from jan.kratochvil AT redhat.com
-rw-r--r--ChangeLog6
-rw-r--r--channels.c11
-rw-r--r--misc.c11
-rw-r--r--misc.h1
-rw-r--r--sshd.c10
5 files changed, 24 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 9a17b25ae..c2e6cadc6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
120091107 120091107
2 - (djm) [channels.c misc.c misc.h sshd.c] add missing setsockopt() to
3 set IPV6_V6ONLY for local forwarding with GatwayPorts=yes. Unify
4 setting IPV6_V6ONLY behind a new function misc.c:sock_set_v6only()
5 report and fix from jan.kratochvil AT redhat.com
6
720091107
2 - (dtucker) [authfile.c] Fall back to 3DES for the encryption of private 8 - (dtucker) [authfile.c] Fall back to 3DES for the encryption of private
3 keys when built with OpenSSL versions that don't do AES. 9 keys when built with OpenSSL versions that don't do AES.
4 10
diff --git a/channels.c b/channels.c
index e8b8aa07e..22e7f628b 100644
--- a/channels.c
+++ b/channels.c
@@ -2577,6 +2577,8 @@ channel_setup_fwd_listener(int type, const char *listen_addr,
2577 } 2577 }
2578 2578
2579 channel_set_reuseaddr(sock); 2579 channel_set_reuseaddr(sock);
2580 if (ai->ai_family == AF_INET6)
2581 sock_set_v6only(sock);
2580 2582
2581 debug("Local forwarding listening on %s port %s.", 2583 debug("Local forwarding listening on %s port %s.",
2582 ntop, strport); 2584 ntop, strport);
@@ -3108,13 +3110,8 @@ x11_create_display_inet(int x11_display_offset, int x11_use_localhost,
3108 continue; 3110 continue;
3109 } 3111 }
3110 } 3112 }
3111#ifdef IPV6_V6ONLY 3113 if (ai->ai_family == AF_INET6)
3112 if (ai->ai_family == AF_INET6) { 3114 sock_set_v6only(sock);
3113 int on = 1;
3114 if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0)
3115 error("setsockopt IPV6_V6ONLY: %.100s", strerror(errno));
3116 }
3117#endif
3118 if (x11_use_localhost) 3115 if (x11_use_localhost)
3119 channel_set_reuseaddr(sock); 3116 channel_set_reuseaddr(sock);
3120 if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) { 3117 if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
diff --git a/misc.c b/misc.c
index 143dbf0e2..4dc152310 100644
--- a/misc.c
+++ b/misc.c
@@ -849,3 +849,14 @@ ms_to_timeval(struct timeval *tv, int ms)
849 tv->tv_usec = (ms % 1000) * 1000; 849 tv->tv_usec = (ms % 1000) * 1000;
850} 850}
851 851
852void
853sock_set_v6only(int s)
854{
855#ifdef IPV6_V6ONLY
856 int on = 1;
857
858 debug3("%s: set socket %d IPV6_V6ONLY", __func__, s);
859 if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1)
860 error("setsockopt IPV6_V6ONLY: %s", strerror(errno));
861#endif
862}
diff --git a/misc.h b/misc.h
index 5da170d2f..e26b0aaff 100644
--- a/misc.h
+++ b/misc.h
@@ -35,6 +35,7 @@ char *tohex(const void *, size_t);
35void sanitise_stdfd(void); 35void sanitise_stdfd(void);
36void ms_subtract_diff(struct timeval *, int *); 36void ms_subtract_diff(struct timeval *, int *);
37void ms_to_timeval(struct timeval *, int); 37void ms_to_timeval(struct timeval *, int);
38void sock_set_v6only(int);
38 39
39struct passwd *pwcopy(struct passwd *); 40struct passwd *pwcopy(struct passwd *);
40const char *ssh_gai_strerror(int); 41const char *ssh_gai_strerror(int);
diff --git a/sshd.c b/sshd.c
index 13a455d1f..04d8f9fa0 100644
--- a/sshd.c
+++ b/sshd.c
@@ -979,15 +979,9 @@ server_listen(void)
979 &on, sizeof(on)) == -1) 979 &on, sizeof(on)) == -1)
980 error("setsockopt SO_REUSEADDR: %s", strerror(errno)); 980 error("setsockopt SO_REUSEADDR: %s", strerror(errno));
981 981
982#ifdef IPV6_V6ONLY
983 /* Only communicate in IPv6 over AF_INET6 sockets. */ 982 /* Only communicate in IPv6 over AF_INET6 sockets. */
984 if (ai->ai_family == AF_INET6) { 983 if (ai->ai_family == AF_INET6)
985 if (setsockopt(listen_sock, IPPROTO_IPV6, IPV6_V6ONLY, 984 sock_set_v6only(listen_sock);
986 &on, sizeof(on)) == -1)
987 error("setsockopt IPV6_V6ONLY: %s",
988 strerror(errno));
989 }
990#endif
991 985
992 debug("Bind to port %s on %s.", strport, ntop); 986 debug("Bind to port %s on %s.", strport, ntop);
993 987