View | Details | Raw Unified | Return to bug 2784 | Differences between
and this patch

Collapse All | Expand All

(-)a/channels.c (-19 / +39 lines)
Lines 112-117 typedef struct { Link Here
112
	char *listen_host;		/* Remote side should listen address. */
112
	char *listen_host;		/* Remote side should listen address. */
113
	char *listen_path;		/* Remote side should listen path. */
113
	char *listen_path;		/* Remote side should listen path. */
114
	int listen_port;		/* Remote side should listen port. */
114
	int listen_port;		/* Remote side should listen port. */
115
	char *rdomain;			/* Routing Domain used for forwards */
115
	Channel *downstream;		/* Downstream mux*/
116
	Channel *downstream;		/* Downstream mux*/
116
} ForwardPermission;
117
} ForwardPermission;
117
118
Lines 448-453 fwd_perm_clear(ForwardPermission *fp) Link Here
448
	free(fp->host_to_connect);
449
	free(fp->host_to_connect);
449
	free(fp->listen_host);
450
	free(fp->listen_host);
450
	free(fp->listen_path);
451
	free(fp->listen_path);
452
	free(fp->rdomain);
451
	bzero(fp, sizeof(*fp));
453
	bzero(fp, sizeof(*fp));
452
}
454
}
453
455
Lines 457-463 static int Link Here
457
fwd_perm_list_add(struct ssh *ssh, int which,
459
fwd_perm_list_add(struct ssh *ssh, int which,
458
    const char *host_to_connect, int port_to_connect,
460
    const char *host_to_connect, int port_to_connect,
459
    const char *listen_host, const char *listen_path, int listen_port,
461
    const char *listen_host, const char *listen_path, int listen_port,
460
    Channel *downstream)
462
    Channel *downstream, const char *rdomain)
