summaryrefslogtreecommitdiffstats
path: root/packet.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-01-22 00:49:34 +0000
committerDamien Miller <djm@mindrot.org>2022-01-25 12:18:35 +1100
commitb30d32159dc3c7052f4bfdf36357996c905af739 (patch)
tree25d0f90b2823952c57e6d72f4dad0c4aec5d6592 /packet.c
parenta1a8efeaaa9cccb15cdc0a2bd7c347a149a3a7e3 (diff)
upstream: add a ssh_packet_process_read() function that reads from
a fd directly into the transport input buffer. Use this in the client and server mainloops to avoid unnecessary copying. It also lets us use a more greedy read size without penalty. Yields a 2-3% performance gain on cipher-speed.sh (in a fairly unscientific test tbf) feedback dtucker@ ok markus@ OpenBSD-Commit-ID: df4112125bf79d8e38e79a77113e1b373078e632
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/packet.c b/packet.c
index 5a50fcd9..bde6c104 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.306 2022/01/21 06:58:06 djm Exp $ */
+/* $OpenBSD: packet.c,v 1.307 2022/01/22 00:49:34 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1784,6 +1784,31 @@ ssh_packet_process_incoming(struct ssh *ssh, const char *buf, u_int len)
return 0;
}
+/* Reads and buffers data from the specified fd */
+int
+ssh_packet_process_read(struct ssh *ssh, int fd)
+{
+ struct session_state *state = ssh->state;
+ int r;
+ size_t rlen;
+
+ if ((r = sshbuf_read(fd, state->input, PACKET_MAX_SIZE, &rlen)) != 0)
+ return r;
+
+ if (state->packet_discard) {
+ if ((r = sshbuf_consume_end(state->input, rlen)) != 0)
+ return r;
+ state->keep_alive_timeouts = 0; /* ?? */
+ if (rlen >= state->packet_discard) {
+ if ((r = ssh_packet_stop_discard(ssh)) != 0)
+ return r;
+ }
+ state->packet_discard -= rlen;
+ return 0;
+ }
+ return 0;
+}
+
int
ssh_packet_remaining(struct ssh *ssh)
{