Lines Matching refs:c
93 chan_set_istate(Channel *c, u_int next) in chan_set_istate() argument
95 if (c->istate > CHAN_INPUT_CLOSED || next > CHAN_INPUT_CLOSED) in chan_set_istate()
96 fatal("chan_set_istate: bad state %d -> %d", c->istate, next); in chan_set_istate()
97 debug2("channel %d: input %s -> %s", c->self, istates[c->istate], in chan_set_istate()
99 c->istate = next; in chan_set_istate()
103 chan_set_ostate(Channel *c, u_int next) in chan_set_ostate() argument
105 if (c->ostate > CHAN_OUTPUT_CLOSED || next > CHAN_OUTPUT_CLOSED) in chan_set_ostate()
106 fatal("chan_set_ostate: bad state %d -> %d", c->ostate, next); in chan_set_ostate()
107 debug2("channel %d: output %s -> %s", c->self, ostates[c->ostate], in chan_set_ostate()
109 c->ostate = next; in chan_set_ostate()
113 chan_read_failed(struct ssh *ssh, Channel *c) in chan_read_failed() argument
115 debug2("channel %d: read failed", c->self); in chan_read_failed()
116 switch (c->istate) { in chan_read_failed()
118 chan_shutdown_read(ssh, c); in chan_read_failed()
119 chan_set_istate(c, CHAN_INPUT_WAIT_DRAIN); in chan_read_failed()
123 c->self, c->istate); in chan_read_failed()
129 chan_ibuf_empty(struct ssh *ssh, Channel *c) in chan_ibuf_empty() argument
131 debug2("channel %d: ibuf empty", c->self); in chan_ibuf_empty()
132 if (sshbuf_len(c->input)) { in chan_ibuf_empty()
134 c->self); in chan_ibuf_empty()
137 switch (c->istate) { in chan_ibuf_empty()
139 if (!(c->flags & (CHAN_CLOSE_SENT|CHAN_LOCAL))) in chan_ibuf_empty()
140 chan_send_eof2(ssh, c); in chan_ibuf_empty()
141 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_ibuf_empty()
145 c->self, c->istate); in chan_ibuf_empty()
151 chan_obuf_empty(struct ssh *ssh, Channel *c) in chan_obuf_empty() argument
153 debug2("channel %d: obuf empty", c->self); in chan_obuf_empty()
154 if (sshbuf_len(c->output)) { in chan_obuf_empty()
156 c->self); in chan_obuf_empty()
159 switch (c->ostate) { in chan_obuf_empty()
161 chan_shutdown_write(ssh, c); in chan_obuf_empty()
162 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_obuf_empty()
166 c->self, c->ostate); in chan_obuf_empty()
172 chan_rcvd_eow(struct ssh *ssh, Channel *c) in chan_rcvd_eow() argument
174 debug2("channel %d: rcvd eow", c->self); in chan_rcvd_eow()
175 switch (c->istate) { in chan_rcvd_eow()
177 chan_shutdown_read(ssh, c); in chan_rcvd_eow()
178 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_eow()
184 chan_send_eof2(struct ssh *ssh, Channel *c) in chan_send_eof2() argument
188 debug2("channel %d: send eof", c->self); in chan_send_eof2()
189 switch (c->istate) { in chan_send_eof2()
191 if (!c->have_remote_id) in chan_send_eof2()
192 fatal_f("channel %d: no remote_id", c->self); in chan_send_eof2()
194 (r = sshpkt_put_u32(ssh, c->remote_id)) != 0 || in chan_send_eof2()
197 c->flags |= CHAN_EOF_SENT; in chan_send_eof2()
201 c->self, c->istate); in chan_send_eof2()
207 chan_send_close2(struct ssh *ssh, Channel *c) in chan_send_close2() argument
211 debug2("channel %d: send close", c->self); in chan_send_close2()
212 if (c->ostate != CHAN_OUTPUT_CLOSED || in chan_send_close2()
213 c->istate != CHAN_INPUT_CLOSED) { in chan_send_close2()
215 c->self, c->istate, c->ostate); in chan_send_close2()
216 } else if (c->flags & CHAN_CLOSE_SENT) { in chan_send_close2()
217 error("channel %d: already sent close", c->self); in chan_send_close2()
219 if (!c->have_remote_id) in chan_send_close2()
220 fatal_f("channel %d: no remote_id", c->self); in chan_send_close2()
222 (r = sshpkt_put_u32(ssh, c->remote_id)) != 0 || in chan_send_close2()
225 c->flags |= CHAN_CLOSE_SENT; in chan_send_close2()
230 chan_send_eow2(struct ssh *ssh, Channel *c) in chan_send_eow2() argument
234 debug2("channel %d: send eow", c->self); in chan_send_eow2()
235 if (c->ostate == CHAN_OUTPUT_CLOSED) { in chan_send_eow2()
237 c->self); in chan_send_eow2()
242 if (!c->have_remote_id) in chan_send_eow2()
243 fatal_f("channel %d: no remote_id", c->self); in chan_send_eow2()
245 (r = sshpkt_put_u32(ssh, c->remote_id)) != 0 || in chan_send_eow2()
255 chan_rcvd_ieof(struct ssh *ssh, Channel *c) in chan_rcvd_ieof() argument
257 debug2("channel %d: rcvd eof", c->self); in chan_rcvd_ieof()
258 c->flags |= CHAN_EOF_RCVD; in chan_rcvd_ieof()
259 if (c->ostate == CHAN_OUTPUT_OPEN) in chan_rcvd_ieof()
260 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_ieof()
261 if (c->ostate == CHAN_OUTPUT_WAIT_DRAIN && in chan_rcvd_ieof()
262 sshbuf_len(c->output) == 0 && in chan_rcvd_ieof()
263 !CHANNEL_EFD_OUTPUT_ACTIVE(c)) in chan_rcvd_ieof()
264 chan_obuf_empty(ssh, c); in chan_rcvd_ieof()
268 chan_rcvd_oclose(struct ssh *ssh, Channel *c) in chan_rcvd_oclose() argument
270 debug2("channel %d: rcvd close", c->self); in chan_rcvd_oclose()
271 if (!(c->flags & CHAN_LOCAL)) { in chan_rcvd_oclose()
272 if (c->flags & CHAN_CLOSE_RCVD) in chan_rcvd_oclose()
274 c->self); in chan_rcvd_oclose()
275 c->flags |= CHAN_CLOSE_RCVD; in chan_rcvd_oclose()
277 if (c->type == SSH_CHANNEL_LARVAL) { in chan_rcvd_oclose()
279 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_rcvd_oclose()
280 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose()
283 switch (c->ostate) { in chan_rcvd_oclose()
289 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_oclose()
292 switch (c->istate) { in chan_rcvd_oclose()
294 chan_shutdown_read(ssh, c); in chan_rcvd_oclose()
295 chan_shutdown_extended_read(ssh, c); in chan_rcvd_oclose()
296 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose()
299 if (!(c->flags & CHAN_LOCAL)) in chan_rcvd_oclose()
300 chan_send_eof2(ssh, c); in chan_rcvd_oclose()
301 chan_shutdown_extended_read(ssh, c); in chan_rcvd_oclose()
302 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose()
308 chan_write_failed(struct ssh *ssh, Channel *c) in chan_write_failed() argument
310 debug2("channel %d: write failed", c->self); in chan_write_failed()
311 switch (c->ostate) { in chan_write_failed()
314 chan_shutdown_write(ssh, c); in chan_write_failed()
315 if (strcmp(c->ctype, "session") == 0) in chan_write_failed()
316 chan_send_eow2(ssh, c); in chan_write_failed()
317 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_write_failed()
321 c->self, c->ostate); in chan_write_failed()
327 chan_mark_dead(struct ssh *ssh, Channel *c) in chan_mark_dead() argument
329 c->type = SSH_CHANNEL_ZOMBIE; in chan_mark_dead()
333 chan_is_dead(struct ssh *ssh, Channel *c, int do_send) in chan_is_dead() argument
335 if (c->type == SSH_CHANNEL_ZOMBIE) { in chan_is_dead()
336 debug2("channel %d: zombie", c->self); in chan_is_dead()
339 if (c->istate != CHAN_INPUT_CLOSED || c->ostate != CHAN_OUTPUT_CLOSED) in chan_is_dead()
342 c->extended_usage == CHAN_EXTENDED_WRITE && in chan_is_dead()
343 c->efd != -1 && in chan_is_dead()
344 sshbuf_len(c->extended) > 0) { in chan_is_dead()
346 c->self, c->efd, sshbuf_len(c->extended)); in chan_is_dead()
349 if (c->flags & CHAN_LOCAL) { in chan_is_dead()
350 debug2("channel %d: is dead (local)", c->self); in chan_is_dead()
353 if (!(c->flags & CHAN_CLOSE_SENT)) { in chan_is_dead()
355 chan_send_close2(ssh, c); in chan_is_dead()
358 if (c->flags & CHAN_CLOSE_RCVD) { in chan_is_dead()
360 c->self); in chan_is_dead()
365 if ((c->flags & CHAN_CLOSE_SENT) && in chan_is_dead()
366 (c->flags & CHAN_CLOSE_RCVD)) { in chan_is_dead()
367 debug2("channel %d: is dead", c->self); in chan_is_dead()
375 chan_shutdown_write(struct ssh *ssh, Channel *c) in chan_shutdown_write() argument
377 sshbuf_reset(c->output); in chan_shutdown_write()
378 if (c->type == SSH_CHANNEL_LARVAL) in chan_shutdown_write()
382 c->self, c->istate, c->ostate, c->sock, c->wfd, c->efd, in chan_shutdown_write()
383 channel_format_extended_usage(c)); in chan_shutdown_write()
384 if (c->sock != -1) { in chan_shutdown_write()
385 if (shutdown(c->sock, SHUT_WR) == -1) { in chan_shutdown_write()
387 "fd %d [i%d o%d]: %.100s", c->self, c->sock, in chan_shutdown_write()
388 c->istate, c->ostate, strerror(errno)); in chan_shutdown_write()
391 if (channel_close_fd(ssh, c, &c->wfd) < 0) { in chan_shutdown_write()
393 "fd %d [i%d o%d]: %.100s", c->self, c->wfd, in chan_shutdown_write()
394 c->istate, c->ostate, strerror(errno)); in chan_shutdown_write()
400 chan_shutdown_read(struct ssh *ssh, Channel *c) in chan_shutdown_read() argument
402 if (c->type == SSH_CHANNEL_LARVAL) in chan_shutdown_read()
405 c->self, c->istate, c->ostate, c->sock, c->rfd, c->efd, in chan_shutdown_read()
406 channel_format_extended_usage(c)); in chan_shutdown_read()
407 if (c->sock != -1) { in chan_shutdown_read()
413 if (shutdown(c->sock, SHUT_RD) == -1 && errno != ENOTCONN) { in chan_shutdown_read()
415 "fd %d [i%d o%d]: %.100s", c->self, c->sock, in chan_shutdown_read()
416 c->istate, c->ostate, strerror(errno)); in chan_shutdown_read()
419 if (channel_close_fd(ssh, c, &c->rfd) < 0) { in chan_shutdown_read()
421 "fd %d [i%d o%d]: %.100s", c->self, c->rfd, in chan_shutdown_read()
422 c->istate, c->ostate, strerror(errno)); in chan_shutdown_read()
428 chan_shutdown_extended_read(struct ssh *ssh, Channel *c) in chan_shutdown_extended_read() argument
430 if (c->type == SSH_CHANNEL_LARVAL || c->efd == -1) in chan_shutdown_extended_read()
432 if (c->extended_usage != CHAN_EXTENDED_READ && in chan_shutdown_extended_read()
433 c->extended_usage != CHAN_EXTENDED_IGNORE) in chan_shutdown_extended_read()
436 c->self, c->istate, c->ostate, c->sock, c->rfd, c->efd, in chan_shutdown_extended_read()
437 channel_format_extended_usage(c)); in chan_shutdown_extended_read()
438 if (channel_close_fd(ssh, c, &c->efd) < 0) { in chan_shutdown_extended_read()
440 "extended fd %d [i%d o%d]: %.100s", c->self, c->efd, in chan_shutdown_extended_read()
441 c->istate, c->ostate, strerror(errno)); in chan_shutdown_extended_read()