View | Details | Raw Unified | Return to bug 1363 | Differences between
and this patch

Collapse All | Expand All

(-)misc.c (+20 lines)
Lines 803-805 put_u16(void *vp, u_int16_t v) Link Here
803
	p[0] = (u_char)(v >> 8) & 0xff;
803
	p[0] = (u_char)(v >> 8) & 0xff;
804
	p[1] = (u_char)v & 0xff;
804
	p[1] = (u_char)v & 0xff;
805
}
805
}
806
807
void
808
ms_subtract_diff(struct timeval *start, int *ms)
809
{
810
	struct timeval diff, finish;
811
812
	gettimeofday(&finish, NULL);
813
	timersub(&finish, start, &diff);	
814
	*ms -= (diff.tv_sec * 1000) + (diff.tv_usec / 1000);
815
}
816
817
void
818
ms_to_timeval(struct timeval *tv, int ms)
819
{
820
	if (ms < 0)
821
		ms = 0;
822
	tv->tv_sec = ms / 1000;
823
	tv->tv_usec = (ms % 1000) * 1000;
824
}
825
(-)misc.h (+2 lines)
Lines 33-38 char *tilde_expand_filename(const char * Link Here
33
char	*percent_expand(const char *, ...) __attribute__((__sentinel__));
33
char	*percent_expand(const char *, ...) __attribute__((__sentinel__));
34
char	*tohex(const void *, size_t);
34
char	*tohex(const void *, size_t);
35
void	 sanitise_stdfd(void);
35
void	 sanitise_stdfd(void);
36
void	 ms_subtract_diff(struct timeval *, int *);
37
void	 ms_to_timeval(struct timeval *, int);
36
38
37
struct passwd *pwcopy(struct passwd *);
39
struct passwd *pwcopy(struct passwd *);
38
40
(-)packet.c (-8 / +75 lines)
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);
(-)packet.h (+1 lines)
Lines 21-26 Link Here
21
#include <openssl/bn.h>
21
#include <openssl/bn.h>
22
22
23
void     packet_set_connection(int, int);
23
void     packet_set_connection(int, int);
24
void     packet_set_timeout(int, int);
24
void     packet_set_nonblocking(void);
25
void     packet_set_nonblocking(void);
25
int      packet_get_connection_in(void);
26
int      packet_get_connection_in(void);
26
int      packet_get_connection_out(void);
27
int      packet_get_connection_out(void);
(-)sshconnect.c (-17 / +4 lines)
Lines 64-86 extern pid_t proxy_command_pid; Link Here
64
static int show_other_keys(const char *, Key *);
64
static int show_other_keys(const char *, Key *);
65
static void warn_changed_key(Key *);
65
static void warn_changed_key(Key *);
66
66
67
static void
68
ms_subtract_diff(struct timeval *start, int *ms)
69
{
70
	struct timeval diff, finish;
71
72
	gettimeofday(&finish, NULL);
73
	timersub(&finish, start, &diff);	
74
	*ms -= (diff.tv_sec * 1000) + (diff.tv_usec / 1000);
75
}
76
77
static void
78
ms_to_timeval(struct timeval *tv, int ms)
79
{
80
	tv->tv_sec = ms / 1000;
81
	tv->tv_usec = (ms % 1000) * 1000;
82
}
83
84
/*
67
/*
85
 * Connect to the given ssh server using a proxy command.
68
 * Connect to the given ssh server using a proxy command.
86
 */
69
 */
Lines 165-170 ssh_proxy_connect(const char *host, u_sh Link Here
165
148
166
	/* Set the connection file descriptors. */
149
	/* Set the connection file descriptors. */
167
	packet_set_connection(pout[0], pin[1]);
150
	packet_set_connection(pout[0], pin[1]);
151
	packet_set_timeout(options.server_alive_interval,
152
	    options.server_alive_count_max);
168
153
169
	/* Indicate OK return */
154
	/* Indicate OK return */
170
	return 0;
155
	return 0;
Lines 409-414 ssh_connect(const char *host, struct soc Link Here
409
394
410
	/* Set the connection. */
395
	/* Set the connection. */
411
	packet_set_connection(sock, sock);
396
	packet_set_connection(sock, sock);
397
	packet_set_timeout(options.server_alive_interval,
398
	    options.server_alive_count_max);
412
399
413
	return 0;
400
	return 0;
414
}
401
}
(-)sshd.c (+2 lines)
Lines 1611-1616 main(int ac, char **av) Link Here
1611
	 * not have a key.
1611
	 * not have a key.
1612
	 */
1612
	 */
1613
	packet_set_connection(sock_in, sock_out);
1613
	packet_set_connection(sock_in, sock_out);
1614
	packet_set_timeout(options.client_alive_interval,
1615
	    options.client_alive_count_max);
1614
	packet_set_server();
1616
	packet_set_server();
1615
1617
1616
	/* Set SO_KEEPALIVE if requested. */
1618
	/* Set SO_KEEPALIVE if requested. */

Return to bug 1363