|
Lines 2415-2421
channel_set_af(int af)
Link Here
|
| 2415 |
} |
2415 |
} |
| 2416 |
|
2416 |
|
| 2417 |
static int |
2417 |
static int |
| 2418 |
channel_setup_fwd_listener(int type, const char *listen_addr, u_short listen_port, |
2418 |
channel_setup_fwd_listener(int type, const char *listen_addr, |
|
|
2419 |
u_short listen_port, int *allocated_listen_port, |
| 2419 |
const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
2420 |
const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
| 2420 |
{ |
2421 |
{ |
| 2421 |
Channel *c; |
2422 |
Channel *c; |
|
Lines 2423-2428
channel_setup_fwd_listener(int type, con
Link Here
|
| 2423 |
struct addrinfo hints, *ai, *aitop; |
2424 |
struct addrinfo hints, *ai, *aitop; |
| 2424 |
const char *host, *addr; |
2425 |
const char *host, *addr; |
| 2425 |
char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
2426 |
char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
|
|
2427 |
in_port_t *lport_p; |
| 2426 |
|
2428 |
|
| 2427 |
host = (type == SSH_CHANNEL_RPORT_LISTENER) ? |
2429 |
host = (type == SSH_CHANNEL_RPORT_LISTENER) ? |
| 2428 |
listen_addr : host_to_connect; |
2430 |
listen_addr : host_to_connect; |
|
Lines 2491-2500
channel_setup_fwd_listener(int type, con
Link Here
|
| 2491 |
} |
2493 |
} |
| 2492 |
return 0; |
2494 |
return 0; |
| 2493 |
} |
2495 |
} |
| 2494 |
|
2496 |
if (allocated_listen_port != NULL) |
|
|
2497 |
*allocated_listen_port = 0; |
| 2495 |
for (ai = aitop; ai; ai = ai->ai_next) { |
2498 |
for (ai = aitop; ai; ai = ai->ai_next) { |
| 2496 |
if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) |
2499 |
switch (ai->ai_family) { |
|
|
2500 |
case AF_INET: |
| 2501 |
lport_p = &((struct sockaddr_in *)ai->ai_addr)-> |
| 2502 |
sin_port; |
| 2503 |
break; |
| 2504 |
case AF_INET6: |
| 2505 |
lport_p = &((struct sockaddr_in6 *)ai->ai_addr)-> |
| 2506 |
sin6_port; |
| 2507 |
break; |
| 2508 |
default: |
| 2497 |
continue; |
2509 |
continue; |
|
|
2510 |
} |
| 2511 |
/* |
| 2512 |
* If allocating a port for -R forwards, then use the |
| 2513 |
* same port for all address families. |
| 2514 |
*/ |
| 2515 |
if (type == SSH_CHANNEL_RPORT_LISTENER && listen_port == 0 && |
| 2516 |
allocated_listen_port != NULL && *allocated_listen_port > 0) |
| 2517 |
*lport_p = htons(*allocated_listen_port); |
| 2518 |
|
| 2498 |
if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop, sizeof(ntop), |
2519 |
if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop, sizeof(ntop), |
| 2499 |
strport, sizeof(strport), NI_NUMERICHOST|NI_NUMERICSERV) != 0) { |
2520 |
strport, sizeof(strport), NI_NUMERICHOST|NI_NUMERICSERV) != 0) { |
| 2500 |
error("channel_setup_fwd_listener: getnameinfo failed"); |
2521 |
error("channel_setup_fwd_listener: getnameinfo failed"); |
|
Lines 2510-2516
channel_setup_fwd_listener(int type, con
Link Here
|
| 2510 |
|
2531 |
|
| 2511 |
channel_set_reuseaddr(sock); |
2532 |
channel_set_reuseaddr(sock); |
| 2512 |
|
2533 |
|
| 2513 |
debug("Local forwarding listening on %s port %s.", ntop, strport); |
2534 |
debug("Local forwarding listening on %s port %s.", |
|
|
2535 |
ntop, strport); |
| 2514 |
|
2536 |
|
| 2515 |
/* Bind the socket to the address. */ |
2537 |
/* Bind the socket to the address. */ |
| 2516 |
if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) { |
2538 |
if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) { |
|
Lines 2525-2530
channel_setup_fwd_listener(int type, con
Link Here
|
| 2525 |
close(sock); |
2547 |
close(sock); |
| 2526 |
continue; |
2548 |
continue; |
| 2527 |
} |
2549 |
} |
|
|
2550 |
|
| 2551 |
/* |
| 2552 |
* listen_port == 0 requests a dynamically allocated port - |
| 2553 |
* record what we got. |
| 2554 |
*/ |
| 2555 |
if (type == SSH_CHANNEL_RPORT_LISTENER && listen_port == 0 && |
| 2556 |
allocated_listen_port != NULL && |
| 2557 |
*allocated_listen_port == 0) { |
| 2558 |
*allocated_listen_port = get_sock_port(sock, 1); |
| 2559 |
debug("Allocated listen port %d", |
| 2560 |
*allocated_listen_port); |
| 2561 |
} |
| 2562 |
|
| 2528 |
/* Allocate a channel number for the socket. */ |
2563 |
/* Allocate a channel number for the socket. */ |
| 2529 |
c = channel_new("port listener", type, sock, sock, -1, |
2564 |
c = channel_new("port listener", type, sock, sock, -1, |
| 2530 |
CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT, |
2565 |
CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT, |
|
Lines 2568-2584
channel_setup_local_fwd_listener(const c
Link Here
|
| 2568 |
const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
2603 |
const char *host_to_connect, u_short port_to_connect, int gateway_ports) |
| 2569 |
{ |
2604 |
{ |
| 2570 |
return channel_setup_fwd_listener(SSH_CHANNEL_PORT_LISTENER, |
2605 |
return channel_setup_fwd_listener(SSH_CHANNEL_PORT_LISTENER, |
| 2571 |
listen_host, listen_port, host_to_connect, port_to_connect, |
2606 |
listen_host, listen_port, NULL, host_to_connect, port_to_connect, |
| 2572 |
gateway_ports); |
2607 |
gateway_ports); |
| 2573 |
} |
2608 |
} |
| 2574 |
|
2609 |
|
| 2575 |
/* protocol v2 remote port fwd, used by sshd */ |
2610 |
/* protocol v2 remote port fwd, used by sshd */ |
| 2576 |
int |
2611 |
int |
| 2577 |
channel_setup_remote_fwd_listener(const char *listen_address, |
2612 |
channel_setup_remote_fwd_listener(const char *listen_address, |
| 2578 |
u_short listen_port, int gateway_ports) |
2613 |
u_short listen_port, int *allocated_listen_port, int gateway_ports) |
| 2579 |
{ |
2614 |
{ |
| 2580 |
return channel_setup_fwd_listener(SSH_CHANNEL_RPORT_LISTENER, |
2615 |
return channel_setup_fwd_listener(SSH_CHANNEL_RPORT_LISTENER, |
| 2581 |
listen_address, listen_port, NULL, 0, gateway_ports); |
2616 |
listen_address, listen_port, allocated_listen_port, |
|
|
2617 |
NULL, 0, gateway_ports); |
| 2582 |
} |
2618 |
} |
| 2583 |
|
2619 |
|
| 2584 |
/* |
2620 |
/* |