summaryrefslogtreecommitdiff
path: root/packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/packet.c b/packet.c
index 7c150fde7..e2607b20f 100644
--- a/packet.c
+++ b/packet.c
@@ -79,6 +79,8 @@ RCSID("$OpenBSD: packet.c,v 1.116 2004/10/20 11:48:53 markus Exp $");
79static int connection_in = -1; 79static int connection_in = -1;
80static int connection_out = -1; 80static int connection_out = -1;
81 81
82static int setup_timeout = -1;
83
82/* Protocol flags for the remote side. */ 84/* Protocol flags for the remote side. */
83static u_int remote_protocol_flags = 0; 85static u_int remote_protocol_flags = 0;
84 86
@@ -146,7 +148,7 @@ TAILQ_HEAD(, packet) outgoing;
146 * packet_set_encryption_key is called. 148 * packet_set_encryption_key is called.
147 */ 149 */
148void 150void
149packet_set_connection(int fd_in, int fd_out) 151packet_set_connection(int fd_in, int fd_out, int new_setup_timeout)
150{ 152{
151 Cipher *none = cipher_by_name("none"); 153 Cipher *none = cipher_by_name("none");
152 154
@@ -154,6 +156,7 @@ packet_set_connection(int fd_in, int fd_out)
154 fatal("packet_set_connection: cannot load cipher 'none'"); 156 fatal("packet_set_connection: cannot load cipher 'none'");
155 connection_in = fd_in; 157 connection_in = fd_in;
156 connection_out = fd_out; 158 connection_out = fd_out;
159 setup_timeout = new_setup_timeout;
157 cipher_init(&send_context, none, (const u_char *)"", 160 cipher_init(&send_context, none, (const u_char *)"",
158 0, NULL, 0, CIPHER_ENCRYPT); 161 0, NULL, 0, CIPHER_ENCRYPT);
159 cipher_init(&receive_context, none, (const u_char *)"", 162 cipher_init(&receive_context, none, (const u_char *)"",
@@ -827,6 +830,7 @@ packet_read_seqnr(u_int32_t *seqnr_p)
827 int type, len; 830 int type, len;
828 fd_set *setp; 831 fd_set *setp;
829 char buf[8192]; 832 char buf[8192];
833 struct timeval tv, *tvp;
830 DBG(debug("packet_read()")); 834 DBG(debug("packet_read()"));
831 835
832 setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) * 836 setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) *
@@ -858,11 +862,21 @@ packet_read_seqnr(u_int32_t *seqnr_p)
858 sizeof(fd_mask)); 862 sizeof(fd_mask));
859 FD_SET(connection_in, setp); 863 FD_SET(connection_in, setp);
860 864
865 if (setup_timeout > 0) {
866 tvp = &tv;
867 tv.tv_sec = setup_timeout;
868 tv.tv_usec = 0;
869 } else
870 tvp = 0;
871
861 /* Wait for some data to arrive. */ 872 /* Wait for some data to arrive. */
862 while (select(connection_in + 1, setp, NULL, NULL, NULL) == -1 && 873 while (select(connection_in + 1, setp, NULL, NULL, tvp) == -1 &&
863 (errno == EAGAIN || errno == EINTR)) 874 (errno == EAGAIN || errno == EINTR))
864 ; 875 ;
865 876
877 if (!FD_ISSET(connection_in, setp))
878 fatal("packet_read: Setup timeout expired, giving up");
879
866 /* Read data from the socket. */ 880 /* Read data from the socket. */
867 len = read(connection_in, buf, sizeof(buf)); 881 len = read(connection_in, buf, sizeof(buf));
868 if (len == 0) { 882 if (len == 0) {