From 17f02f0a582588c2df79e9031a3d2ae8126e94ff Mon Sep 17 00:00:00 2001 From: djm Date: Mon, 19 May 2008 04:59:37 +0000 Subject: [PATCH] - markus@cvs.openbsd.org 2008/05/08 06:59:01 [bufaux.c buffer.h channels.c packet.c packet.h] avoid extra malloc/copy/free when receiving data over the net; ~10% speedup for localhost-scp; ok djm@ --- ChangeLog | 4 ++++ bufaux.c | 18 +++++++++++++++++- buffer.h | 3 ++- channels.c | 9 +++------ packet.c | 8 +++++++- packet.h | 3 ++- 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf3907ed..56a1d55b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -58,6 +58,10 @@ - jmc@cvs.openbsd.org 2008/05/07 08:00:14 [sshd_config.5] sort; + - markus@cvs.openbsd.org 2008/05/08 06:59:01 + [bufaux.c buffer.h channels.c packet.c packet.h] + avoid extra malloc/copy/free when receiving data over the net; + ~10% speedup for localhost-scp; ok djm@ 20080403 - (djm) [openbsd-compat/bsd-poll.c] Include stdlib.h to avoid compile- diff --git a/bufaux.c b/bufaux.c index cbdc22c6..f0336399 100644 --- a/bufaux.c +++ b/bufaux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bufaux.c,v 1.44 2006/08/03 03:34:41 deraadt Exp $ */ +/* $OpenBSD: bufaux.c,v 1.45 2008/05/08 06:59:01 markus Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -197,6 +197,22 @@ buffer_get_string(Buffer *buffer, u_int *length_ptr) return (ret); } +void * +buffer_get_string_ptr(Buffer *buffer, u_int *length_ptr) +{ + void *ptr; + u_int len; + + len = buffer_get_int(buffer); + if (len > 256 * 1024) + fatal("buffer_get_string_ptr: bad string length %u", len); + ptr = buffer_ptr(buffer); + buffer_consume(buffer, len); + if (length_ptr) + *length_ptr = len; + return (ptr); +} + /* * Stores and arbitrary binary string in the buffer. */ diff --git a/buffer.h b/buffer.h index ecc4aea8..d0f354ee 100644 --- a/buffer.h +++ b/buffer.h @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.h,v 1.16 2006/08/03 03:34:41 deraadt Exp $ */ +/* $OpenBSD: buffer.h,v 1.17 2008/05/08 06:59:01 markus Exp $ */ /* * Author: Tatu Ylonen @@ -66,6 +66,7 @@ int buffer_get_char(Buffer *); void buffer_put_char(Buffer *, int); void *buffer_get_string(Buffer *, u_int *); +void *buffer_get_string_ptr(Buffer *, u_int *); void buffer_put_string(Buffer *, const void *, u_int); void buffer_put_cstring(Buffer *, const char *); diff --git a/channels.c b/channels.c index b6bd901f..05c23e59 100644 --- a/channels.c +++ b/channels.c @@ -1,4 +1,4 @@ -/* $OpenBSD: channels.c,v 1.273 2008/04/02 21:36:51 markus Exp $ */ +/* $OpenBSD: channels.c,v 1.274 2008/05/08 06:59:01 markus Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -2012,7 +2012,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt) return; /* Get the data. */ - data = packet_get_string(&data_len); + data = packet_get_string_ptr(&data_len); /* * Ignore data for protocol > 1.3 if output end is no longer open. @@ -2026,7 +2026,6 @@ channel_input_data(int type, u_int32_t seq, void *ctxt) c->local_window -= data_len; c->local_consumed += data_len; } - xfree(data); return; } @@ -2038,17 +2037,15 @@ channel_input_data(int type, u_int32_t seq, void *ctxt) if (data_len > c->local_window) { logit("channel %d: rcvd too much data %d, win %d", c->self, data_len, c->local_window); - xfree(data); return; } c->local_window -= data_len; } - packet_check_eom(); if (c->datagram) buffer_put_string(&c->output, data, data_len); else buffer_append(&c->output, data, data_len); - xfree(data); + packet_check_eom(); } /* ARGSUSED */ diff --git a/packet.c b/packet.c index 6afe24b9..a34c040d 100644 --- a/packet.c +++ b/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.151 2008/02/22 20:44:02 dtucker Exp $ */ +/* $OpenBSD: packet.c,v 1.152 2008/05/08 06:59:01 markus Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -1332,6 +1332,12 @@ packet_get_string(u_int *length_ptr) return buffer_get_string(&incoming_packet, length_ptr); } +void * +packet_get_string_ptr(u_int *length_ptr) +{ + return buffer_get_string_ptr(&incoming_packet, length_ptr); +} + /* * Sends a diagnostic message from the server to the client. This message * can be sent at any time (but not while constructing another message). The diff --git a/packet.h b/packet.h index c1b9b3bd..927e0831 100644 --- a/packet.h +++ b/packet.h @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.h,v 1.46 2008/02/22 20:44:02 dtucker Exp $ */ +/* $OpenBSD: packet.h,v 1.47 2008/05/08 06:59:01 markus Exp $ */ /* * Author: Tatu Ylonen @@ -58,6 +58,7 @@ void packet_get_bignum(BIGNUM * value); void packet_get_bignum2(BIGNUM * value); void *packet_get_raw(u_int *length_ptr); void *packet_get_string(u_int *length_ptr); +void *packet_get_string_ptr(u_int *length_ptr); void packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2))); void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); -- 2.45.1