From: "cron2 (Code Review)" Date: Fri, 27 Dec 2024 17:37:29 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., gianmarco@...2726..., openvpn-devel@lists.sourceforge.net, frank@...2641..., a@...2181... Message-ID: <496ebeccb55cdfe13d169e37ecd63e3583c67d40-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="PlCzBR4Pcqk="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: override ai_family if 'local' numeric address was specified List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: its_Giaan Cc: plaisthos , flichtenheld , openvpn-devel --PlCzBR4Pcqk= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/76= 2?usp=3Demail ) Change subject: override ai_family if 'local' numeric address was specified ...................................................................... override ai_family if 'local' numeric address was specified 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 Signed-off-by: Gianmarco De Gregori Acked-by: Gert Doering Message-Id: <20241227161755.4010-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30= 257.html Signed-off-by: Gert Doering --- M src/openvpn/socket.c 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 01874fe..b895bd4 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -467,9 +467,8 @@ sig_info =3D &sigrec; } - /* try numeric ipv6 addr first */ + /* try numeric ip addr first */ CLEAR(hints); - hints.ai_family =3D ai_family; hints.ai_flags =3D AI_NUMERICHOST; if (flags & GETADDR_PASSIVE) @@ -486,6 +485,13 @@ hints.ai_socktype =3D SOCK_STREAM; } + /* if hostname is not set, we want to bind to 'ANY', with + * the correct address family - v4-only or v6/v6-dual-stack */ + if (!hostname) + { + hints.ai_family =3D ai_family; + } + status =3D getaddrinfo(hostname, servname, &hints, res); if (status !=3D 0) /* parse as numeric address failed? */ @@ -497,6 +503,10 @@ const char *fmt; int level =3D 0; + /* this is not a numeric IP, therefore force resolution using the + * provided ai_family */ + hints.ai_family =3D ai_family; + if (hostname && (flags & GETADDR_RANDOMIZE)) { hostname =3D hostname_randomize(hostname, &gc); @@ -1690,6 +1700,10 @@ sock->local_host, sock->local_port, gai_strerror(status)); } + + /* the resolved 'local entry' might have a different family than w= hat + * was globally configured */ + sock->info.af =3D sock->info.lsa->bind_local->ai_family; } gc_free(&gc); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/762?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ie2471e6b2d6974e70423b09918ad1c2136253754 Gerrit-Change-Number: 762 Gerrit-PatchSet: 10 Gerrit-Owner: its_Giaan Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-CC: ordex Gerrit-MessageType: merged --PlCzBR4Pcqk= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

override ai_family if 'local' numeric =
address was specified

This change ensures that when a numeric IP add= ress is specified
as argument to a 'local' directive, its ai_fam= ily overrides
the one extracted from the 'proto' config option.<= br>
Change-Id: Ie2471e6b2d6974e70423b09918ad1c2136253754
Signed-off-b= y: Antonio Quartulli <a@...2181...>
Signed-off-by: Gianmarco De Gr= egori <gianmarco@...2726...>
Acked-by: Gert Doering <gert@...1711...= 96...>
Message-Id: <20241227161755.4010-1-gert@...1296...>
U= RL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg302= 57.html
Signed-off-by: Gert Doering <gert@...1296...>
---
M = src/openvpn/socket.c
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index 01874fe..b895bd4 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -467,9 +467,8 = @@
sig_info =3D &sigrec;
= }

- = /* try numeric ipv6 addr first */
+ /* try numeric ip addr first */
CL= EAR(hints);
- hints.= ai_family =3D ai_family;
hints.ai_flags =3D AI_NUMERIC= HOST;

if (flags & GETADDR_PASSIV= E)
@@ -486,6 +485,13 @@
hints.ai_s= ocktype =3D SOCK_STREAM;
}
+ /* if hostname is not set= , we want to bind to 'ANY', with
+ * the correct address family - v4-only or v6/v6-d= ual-stack */
+ if = (!hostname)
+ {
+ hints.ai_famil= y =3D ai_family;
+ = }
+
= status =3D getaddrinfo(hostname, servname, &hints, res);
if (status !=3D 0) /* parse as numeric addres= s failed? */
@@ -497,6 +503,10 @@
= const char *fmt;
int level =3D 0;
=
+ /* this is= not a numeric IP, therefore force resolution using the
+ * provided ai_family */=
+ hints.ai_family = =3D ai_family;
+
if (hostname && (flags & GETADDR_RANDOMIZE= ))
{
hostname =3D hos= tname_randomize(hostname, &gc);
@@ -1690,6 +1700,10 @@<= /span>
sock->local_host, sock->local_port,<= /span>
gai_strerror(status));
= }
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ /* the resolved 'lo= cal entry' might have a different family than what

+ * was globally configured */
+ sock->info.= af =3D sock->info.lsa->bind_local->ai_family;
= }

gc_free(&gc);

To view, visit change 762. To unsubscribe, or for help writ= ing mail filters, visit sett= ings.

<= link itemprop=3D"url" href=3D"http://gerrit.openvpn.net/c/openvpn/+/762?usp= =3Demail"/>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie2471e6b2d6974e70423b09918a= d1c2136253754
Gerrit-Change-Number: 762
Gerrit-PatchSet: 10
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-CC: ordex <a@...2181...>
Gerrit-MessageType: merged
--PlCzBR4Pcqk=--