|
Lines 132-137
static int server_side = 0;
Link Here
|
| 132 |
/* Set to true if we are authenticated. */ |
132 |
/* Set to true if we are authenticated. */ |
| 133 |
static int after_authentication = 0; |
133 |
static int after_authentication = 0; |
| 134 |
|
134 |
|
|
|
135 |
/* Set to the maximum time that we will wait to send or receive a packet */ |
| 136 |
static int packet_timeout_ms = -1; |
| 137 |
|
| 135 |
/* Session key information for Encryption and MAC */ |
138 |
/* Session key information for Encryption and MAC */ |
| 136 |
Newkeys *newkeys[MODE_MAX]; |
139 |
Newkeys *newkeys[MODE_MAX]; |
| 137 |
static struct packet_state { |
140 |
static struct packet_state { |
|
Lines 185-190
packet_set_connection(int fd_in, int fd_
Link Here
|
| 185 |
} |
188 |
} |
| 186 |
} |
189 |
} |
| 187 |
|
190 |
|
|
|
191 |
void |
| 192 |
packet_set_timeout(int timeout, int count) |
| 193 |
{ |
| 194 |
if (timeout == 0 || count == 0) { |
| 195 |
packet_timeout_ms = -1; |
| 196 |
return; |
| 197 |
} |
| 198 |
if ((INT_MAX / 1000) / count < timeout) |
| 199 |
packet_timeout_ms = INT_MAX; |
| 200 |
else |
| 201 |
packet_timeout_ms = timeout * count * 1000; |
| 202 |
} |
| 203 |
|
| 188 |
/* Returns 1 if remote host is connected via socket, 0 if not. */ |
204 |
/* Returns 1 if remote host is connected via socket, 0 if not. */ |
| 189 |
|
205 |
|
| 190 |
int |
206 |
int |
|
Lines 880-889
packet_send(void)
Link Here
|
| 880 |
int |
896 |
int |
| 881 |
packet_read_seqnr(u_int32_t *seqnr_p) |
897 |
packet_read_seqnr(u_int32_t *seqnr_p) |
| 882 |
{ |
898 |
{ |
| 883 |
int type, len; |
899 |
int type, len, ret, ms_remain; |
| 884 |
fd_set *setp; |
900 |
fd_set *setp; |
| 885 |
char buf[8192]; |
901 |
char buf[8192]; |
| 886 |
DBG(debug("packet_read()")); |
902 |
DBG(debug("packet_read()")); |
|
|
903 |
struct timeval timeout, start, *timeoutp = NULL; |
| 887 |
|
904 |
|
| 888 |
setp = (fd_set *)xcalloc(howmany(connection_in+1, NFDBITS), |
905 |
setp = (fd_set *)xcalloc(howmany(connection_in+1, NFDBITS), |
| 889 |
sizeof(fd_mask)); |
906 |
sizeof(fd_mask)); |
|
Lines 914-924
packet_read_seqnr(u_int32_t *seqnr_p)
Link Here
|
| 914 |
sizeof(fd_mask)); |
931 |
sizeof(fd_mask)); |
| 915 |
FD_SET(connection_in, setp); |
932 |
FD_SET(connection_in, setp); |
| 916 |
|
933 |
|
|
|
934 |
if (packet_timeout_ms > 0) { |
| 935 |
ms_remain = packet_timeout_ms; |
| 936 |
timeoutp = &timeout; |
| 937 |
} |
| 917 |
/* Wait for some data to arrive. */ |
938 |
/* Wait for some data to arrive. */ |
| 918 |
while (select(connection_in + 1, setp, NULL, NULL, NULL) == -1 && |
939 |
for (;;) { |
| 919 |
(errno == EAGAIN || errno == EINTR)) |
940 |
if (packet_timeout_ms != -1) { |
| 920 |
; |
941 |
ms_to_timeval(&timeout, ms_remain); |
| 921 |
|
942 |
gettimeofday(&start, NULL); |
|
|
943 |
} |
| 944 |
if ((ret = select(connection_in + 1, setp, NULL, |
| 945 |
NULL, timeoutp)) >= 0) |
| 946 |
break; |
| 947 |
if (errno != EAGAIN && errno != EINTR) |
| 948 |
break; |
| 949 |
if (packet_timeout_ms == -1) |
| 950 |
continue; |
| 951 |
ms_subtract_diff(&start, &ms_remain); |
| 952 |
if (ms_remain <= 0) { |
| 953 |
ret = 0; |
| 954 |
break; |
| 955 |
} |
| 956 |
} |
| 957 |
if (ret == 0) { |
| 958 |
logit("Connection to %.200s timed out while " |
| 959 |
"waiting to read", get_remote_ipaddr()); |
| 960 |
cleanup_exit(255); |
| 961 |
} |
| 922 |
/* Read data from the socket. */ |
962 |
/* Read data from the socket. */ |
| 923 |
len = read(connection_in, buf, sizeof(buf)); |
963 |
len = read(connection_in, buf, sizeof(buf)); |
| 924 |
if (len == 0) { |
964 |
if (len == 0) { |
|
Lines 1432-1437
void
Link Here
|
| 1432 |
packet_write_wait(void) |
1472 |
packet_write_wait(void) |
| 1433 |
{ |
1473 |
{ |
| 1434 |
fd_set *setp; |
1474 |
fd_set *setp; |
|
|
1475 |
int ret, ms_remain; |
| 1476 |
struct timeval start, timeout, *timeoutp = NULL; |
| 1435 |
|
1477 |
|
| 1436 |
setp = (fd_set *)xcalloc(howmany(connection_out + 1, NFDBITS), |
1478 |
setp = (fd_set *)xcalloc(howmany(connection_out + 1, NFDBITS), |
| 1437 |
sizeof(fd_mask)); |
1479 |
sizeof(fd_mask)); |
|
Lines 1440-1448
packet_write_wait(void)
Link Here
|
| 1440 |
memset(setp, 0, howmany(connection_out + 1, NFDBITS) * |
1482 |
memset(setp, 0, howmany(connection_out + 1, NFDBITS) * |
| 1441 |
sizeof(fd_mask)); |
1483 |
sizeof(fd_mask)); |
| 1442 |
FD_SET(connection_out, setp); |
1484 |
FD_SET(connection_out, setp); |
| 1443 |
while (select(connection_out + 1, NULL, setp, NULL, NULL) == -1 && |
1485 |
|
| 1444 |
(errno == EAGAIN || errno == EINTR)) |
1486 |
if (packet_timeout_ms > 0) { |
| 1445 |
; |
1487 |
ms_remain = packet_timeout_ms; |
|
|
1488 |
timeoutp = &timeout; |
| 1489 |
} |
| 1490 |
for (;;) { |
| 1491 |
if (packet_timeout_ms != -1) { |
| 1492 |
ms_to_timeval(&timeout, ms_remain); |
| 1493 |
gettimeofday(&start, NULL); |
| 1494 |
} |
| 1495 |
if ((ret = select(connection_out + 1, NULL, setp, |
| 1496 |
NULL, timeoutp)) >= 0) |
| 1497 |
break; |
| 1498 |
if (errno != EAGAIN && errno != EINTR) |
| 1499 |
break; |
| 1500 |
if (packet_timeout_ms == -1) |
| 1501 |
continue; |
| 1502 |
ms_subtract_diff(&start, &ms_remain); |
| 1503 |
if (ms_remain <= 0) { |
| 1504 |
ret = 0; |
| 1505 |
break; |
| 1506 |
} |
| 1507 |
} |
| 1508 |
if (ret == 0) { |
| 1509 |
logit("Connection to %.200s timed out while " |
| 1510 |
"waiting to write", get_remote_ipaddr()); |
| 1511 |
cleanup_exit(255); |
| 1512 |
} |
| 1446 |
packet_write_poll(); |
1513 |
packet_write_poll(); |
| 1447 |
} |
1514 |
} |
| 1448 |
xfree(setp); |
1515 |
xfree(setp); |