summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/packet.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2021-11-13 21:14:14 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2021-11-13 21:14:14 +0000
commitdf21a02c5aa1af301932bc4f3c3ca413c1cf99c5 (patch)
tree6fbf1fe32e4cafe5d4e55733d5788df7dc5886b1 /usr.bin/ssh/packet.c
parentec1d50271610cb64a1ab8aa18289725a9c619ae3 (diff)
replace select() with ppoll(), including converting timeval's to timespec's
to make things easier. back and forth and ok; djm
Diffstat (limited to 'usr.bin/ssh/packet.c')
-rw-r--r--usr.bin/ssh/packet.c59
1 files changed, 20 insertions, 39 deletions
diff --git a/usr.bin/ssh/packet.c b/usr.bin/ssh/packet.c
index 240186162bb..21741e16a18 100644
--- a/usr.bin/ssh/packet.c
+++ b/usr.bin/ssh/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.301 2021/07/16 09:00:23 djm Exp $ */
+/* $OpenBSD: packet.c,v 1.302 2021/11/13 21:14:13 deraadt Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1305,17 +1305,13 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
{
struct session_state *state = ssh->state;
int len, r, ms_remain;
- fd_set *setp;
+ struct pollfd pfd;
char buf[8192];
- struct timeval timeout, start, *timeoutp = NULL;
+ struct timeval start;
+ struct timespec timespec, *timespecp = NULL;
DBG(debug("packet_read()"));
- setp = calloc(howmany(state->connection_in + 1,
- NFDBITS), sizeof(fd_mask));
- if (setp == NULL)
- return SSH_ERR_ALLOC_FAIL;
-
/*
* Since we are blocking, ensure that all written packets have
* been sent.
@@ -1336,22 +1332,20 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
* Otherwise, wait for some data to arrive, add it to the
* buffer, and try again.
*/
- memset(setp, 0, howmany(state->connection_in + 1,
- NFDBITS) * sizeof(fd_mask));
- FD_SET(state->connection_in, setp);
+ pfd.fd = state->connection_in;
+ pfd.events = POLLIN;
if (state->packet_timeout_ms > 0) {
ms_remain = state->packet_timeout_ms;
- timeoutp = &timeout;
+ timespecp = &timespec;
}
/* Wait for some data to arrive. */
for (;;) {
if (state->packet_timeout_ms > 0) {
- ms_to_timeval(&timeout, ms_remain);
+ ms_to_timespec(&timespec, ms_remain);
monotime_tv(&start);
}
- if ((r = select(state->connection_in + 1, setp,
- NULL, NULL, timeoutp)) >= 0)
+ if ((r = ppoll(&pfd, 1, timespecp, NULL)) >= 0)
break;
if (errno != EAGAIN && errno != EINTR) {
r = SSH_ERR_SYSTEM_ERROR;
@@ -1385,7 +1379,6 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
goto out;
}
out:
- free(setp);
return r;
}
@@ -1964,35 +1957,28 @@ ssh_packet_write_poll(struct ssh *ssh)
int
ssh_packet_write_wait(struct ssh *ssh)
{
- fd_set *setp;
int ret, r, ms_remain = 0;
- struct timeval start, timeout, *timeoutp = NULL;
+ struct timeval start;
+ struct timespec timespec, *timespecp = NULL;
struct session_state *state = ssh->state;
+ struct pollfd pfd;
- setp = calloc(howmany(state->connection_out + 1,
- NFDBITS), sizeof(fd_mask));
- if (setp == NULL)
- return SSH_ERR_ALLOC_FAIL;
- if ((r = ssh_packet_write_poll(ssh)) != 0) {
- free(setp);
+ if ((r = ssh_packet_write_poll(ssh)) != 0)
return r;
- }
while (ssh_packet_have_data_to_write(ssh)) {
- memset(setp, 0, howmany(state->connection_out + 1,
- NFDBITS) * sizeof(fd_mask));
- FD_SET(state->connection_out, setp);
+ pfd.fd = state->connection_out;
+ pfd.events = POLLOUT;
if (state->packet_timeout_ms > 0) {
ms_remain = state->packet_timeout_ms;
- timeoutp = &timeout;
+ timespecp = &timespec;
}
for (;;) {
if (state->packet_timeout_ms > 0) {
- ms_to_timeval(&timeout, ms_remain);
+ ms_to_timespec(&timespec, ms_remain);
monotime_tv(&start);
}
- if ((ret = select(state->connection_out + 1,
- NULL, setp, NULL, timeoutp)) >= 0)
+ if ((ret = ppoll(&pfd, 1, timespecp, NULL)) >= 0)
break;
if (errno != EAGAIN && errno != EINTR)
break;
@@ -2004,16 +1990,11 @@ ssh_packet_write_wait(struct ssh *ssh)
break;
}
}
- if (ret == 0) {
- free(setp);
+ if (ret == 0)
return SSH_ERR_CONN_TIMEOUT;
- }
- if ((r = ssh_packet_write_poll(ssh)) != 0) {
- free(setp);
+ if ((r = ssh_packet_write_poll(ssh)) != 0)
return r;
- }
}
- free(setp);
return 0;
}