diff options
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -79,6 +79,8 @@ RCSID("$OpenBSD: packet.c,v 1.119 2005/07/28 17:36:22 markus Exp $"); | |||
79 | static int connection_in = -1; | 79 | static int connection_in = -1; |
80 | static int connection_out = -1; | 80 | static int connection_out = -1; |
81 | 81 | ||
82 | static int setup_timeout = -1; | ||
83 | |||
82 | /* Protocol flags for the remote side. */ | 84 | /* Protocol flags for the remote side. */ |
83 | static u_int remote_protocol_flags = 0; | 85 | static u_int remote_protocol_flags = 0; |
84 | 86 | ||
@@ -152,7 +154,7 @@ TAILQ_HEAD(, packet) outgoing; | |||
152 | * packet_set_encryption_key is called. | 154 | * packet_set_encryption_key is called. |
153 | */ | 155 | */ |
154 | void | 156 | void |
155 | packet_set_connection(int fd_in, int fd_out) | 157 | packet_set_connection(int fd_in, int fd_out, int new_setup_timeout) |
156 | { | 158 | { |
157 | Cipher *none = cipher_by_name("none"); | 159 | Cipher *none = cipher_by_name("none"); |
158 | 160 | ||
@@ -160,6 +162,7 @@ packet_set_connection(int fd_in, int fd_out) | |||
160 | fatal("packet_set_connection: cannot load cipher 'none'"); | 162 | fatal("packet_set_connection: cannot load cipher 'none'"); |
161 | connection_in = fd_in; | 163 | connection_in = fd_in; |
162 | connection_out = fd_out; | 164 | connection_out = fd_out; |
165 | setup_timeout = new_setup_timeout; | ||
163 | cipher_init(&send_context, none, (const u_char *)"", | 166 | cipher_init(&send_context, none, (const u_char *)"", |
164 | 0, NULL, 0, CIPHER_ENCRYPT); | 167 | 0, NULL, 0, CIPHER_ENCRYPT); |
165 | cipher_init(&receive_context, none, (const u_char *)"", | 168 | cipher_init(&receive_context, none, (const u_char *)"", |
@@ -866,6 +869,7 @@ packet_read_seqnr(u_int32_t *seqnr_p) | |||
866 | int type, len; | 869 | int type, len; |
867 | fd_set *setp; | 870 | fd_set *setp; |
868 | char buf[8192]; | 871 | char buf[8192]; |
872 | struct timeval tv, *tvp; | ||
869 | DBG(debug("packet_read()")); | 873 | DBG(debug("packet_read()")); |
870 | 874 | ||
871 | setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) * | 875 | setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) * |
@@ -897,11 +901,21 @@ packet_read_seqnr(u_int32_t *seqnr_p) | |||
897 | sizeof(fd_mask)); | 901 | sizeof(fd_mask)); |
898 | FD_SET(connection_in, setp); | 902 | FD_SET(connection_in, setp); |
899 | 903 | ||
904 | if (setup_timeout > 0) { | ||
905 | tvp = &tv; | ||
906 | tv.tv_sec = setup_timeout; | ||
907 | tv.tv_usec = 0; | ||
908 | } else | ||
909 | tvp = 0; | ||
910 | |||
900 | /* Wait for some data to arrive. */ | 911 | /* Wait for some data to arrive. */ |
901 | while (select(connection_in + 1, setp, NULL, NULL, NULL) == -1 && | 912 | while (select(connection_in + 1, setp, NULL, NULL, tvp) == -1 && |
902 | (errno == EAGAIN || errno == EINTR)) | 913 | (errno == EAGAIN || errno == EINTR)) |
903 | ; | 914 | ; |
904 | 915 | ||
916 | if (!FD_ISSET(connection_in, setp)) | ||
917 | fatal("packet_read: Setup timeout expired, giving up"); | ||
918 | |||
905 | /* Read data from the socket. */ | 919 | /* Read data from the socket. */ |
906 | len = read(connection_in, buf, sizeof(buf)); | 920 | len = read(connection_in, buf, sizeof(buf)); |
907 | if (len == 0) { | 921 | if (len == 0) { |