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 f82a63c47..753abebd8 100644
--- a/packet.c
+++ b/packet.c
@@ -93,6 +93,8 @@
93static int connection_in = -1; 93static int connection_in = -1;
94static int connection_out = -1; 94static int connection_out = -1;
95 95
96static int setup_timeout = -1;
97
96/* Protocol flags for the remote side. */ 98/* Protocol flags for the remote side. */
97static u_int remote_protocol_flags = 0; 99static u_int remote_protocol_flags = 0;
98 100
@@ -166,7 +168,7 @@ TAILQ_HEAD(, packet) outgoing;
166 * packet_set_encryption_key is called. 168 * packet_set_encryption_key is called.
167 */ 169 */
168void 170void
169packet_set_connection(int fd_in, int fd_out) 171packet_set_connection(int fd_in, int fd_out, int new_setup_timeout)
170{ 172{
171 Cipher *none = cipher_by_name("none"); 173 Cipher *none = cipher_by_name("none");
172 174
@@ -174,6 +176,7 @@ packet_set_connection(int fd_in, int fd_out)
174 fatal("packet_set_connection: cannot load cipher 'none'"); 176 fatal("packet_set_connection: cannot load cipher 'none'");
175 connection_in = fd_in; 177 connection_in = fd_in;
176 connection_out = fd_out; 178 connection_out = fd_out;
179 setup_timeout = new_setup_timeout;
177 cipher_init(&send_context, none, (const u_char *)"", 180 cipher_init(&send_context, none, (const u_char *)"",
178 0, NULL, 0, CIPHER_ENCRYPT); 181 0, NULL, 0, CIPHER_ENCRYPT);
179 cipher_init(&receive_context, none, (const u_char *)"", 182 cipher_init(&receive_context, none, (const u_char *)"",
@@ -892,6 +895,7 @@ packet_read_seqnr(u_int32_t *seqnr_p)
892 int type, len; 895 int type, len;
893 fd_set *setp; 896 fd_set *setp;
894 char buf[8192]; 897 char buf[8192];
898 struct timeval tv, *tvp;
895 DBG(debug("packet_read()")); 899 DBG(debug("packet_read()"));
896 900
897 setp = (fd_set *)xcalloc(howmany(connection_in+1, NFDBITS), 901 setp = (fd_set *)xcalloc(howmany(connection_in+1, NFDBITS),
@@ -923,11 +927,21 @@ packet_read_seqnr(u_int32_t *seqnr_p)
923 sizeof(fd_mask)); 927 sizeof(fd_mask));
924 FD_SET(connection_in, setp); 928 FD_SET(connection_in, setp);
925 929
930 if (setup_timeout > 0) {
931 tvp = &tv;
932 tv.tv_sec = setup_timeout;
933 tv.tv_usec = 0;
934 } else
935 tvp = NULL;
936
926 /* Wait for some data to arrive. */ 937 /* Wait for some data to arrive. */
927 while (select(connection_in + 1, setp, NULL, NULL, NULL) == -1 && 938 while (select(connection_in + 1, setp, NULL, NULL, tvp) == -1 &&
928 (errno == EAGAIN || errno == EINTR)) 939 (errno == EAGAIN || errno == EINTR))
929 ; 940 ;
930 941
942 if (!FD_ISSET(connection_in, setp))
943 fatal("packet_read: Setup timeout expired, giving up");
944
931 /* Read data from the socket. */ 945 /* Read data from the socket. */
932 len = read(connection_in, buf, sizeof(buf)); 946 len = read(connection_in, buf, sizeof(buf));
933 if (len == 0) { 947 if (len == 0) {