|
Lines 92-97
struct mux_session_confirm_ctx {
Link Here
|
| 92 |
u_int rid; |
92 |
u_int rid; |
| 93 |
}; |
93 |
}; |
| 94 |
|
94 |
|
|
|
95 |
/* Context for stdio fwd open confirmation callback */ |
| 96 |
struct mux_stdio_confirm_ctx { |
| 97 |
u_int rid; |
| 98 |
}; |
| 99 |
|
| 95 |
/* Context for global channel callback */ |
100 |
/* Context for global channel callback */ |
| 96 |
struct mux_channel_confirm_ctx { |
101 |
struct mux_channel_confirm_ctx { |
| 97 |
u_int cid; /* channel id */ |
102 |
u_int cid; /* channel id */ |
|
Lines 144-149
struct mux_master_state {
Link Here
|
| 144 |
#define MUX_FWD_DYNAMIC 3 |
149 |
#define MUX_FWD_DYNAMIC 3 |
| 145 |
|
150 |
|
| 146 |
static void mux_session_confirm(int, int, void *); |
151 |
static void mux_session_confirm(int, int, void *); |
|
|
152 |
static void mux_stdio_confirm(int, int, void *); |
| 147 |
|
153 |
|
| 148 |
static int process_mux_master_hello(u_int, Channel *, Buffer *, Buffer *); |
154 |
static int process_mux_master_hello(u_int, Channel *, Buffer *, Buffer *); |
| 149 |
static int process_mux_new_session(u_int, Channel *, Buffer *, Buffer *); |
155 |
static int process_mux_new_session(u_int, Channel *, Buffer *, Buffer *); |
|
Lines 870-875
process_mux_stdio_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
Link Here
|
| 870 |
char *reserved, *chost; |
876 |
char *reserved, *chost; |
| 871 |
u_int cport, i, j; |
877 |
u_int cport, i, j; |
| 872 |
int new_fd[2]; |
878 |
int new_fd[2]; |
|
|
879 |
struct mux_stdio_confirm_ctx *cctx; |
| 873 |
|
880 |
|
| 874 |
chost = reserved = NULL; |
881 |
chost = reserved = NULL; |
| 875 |
if ((reserved = buffer_get_string_ret(m, NULL)) == NULL || |
882 |
if ((reserved = buffer_get_string_ret(m, NULL)) == NULL || |
|
Lines 949-963
process_mux_stdio_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
Link Here
|
| 949 |
|
956 |
|
| 950 |
channel_register_cleanup(nc->self, mux_master_session_cleanup_cb, 1); |
957 |
channel_register_cleanup(nc->self, mux_master_session_cleanup_cb, 1); |
| 951 |
|
958 |
|
| 952 |
/* prepare reply */ |
959 |
cctx = xcalloc(1, sizeof(*cctx)); |
| 953 |
/* XXX defer until channel confirmed */ |
960 |
cctx->rid = rid; |
| 954 |
buffer_put_int(r, MUX_S_SESSION_OPENED); |
961 |
channel_register_open_confirm(nc->self, mux_stdio_confirm, cctx); |
| 955 |
buffer_put_int(r, rid); |
962 |
c->mux_pause = 1; /* stop handling messages until open_confirm done */ |
| 956 |
buffer_put_int(r, nc->self); |
|
|
| 957 |
|
963 |
|
|
|
964 |
/* reply is deferred, sent by mux_session_confirm */ |
| 958 |
return 0; |
965 |
return 0; |
| 959 |
} |
966 |
} |
| 960 |
|
967 |
|
|
|
968 |
/* Callback on open confirmation in mux master for a mux stdio fwd session. */ |
| 969 |
static void |
| 970 |
mux_stdio_confirm(int id, int success, void *arg) |
| 971 |
{ |
| 972 |
struct mux_stdio_confirm_ctx *cctx = arg; |
| 973 |
Channel *c, *cc; |
| 974 |
Buffer reply; |
| 975 |
|
| 976 |
if (cctx == NULL) |
| 977 |
fatal("%s: cctx == NULL", __func__); |
| 978 |
if ((c = channel_by_id(id)) == NULL) |
| 979 |
fatal("%s: no channel for id %d", __func__, id); |
| 980 |
if ((cc = channel_by_id(c->ctl_chan)) == NULL) |
| 981 |
fatal("%s: channel %d lacks control channel %d", __func__, |
| 982 |
id, c->ctl_chan); |
| 983 |
|
| 984 |
if (!success) { |
| 985 |
debug3("%s: sending failure reply", __func__); |
| 986 |
/* prepare reply */ |
| 987 |
buffer_init(&reply); |
| 988 |
buffer_put_int(&reply, MUX_S_FAILURE); |
| 989 |
buffer_put_int(&reply, cctx->rid); |
| 990 |
buffer_put_cstring(&reply, "Session open refused by peer"); |
| 991 |
goto done; |
| 992 |
} |
| 993 |
|
| 994 |
debug3("%s: sending success reply", __func__); |
| 995 |
/* prepare reply */ |
| 996 |
buffer_init(&reply); |
| 997 |
buffer_put_int(&reply, MUX_S_SESSION_OPENED); |
| 998 |
buffer_put_int(&reply, cctx->rid); |
| 999 |
buffer_put_int(&reply, c->self); |
| 1000 |
|
| 1001 |
done: |
| 1002 |
/* Send reply */ |
| 1003 |
buffer_put_string(&cc->output, buffer_ptr(&reply), buffer_len(&reply)); |
| 1004 |
buffer_free(&reply); |
| 1005 |
|
| 1006 |
if (cc->mux_pause <= 0) |
| 1007 |
fatal("%s: mux_pause %d", __func__, cc->mux_pause); |
| 1008 |
cc->mux_pause = 0; /* start processing messages again */ |
| 1009 |
c->open_confirm_ctx = NULL; |
| 1010 |
free(cctx); |
| 1011 |
} |
| 1012 |
|
| 961 |
static int |
1013 |
static int |
| 962 |
process_mux_stop_listening(u_int rid, Channel *c, Buffer *m, Buffer *r) |
1014 |
process_mux_stop_listening(u_int rid, Channel *c, Buffer *m, Buffer *r) |
| 963 |
{ |
1015 |
{ |
|
Lines 1902-1908
mux_client_request_stdio_fwd(int fd)
Link Here
|
| 1902 |
case MUX_S_FAILURE: |
1954 |
case MUX_S_FAILURE: |
| 1903 |
e = buffer_get_string(&m, NULL); |
1955 |
e = buffer_get_string(&m, NULL); |
| 1904 |
buffer_free(&m); |
1956 |
buffer_free(&m); |
| 1905 |
fatal("%s: stdio forwarding request failed: %s", __func__, e); |
1957 |
fatal("Stdio forwarding request failed: %s", e); |
| 1906 |
default: |
1958 |
default: |
| 1907 |
buffer_free(&m); |
1959 |
buffer_free(&m); |
| 1908 |
error("%s: unexpected response from master 0x%08x", |
1960 |
error("%s: unexpected response from master 0x%08x", |