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 daae9ffaa..f557cd75d 100644
--- a/packet.c
+++ b/packet.c
@@ -79,6 +79,8 @@ RCSID("$OpenBSD: packet.c,v 1.112 2003/09/23 20:17:11 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, "", 0, NULL, 0, CIPHER_ENCRYPT); 160 cipher_init(&send_context, none, "", 0, NULL, 0, CIPHER_ENCRYPT);
158 cipher_init(&receive_context, none, "", 0, NULL, 0, CIPHER_DECRYPT); 161 cipher_init(&receive_context, none, "", 0, NULL, 0, CIPHER_DECRYPT);
159 newkeys[MODE_IN] = newkeys[MODE_OUT] = NULL; 162 newkeys[MODE_IN] = newkeys[MODE_OUT] = NULL;
@@ -828,6 +831,7 @@ packet_read_seqnr(u_int32_t *seqnr_p)
828 int type, len; 831 int type, len;
829 fd_set *setp; 832 fd_set *setp;
830 char buf[8192]; 833 char buf[8192];
834 struct timeval tv, *tvp;
831 DBG(debug("packet_read()")); 835 DBG(debug("packet_read()"));
832 836
833 setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) * 837 setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) *
@@ -859,11 +863,21 @@ packet_read_seqnr(u_int32_t *seqnr_p)
859 sizeof(fd_mask)); 863 sizeof(fd_mask));
860 FD_SET(connection_in, setp); 864 FD_SET(connection_in, setp);
861 865
866 if (setup_timeout > 0) {
867 tvp = &tv;
868 tv.tv_sec = setup_timeout;
869 tv.tv_usec = 0;
870 } else
871 tvp = 0;
872
862 /* Wait for some data to arrive. */ 873 /* Wait for some data to arrive. */
863 while (select(connection_in + 1, setp, NULL, NULL, NULL) == -1 && 874 while (select(connection_in + 1, setp, NULL, NULL, tvp) == -1 &&
864 (errno == EAGAIN || errno == EINTR)) 875 (errno == EAGAIN || errno == EINTR))
865 ; 876 ;
866 877
878 if (!FD_ISSET(connection_in, setp))
879 fatal("packet_read: Setup timeout expired, giving up");
880
867 /* Read data from the socket. */ 881 /* Read data from the socket. */
868 len = read(connection_in, buf, sizeof(buf)); 882 len = read(connection_in, buf, sizeof(buf));
869 if (len == 0) { 883 if (len == 0) {