461
{
463
{
462
	ForwardPermission **fpl;
464
	ForwardPermission **fpl;
463
	u_int n, *nfpl;
465
	u_int n, *nfpl;
Lines 486-491 fwd_perm_list_add(struct ssh *ssh, int which, Link Here
486
	(*fpl)[n].listen_host = MAYBE_DUP(listen_host);
488
	(*fpl)[n].listen_host = MAYBE_DUP(listen_host);
487
	(*fpl)[n].listen_path = MAYBE_DUP(listen_path);
489
	(*fpl)[n].listen_path = MAYBE_DUP(listen_path);
488
	(*fpl)[n].listen_port = listen_port;
490
	(*fpl)[n].listen_port = listen_port;
491
	(*fpl)[n].rdomain = MAYBE_DUP(rdomain);
489
	(*fpl)[n].downstream = downstream;
492
	(*fpl)[n].downstream = downstream;
490
#undef MAYBE_DUP
493
#undef MAYBE_DUP
491
	return (int)n;
494
	return (int)n;
Lines 2732-2738 channel_proxy_downstream(struct ssh *ssh, Channel *downstream) Link Here
2732
		}
2735
		}
2733
		/* Record that connection to this host/port is permitted. */
2736
		/* Record that connection to this host/port is permitted. */
2734
		fwd_perm_list_add(ssh, FWDPERM_USER, "<mux>", -1,
2737
		fwd_perm_list_add(ssh, FWDPERM_USER, "<mux>", -1,
2735
		    listen_host, NULL, (int)listen_port, downstream);
2738
		    listen_host, NULL, (int)listen_port, downstream, NULL);
2736
		listen_host = NULL;
2739
		listen_host = NULL;
2737
		break;
2740
		break;
2738
	case SSH2_MSG_CHANNEL_CLOSE:
2741
	case SSH2_MSG_CHANNEL_CLOSE:
Lines 3688-3694 int Link Here
3688
channel_request_remote_forwarding(struct ssh *ssh, struct Forward *fwd)
3691
channel_request_remote_forwarding(struct ssh *ssh, struct Forward *fwd)
3689
{
3692
{
3690
	int r, success = 0, idx = -1;
3693
	int r, success = 0, idx = -1;
3691
	char *host_to_connect, *listen_host, *listen_path;
3694
	char *host_to_connect, *listen_host, *listen_path, *rdomain;
3692
	int port_to_connect, listen_port;
3695
	int port_to_connect, listen_port;
3693
3696
3694
	/* Send the forward request to the remote side. */
3697
	/* Send the forward request to the remote side. */
Lines 3718-3724 channel_request_remote_forwarding(struct ssh *ssh, struct Forward *fwd) Link Here
3718
	success = 1;
3721
	success = 1;
3719
	if (success) {
3722
	if (success) {
3720
		/* Record that connection to this host/port is permitted. */
3723
		/* Record that connection to this host/port is permitted. */
3721
		host_to_connect = listen_host = listen_path = NULL;
3724
		host_to_connect = listen_host = listen_path = rdomain = NULL;
3722
		port_to_connect = listen_port = 0;
3725
		port_to_connect = listen_port = 0;
3723
		if (fwd->connect_path != NULL) {
3726
		if (fwd->connect_path != NULL) {
3724
			host_to_connect = xstrdup(fwd->connect_path);
3727
			host_to_connect = xstrdup(fwd->connect_path);
Lines 3726-3731 channel_request_remote_forwarding(struct ssh *ssh, struct Forward *fwd) Link Here
3726
		} else {
3729
		} else {
3727
			host_to_connect = xstrdup(fwd->connect_host);
3730
			host_to_connect = xstrdup(fwd->connect_host);
3728
			port_to_connect = fwd->connect_port;
3731
			port_to_connect = fwd->connect_port;
3732
			if (fwd->rdomain != NULL)
3733
				rdomain = xstrdup(fwd->rdomain) ;
3729
		}
3734
		}
3730
		if (fwd->listen_path != NULL) {
3735
		if (fwd->listen_path != NULL) {
3731
			listen_path = xstrdup(fwd->listen_path);
3736
			listen_path = xstrdup(fwd->listen_path);
Lines 3737-3743 channel_request_remote_forwarding(struct ssh *ssh, struct Forward *fwd) Link Here
3737
		}
3742
		}
3738
		idx = fwd_perm_list_add(ssh, FWDPERM_USER,
3743
		idx = fwd_perm_list_add(ssh, FWDPERM_USER,
3739
		    host_to_connect, port_to_connect,
3744
		    host_to_connect, port_to_connect,
3740
		    listen_host, listen_path, listen_port, NULL);
3745
		    listen_host, listen_path, listen_port, NULL, rdomain);
3741
	}
3746
	}
3742
	return idx;
3747
	return idx;
3743
}
3748
}
Lines 3904-3910 channel_add_permitted_opens(struct ssh *ssh, char *host, int port) Link Here
3904
	struct ssh_channels *sc = ssh->chanctxt;
3909
	struct ssh_channels *sc = ssh->chanctxt;
3905
3910
3906
	debug("allow port forwarding to host %s port %d", host, port);
3911
	debug("allow port forwarding to host %s port %d", host, port);
3907
	fwd_perm_list_add(ssh, FWDPERM_USER, host, port, NULL, NULL, 0, NULL);
3912
	fwd_perm_list_add(ssh, FWDPERM_USER, host, port, NULL, NULL, 0, NULL,
3913
	    NULL);
3908
	sc->all_opens_permitted = 0;
3914
	sc->all_opens_permitted = 0;
3909
}
3915
}
3910
3916
Lines 3941-3954 channel_add_adm_permitted_opens(struct ssh *ssh, char *host, int port) Link Here
3941
{
3947
{
3942
	debug("config allows port forwarding to host %s port %d", host, port);
3948
	debug("config allows port forwarding to host %s port %d", host, port);
3943
	return fwd_perm_list_add(ssh, FWDPERM_ADMIN, host, port,
3949
	return fwd_perm_list_add(ssh, FWDPERM_ADMIN, host, port,
3944
	    NULL, NULL, 0, NULL);
3950
	    NULL, NULL, 0, NULL, NULL);
3945
}
3951
}
3946
3952
3947
void
3953
void
3948
channel_disable_adm_local_opens(struct ssh *ssh)
3954
channel_disable_adm_local_opens(struct ssh *ssh)
3949
{
3955
{
3950
	channel_clear_adm_permitted_opens(ssh);
3956
	channel_clear_adm_permitted_opens(ssh);
3951
	fwd_perm_list_add(ssh, FWDPERM_ADMIN, NULL, 0, NULL, NULL, 0, NULL);
3957
	fwd_perm_list_add(ssh, FWDPERM_ADMIN, NULL, 0, NULL, NULL, 0, NULL,
3958
	    NULL);
3952
}
3959
}
3953
3960
3954
void
3961
void
Lines 4023-4032 connect_next(struct channel_connect *cctx) Link Here
4023
		}
