Skip to content

Commit

Permalink
Support IPv6 towards port-share proxy receiver
Browse files Browse the repository at this point in the history
While port-share already supports IPv6 connections from clients, it only
supported IPv4 connections towards the proxy receiver. The used
common/shared OpenVPN machinery is already IPv6-ready, so all needed was
to use properly-sized `sockaddr` structs and removing hardcoded IPv4
restrictions.

Signed-off-by: Corubba Smith <[email protected]>
Acked-by: Gert Doering <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg30115.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
corubba authored and cron2 committed Dec 25, 2024
1 parent 5aa7ce4 commit 993449a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/openvpn/ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ proxy_connection_io_requeue(struct proxy_connection *pc, const int rwflags_new,
static bool
proxy_entry_new(struct proxy_connection **list,
struct event_set *es,
const struct sockaddr_in server_addr,
const struct openvpn_sockaddr server_addr,
const socket_descriptor_t sd_client,
struct buffer *initial_data,
const char *journal_dir)
Expand All @@ -425,12 +425,12 @@ proxy_entry_new(struct proxy_connection **list,
struct proxy_connection *cp;

/* connect to port share server */
if ((sd_server = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
if ((sd_server = socket(server_addr.addr.sa.sa_family, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
msg(M_WARN|M_ERRNO, "PORT SHARE PROXY: cannot create socket");
return false;
}
status = openvpn_connect(sd_server, (const struct sockaddr *) &server_addr, 5, NULL);
status = openvpn_connect(sd_server, &server_addr.addr.sa, 5, NULL);
if (status)
{
msg(M_WARN, "PORT SHARE PROXY: connect to port-share server failed");
Expand Down Expand Up @@ -492,7 +492,7 @@ static bool
control_message_from_parent(const socket_descriptor_t sd_control,
struct proxy_connection **list,
struct event_set *es,
const struct sockaddr_in server_addr,
const struct openvpn_sockaddr server_addr,
const int max_initial_buf,
const char *journal_dir)
{
Expand Down Expand Up @@ -740,7 +740,7 @@ proxy_connection_io_dispatch(struct proxy_connection *pc,
* This is the main function for the port share proxy background process.
*/
static void
port_share_proxy(const struct sockaddr_in hostaddr,
port_share_proxy(const struct openvpn_sockaddr hostaddr,
const socket_descriptor_t sd_control,
const int max_initial_buf,
const char *journal_dir)
Expand Down Expand Up @@ -822,7 +822,7 @@ port_share_open(const char *host,
{
pid_t pid;
socket_descriptor_t fd[2];
struct sockaddr_in hostaddr;
struct openvpn_sockaddr hostaddr;
struct port_share *ps;
int status;
struct addrinfo *ai;
Expand All @@ -836,11 +836,20 @@ port_share_open(const char *host,
*/

status = openvpn_getaddrinfo(GETADDR_RESOLVE|GETADDR_FATAL,
host, port, 0, NULL, AF_INET, &ai);
host, port, 0, NULL, AF_UNSPEC, &ai);
ASSERT(status==0);
hostaddr = *((struct sockaddr_in *) ai->ai_addr);
ASSERT(sizeof(hostaddr.addr) >= ai->ai_addrlen);
memcpy(&hostaddr.addr.sa, ai->ai_addr, ai->ai_addrlen);
freeaddrinfo(ai);

if (msg_test(D_PS_PROXY_DEBUG))
{
struct gc_arena gc = gc_new();
dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: receiver will be %s",
print_openvpn_sockaddr(&hostaddr, &gc));
gc_free(&gc);
}

/*
* Make a socket for foreground and background processes
* to communicate.
Expand Down

0 comments on commit 993449a

Please sign in to comment.