From 0ce92248a08ced3bc33b212d8841b9a8eb322d38 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 18 May 2018 07:22:57 +0100 Subject: [PATCH] Factor out general processing for all packets. NFC: I'm just moving a small piece of code out into a separate function, which does processing on incoming SSH-2 packets that is completely independent of the packet type. (Specifically, we count up the total amount of data so far transferred, and use it to trigger a rekey when we get over the per-session-key data limit.) The aim is that I'll be able to call this function from a central location that's not SSH-2 specific, by using a function pointer that points to this function in SSH-2 mode or is null in SSH-1 mode. --- ssh.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ssh.c b/ssh.c index 74e885b8..dfc9a553 100644 --- a/ssh.c +++ b/ssh.c @@ -396,6 +396,7 @@ static void ssh_channel_close_local(struct ssh_channel *c, char const *reason); static void ssh_channel_destroy(struct ssh_channel *c); static void ssh_channel_unthrottle(struct ssh_channel *c, int bufsize); static void ssh2_msg_something_unimplemented(Ssh ssh, struct Packet *pktin); +static void ssh2_general_packet_processing(Ssh ssh, struct Packet *pktin); /* * Buffer management constants. There are several of these for @@ -12221,6 +12222,15 @@ static void ssh2_timer(void *ctx, unsigned long now) (void) ssh2_timer_update(ssh, 0); } +static void ssh2_general_packet_processing(Ssh ssh, struct Packet *pktin) +{ + ssh->incoming_data_size += pktin->encrypted_len; + if (!ssh->kex_in_progress && + ssh->max_data_size != 0 && + ssh->incoming_data_size > ssh->max_data_size) + do_ssh2_transport(ssh, "too much data received", -1, NULL); +} + static void ssh2_protocol(Ssh ssh, const void *vin, int inlen, struct Packet *pktin) { @@ -12228,13 +12238,7 @@ static void ssh2_protocol(Ssh ssh, const void *vin, int inlen, if (ssh->state == SSH_STATE_CLOSED) return; - if (pktin) { - ssh->incoming_data_size += pktin->encrypted_len; - if (!ssh->kex_in_progress && - ssh->max_data_size != 0 && - ssh->incoming_data_size > ssh->max_data_size) - do_ssh2_transport(ssh, "too much data received", -1, NULL); - } + ssh2_general_packet_processing(ssh, pktin); if (pktin) ssh->packet_dispatch[pktin->type](ssh, pktin);