Lines Matching defs:c
1 /* $OpenBSD: nchan.c,v 1.76 2024/07/25 22:40:08 djm Exp $ */
3 * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved.
91 chan_set_istate(Channel *c, u_int next)
93 if (c->istate > CHAN_INPUT_CLOSED || next > CHAN_INPUT_CLOSED)
94 fatal("chan_set_istate: bad state %d -> %d", c->istate, next);
95 debug2("channel %d: input %s -> %s", c->self, istates[c->istate],
97 c->istate = next;
101 chan_set_ostate(Channel *c, u_int next)
103 if (c->ostate > CHAN_OUTPUT_CLOSED || next > CHAN_OUTPUT_CLOSED)
104 fatal("chan_set_ostate: bad state %d -> %d", c->ostate, next);
105 debug2("channel %d: output %s -> %s", c->self, ostates[c->ostate],
107 c->ostate = next;
111 chan_read_failed(struct ssh *ssh, Channel *c)
113 debug2("channel %d: read failed", c->self);
114 switch (c->istate) {
116 chan_shutdown_read(ssh, c);
117 chan_set_istate(c, CHAN_INPUT_WAIT_DRAIN);
121 c->self, c->istate);
127 chan_ibuf_empty(struct ssh *ssh, Channel *c)
129 debug2("channel %d: ibuf empty", c->self);
130 if (sshbuf_len(c->input)) {
132 c->self);
135 switch (c->istate) {
137 if (!(c->flags & (CHAN_CLOSE_SENT|CHAN_LOCAL)))
138 chan_send_eof2(ssh, c);
139 chan_set_istate(c, CHAN_INPUT_CLOSED);
143 c->self, c->istate);
149 chan_obuf_empty(struct ssh *ssh, Channel *c)
151 debug2("channel %d: obuf empty", c->self);
152 if (sshbuf_len(c->output)) {
154 c->self);
157 switch (c->ostate) {
159 chan_shutdown_write(ssh, c);
160 chan_set_ostate(c, CHAN_OUTPUT_CLOSED);
164 c->self, c->ostate);
170 chan_rcvd_eow(struct ssh *ssh, Channel *c)
172 debug2("channel %d: rcvd eow", c->self);
173 switch (c->istate) {
175 chan_shutdown_read(ssh, c);
176 chan_set_istate(c, CHAN_INPUT_CLOSED);
182 chan_send_eof2(struct ssh *ssh, Channel *c)
186 debug2("channel %d: send eof", c->self);
187 switch (c->istate) {
189 if (!c->have_remote_id)
190 fatal_f("channel %d: no remote_id", c->self);
192 (r = sshpkt_put_u32(ssh, c->remote_id)) != 0 ||
195 c->flags |= CHAN_EOF_SENT;
199 c->self, c->istate);
205 chan_send_close2(struct ssh *ssh, Channel *c)
209 debug2("channel %d: send_close2", c->self);
210 if (c->ostate != CHAN_OUTPUT_CLOSED ||
211 c->istate != CHAN_INPUT_CLOSED) {
213 c->self, c->istate, c->ostate);
214 } else if (c->flags & CHAN_CLOSE_SENT) {
215 error("channel %d: already sent close", c->self);
217 if (!c->have_remote_id)
218 fatal_f("channel %d: no remote_id", c->self);
219 debug2("channel %d: send close for remote id %u", c->self,
220 c->remote_id);
222 (r = sshpkt_put_u32(ssh, c->remote_id)) != 0 ||
225 c->flags |= CHAN_CLOSE_SENT;
230 chan_send_eow2(struct ssh *ssh, Channel *c)
234 debug2("channel %d: send eow", c->self);
235 if (c->ostate == CHAN_OUTPUT_CLOSED) {
237 c->self);
242 if (!c->have_remote_id)
243 fatal_f("channel %d: no remote_id", c->self);
245 (r = sshpkt_put_u32(ssh, c->remote_id)) != 0 ||
255 chan_rcvd_ieof(struct ssh *ssh, Channel *c)
257 debug2("channel %d: rcvd eof", c->self);
258 c->flags |= CHAN_EOF_RCVD;
259 if (c->ostate == CHAN_OUTPUT_OPEN)
260 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN);
261 if (c->ostate == CHAN_OUTPUT_WAIT_DRAIN &&
262 sshbuf_len(c->output) == 0 &&
263 !CHANNEL_EFD_OUTPUT_ACTIVE(c))
264 chan_obuf_empty(ssh, c);
268 chan_rcvd_oclose(struct ssh *ssh, Channel *c)
270 debug2("channel %d: rcvd close", c->self);
271 if (!(c->flags & CHAN_LOCAL)) {
272 if (c->flags & CHAN_CLOSE_RCVD)
274 c->self);
275 c->flags |= CHAN_CLOSE_RCVD;
277 if (c->type == SSH_CHANNEL_LARVAL) {
279 chan_set_ostate(c, CHAN_OUTPUT_CLOSED);
280 chan_set_istate(c, CHAN_INPUT_CLOSED);
283 switch (c->ostate) {
289 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN);
292 switch (c->istate) {
294 chan_shutdown_read(ssh, c);
295 chan_shutdown_extended_read(ssh, c);
296 chan_set_istate(c, CHAN_INPUT_CLOSED);
299 if (!(c->flags & CHAN_LOCAL))
300 chan_send_eof2(ssh, c);
301 chan_shutdown_extended_read(ssh, c);
302 chan_set_istate(c, CHAN_INPUT_CLOSED);
308 chan_write_failed(struct ssh *ssh, Channel *c)
310 debug2("channel %d: write failed", c->self);
311 switch (c->ostate) {
314 chan_shutdown_write(ssh, c);
315 if (strcmp(c->ctype, "session") == 0)
316 chan_send_eow2(ssh, c);
317 chan_set_ostate(c, CHAN_OUTPUT_CLOSED);
321 c->self, c->ostate);
327 chan_mark_dead(struct ssh *ssh, Channel *c)
329 c->type = SSH_CHANNEL_ZOMBIE;
333 chan_is_dead(struct ssh *ssh, Channel *c, int do_send)
335 if (c->type == SSH_CHANNEL_ZOMBIE) {
336 debug2("channel %d: zombie", c->self);
339 if (c->istate != CHAN_INPUT_CLOSED || c->ostate != CHAN_OUTPUT_CLOSED)
342 c->extended_usage == CHAN_EXTENDED_WRITE &&
343 c->efd != -1 &&
344 sshbuf_len(c->extended) > 0) {
346 c->self, c->efd, sshbuf_len(c->extended));
349 if (c->flags & CHAN_LOCAL) {
350 debug2("channel %d: is dead (local)", c->self);
353 if (!(c->flags & CHAN_CLOSE_SENT)) {
355 chan_send_close2(ssh, c);
358 if (c->flags & CHAN_CLOSE_RCVD) {
360 c->self);
365 if ((c->flags & CHAN_CLOSE_SENT) &&
366 (c->flags & CHAN_CLOSE_RCVD)) {
367 debug2("channel %d: is dead", c->self);
375 chan_shutdown_write(struct ssh *ssh, Channel *c)
377 sshbuf_reset(c->output);
378 if (c->type == SSH_CHANNEL_LARVAL)
382 c->self, c->istate, c->ostate, c->sock, c->wfd, c->efd,
383 channel_format_extended_usage(c));
384 if (c->sock != -1) {
385 if (shutdown(c->sock, SHUT_WR) == -1) {
387 "fd %d [i%d o%d]: %.100s", c->self, c->sock,
388 c->istate, c->ostate, strerror(errno));
391 if (channel_close_fd(ssh, c, &c->wfd) < 0) {
393 "fd %d [i%d o%d]: %.100s", c->self, c->wfd,
394 c->istate, c->ostate, strerror(errno));
400 chan_shutdown_read(struct ssh *ssh, Channel *c)
402 if (c->type == SSH_CHANNEL_LARVAL)
405 c->self, c->istate, c->ostate, c->sock, c->rfd, c->efd,
406 channel_format_extended_usage(c));
407 if (c->sock != -1) {
408 if (shutdown(c->sock, SHUT_RD) == -1) {
410 "fd %d [i%d o%d]: %.100s", c->self, c->sock,
411 c->istate, c->ostate, strerror(errno));
414 if (channel_close_fd(ssh, c, &c->rfd) < 0) {
416 "fd %d [i%d o%d]: %.100s", c->self, c->rfd,
417 c->istate, c->ostate, strerror(errno));
423 chan_shutdown_extended_read(struct ssh *ssh, Channel *c)
425 if (c->type == SSH_CHANNEL_LARVAL || c->efd == -1)
427 if (c->extended_usage != CHAN_EXTENDED_READ &&
428 c->extended_usage != CHAN_EXTENDED_IGNORE)
431 c->self, c->istate, c->ostate, c->sock, c->rfd, c->efd,
432 channel_format_extended_usage(c));
433 if (channel_close_fd(ssh, c, &c->efd) < 0) {
435 "extended fd %d [i%d o%d]: %.100s", c->self, c->efd,
436 c->istate, c->ostate, strerror(errno));