summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-10-04 01:04:52 +0000
committerDamien Miller <djm@mindrot.org>2018-10-04 17:50:22 +1000
commit6f1aabb128246f445e33b8844fad3de9cb1d18cb (patch)
treeee4622587e8c0d8704a6a539d73dfb18aa0a050a /channels.c
parentf1dd179e122bdfdb7ca3072d9603607740efda05 (diff)
upstream: factor out channel status formatting from
channel_open_message() so we can use it in other debug messages OpenBSD-Commit-ID: 9c3903ca28fcabad57f566c9d0045b41ab7d52ba
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/channels.c b/channels.c
index bd68177b7..c85d46abd 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.c,v 1.385 2018/10/04 00:10:11 djm Exp $ */ 1/* $OpenBSD: channels.c,v 1.386 2018/10/04 01:04:52 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -818,6 +818,22 @@ channel_format_extended_usage(const Channel *c)
818 } 818 }
819} 819}
820 820
821static char *
822channel_format_status(const Channel *c)
823{
824 char *ret = NULL;
825
826 xasprintf(&ret, "t%d %s%u i%u/%zu o%u/%zu e[%s]/%zu "
827 "fd %d/%d/%d sock %d cc %d",
828 c->type,
829 c->have_remote_id ? "r" : "nr", c->remote_id,
830 c->istate, sshbuf_len(c->input),
831 c->ostate, sshbuf_len(c->output),
832 channel_format_extended_usage(c), sshbuf_len(c->extended),
833 c->rfd, c->wfd, c->efd, c->sock, c->ctl_chan);
834 return ret;
835}
836
821/* 837/*
822 * Returns a message describing the currently open forwarded connections, 838 * Returns a message describing the currently open forwarded connections,
823 * suitable for sending to the client. The message contains crlf pairs for 839 * suitable for sending to the client. The message contains crlf pairs for
@@ -830,7 +846,7 @@ channel_open_message(struct ssh *ssh)
830 Channel *c; 846 Channel *c;
831 u_int i; 847 u_int i;
832 int r; 848 int r;
833 char *ret; 849 char *cp, *ret;
834 850
835 if ((buf = sshbuf_new()) == NULL) 851 if ((buf = sshbuf_new()) == NULL)
836 fatal("%s: sshbuf_new", __func__); 852 fatal("%s: sshbuf_new", __func__);
@@ -863,19 +879,14 @@ channel_open_message(struct ssh *ssh)
863 case SSH_CHANNEL_X11_OPEN: 879 case SSH_CHANNEL_X11_OPEN:
864 case SSH_CHANNEL_MUX_PROXY: 880 case SSH_CHANNEL_MUX_PROXY:
865 case SSH_CHANNEL_MUX_CLIENT: 881 case SSH_CHANNEL_MUX_CLIENT:
866 if ((r = sshbuf_putf(buf, " #%d %.300s " 882 cp = channel_format_status(c);
867 "(t%d %s%u i%u/%zu o%u/%zu " 883 if ((r = sshbuf_putf(buf, " #%d %.300s (%s)\r\n",
868 "fd %d/%d/%d [%s] sock %d cc %d)\r\n", 884 c->self, c->remote_name, cp)) != 0) {
869 c->self, c->remote_name, 885 free(cp);
870 c->type,
871 c->have_remote_id ? "r" : "nr", c->remote_id,
872 c->istate, sshbuf_len(c->input),
873 c->ostate, sshbuf_len(c->output),
874 c->rfd, c->wfd, c->efd,
875 channel_format_extended_usage(c),
876 c->sock, c->ctl_chan)) != 0)
877 fatal("%s: sshbuf_putf: %s", 886 fatal("%s: sshbuf_putf: %s",
878 __func__, ssh_err(r)); 887 __func__, ssh_err(r));
888 }
889 free(cp);
879 continue; 890 continue;
880 default: 891 default:
881 fatal("%s: bad channel type %d", __func__, c->type); 892 fatal("%s: bad channel type %d", __func__, c->type);