|
Lines 2438-2444
channel_set_af(int af)
Link Here
|
| 2438 |
} |
2438 |
} |
| 2439 |
|
2439 |
|
| 2440 |
static int |
2440 |
static int |
| 2441 |
channel_setup_fwd_listener(int type, const char *listen_addr, u_short listen_port, |
2441 |
channel_setup_fwd_listener(int type, const char *listen_addr, |
|
|
2442 |
u_short listen_port, int *allocated_listen_port, |
| 2442 |
const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
2443 |
const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
| 2443 |
{ |
2444 |
{ |
| 2444 |
Channel *c; |
2445 |
Channel *c; |
|
Lines 2446-2451
channel_setup_fwd_listener(int type, con
Link Here
|
| 2446 |
struct addrinfo hints, *ai, *aitop; |
2447 |
struct addrinfo hints, *ai, *aitop; |
| 2447 |
const char *host, *addr; |
2448 |
const char *host, *addr; |
| 2448 |
char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
2449 |
char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
|
|
2450 |
in_port_t *lport_p; |
| 2449 |
|
2451 |
|
| 2450 |
host = (type == SSH_CHANNEL_RPORT_LISTENER) ? |
2452 |
host = (type == SSH_CHANNEL_RPORT_LISTENER) ? |
| 2451 |
listen_addr : host_to_connect; |
2453 |
listen_addr : host_to_connect; |
|
Lines 2514-2523
channel_setup_fwd_listener(int type, con
Link Here
|
| 2514 |
} |
2516 |
} |
| 2515 |
return 0; |
2517 |
return 0; |
| 2516 |
} |
2518 |
} |
| 2517 |
|
2519 |
if (allocated_listen_port != NULL) |
|
|
2520 |
*allocated_listen_port = 0; |
| 2518 |
for (ai = aitop; ai; ai = ai->ai_next) { |
2521 |
for (ai = aitop; ai; ai = ai->ai_next) { |
| 2519 |
if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) |
2522 |
switch (ai->ai_family) { |
|
|
2523 |
case AF_INET: |
| 2524 |
lport_p = &((struct sockaddr_in *)ai->ai_addr)-> |
| 2525 |
sin_port; |
| 2526 |
break; |
| 2527 |
case AF_INET6: |
| 2528 |
lport_p = &((struct sockaddr_in6 *)ai->ai_addr)-> |
| 2529 |
sin6_port; |
| 2530 |
break; |
| 2531 |
default: |
| 2520 |
continue; |
2532 |
continue; |
|
|
2533 |
} |
| 2534 |
/* |
| 2535 |
* If allocating a port for -R forwards, then use the |
| 2536 |
* same port for all address families. |
| 2537 |
*/ |
| 2538 |
if (type == SSH_CHANNEL_RPORT_LISTENER && listen_port == 0 && |
| 2539 |
allocated_listen_port != NULL && *allocated_listen_port > 0) |
| 2540 |
*lport_p = htons(*allocated_listen_port); |
| 2541 |
|
| 2521 |
if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop, sizeof(ntop), |
2542 |
if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop, sizeof(ntop), |
| 2522 |
strport, sizeof(strport), NI_NUMERICHOST|NI_NUMERICSERV) != 0) { |
2543 |
strport, sizeof(strport), NI_NUMERICHOST|NI_NUMERICSERV) != 0) { |
| 2523 |
error("channel_setup_fwd_listener: getnameinfo failed"); |
2544 |
error("channel_setup_fwd_listener: getnameinfo failed"); |
|
Lines 2533-2539
channel_setup_fwd_listener(int type, con
Link Here
|
| 2533 |
|
2554 |
|
| 2534 |
channel_set_reuseaddr(sock); |
2555 |
channel_set_reuseaddr(sock); |
| 2535 |
|
2556 |
|
| 2536 |
debug("Local forwarding listening on %s port %s.", ntop, strport); |
2557 |
debug("Local forwarding listening on %s port %s.", |
|
|
2558 |
ntop, strport); |
| 2537 |
|
2559 |
|
| 2538 |
/* Bind the socket to the address. */ |
2560 |
/* Bind the socket to the address. */ |
| 2539 |
if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) { |
2561 |
if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) { |
|
Lines 2548-2553
channel_setup_fwd_listener(int type, con
Link Here
|
| 2548 |
close(sock); |
2570 |
close(sock); |
| 2549 |
continue; |
2571 |
continue; |
| 2550 |
} |
2572 |
} |
|
|
2573 |
|
| 2574 |
/* |
| 2575 |
* listen_port == 0 requests a dynamically allocated port - |
| 2576 |
* record what we got. |
| 2577 |
*/ |
| 2578 |
if (type == SSH_CHANNEL_RPORT_LISTENER && listen_port == 0 && |
| 2579 |
allocated_listen_port != NULL && |
| 2580 |
*allocated_listen_port == 0) { |
| 2581 |
*allocated_listen_port = get_sock_port(sock, 1); |
| 2582 |
debug("Allocated listen port %d", |
| 2583 |
*allocated_listen_port); |
| 2584 |
} |
| 2585 |
|
| 2551 |
/* Allocate a channel number for the socket. */ |
2586 |
/* Allocate a channel number for the socket. */ |
| 2552 |
c = channel_new("port listener", type, sock, sock, -1, |
2587 |
c = channel_new("port listener", type, sock, sock, -1, |
| 2553 |
CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT, |
2588 |
CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT, |
|
Lines 2590-2606
channel_setup_local_fwd_listener(const c
Link Here
|
| 2590 |
const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
2625 |
const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
| 2591 |
{ |
2626 |
{ |
| 2592 |
return channel_setup_fwd_listener(SSH_CHANNEL_PORT_LISTENER, |
2627 |
return channel_setup_fwd_listener(SSH_CHANNEL_PORT_LISTENER, |
| 2593 |
listen_host, listen_port, host_to_connect, port_to_connect, |
2628 |
listen_host, listen_port, NULL, host_to_connect, port_to_connect, |
| 2594 |
gateway_ports); |
2629 |
gateway_ports); |
| 2595 |
} |
2630 |
} |
| 2596 |
|
2631 |
|
| 2597 |
/* protocol v2 remote port fwd, used by sshd */ |
2632 |
/* protocol v2 remote port fwd, used by sshd */ |
| 2598 |
int |
2633 |
int |
| 2599 |
channel_setup_remote_fwd_listener(const char *listen_address, |
2634 |
channel_setup_remote_fwd_listener(const char *listen_address, |
| 2600 |
u_short listen_port, int gateway_ports) |
2635 |
u_short listen_port, int *allocated_listen_port, int gateway_ports) |
| 2601 |
{ |
2636 |
{ |
| 2602 |
return channel_setup_fwd_listener(SSH_CHANNEL_RPORT_LISTENER, |
2637 |
return channel_setup_fwd_listener(SSH_CHANNEL_RPORT_LISTENER, |
| 2603 |
listen_address, listen_port, NULL, 0, gateway_ports); |
2638 |
listen_address, listen_port, allocated_listen_port, |
|
|
2639 |
NULL, 0, gateway_ports); |
| 2604 |
} |
2640 |
} |
| 2605 |
|
2641 |
|
| 2606 |
/* |
2642 |
/* |