diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2017-04-30 23:13:26 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2017-04-30 23:13:26 +0000 |
commit | b6d5127487b68751ff0811c07e09120ecc6b2feb (patch) | |
tree | 2dc5ae3d8f4c8563497650960419e625bb7b7750 /usr.bin/ssh/nchan.c | |
parent | 591337e548607602b93aa632a88e549f17c3d786 (diff) |
remove compat20/compat13/compat15 variables
ok markus@
Diffstat (limited to 'usr.bin/ssh/nchan.c')
-rw-r--r-- | usr.bin/ssh/nchan.c | 266 |
1 files changed, 66 insertions, 200 deletions
diff --git a/usr.bin/ssh/nchan.c b/usr.bin/ssh/nchan.c index 3e786cb92b0..7d6c150cd6c 100644 --- a/usr.bin/ssh/nchan.c +++ b/usr.bin/ssh/nchan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nchan.c,v 1.63 2010/01/26 01:28:35 djm Exp $ */ +/* $OpenBSD: nchan.c,v 1.64 2017/04/30 23:13:25 djm Exp $ */ /* * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved. * @@ -72,9 +72,6 @@ /* * ACTIONS: should never update the channel states */ -static void chan_send_ieof1(Channel *); -static void chan_send_oclose1(Channel *); -static void chan_send_close2(Channel *); static void chan_send_eof2(Channel *); static void chan_send_eow2(Channel *); @@ -94,6 +91,7 @@ chan_set_istate(Channel *c, u_int next) istates[next]); c->istate = next; } + static void chan_set_ostate(Channel *c, u_int next) { @@ -104,34 +102,6 @@ chan_set_ostate(Channel *c, u_int next) c->ostate = next; } -/* - * SSH1 specific implementation of event functions - */ - -static void -chan_rcvd_oclose1(Channel *c) -{ - debug2("channel %d: rcvd oclose", c->self); - switch (c->istate) { - case CHAN_INPUT_WAIT_OCLOSE: - chan_set_istate(c, CHAN_INPUT_CLOSED); - break; - case CHAN_INPUT_OPEN: - chan_shutdown_read(c); - chan_send_ieof1(c); - chan_set_istate(c, CHAN_INPUT_CLOSED); - break; - case CHAN_INPUT_WAIT_DRAIN: - /* both local read_failed and remote write_failed */ - chan_send_ieof1(c); - chan_set_istate(c, CHAN_INPUT_CLOSED); - break; - default: - error("channel %d: protocol error: rcvd_oclose for istate %d", - c->self, c->istate); - return; - } -} void chan_read_failed(Channel *c) { @@ -147,6 +117,7 @@ chan_read_failed(Channel *c) break; } } + void chan_ibuf_empty(Channel *c) { @@ -158,14 +129,9 @@ chan_ibuf_empty(Channel *c) } switch (c->istate) { case CHAN_INPUT_WAIT_DRAIN: - if (compat20) { - if (!(c->flags & (CHAN_CLOSE_SENT|CHAN_LOCAL))) - chan_send_eof2(c); - chan_set_istate(c, CHAN_INPUT_CLOSED); - } else { - chan_send_ieof1(c); - chan_set_istate(c, CHAN_INPUT_WAIT_OCLOSE); - } + if (!(c->flags & (CHAN_CLOSE_SENT|CHAN_LOCAL))) + chan_send_eof2(c); + chan_set_istate(c, CHAN_INPUT_CLOSED); break; default: error("channel %d: chan_ibuf_empty for istate %d", @@ -173,44 +139,7 @@ chan_ibuf_empty(Channel *c) break; } } -static void -chan_rcvd_ieof1(Channel *c) -{ - debug2("channel %d: rcvd ieof", c->self); - switch (c->ostate) { - case CHAN_OUTPUT_OPEN: - chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); - break; - case CHAN_OUTPUT_WAIT_IEOF: - chan_set_ostate(c, CHAN_OUTPUT_CLOSED); - break; - default: - error("channel %d: protocol error: rcvd_ieof for ostate %d", - c->self, c->ostate); - break; - } -} -static void -chan_write_failed1(Channel *c) -{ - debug2("channel %d: write failed", c->self); - switch (c->ostate) { - case CHAN_OUTPUT_OPEN: - chan_shutdown_write(c); - chan_send_oclose1(c); - chan_set_ostate(c, CHAN_OUTPUT_WAIT_IEOF); - break; - case CHAN_OUTPUT_WAIT_DRAIN: - chan_shutdown_write(c); - chan_send_oclose1(c); - chan_set_ostate(c, CHAN_OUTPUT_CLOSED); - break; - default: - error("channel %d: chan_write_failed for ostate %d", - c->self, c->ostate); - break; - } -} + void chan_obuf_empty(Channel *c) { @@ -223,8 +152,6 @@ chan_obuf_empty(Channel *c) switch (c->ostate) { case CHAN_OUTPUT_WAIT_DRAIN: chan_shutdown_write(c); - if (!compat20) - chan_send_oclose1(c); chan_set_ostate(c, CHAN_OUTPUT_CLOSED); break; default: @@ -233,82 +160,6 @@ chan_obuf_empty(Channel *c) break; } } -static void -chan_send_ieof1(Channel *c) -{ - debug2("channel %d: send ieof", c->self); - switch (c->istate) { - case CHAN_INPUT_OPEN: - case CHAN_INPUT_WAIT_DRAIN: - packet_start(SSH_MSG_CHANNEL_INPUT_EOF); - packet_put_int(c->remote_id); - packet_send(); - break; - default: - error("channel %d: cannot send ieof for istate %d", - c->self, c->istate); - break; - } -} -static void -chan_send_oclose1(Channel *c) -{ - debug2("channel %d: send oclose", c->self); - switch (c->ostate) { - case CHAN_OUTPUT_OPEN: - case CHAN_OUTPUT_WAIT_DRAIN: - buffer_clear(&c->output); - packet_start(SSH_MSG_CHANNEL_OUTPUT_CLOSE); - packet_put_int(c->remote_id); - packet_send(); - break; - default: - error("channel %d: cannot send oclose for ostate %d", - c->self, c->ostate); - break; - } -} - -/* - * the same for SSH2 - */ -static void -chan_rcvd_close2(Channel *c) -{ - debug2("channel %d: rcvd close", c->self); - if (!(c->flags & CHAN_LOCAL)) { - if (c->flags & CHAN_CLOSE_RCVD) - error("channel %d: protocol error: close rcvd twice", - c->self); - c->flags |= CHAN_CLOSE_RCVD; - } - if (c->type == SSH_CHANNEL_LARVAL) { - /* tear down larval channels immediately */ - chan_set_ostate(c, CHAN_OUTPUT_CLOSED); - chan_set_istate(c, CHAN_INPUT_CLOSED); - return; - } - switch (c->ostate) { - case CHAN_OUTPUT_OPEN: - /* - * wait until a data from the channel is consumed if a CLOSE - * is received - */ - chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); - break; - } - switch (c->istate) { - case CHAN_INPUT_OPEN: - chan_shutdown_read(c); - chan_set_istate(c, CHAN_INPUT_CLOSED); - break; - case CHAN_INPUT_WAIT_DRAIN: - if (!(c->flags & CHAN_LOCAL)) - chan_send_eof2(c); - chan_set_istate(c, CHAN_INPUT_CLOSED); - break; - } -} void chan_rcvd_eow(Channel *c) @@ -321,32 +172,7 @@ chan_rcvd_eow(Channel *c) break; } } -static void -chan_rcvd_eof2(Channel *c) -{ - debug2("channel %d: rcvd eof", c->self); - c->flags |= CHAN_EOF_RCVD; - if (c->ostate == CHAN_OUTPUT_OPEN) - chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); -} -static void -chan_write_failed2(Channel *c) -{ - debug2("channel %d: write failed", c->self); - switch (c->ostate) { - case CHAN_OUTPUT_OPEN: - case CHAN_OUTPUT_WAIT_DRAIN: - chan_shutdown_write(c); - if (strcmp(c->ctype, "session") == 0) - chan_send_eow2(c); - chan_set_ostate(c, CHAN_OUTPUT_CLOSED); - break; - default: - error("channel %d: chan_write_failed for ostate %d", - c->self, c->ostate); - break; - } -} + static void chan_send_eof2(Channel *c) { @@ -364,6 +190,7 @@ chan_send_eof2(Channel *c) break; } } + static void chan_send_close2(Channel *c) { @@ -381,6 +208,7 @@ chan_send_close2(Channel *c) c->flags |= CHAN_CLOSE_SENT; } } + static void chan_send_eow2(Channel *c) { @@ -404,30 +232,71 @@ chan_send_eow2(Channel *c) void chan_rcvd_ieof(Channel *c) { - if (compat20) - chan_rcvd_eof2(c); - else - chan_rcvd_ieof1(c); + debug2("channel %d: rcvd eof", c->self); + c->flags |= CHAN_EOF_RCVD; + if (c->ostate == CHAN_OUTPUT_OPEN) + chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); if (c->ostate == CHAN_OUTPUT_WAIT_DRAIN && buffer_len(&c->output) == 0 && !CHANNEL_EFD_OUTPUT_ACTIVE(c)) chan_obuf_empty(c); } + void chan_rcvd_oclose(Channel *c) { - if (compat20) - chan_rcvd_close2(c); - else - chan_rcvd_oclose1(c); + debug2("channel %d: rcvd close", c->self); + if (!(c->flags & CHAN_LOCAL)) { + if (c->flags & CHAN_CLOSE_RCVD) + error("channel %d: protocol error: close rcvd twice", + c->self); + c->flags |= CHAN_CLOSE_RCVD; + } + if (c->type == SSH_CHANNEL_LARVAL) { + /* tear down larval channels immediately */ + chan_set_ostate(c, CHAN_OUTPUT_CLOSED); + chan_set_istate(c, CHAN_INPUT_CLOSED); + return; + } + switch (c->ostate) { + case CHAN_OUTPUT_OPEN: + /* + * wait until a data from the channel is consumed if a CLOSE + * is received + */ + chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); + break; + } + switch (c->istate) { + case CHAN_INPUT_OPEN: + chan_shutdown_read(c); + chan_set_istate(c, CHAN_INPUT_CLOSED); + break; + case CHAN_INPUT_WAIT_DRAIN: + if (!(c->flags & CHAN_LOCAL)) + chan_send_eof2(c); + chan_set_istate(c, CHAN_INPUT_CLOSED); + break; + } } + void chan_write_failed(Channel *c) { - if (compat20) - chan_write_failed2(c); - else - chan_write_failed1(c); + debug2("channel %d: write failed", c->self); + switch (c->ostate) { + case CHAN_OUTPUT_OPEN: + case CHAN_OUTPUT_WAIT_DRAIN: + chan_shutdown_write(c); + if (strcmp(c->ctype, "session") == 0) + chan_send_eow2(c); + chan_set_ostate(c, CHAN_OUTPUT_CLOSED); + break; + default: + error("channel %d: chan_write_failed for ostate %d", + c->self, c->ostate); + break; + } } void @@ -445,10 +314,6 @@ chan_is_dead(Channel *c, int do_send) } if (c->istate != CHAN_INPUT_CLOSED || c->ostate != CHAN_OUTPUT_CLOSED) return 0; - if (!compat20) { - debug2("channel %d: is dead", c->self); - return 1; - } if ((datafellows & SSH_BUG_EXTEOF) && c->extended_usage == CHAN_EXTENDED_WRITE && c->efd != -1 && @@ -486,7 +351,7 @@ static void chan_shutdown_write(Channel *c) { buffer_clear(&c->output); - if (compat20 && c->type == SSH_CHANNEL_LARVAL) + if (c->type == SSH_CHANNEL_LARVAL) return; /* shutdown failure is allowed if write failed already */ debug2("channel %d: close_write", c->self); @@ -502,10 +367,11 @@ chan_shutdown_write(Channel *c) c->self, c->wfd, strerror(errno)); } } + static void chan_shutdown_read(Channel *c) { - if (compat20 && c->type == SSH_CHANNEL_LARVAL) + if (c->type == SSH_CHANNEL_LARVAL) return; debug2("channel %d: close_read", c->self); if (c->sock != -1) { |