Lines Matching refs:c
83 chan_set_istate(Channel *c, u_int next) in chan_set_istate() argument
85 if (c->istate > CHAN_INPUT_CLOSED || next > CHAN_INPUT_CLOSED) in chan_set_istate()
86 fatal("chan_set_istate: bad state %d -> %d", c->istate, next); in chan_set_istate()
87 debug("channel %d: input %s -> %s", c->self, istates[c->istate], in chan_set_istate()
89 c->istate = next; in chan_set_istate()
92 chan_set_ostate(Channel *c, u_int next) in chan_set_ostate() argument
94 if (c->ostate > CHAN_OUTPUT_CLOSED || next > CHAN_OUTPUT_CLOSED) in chan_set_ostate()
95 fatal("chan_set_ostate: bad state %d -> %d", c->ostate, next); in chan_set_ostate()
96 debug("channel %d: output %s -> %s", c->self, ostates[c->ostate], in chan_set_ostate()
98 c->ostate = next; in chan_set_ostate()
106 chan_rcvd_oclose1(Channel *c) in chan_rcvd_oclose1() argument
108 debug("channel %d: rcvd oclose", c->self); in chan_rcvd_oclose1()
109 switch (c->istate) { in chan_rcvd_oclose1()
111 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose1()
114 chan_shutdown_read(c); in chan_rcvd_oclose1()
115 chan_send_ieof1(c); in chan_rcvd_oclose1()
116 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose1()
120 chan_send_ieof1(c); in chan_rcvd_oclose1()
121 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose1()
125 c->self, c->istate); in chan_rcvd_oclose1()
130 chan_read_failed(Channel *c) in chan_read_failed() argument
132 debug("channel %d: read failed", c->self); in chan_read_failed()
133 switch (c->istate) { in chan_read_failed()
135 chan_shutdown_read(c); in chan_read_failed()
136 chan_set_istate(c, CHAN_INPUT_WAIT_DRAIN); in chan_read_failed()
140 c->self, c->istate); in chan_read_failed()
145 chan_ibuf_empty(Channel *c) in chan_ibuf_empty() argument
147 debug("channel %d: ibuf empty", c->self); in chan_ibuf_empty()
148 if (buffer_len(&c->input)) { in chan_ibuf_empty()
150 c->self); in chan_ibuf_empty()
153 switch (c->istate) { in chan_ibuf_empty()
156 if (!(c->flags & CHAN_CLOSE_SENT)) in chan_ibuf_empty()
157 chan_send_eof2(c); in chan_ibuf_empty()
158 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_ibuf_empty()
160 chan_send_ieof1(c); in chan_ibuf_empty()
161 chan_set_istate(c, CHAN_INPUT_WAIT_OCLOSE); in chan_ibuf_empty()
166 c->self, c->istate); in chan_ibuf_empty()
171 chan_rcvd_ieof1(Channel *c) in chan_rcvd_ieof1() argument
173 debug("channel %d: rcvd ieof", c->self); in chan_rcvd_ieof1()
174 switch (c->ostate) { in chan_rcvd_ieof1()
176 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_ieof1()
179 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_rcvd_ieof1()
183 c->self, c->ostate); in chan_rcvd_ieof1()
188 chan_write_failed1(Channel *c) in chan_write_failed1() argument
190 debug("channel %d: write failed", c->self); in chan_write_failed1()
191 switch (c->ostate) { in chan_write_failed1()
193 chan_shutdown_write(c); in chan_write_failed1()
194 chan_send_oclose1(c); in chan_write_failed1()
195 chan_set_ostate(c, CHAN_OUTPUT_WAIT_IEOF); in chan_write_failed1()
198 chan_shutdown_write(c); in chan_write_failed1()
199 chan_send_oclose1(c); in chan_write_failed1()
200 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_write_failed1()
204 c->self, c->ostate); in chan_write_failed1()
209 chan_obuf_empty(Channel *c) in chan_obuf_empty() argument
211 debug("channel %d: obuf empty", c->self); in chan_obuf_empty()
212 if (buffer_len(&c->output)) { in chan_obuf_empty()
214 c->self); in chan_obuf_empty()
217 switch (c->ostate) { in chan_obuf_empty()
219 chan_shutdown_write(c); in chan_obuf_empty()
221 chan_send_oclose1(c); in chan_obuf_empty()
222 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_obuf_empty()
226 c->self, c->ostate); in chan_obuf_empty()
231 chan_send_ieof1(Channel *c) in chan_send_ieof1() argument
233 debug("channel %d: send ieof", c->self); in chan_send_ieof1()
234 switch (c->istate) { in chan_send_ieof1()
238 packet_put_int(c->remote_id); in chan_send_ieof1()
243 c->self, c->istate); in chan_send_ieof1()
248 chan_send_oclose1(Channel *c) in chan_send_oclose1() argument
250 debug("channel %d: send oclose", c->self); in chan_send_oclose1()
251 switch (c->ostate) { in chan_send_oclose1()
254 buffer_clear(&c->output); in chan_send_oclose1()
256 packet_put_int(c->remote_id); in chan_send_oclose1()
261 c->self, c->ostate); in chan_send_oclose1()
270 chan_rcvd_close2(Channel *c) in chan_rcvd_close2() argument
272 debug("channel %d: rcvd close", c->self); in chan_rcvd_close2()
273 if (c->flags & CHAN_CLOSE_RCVD) in chan_rcvd_close2()
274 error("channel %d: protocol error: close rcvd twice", c->self); in chan_rcvd_close2()
275 c->flags |= CHAN_CLOSE_RCVD; in chan_rcvd_close2()
276 if (c->type == SSH_CHANNEL_LARVAL) { in chan_rcvd_close2()
278 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_rcvd_close2()
279 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_close2()
282 switch (c->ostate) { in chan_rcvd_close2()
288 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_close2()
291 switch (c->istate) { in chan_rcvd_close2()
293 chan_shutdown_read(c); in chan_rcvd_close2()
294 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_close2()
297 chan_send_eof2(c); in chan_rcvd_close2()
298 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_close2()
303 chan_rcvd_eow(Channel *c) in chan_rcvd_eow() argument
305 debug2("channel %d: rcvd eow", c->self); in chan_rcvd_eow()
306 switch (c->istate) { in chan_rcvd_eow()
308 chan_shutdown_read(c); in chan_rcvd_eow()
309 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_eow()
314 chan_rcvd_eof2(Channel *c) in chan_rcvd_eof2() argument
316 debug("channel %d: rcvd eof", c->self); in chan_rcvd_eof2()
317 c->flags |= CHAN_EOF_RCVD; in chan_rcvd_eof2()
318 if (c->ostate == CHAN_OUTPUT_OPEN) in chan_rcvd_eof2()
319 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_eof2()
322 chan_write_failed2(Channel *c) in chan_write_failed2() argument
324 debug("channel %d: write failed", c->self); in chan_write_failed2()
325 switch (c->ostate) { in chan_write_failed2()
328 chan_shutdown_write(c); in chan_write_failed2()
329 if (strcmp(c->ctype, "session") == 0) in chan_write_failed2()
330 chan_send_eow2(c); in chan_write_failed2()
331 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_write_failed2()
335 c->self, c->ostate); in chan_write_failed2()
340 chan_send_eof2(Channel *c) in chan_send_eof2() argument
342 debug("channel %d: send eof", c->self); in chan_send_eof2()
343 switch (c->istate) { in chan_send_eof2()
346 packet_put_int(c->remote_id); in chan_send_eof2()
348 c->flags |= CHAN_EOF_SENT; in chan_send_eof2()
352 c->self, c->istate); in chan_send_eof2()
357 chan_send_close2(Channel *c) in chan_send_close2() argument
359 debug("channel %d: send close", c->self); in chan_send_close2()
360 if (c->ostate != CHAN_OUTPUT_CLOSED || in chan_send_close2()
361 c->istate != CHAN_INPUT_CLOSED) { in chan_send_close2()
363 c->self, c->istate, c->ostate); in chan_send_close2()
364 } else if (c->flags & CHAN_CLOSE_SENT) { in chan_send_close2()
365 error("channel %d: already sent close", c->self); in chan_send_close2()
368 packet_put_int(c->remote_id); in chan_send_close2()
370 c->flags |= CHAN_CLOSE_SENT; in chan_send_close2()
374 chan_send_eow2(Channel *c) in chan_send_eow2() argument
376 debug2("channel %d: send eow", c->self); in chan_send_eow2()
377 if (c->ostate == CHAN_OUTPUT_CLOSED) { in chan_send_eow2()
379 c->self); in chan_send_eow2()
383 packet_put_int(c->remote_id); in chan_send_eow2()
392 chan_rcvd_ieof(Channel *c) in chan_rcvd_ieof() argument
395 chan_rcvd_eof2(c); in chan_rcvd_ieof()
397 chan_rcvd_ieof1(c); in chan_rcvd_ieof()
398 if (c->ostate == CHAN_OUTPUT_WAIT_DRAIN && in chan_rcvd_ieof()
399 buffer_len(&c->output) == 0 && in chan_rcvd_ieof()
400 !CHANNEL_EFD_OUTPUT_ACTIVE(c)) in chan_rcvd_ieof()
401 chan_obuf_empty(c); in chan_rcvd_ieof()
404 chan_rcvd_oclose(Channel *c) in chan_rcvd_oclose() argument
407 chan_rcvd_close2(c); in chan_rcvd_oclose()
409 chan_rcvd_oclose1(c); in chan_rcvd_oclose()
412 chan_write_failed(Channel *c) in chan_write_failed() argument
415 chan_write_failed2(c); in chan_write_failed()
417 chan_write_failed1(c); in chan_write_failed()
421 chan_mark_dead(Channel *c) in chan_mark_dead() argument
423 c->type = SSH_CHANNEL_ZOMBIE; in chan_mark_dead()
427 chan_is_dead(Channel *c, int send) in chan_is_dead() argument
429 if (c->type == SSH_CHANNEL_ZOMBIE) { in chan_is_dead()
430 debug("channel %d: zombie", c->self); in chan_is_dead()
433 if (c->istate != CHAN_INPUT_CLOSED || c->ostate != CHAN_OUTPUT_CLOSED) in chan_is_dead()
436 debug("channel %d: is dead", c->self); in chan_is_dead()
440 c->extended_usage == CHAN_EXTENDED_WRITE && in chan_is_dead()
441 c->efd != -1 && in chan_is_dead()
442 buffer_len(&c->extended) > 0) { in chan_is_dead()
444 c->self, c->efd, buffer_len(&c->extended)); in chan_is_dead()
447 if (!(c->flags & CHAN_CLOSE_SENT)) { in chan_is_dead()
449 chan_send_close2(c); in chan_is_dead()
452 if (c->flags & CHAN_CLOSE_RCVD) { in chan_is_dead()
454 c->self); in chan_is_dead()
459 if ((c->flags & CHAN_CLOSE_SENT) && in chan_is_dead()
460 (c->flags & CHAN_CLOSE_RCVD)) { in chan_is_dead()
461 debug("channel %d: is dead", c->self); in chan_is_dead()
469 chan_shutdown_write(Channel *c) in chan_shutdown_write() argument
471 buffer_clear(&c->output); in chan_shutdown_write()
472 if (compat20 && c->type == SSH_CHANNEL_LARVAL) in chan_shutdown_write()
475 debug("channel %d: close_write", c->self); in chan_shutdown_write()
476 if (c->sock != -1) { in chan_shutdown_write()
477 if (shutdown(c->sock, SHUT_WR) < 0) in chan_shutdown_write()
480 c->self, c->sock, strerror(errno)); in chan_shutdown_write()
482 if (channel_close_fd(&c->wfd) < 0) in chan_shutdown_write()
485 c->self, c->wfd, strerror(errno)); in chan_shutdown_write()
489 chan_shutdown_read(Channel *c) in chan_shutdown_read() argument
491 if (compat20 && c->type == SSH_CHANNEL_LARVAL) in chan_shutdown_read()
493 debug("channel %d: close_read", c->self); in chan_shutdown_read()
494 if (c->sock != -1) { in chan_shutdown_read()
500 if (shutdown(c->sock, SHUT_RD) < 0 in chan_shutdown_read()
504 c->self, c->sock, c->istate, c->ostate, in chan_shutdown_read()
507 if (channel_close_fd(&c->rfd) < 0) in chan_shutdown_read()
510 c->self, c->rfd, strerror(errno)); in chan_shutdown_read()