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.110 2003/09/19 09:02:02 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 | ||
@@ -146,7 +148,7 @@ TAILQ_HEAD(, packet) outgoing; | |||
146 | * packet_set_encryption_key is called. | 148 | * packet_set_encryption_key is called. |
147 | */ | 149 | */ |
148 | void | 150 | void |
149 | packet_set_connection(int fd_in, int fd_out) | 151 | packet_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; |
@@ -830,6 +833,7 @@ packet_read_seqnr(u_int32_t *seqnr_p) | |||
830 | int type, len; | 833 | int type, len; |
831 | fd_set *setp; | 834 | fd_set *setp; |
832 | char buf[8192]; | 835 | char buf[8192]; |
836 | struct timeval tv, *tvp; | ||
833 | DBG(debug("packet_read()")); | 837 | DBG(debug("packet_read()")); |
834 | 838 | ||
835 | setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) * | 839 | setp = (fd_set *)xmalloc(howmany(connection_in+1, NFDBITS) * |
@@ -861,11 +865,21 @@ packet_read_seqnr(u_int32_t *seqnr_p) | |||
861 | sizeof(fd_mask)); | 865 | sizeof(fd_mask)); |
862 | FD_SET(connection_in, setp); | 866 | FD_SET(connection_in, setp); |
863 | 867 | ||
868 | if (setup_timeout > 0) { | ||
869 | tvp = &tv; | ||
870 | tv.tv_sec = setup_timeout; | ||
871 | tv.tv_usec = 0; | ||
872 | } else | ||
873 | tvp = 0; | ||
874 | |||
864 | /* Wait for some data to arrive. */ | 875 | /* Wait for some data to arrive. */ |
865 | while (select(connection_in + 1, setp, NULL, NULL, NULL) == -1 && | 876 | while (select(connection_in + 1, setp, NULL, NULL, tvp) == -1 && |
866 | (errno == EAGAIN || errno == EINTR)) | 877 | (errno == EAGAIN || errno == EINTR)) |
867 | ; | 878 | ; |
868 | 879 | ||
880 | if (!FD_ISSET(connection_in, setp)) | ||
881 | fatal("packet_read: Setup timeout expired, giving up"); | ||
882 | |||
869 | /* Read data from the socket. */ | 883 | /* Read data from the socket. */ |
870 | len = read(connection_in, buf, sizeof(buf)); | 884 | len = read(connection_in, buf, sizeof(buf)); |
871 | if (len == 0) { | 885 | if (len == 0) { |