Skip to content

Commit

Permalink
override ai_family if 'local' numeric address was specified
Browse files Browse the repository at this point in the history
This change ensures that when a numeric IP address is specified
as argument to a 'local' directive, its ai_family overrides
the one extracted from the 'proto' config option.

Change-Id: Ie2471e6b2d6974e70423b09918ad1c2136253754
Signed-off-by: Antonio Quartulli <[email protected]>
Signed-off-by: Gianmarco De Gregori <[email protected]>
Acked-by: Gert Doering <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg30188.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
ordex authored and cron2 committed Dec 24, 2024
1 parent f0c26b0 commit f190721
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/openvpn/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,8 @@ openvpn_getaddrinfo(unsigned int flags,
sig_info = &sigrec;
}

/* try numeric ipv6 addr first */
/* try numeric ip addr first */
CLEAR(hints);
hints.ai_family = ai_family;
hints.ai_flags = AI_NUMERICHOST;

if (flags & GETADDR_PASSIVE)
Expand Down Expand Up @@ -497,6 +496,10 @@ openvpn_getaddrinfo(unsigned int flags,
const char *fmt;
int level = 0;

/* this is not a numeric IP, therefore force resolution using the
* provided ai_family */
hints.ai_family = ai_family;

if (hostname && (flags & GETADDR_RANDOMIZE))
{
hostname = hostname_randomize(hostname, &gc);
Expand Down Expand Up @@ -1690,6 +1693,10 @@ resolve_bind_local(struct link_socket *sock, const sa_family_t af)
sock->local_host, sock->local_port,
gai_strerror(status));
}

/* the resolved 'local entry' might have a different family than what
* was globally configured */
sock->info.af = sock->info.lsa->bind_local->ai_family;
}

gc_free(&gc);
Expand Down

0 comments on commit f190721

Please sign in to comment.