4030
		}
4024
		if (set_nonblock(sock) == -1)
4031
		if (set_nonblock(sock) == -1)
4025
			fatal("%s: set_nonblock(%d)", __func__, sock);
4032
			fatal("%s: set_nonblock(%d)", __func__, sock);
4033
		if (cctx->rdomain != NULL &&
4034
		    set_rdomain(sock, cctx->rdomain) == -1) {
4035
			close(sock);
4036
			continue;
4037
		}
4038
4026
		if (connect(sock, cctx->ai->ai_addr,
4039
		if (connect(sock, cctx->ai->ai_addr,
4027
		    cctx->ai->ai_addrlen) == -1 && errno != EINPROGRESS) {
4040
		    cctx->ai->ai_addrlen) == -1 && errno != EINPROGRESS) {
4028
			debug("connect_next: host %.100s ([%.100s]:%s): "
4041
			debug("connect_next: host %.100s ([%.100s]:%s%s%s): "
4029
			    "%.100s", cctx->host, ntop, strport,
4042
			    "%.100s", cctx->host, ntop, strport,
4043
			    cctx->rdomain == NULL ? "" : " rdomain ",
4044
			    cctx->rdomain == NULL ? "" : cctx->rdomain,
4030
			    strerror(errno));
4045
			    strerror(errno));
4031
			saved_errno = errno;
4046
			saved_errno = errno;
4032
			close(sock);
4047
			close(sock);
Lines 4035-4042 connect_next(struct channel_connect *cctx) Link Here
4035
		}
4050
		}
4036
		if (cctx->ai->ai_family != AF_UNIX)
4051
		if (cctx->ai->ai_family != AF_UNIX)
4037
			set_nodelay(sock);
4052
			set_nodelay(sock);
4038
		debug("connect_next: host %.100s ([%.100s]:%s) "
4053
		debug("connect_next: host %.100s ([%.100s]:%s%s%s) "
4039
		    "in progress, fd=%d", cctx->host, ntop, strport, sock);
4054
		    "in progress, fd=%d", cctx->host, ntop, strport,
4055
		    cctx->rdomain == NULL ? "" : " rdomain ",
4056
		    cctx->rdomain == NULL ? "" : cctx->rdomain, sock);
4040
		cctx->ai = cctx->ai->ai_next;
4057
		cctx->ai = cctx->ai->ai_next;
4041
		return sock;
4058
		return sock;
4042
	}
4059
	}
