Lines Matching refs:c

84 chan_set_istate(Channel *c, u_int next)  in chan_set_istate()  argument
86 if (c->istate > CHAN_INPUT_CLOSED || next > CHAN_INPUT_CLOSED) in chan_set_istate()
87 fatal("chan_set_istate: bad state %d -> %d", c->istate, next); in chan_set_istate()
88 debug("channel %d: input %s -> %s", c->self, istates[c->istate], in chan_set_istate()
90 c->istate = next; in chan_set_istate()
93 chan_set_ostate(Channel *c, u_int next) in chan_set_ostate() argument
95 if (c->ostate > CHAN_OUTPUT_CLOSED || next > CHAN_OUTPUT_CLOSED) in chan_set_ostate()
96 fatal("chan_set_ostate: bad state %d -> %d", c->ostate, next); in chan_set_ostate()
97 debug("channel %d: output %s -> %s", c->self, ostates[c->ostate], in chan_set_ostate()
99 c->ostate = next; in chan_set_ostate()
107 chan_rcvd_oclose1(Channel *c) in chan_rcvd_oclose1() argument
109 debug("channel %d: rcvd oclose", c->self); in chan_rcvd_oclose1()
110 switch (c->istate) { in chan_rcvd_oclose1()
112 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose1()
115 chan_shutdown_read(c); in chan_rcvd_oclose1()
116 chan_send_ieof1(c); in chan_rcvd_oclose1()
117 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose1()
121 chan_send_ieof1(c); in chan_rcvd_oclose1()
122 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose1()
126 c->self, c->istate); in chan_rcvd_oclose1()
131 chan_read_failed(Channel *c) in chan_read_failed() argument
133 debug("channel %d: read failed", c->self); in chan_read_failed()
134 switch (c->istate) { in chan_read_failed()
136 chan_shutdown_read(c); in chan_read_failed()
137 chan_set_istate(c, CHAN_INPUT_WAIT_DRAIN); in chan_read_failed()
141 c->self, c->istate); in chan_read_failed()
146 chan_ibuf_empty(Channel *c) in chan_ibuf_empty() argument
148 debug("channel %d: ibuf empty", c->self); in chan_ibuf_empty()
149 if (buffer_len(&c->input)) { in chan_ibuf_empty()
151 c->self); in chan_ibuf_empty()
154 switch (c->istate) { in chan_ibuf_empty()
157 if (!(c->flags & CHAN_CLOSE_SENT)) in chan_ibuf_empty()
158 chan_send_eof2(c); in chan_ibuf_empty()
159 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_ibuf_empty()
161 chan_send_ieof1(c); in chan_ibuf_empty()
162 chan_set_istate(c, CHAN_INPUT_WAIT_OCLOSE); in chan_ibuf_empty()
167 c->self, c->istate); in chan_ibuf_empty()
172 chan_rcvd_ieof1(Channel *c) in chan_rcvd_ieof1() argument
174 debug("channel %d: rcvd ieof", c->self); in chan_rcvd_ieof1()
175 switch (c->ostate) { in chan_rcvd_ieof1()
177 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_ieof1()
180 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_rcvd_ieof1()
184 c->self, c->ostate); in chan_rcvd_ieof1()
189 chan_write_failed1(Channel *c) in chan_write_failed1() argument
191 debug("channel %d: write failed", c->self); in chan_write_failed1()
192 switch (c->ostate) { in chan_write_failed1()
194 chan_shutdown_write(c); in chan_write_failed1()
195 chan_send_oclose1(c); in chan_write_failed1()
196 chan_set_ostate(c, CHAN_OUTPUT_WAIT_IEOF); in chan_write_failed1()
199 chan_shutdown_write(c); in chan_write_failed1()
200 chan_send_oclose1(c); in chan_write_failed1()
201 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_write_failed1()
205 c->self, c->ostate); in chan_write_failed1()
210 chan_obuf_empty(Channel *c) in chan_obuf_empty() argument
212 debug("channel %d: obuf empty", c->self); in chan_obuf_empty()
213 if (buffer_len(&c->output)) { in chan_obuf_empty()
215 c->self); in chan_obuf_empty()
218 switch (c->ostate) { in chan_obuf_empty()
220 chan_shutdown_write(c); in chan_obuf_empty()
222 chan_send_oclose1(c); in chan_obuf_empty()
223 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_obuf_empty()
227 c->self, c->ostate); in chan_obuf_empty()
232 chan_send_ieof1(Channel *c) in chan_send_ieof1() argument
234 debug("channel %d: send ieof", c->self); in chan_send_ieof1()
235 switch (c->istate) { in chan_send_ieof1()
239 packet_put_int(c->remote_id); in chan_send_ieof1()
244 c->self, c->istate); in chan_send_ieof1()
249 chan_send_oclose1(Channel *c) in chan_send_oclose1() argument
251 debug("channel %d: send oclose", c->self); in chan_send_oclose1()
252 switch (c->ostate) { in chan_send_oclose1()
255 buffer_clear(&c->output); in chan_send_oclose1()
257 packet_put_int(c->remote_id); in chan_send_oclose1()
262 c->self, c->ostate); in chan_send_oclose1()
271 chan_rcvd_close2(Channel *c) in chan_rcvd_close2() argument
273 debug("channel %d: rcvd close", c->self); in chan_rcvd_close2()
274 if (c->flags & CHAN_CLOSE_RCVD) in chan_rcvd_close2()
275 error("channel %d: protocol error: close rcvd twice", c->self); in chan_rcvd_close2()
276 c->flags |= CHAN_CLOSE_RCVD; in chan_rcvd_close2()
277 if (c->type == SSH_CHANNEL_LARVAL) { in chan_rcvd_close2()
279 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_rcvd_close2()
280 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_close2()
283 switch (c->ostate) { in chan_rcvd_close2()
289 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_close2()
292 switch (c->istate) { in chan_rcvd_close2()
294 chan_shutdown_read(c); in chan_rcvd_close2()
295 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_close2()
298 chan_send_eof2(c); in chan_rcvd_close2()
299 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_close2()
304 chan_rcvd_eof2(Channel *c) in chan_rcvd_eof2() argument
306 debug("channel %d: rcvd eof", c->self); in chan_rcvd_eof2()
307 c->flags |= CHAN_EOF_RCVD; in chan_rcvd_eof2()
308 if (c->ostate == CHAN_OUTPUT_OPEN) in chan_rcvd_eof2()
309 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_eof2()
312 chan_write_failed2(Channel *c) in chan_write_failed2() argument
314 debug("channel %d: write failed", c->self); in chan_write_failed2()
315 switch (c->ostate) { in chan_write_failed2()
318 chan_shutdown_write(c); in chan_write_failed2()
319 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_write_failed2()
323 c->self, c->ostate); in chan_write_failed2()
328 chan_send_eof2(Channel *c) in chan_send_eof2() argument
330 debug("channel %d: send eof", c->self); in chan_send_eof2()
331 switch (c->istate) { in chan_send_eof2()
334 packet_put_int(c->remote_id); in chan_send_eof2()
336 c->flags |= CHAN_EOF_SENT; in chan_send_eof2()
340 c->self, c->istate); in chan_send_eof2()
345 chan_send_close2(Channel *c) in chan_send_close2() argument
347 debug("channel %d: send close", c->self); in chan_send_close2()
348 if (c->ostate != CHAN_OUTPUT_CLOSED || in chan_send_close2()
349 c->istate != CHAN_INPUT_CLOSED) { in chan_send_close2()
351 c->self, c->istate, c->ostate); in chan_send_close2()
352 } else if (c->flags & CHAN_CLOSE_SENT) { in chan_send_close2()
353 error("channel %d: already sent close", c->self); in chan_send_close2()
356 packet_put_int(c->remote_id); in chan_send_close2()
358 c->flags |= CHAN_CLOSE_SENT; in chan_send_close2()
365 chan_rcvd_ieof(Channel *c) in chan_rcvd_ieof() argument
368 chan_rcvd_eof2(c); in chan_rcvd_ieof()
370 chan_rcvd_ieof1(c); in chan_rcvd_ieof()
371 if (c->ostate == CHAN_OUTPUT_WAIT_DRAIN && in chan_rcvd_ieof()
372 buffer_len(&c->output) == 0 && in chan_rcvd_ieof()
373 !CHANNEL_EFD_OUTPUT_ACTIVE(c)) in chan_rcvd_ieof()
374 chan_obuf_empty(c); in chan_rcvd_ieof()
377 chan_rcvd_oclose(Channel *c) in chan_rcvd_oclose() argument
380 chan_rcvd_close2(c); in chan_rcvd_oclose()
382 chan_rcvd_oclose1(c); in chan_rcvd_oclose()
385 chan_write_failed(Channel *c) in chan_write_failed() argument
388 chan_write_failed2(c); in chan_write_failed()
390 chan_write_failed1(c); in chan_write_failed()
394 chan_mark_dead(Channel *c) in chan_mark_dead() argument
396 c->type = SSH_CHANNEL_ZOMBIE; in chan_mark_dead()
400 chan_is_dead(Channel *c, int send) in chan_is_dead() argument
402 if (c->type == SSH_CHANNEL_ZOMBIE) { in chan_is_dead()
403 debug("channel %d: zombie", c->self); in chan_is_dead()
406 if (c->istate != CHAN_INPUT_CLOSED || c->ostate != CHAN_OUTPUT_CLOSED) in chan_is_dead()
409 debug("channel %d: is dead", c->self); in chan_is_dead()
413 c->extended_usage == CHAN_EXTENDED_WRITE && in chan_is_dead()
414 c->efd != -1 && in chan_is_dead()
415 buffer_len(&c->extended) > 0) { in chan_is_dead()
417 c->self, c->efd, buffer_len(&c->extended)); in chan_is_dead()
420 if (!(c->flags & CHAN_CLOSE_SENT)) { in chan_is_dead()
422 chan_send_close2(c); in chan_is_dead()
425 if (c->flags & CHAN_CLOSE_RCVD) { in chan_is_dead()
427 c->self); in chan_is_dead()
432 if ((c->flags & CHAN_CLOSE_SENT) && in chan_is_dead()
433 (c->flags & CHAN_CLOSE_RCVD)) { in chan_is_dead()
434 debug("channel %d: is dead", c->self); in chan_is_dead()
442 chan_shutdown_write(Channel *c) in chan_shutdown_write() argument
444 buffer_clear(&c->output); in chan_shutdown_write()
445 if (compat20 && c->type == SSH_CHANNEL_LARVAL) in chan_shutdown_write()
448 debug("channel %d: close_write", c->self); in chan_shutdown_write()
449 if (c->sock != -1) { in chan_shutdown_write()
450 if (shutdown(c->sock, SHUT_WR) < 0) in chan_shutdown_write()
453 c->self, c->sock, strerror(errno)); in chan_shutdown_write()
455 if (channel_close_fd(&c->wfd) < 0) in chan_shutdown_write()
458 c->self, c->wfd, strerror(errno)); in chan_shutdown_write()
462 chan_shutdown_read(Channel *c) in chan_shutdown_read() argument
464 if (compat20 && c->type == SSH_CHANNEL_LARVAL) in chan_shutdown_read()
466 debug("channel %d: close_read", c->self); in chan_shutdown_read()
467 if (c->sock != -1) { in chan_shutdown_read()
473 if (shutdown(c->sock, SHUT_RD) < 0 in chan_shutdown_read()
477 c->self, c->sock, c->istate, c->ostate, in chan_shutdown_read()
480 if (channel_close_fd(&c->rfd) < 0) in chan_shutdown_read()
483 c->self, c->rfd, strerror(errno)); in chan_shutdown_read()