diff options
author | Damien Miller <djm@mindrot.org> | 2008-05-19 14:59:37 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2008-05-19 14:59:37 +1000 |
commit | db255cad0531047a3e35a95af74ad2e03b054412 (patch) | |
tree | 7452c18135999436612dcb4e6e7d9c9f2abfe90f | |
parent | e9890193032b4bba7afa40d4fc003bbf629afba2 (diff) |
- 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@
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | bufaux.c | 18 | ||||
-rw-r--r-- | buffer.h | 3 | ||||
-rw-r--r-- | channels.c | 9 | ||||
-rw-r--r-- | packet.c | 8 | ||||
-rw-r--r-- | packet.h | 3 |
6 files changed, 36 insertions, 11 deletions
@@ -58,6 +58,10 @@ | |||
58 | - jmc@cvs.openbsd.org 2008/05/07 08:00:14 | 58 | - jmc@cvs.openbsd.org 2008/05/07 08:00:14 |
59 | [sshd_config.5] | 59 | [sshd_config.5] |
60 | sort; | 60 | sort; |
61 | - markus@cvs.openbsd.org 2008/05/08 06:59:01 | ||
62 | [bufaux.c buffer.h channels.c packet.c packet.h] | ||
63 | avoid extra malloc/copy/free when receiving data over the net; | ||
64 | ~10% speedup for localhost-scp; ok djm@ | ||
61 | 65 | ||
62 | 20080403 | 66 | 20080403 |
63 | - (djm) [openbsd-compat/bsd-poll.c] Include stdlib.h to avoid compile- | 67 | - (djm) [openbsd-compat/bsd-poll.c] Include stdlib.h to avoid compile- |
@@ -3918,4 +3922,4 @@ | |||
3918 | OpenServer 6 and add osr5bigcrypt support so when someone migrates | 3922 | OpenServer 6 and add osr5bigcrypt support so when someone migrates |
3919 | passwords between UnixWare and OpenServer they will still work. OK dtucker@ | 3923 | passwords between UnixWare and OpenServer they will still work. OK dtucker@ |
3920 | 3924 | ||
3921 | $Id: ChangeLog,v 1.4918 2008/05/19 04:59:02 djm Exp $ | 3925 | $Id: ChangeLog,v 1.4919 2008/05/19 04:59:37 djm Exp $ |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bufaux.c,v 1.44 2006/08/03 03:34:41 deraadt Exp $ */ | 1 | /* $OpenBSD: bufaux.c,v 1.45 2008/05/08 06:59:01 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -197,6 +197,22 @@ buffer_get_string(Buffer *buffer, u_int *length_ptr) | |||
197 | return (ret); | 197 | return (ret); |
198 | } | 198 | } |
199 | 199 | ||
200 | void * | ||
201 | buffer_get_string_ptr(Buffer *buffer, u_int *length_ptr) | ||
202 | { | ||
203 | void *ptr; | ||
204 | u_int len; | ||
205 | |||
206 | len = buffer_get_int(buffer); | ||
207 | if (len > 256 * 1024) | ||
208 | fatal("buffer_get_string_ptr: bad string length %u", len); | ||
209 | ptr = buffer_ptr(buffer); | ||
210 | buffer_consume(buffer, len); | ||
211 | if (length_ptr) | ||
212 | *length_ptr = len; | ||
213 | return (ptr); | ||
214 | } | ||
215 | |||
200 | /* | 216 | /* |
201 | * Stores and arbitrary binary string in the buffer. | 217 | * Stores and arbitrary binary string in the buffer. |
202 | */ | 218 | */ |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: buffer.h,v 1.16 2006/08/03 03:34:41 deraadt Exp $ */ | 1 | /* $OpenBSD: buffer.h,v 1.17 2008/05/08 06:59:01 markus Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
@@ -66,6 +66,7 @@ int buffer_get_char(Buffer *); | |||
66 | void buffer_put_char(Buffer *, int); | 66 | void buffer_put_char(Buffer *, int); |
67 | 67 | ||
68 | void *buffer_get_string(Buffer *, u_int *); | 68 | void *buffer_get_string(Buffer *, u_int *); |
69 | void *buffer_get_string_ptr(Buffer *, u_int *); | ||
69 | void buffer_put_string(Buffer *, const void *, u_int); | 70 | void buffer_put_string(Buffer *, const void *, u_int); |
70 | void buffer_put_cstring(Buffer *, const char *); | 71 | void buffer_put_cstring(Buffer *, const char *); |
71 | 72 | ||
diff --git a/channels.c b/channels.c index b6bd901f0..05c23e59c 100644 --- a/channels.c +++ b/channels.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: channels.c,v 1.273 2008/04/02 21:36:51 markus Exp $ */ | 1 | /* $OpenBSD: channels.c,v 1.274 2008/05/08 06:59:01 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -2012,7 +2012,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt) | |||
2012 | return; | 2012 | return; |
2013 | 2013 | ||
2014 | /* Get the data. */ | 2014 | /* Get the data. */ |
2015 | data = packet_get_string(&data_len); | 2015 | data = packet_get_string_ptr(&data_len); |
2016 | 2016 | ||
2017 | /* | 2017 | /* |
2018 | * Ignore data for protocol > 1.3 if output end is no longer open. | 2018 | * 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) | |||
2026 | c->local_window -= data_len; | 2026 | c->local_window -= data_len; |
2027 | c->local_consumed += data_len; | 2027 | c->local_consumed += data_len; |
2028 | } | 2028 | } |
2029 | xfree(data); | ||
2030 | return; | 2029 | return; |
2031 | } | 2030 | } |
2032 | 2031 | ||
@@ -2038,17 +2037,15 @@ channel_input_data(int type, u_int32_t seq, void *ctxt) | |||
2038 | if (data_len > c->local_window) { | 2037 | if (data_len > c->local_window) { |
2039 | logit("channel %d: rcvd too much data %d, win %d", | 2038 | logit("channel %d: rcvd too much data %d, win %d", |
2040 | c->self, data_len, c->local_window); | 2039 | c->self, data_len, c->local_window); |
2041 | xfree(data); | ||
2042 | return; | 2040 | return; |
2043 | } | 2041 | } |
2044 | c->local_window -= data_len; | 2042 | c->local_window -= data_len; |
2045 | } | 2043 | } |
2046 | packet_check_eom(); | ||
2047 | if (c->datagram) | 2044 | if (c->datagram) |
2048 | buffer_put_string(&c->output, data, data_len); | 2045 | buffer_put_string(&c->output, data, data_len); |
2049 | else | 2046 | else |
2050 | buffer_append(&c->output, data, data_len); | 2047 | buffer_append(&c->output, data, data_len); |
2051 | xfree(data); | 2048 | packet_check_eom(); |
2052 | } | 2049 | } |
2053 | 2050 | ||
2054 | /* ARGSUSED */ | 2051 | /* ARGSUSED */ |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: packet.c,v 1.151 2008/02/22 20:44:02 dtucker Exp $ */ | 1 | /* $OpenBSD: packet.c,v 1.152 2008/05/08 06:59:01 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -1332,6 +1332,12 @@ packet_get_string(u_int *length_ptr) | |||
1332 | return buffer_get_string(&incoming_packet, length_ptr); | 1332 | return buffer_get_string(&incoming_packet, length_ptr); |
1333 | } | 1333 | } |
1334 | 1334 | ||
1335 | void * | ||
1336 | packet_get_string_ptr(u_int *length_ptr) | ||
1337 | { | ||
1338 | return buffer_get_string_ptr(&incoming_packet, length_ptr); | ||
1339 | } | ||
1340 | |||
1335 | /* | 1341 | /* |
1336 | * Sends a diagnostic message from the server to the client. This message | 1342 | * Sends a diagnostic message from the server to the client. This message |
1337 | * can be sent at any time (but not while constructing another message). The | 1343 | * can be sent at any time (but not while constructing another message). The |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: packet.h,v 1.46 2008/02/22 20:44:02 dtucker Exp $ */ | 1 | /* $OpenBSD: packet.h,v 1.47 2008/05/08 06:59:01 markus Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
@@ -58,6 +58,7 @@ void packet_get_bignum(BIGNUM * value); | |||
58 | void packet_get_bignum2(BIGNUM * value); | 58 | void packet_get_bignum2(BIGNUM * value); |
59 | void *packet_get_raw(u_int *length_ptr); | 59 | void *packet_get_raw(u_int *length_ptr); |
60 | void *packet_get_string(u_int *length_ptr); | 60 | void *packet_get_string(u_int *length_ptr); |
61 | void *packet_get_string_ptr(u_int *length_ptr); | ||
61 | void packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2))); | 62 | void packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
62 | void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); | 63 | void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
63 | 64 | ||