Lines 4047-4052 static void Link Here
4047
channel_connect_ctx_free(struct channel_connect *cctx)
4064
channel_connect_ctx_free(struct channel_connect *cctx)
4048
{
4065
{
4049
	free(cctx->host);
4066
	free(cctx->host);
4067
	free(cctx->rdomain);
4050
	if (cctx->aitop) {
4068
	if (cctx->aitop) {
4051
		if (cctx->aitop->ai_family == AF_UNIX)
4069
		if (cctx->aitop->ai_family == AF_UNIX)
4052
			free(cctx->aitop);
4070
			free(cctx->aitop);
Lines 4063-4069 channel_connect_ctx_free(struct channel_connect *cctx) Link Here
4063
static int
4081
static int
4064
connect_to_helper(struct ssh *ssh, const char *name, int port, int socktype,
4082
connect_to_helper(struct ssh *ssh, const char *name, int port, int socktype,
4065
    char *ctype, char *rname, struct channel_connect *cctx,
4083
    char *ctype, char *rname, struct channel_connect *cctx,
4066
    int *reason, const char **errmsg)
4084
    int *reason, const char **errmsg, const char *rdomain)
4067
{
4085
{
4068
	struct addrinfo hints;
4086
	struct addrinfo hints;
4069
	int gaierr;
4087
	int gaierr;
Lines 4115-4120 connect_to_helper(struct ssh *ssh, const char *name, int port, int socktype, Link Here
4115
	cctx->host = xstrdup(name);
4133
	cctx->host = xstrdup(name);
4116
	cctx->port = port;
4134
	cctx->port = port;
4117
	cctx->ai = cctx->aitop;
4135
	cctx->ai = cctx->aitop;
4136
	cctx->rdomain = rdomain ? xstrdup(rdomain) : NULL;
4118
4137
4119
	if ((sock = connect_next(cctx)) == -1) {
4138
	if ((sock = connect_next(cctx)) == -1) {
4120
		error("connect to %.100s port %d failed: %s",
4139
		error("connect to %.100s port %d failed: %s",
Lines 4128-4134 connect_to_helper(struct ssh *ssh, const char *name, int port, int socktype, Link Here
4128
/* Return CONNECTING channel to remote host:port or local socket path */
4147
/* Return CONNECTING channel to remote host:port or local socket path */
4129
static Channel *
4148
static Channel *
4130
connect_to(struct ssh *ssh, const char *host, int port,
4149
connect_to(struct ssh *ssh, const char *host, int port,
4131
    char *ctype, char *rname)
4150
    char *ctype, char *rname, const char *rdomain)
4132
{
4151
{
4133
	struct channel_connect cctx;
4152
	struct channel_connect cctx;
4134
	Channel *c;
4153
	Channel *c;
Lines 4136-4142 connect_to(struct ssh *ssh, const char *host, int port, Link Here
4136
4155
4137
	memset(&cctx, 0, sizeof(cctx));
4156
	memset(&cctx, 0, sizeof(cctx));
4138
	sock = connect_to_helper(ssh, host, port, SOCK_STREAM, ctype, rname,
4157
	sock = connect_to_helper(ssh, host, port, SOCK_STREAM, ctype, rname,
4139
	    &cctx, NULL, NULL);
4158
	    &cctx, NULL, NULL, rdomain);
4140
	if (sock == -1) {
4159
	if (sock == -1) {
4141
		channel_connect_ctx_free(&cctx);
4160
		channel_connect_ctx_free(&cctx);
4142
		return NULL;
4161
		return NULL;
Lines 4172-4178 channel_connect_by_listen_address(struct ssh *ssh, const char *listen_host, Link Here
4172
				    ctype, rname);
4191
				    ctype, rname);
4173
			return connect_to(ssh,
4192
			return connect_to(ssh,
4174
			    fp->host_to_connect, fp->port_to_connect,
4193
			    fp->host_to_connect, fp->port_to_connect,
4175
			    ctype, rname);
4194
			    ctype, rname, fp->rdomain);
4176
		}
4195
		}
4177
	}
4196
	}
4178
	error("WARNING: Server requests forwarding for unknown listen_port %d",
4197
	error("WARNING: Server requests forwarding for unknown listen_port %d",
Lines 4193-4199 channel_connect_by_listen_path(struct ssh *ssh, const char *path, Link Here
4193
		if (open_listen_match_streamlocal(fp, path)) {
4212
		if (open_listen_match_streamlocal(fp, path)) {
4194
			return connect_to(ssh,
4213
			return connect_to(ssh,
4195
			    fp->host_to_connect, fp->port_to_connect,
4214
			    fp->host_to_connect, fp->port_to_connect,
4196
			    ctype, rname);
4215
			    ctype, rname, NULL);
4197
		}
4216
		}
4198
	}
4217
	}
4199
	error("WARNING: Server requests forwarding for unknown path %.100s",
4218
	error("WARNING: Server requests forwarding for unknown path %.100s",
Lines 4245-4251 channel_connect_to_port(struct ssh *ssh, const char *host, u_short port, Link Here
4245
4264
4246
	memset(&cctx, 0, sizeof(cctx));
4265
	memset(&cctx, 0, sizeof(cctx));
4247
	sock = connect_to_helper(ssh, host, port, SOCK_STREAM, ctype, rname,
4266
	sock = connect_to_helper(ssh, host, port, SOCK_STREAM, ctype, rname,
4248
	    &cctx, reason, errmsg);
4267
	    &cctx, reason, errmsg, NULL);
4249
	if (sock == -1) {
4268
	if (sock == -1) {
4250
		channel_connect_ctx_free(&cctx);
4269
		channel_connect_ctx_free(&cctx);
4251
		return NULL;
4270
		return NULL;
Lines 4296-4302 channel_connect_to_path(struct ssh *ssh, const char *path, Link Here
4296
		    "but the request was denied.", path);
4315
		    "but the request was denied.", path);
4297
		return NULL;
4316
		return NULL;
4298
	}
4317
	}
4299
	return connect_to(ssh, path, PORT_STREAMLOCAL, ctype, rname);
4318
	return connect_to(ssh, path, PORT_STREAMLOCAL, ctype, rname, NULL);
4300
}
4319
}
4301
4320
4302
void
4321
void
Lines 4360-4366 rdynamic_connect_finish(struct ssh *ssh, Channel *c) Link Here
4360
4379
4361
	memset(&cctx, 0, sizeof(cctx));
4380
	memset(&cctx, 0, sizeof(cctx));
4362
	sock = connect_to_helper(ssh, c->path, c->host_port, SOCK_STREAM, NULL,
4381
	sock = connect_to_helper(ssh, c->path, c->host_port, SOCK_STREAM, NULL,
4363
	    NULL, &cctx, NULL, NULL);
4382
	    NULL, &cctx, NULL, NULL, NULL);
4364
	if (sock == -1)
4383
	if (sock == -1)
4365
		channel_connect_ctx_free(&cctx);
4384
		channel_connect_ctx_free(&cctx);
4366
	else {
4385
	else {
Lines 4433-4438 x11_create_display_inet(struct ssh *ssh, int x11_display_offset, Link Here
4433
				sock_set_v6only(sock);
4452
				sock_set_v6only(sock);
4434
			if (x11_use_localhost)
4453
			if (x11_use_localhost)
4435
				set_reuseaddr(sock);
4454
				set_reuseaddr(sock);
4455
4436
			if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
4456
			if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
4437
				debug2("%s: bind port %d: %.100s", __func__,
4457
				debug2("%s: bind port %d: %.100s", __func__,
4438
				    port, strerror(errno));
4458
				    port, strerror(errno));
(-)a/channels.h (+1 lines)
Lines 91-96 struct channel_connect { Link Here
91
	char *host;
91
	char *host;
92
	int port;
92
	int port;
93
	struct addrinfo *ai, *aitop;
93
	struct addrinfo *ai, *aitop;
94
	char *rdomain;
94
};
95
};
95
96
96
/* Callbacks for mux channels back into client-specific code */
97
/* Callbacks for mux channels back into client-specific code */
(-)a/ssh.1 (+10 lines)
Lines 591-596 Causes most warning and diagnostic messages to be suppressed. Link Here
591
.Xc
591
.Xc
592
.It Fl R Xo
592
.It Fl R Xo
593
.Sm off
593
.Sm off
594
.Ar bind_address : port : host : hostport : routing_domain
595
.Sm on
596
.Xc
597
.It Fl R Xo
598
.Sm off
594
.Oo Ar bind_address : Oc
599
.Oo Ar bind_address : Oc
595
.Ar port : local_socket
600
.Ar port : local_socket
596
.Sm on
601
.Sm on
Lines 661-666 When used together with Link Here
661
.Ic -O forward
666
.Ic -O forward
662
the allocated port will be printed to the standard output.
667
the allocated port will be printed to the standard output.
663
.Pp
668
.Pp
669
.Ar routing_domain
670
can also be specified, which makes the
671
.Ar bind_address
672
mandatory, to bind the local port in a specific Routing Domain.
673
.Pp
664
.It Fl r Ar routing_domain
674
.It Fl r Ar routing_domain
665
Specifies an explicit routing domain (BSD) or VRF (Linux - NOTE: requires cap_net_raw) that is applied to the connection.
675
Specifies an explicit routing domain (BSD) or VRF (Linux - NOTE: requires cap_net_raw) that is applied to the connection.
666
The user session will be bound to this
676
The user session will be bound to this
(-)a/ssh.c (-2 / +6 lines)
Lines 1682-1688 ssh_init_forwarding(struct ssh *ssh, char **ifname) Link Here
1682
	/* Initiate remote TCP/IP port forwardings. */
1682
	/* Initiate remote TCP/IP port forwardings. */
1683
	for (i = 0; i < options.num_remote_forwards; i++) {
1683
	for (i = 0; i < options.num_remote_forwards; i++) {
1684
		debug("Remote connections from %.200s:%d forwarded to "
1684
		debug("Remote connections from %.200s:%d forwarded to "
1685
		    "local address %.200s:%d",
1685
		    "local address %.200s:%d%s%s",
1686
		    (options.remote_forwards[i].listen_path != NULL) ?
1686
		    (options.remote_forwards[i].listen_path != NULL) ?
1687
		    options.remote_forwards[i].listen_path :
1687
		    options.remote_forwards[i].listen_path :
1688
		    (options.remote_forwards[i].listen_host == NULL) ?
1688
		    (options.remote_forwards[i].listen_host == NULL) ?
Lines 1691-1697 ssh_init_forwarding(struct ssh *ssh, char **ifname) Link Here
1691
		    (options.remote_forwards[i].connect_path != NULL) ?
1691
		    (options.remote_forwards[i].connect_path != NULL) ?
1692
		    options.remote_forwards[i].connect_path :
1692
		    options.remote_forwards[i].connect_path :
1693
		    options.remote_forwards[i].connect_host,
1693
		    options.remote_forwards[i].connect_host,
1694
		    options.remote_forwards[i].connect_port);
1694
		    options.remote_forwards[i].connect_port,
1695
		    options.remote_forwards[i].rdomain != NULL ?
1696
		    " rdomain " : "",
1697
		    options.remote_forwards[i].rdomain != NULL ?
1698
		    options.remote_forwards[i].rdomain : "");
1695
		options.remote_forwards[i].handle =
1699
		options.remote_forwards[i].handle =
1696
		    channel_request_remote_forwarding(ssh,
1700
		    channel_request_remote_forwarding(ssh,
1697
		    &options.remote_forwards[i]);
1701
		    &options.remote_forwards[i]);
(-)a/ssh_config.5 (-1 / +5 lines)
Lines 1347-1352 will only succeed if the server's Link Here
1347
.Cm GatewayPorts
1347
.Cm GatewayPorts
1348
option is enabled (see
1348
option is enabled (see
1349
.Xr sshd_config 5 ) .
1349
.Xr sshd_config 5 ) .
1350
.Pp
1351
.Ar bind_address : Ns Ar port : Ns Ar host : Ns Ar hostport : Ns Ar routing_domain
1352
can also be used, which makes the
1353
.Ar bind_address
1354
mandatory, to bind the local port in a specific Routing Domain.
1350
.It Cm RequestTTY
1355
.It Cm RequestTTY
1351
Specifies whether to request a pseudo-tty for the session.
1356
Specifies whether to request a pseudo-tty for the session.
1352
The argument may be one of:
1357
The argument may be one of:
1353
- 

Return to bug 2784