diff options
author | Damien Miller <djm@mindrot.org> | 2000-01-14 15:45:46 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2000-01-14 15:45:46 +1100 |
commit | 34132e54cbd221d17d373fc54f4e3f7b85727f7f (patch) | |
tree | 7c73917b1082ff91786f9e02d25b853bedd1d472 /packet.c | |
parent | 25e4256ad4f453d8a7c1866243ec1984f859b1de (diff) |
- Merged OpenBSD IPv6 patch:
- [sshd.c sshd.8 sshconnect.c ssh.h ssh.c servconf.h servconf.c scp.1]
[scp.c packet.h packet.c login.c log.c canohost.c channels.c]
[hostfile.c sshd_config]
ipv6 support: mostly gethostbyname->getaddrinfo/getnameinfo, new
features: sshd allows multiple ListenAddress and Port options. note
that libwrap is not IPv6-ready. (based on patches from
fujiwara@rcac.tdi.co.jp)
- [ssh.c canohost.c]
more hints (hints.ai_socktype=SOCK_STREAM) for getaddrinfo,
from itojun@
- [channels.c]
listen on _all_ interfaces for X11-Fwd (hints.ai_flags = AI_PASSIVE)
- [packet.h]
allow auth-kerberos for IPv4 only
- [scp.1 sshd.8 servconf.h scp.c]
document -4, -6, and 'ssh -L 2022/::1/22'
- [ssh.c]
'ssh @host' is illegal (null user name), from
karsten@gedankenpolizei.de
- [sshconnect.c]
better error message
- [sshd.c]
allow auth-kerberos for IPv4 only
- Big IPv6 merge:
- Cleanup overrun in sockaddr copying on RHL 6.1
- Replacements for getaddrinfo, getnameinfo, etc based on versions
from patch from KIKUCHI Takahiro <kick@kyoto.wide.ad.jp>
- Replacement for missing structures on systems that lack IPv6
- record_login needed to know about AF_INET6 addresses
- Borrowed more code from OpenBSD: rresvport_af and requisites
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 65 |
1 files changed, 54 insertions, 11 deletions
@@ -15,7 +15,7 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "includes.h" | 17 | #include "includes.h" |
18 | RCSID("$Id: packet.c,v 1.8 1999/12/16 02:18:04 damien Exp $"); | 18 | RCSID("$Id: packet.c,v 1.9 2000/01/14 04:45:50 damien Exp $"); |
19 | 19 | ||
20 | #include "xmalloc.h" | 20 | #include "xmalloc.h" |
21 | #include "buffer.h" | 21 | #include "buffer.h" |
@@ -104,6 +104,48 @@ packet_set_connection(int fd_in, int fd_out) | |||
104 | fatal_add_cleanup((void (*) (void *)) packet_close, NULL); | 104 | fatal_add_cleanup((void (*) (void *)) packet_close, NULL); |
105 | } | 105 | } |
106 | 106 | ||
107 | /* Returns 1 if remote host is connected via socket, 0 if not. */ | ||
108 | |||
109 | int | ||
110 | packet_connection_is_on_socket() | ||
111 | { | ||
112 | struct sockaddr_storage from, to; | ||
113 | socklen_t fromlen, tolen; | ||
114 | |||
115 | /* filedescriptors in and out are the same, so it's a socket */ | ||
116 | if (connection_in == connection_out) | ||
117 | return 1; | ||
118 | fromlen = sizeof(from); | ||
119 | memset(&from, 0, sizeof(from)); | ||
120 | if (getpeername(connection_in, (struct sockaddr *) & from, &fromlen) < 0) | ||
121 | return 0; | ||
122 | tolen = sizeof(to); | ||
123 | memset(&to, 0, sizeof(to)); | ||
124 | if (getsockname(connection_out, (struct sockaddr *)&to, &tolen) < 0) | ||
125 | return 0; | ||
126 | if (fromlen != tolen || memcmp(&from, &to, fromlen) != 0) | ||
127 | return 0; | ||
128 | if (from.ss_family != AF_INET && from.ss_family != AF_INET6) | ||
129 | return 0; | ||
130 | return 1; | ||
131 | } | ||
132 | |||
133 | /* returns 1 if connection is via ipv4 */ | ||
134 | |||
135 | int | ||
136 | packet_connection_is_ipv4() | ||
137 | { | ||
138 | struct sockaddr_storage to; | ||
139 | socklen_t tolen; | ||
140 | |||
141 | memset(&to, 0, sizeof(to)); | ||
142 | if (getsockname(connection_out, (struct sockaddr *)&to, &tolen) < 0) | ||
143 | return 0; | ||
144 | if (to.ss_family != AF_INET) | ||
145 | return 0; | ||
146 | return 1; | ||
147 | } | ||
148 | |||
107 | /* Sets the connection into non-blocking mode. */ | 149 | /* Sets the connection into non-blocking mode. */ |
108 | 150 | ||
109 | void | 151 | void |
@@ -735,19 +777,20 @@ packet_set_interactive(int interactive, int keepalives) | |||
735 | /* Record that we are in interactive mode. */ | 777 | /* Record that we are in interactive mode. */ |
736 | interactive_mode = interactive; | 778 | interactive_mode = interactive; |
737 | 779 | ||
738 | /* | 780 | /* Only set socket options if using a socket. */ |
739 | * Only set socket options if using a socket (as indicated by the | 781 | if (!packet_connection_is_on_socket()) |
740 | * descriptors being the same). | ||
741 | */ | ||
742 | if (connection_in != connection_out) | ||
743 | return; | 782 | return; |
744 | |||
745 | if (keepalives) { | 783 | if (keepalives) { |
746 | /* Set keepalives if requested. */ | 784 | /* Set keepalives if requested. */ |
747 | if (setsockopt(connection_in, SOL_SOCKET, SO_KEEPALIVE, (void *) &on, | 785 | if (setsockopt(connection_in, SOL_SOCKET, SO_KEEPALIVE, (void *) &on, |
748 | sizeof(on)) < 0) | 786 | sizeof(on)) < 0) |
749 | error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); | 787 | error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); |
750 | } | 788 | } |
789 | /* | ||
790 | * IPTOS_LOWDELAY, TCP_NODELAY and IPTOS_THROUGHPUT are IPv4 only | ||
791 | */ | ||
792 | if (!packet_connection_is_ipv4()) | ||
793 | return; | ||
751 | if (interactive) { | 794 | if (interactive) { |
752 | /* | 795 | /* |
753 | * Set IP options for an interactive connection. Use | 796 | * Set IP options for an interactive connection. Use |
@@ -755,10 +798,10 @@ packet_set_interactive(int interactive, int keepalives) | |||
755 | */ | 798 | */ |
756 | int lowdelay = IPTOS_LOWDELAY; | 799 | int lowdelay = IPTOS_LOWDELAY; |
757 | if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, (void *) &lowdelay, | 800 | if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, (void *) &lowdelay, |
758 | sizeof(lowdelay)) < 0) | 801 | sizeof(lowdelay)) < 0) |
759 | error("setsockopt IPTOS_LOWDELAY: %.100s", strerror(errno)); | 802 | error("setsockopt IPTOS_LOWDELAY: %.100s", strerror(errno)); |
760 | if (setsockopt(connection_in, IPPROTO_TCP, TCP_NODELAY, (void *) &on, | 803 | if (setsockopt(connection_in, IPPROTO_TCP, TCP_NODELAY, (void *) &on, |
761 | sizeof(on)) < 0) | 804 | sizeof(on)) < 0) |
762 | error("setsockopt TCP_NODELAY: %.100s", strerror(errno)); | 805 | error("setsockopt TCP_NODELAY: %.100s", strerror(errno)); |
763 | } else { | 806 | } else { |
764 | /* | 807 | /* |
@@ -767,7 +810,7 @@ packet_set_interactive(int interactive, int keepalives) | |||
767 | */ | 810 | */ |
768 | int throughput = IPTOS_THROUGHPUT; | 811 | int throughput = IPTOS_THROUGHPUT; |
769 | if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, (void *) &throughput, | 812 | if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, (void *) &throughput, |
770 | sizeof(throughput)) < 0) | 813 | sizeof(throughput)) < 0) |
771 | error("setsockopt IPTOS_THROUGHPUT: %.100s", strerror(errno)); | 814 | error("setsockopt IPTOS_THROUGHPUT: %.100s", strerror(errno)); |
772 | } | 815 | } |
773 | } | 816 | } |