diff options
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -93,6 +93,8 @@ | |||
93 | static int connection_in = -1; | 93 | static int connection_in = -1; |
94 | static int connection_out = -1; | 94 | static int connection_out = -1; |
95 | 95 | ||
96 | static int setup_timeout = -1; | ||
97 | |||
96 | /* Protocol flags for the remote side. */ | 98 | /* Protocol flags for the remote side. */ |
97 | static u_int remote_protocol_flags = 0; | 99 | static 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 | */ |
168 | void | 170 | void |
169 | packet_set_connection(int fd_in, int fd_out) | 171 | packet_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 *)"", |
@@ -891,6 +894,7 @@ packet_read_seqnr(u_int32_t *seqnr_p) | |||
891 | int type, len; | 894 | int type, len; |
892 | fd_set *setp; | 895 | fd_set *setp; |
893 | char buf[8192]; | 896 | char buf[8192]; |
897 | struct timeval tv, *tvp; | ||
894 | DBG(debug("packet_read()")); | 898 | DBG(debug("packet_read()")); |
895 | 899 | ||
896 | setp = (fd_set *)xcalloc(howmany(connection_in+1, NFDBITS), | 900 | setp = (fd_set *)xcalloc(howmany(connection_in+1, NFDBITS), |
@@ -922,11 +926,21 @@ packet_read_seqnr(u_int32_t *seqnr_p) | |||
922 | sizeof(fd_mask)); | 926 | sizeof(fd_mask)); |
923 | FD_SET(connection_in, setp); | 927 | FD_SET(connection_in, setp); |
924 | 928 | ||
929 | if (setup_timeout > 0) { | ||
930 | tvp = &tv; | ||
931 | tv.tv_sec = setup_timeout; | ||
932 | tv.tv_usec = 0; | ||
933 | } else | ||
934 | tvp = NULL; | ||
935 | |||
925 | /* Wait for some data to arrive. */ | 936 | /* Wait for some data to arrive. */ |
926 | while (select(connection_in + 1, setp, NULL, NULL, NULL) == -1 && | 937 | while (select(connection_in + 1, setp, NULL, NULL, tvp) == -1 && |
927 | (errno == EAGAIN || errno == EINTR)) | 938 | (errno == EAGAIN || errno == EINTR)) |
928 | ; | 939 | ; |
929 | 940 | ||
941 | if (!FD_ISSET(connection_in, setp)) | ||
942 | fatal("packet_read: Setup timeout expired, giving up"); | ||
943 | |||
930 | /* Read data from the socket. */ | 944 | /* Read data from the socket. */ |
931 | len = read(connection_in, buf, sizeof(buf)); | 945 | len = read(connection_in, buf, sizeof(buf)); |
932 | if (len == 0) { | 946 | if (len == 0) { |