From: "plaisthos (Code Review)" Date: Tue, 16 Sep 2025 14:35:42 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., heiko@...515..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <8a587c6c13fe6454dcec65c97705259e287a777f-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="5/g3NlyiVbg="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Allow route_ipv6_match_host to be used outside of route.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: d12fk , openvpn-devel --5/g3NlyiVbg= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: d12fk, flichtenheld. Hello flichtenheld, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1191?usp=3Demail to look at the new patch set (#3). Change subject: Allow route_ipv6_match_host to be used outside of route.c ...................................................................... Allow route_ipv6_match_host to be used outside of route.c Also adjust style a bit to C99 Change-Id: Ief1495b52ea81cac35d78e40264372d3869423f1 Signed-off-by: Arne Schwabe --- M src/openvpn/route.c M src/openvpn/route.h 2 files changed, 23 insertions(+), 14 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/91/1191/3 diff --git a/src/openvpn/route.c b/src/openvpn/route.c index e504485..7eb7a1b 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -710,25 +710,20 @@ return ret; } -/* check whether an IPv6 host address is covered by a given route_ipv6 - * (not the most beautiful implementation in the world, but portable and - * "good enough") - */ -static bool -route_ipv6_match_host(const struct route_ipv6 *r6, const struct in6_addr *= host) +bool +route_ipv6_match_host(const struct in6_addr *network, unsigned int bits, c= onst struct in6_addr *host) { - unsigned int bits =3D r6->netbits; - int i; - unsigned int mask; - + /* (not the most beautiful implementation in the world, but portable a= nd + * "good enough") */ if (bits > 128) { return false; } + int i =3D 0; for (i =3D 0; bits >=3D 8; i++, bits -=3D 8) { - if (r6->network.s6_addr[i] !=3D host->s6_addr[i]) + if (network->s6_addr[i] !=3D host->s6_addr[i]) { return false; } @@ -739,9 +734,9 @@ return true; } - mask =3D 0xff << (8 - bits); + unsigned int mask =3D 0xff << (8 - bits); - if ((r6->network.s6_addr[i] & mask) =3D=3D (host->s6_addr[i] & mask)) + if ((network->s6_addr[i] & mask) =3D=3D (host->s6_addr[i] & mask)) { return true; } @@ -830,7 +825,8 @@ * avoiding routing loops, so ignore this part and let * need_remote_ipv6_route always evaluate to false */ - if (remote_host_ipv6 && route_ipv6_match_host(r6, remote_h= ost_ipv6)) + if (remote_host_ipv6 + && route_ipv6_match_host(&r6->network, r6->netbits, re= mote_host_ipv6)) { need_remote_ipv6_route =3D true; msg(D_ROUTE, diff --git a/src/openvpn/route.h b/src/openvpn/route.h index 9b6a47e..54abe24 100644 --- a/src/openvpn/route.h +++ b/src/openvpn/route.h @@ -426,4 +426,17 @@ return rl && BOOL_CAST(rl->iflags & RL_DID_REDIRECT_DEFAULT_GATEWAY); } + +/** + * check whether an IPv6 host address is covered by a given route_ipv6 + * @param network the network address + * @param bits the network mask + * @param host the host address to be checked if it is contained by the ne= twork + * + * @return true if the host address is covered by the network with the giv= en + * network mask by bits + */ +bool +route_ipv6_match_host(const struct in6_addr *network, unsigned int bits, c= onst struct in6_addr *host); + #endif /* ifndef ROUTE_H */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1191?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: Ief1495b52ea81cac35d78e40264372d3869423f1 Gerrit-Change-Number: 1191 Gerrit-PatchSet: 3 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: d12fk Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-Attention: d12fk Gerrit-MessageType: newpatchset --5/g3NlyiVbg= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: d12fk, flichtenheld.

plaisthos uploaded patch set #3 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1191?usp=3Demail">View Chan= ge

Allow route_ipv6_match_host to be used outside of route.c

Als= o adjust style a bit to C99

Change-Id: Ief1495b52ea81cac35d78e402643= 72d3869423f1
Signed-off-by: Arne Schwabe <arne@...1227...>
---<= br>M src/openvpn/route.c
M src/openvpn/route.h
2 files changed, 23 in= sertions(+), 14 deletions(-)

git pull ssh://gerrit.openvpn.net:29=
418/openvpn refs/changes/91/1191/3
diff --git a/src/openvpn/route.c=
 b/src/openvpn/route.c
index e504485..7eb7a1b 100644=
--- a/src/openvpn/route.c
+++ b/src/openvpn/route= .c
@@ -710,25 +710,20 @@
return ret;
}

-/* check whether an IPv6 host address is covered by a given r= oute_ipv6
- * (not the = most beautiful implementation in the world, but portable and
- * "good enough")
- */
-static bool
-route_ipv6_match_host(const struct route_ipv6 *r6, const s= truct in6_addr *host)
+bool
+route_ipv6_ma= tch_host(const struct in6_addr *network, unsigned int bits, const struct in= 6_addr *host)
{
- unsigned int bits =3D r6->netbits;
- int i;
- unsigned int mask;
-
+ * "go= od enough") */
if (bits > 128)
{
return false;
}


+ int= i =3D 0;
for (i =3D 0; bits >=3D 8; i++, bits -=3D= 8)
{
- if (r6->network.s6_addr[i] !=3D host->s6_addr[i])=
+ if (network->s6= _addr[i] !=3D host->s6_addr[i])
{
return false;
}
@@= -739,9 +734,9 @@
return true;
= }

-= mask =3D 0xff << (8 - bits);
+ unsigned int mask =3D 0xff << (8 - bits);

- if (= (r6->network.s6_addr[i] & mask) =3D=3D (host->s6_addr[i] & ma= sk))
+ if ((networ= k->s6_addr[i] & mask) =3D=3D (host->s6_addr[i] & mask))
{
return true;
= }
@@ -830,7 +825,8 @@
*= avoiding routing loops, so ignore this part and let
= * need_remote_ipv6_route always evaluate to false
*/

- if (remote_host_ipv6 && route_ipv6_match_host(r6,= remote_host_ipv6))
+= if (remote_host_ipv6
+ && route_ipv6_match_host(&= r6->network, r6->netbits, remote_host_ipv6))
= {
need_remote_ipv6_route =3D = true;
msg(D_ROUTE,
dif= f --git a/src/openvpn/route.h b/src/openvpn/route.h
index 9= b6a47e..54abe24 100644
--- a/src/openvpn/route.h
= +++ b/src/openvpn/route.h
@@ -426,4 +426,17 @@=
return rl && BOOL_CAST(rl->iflags & RL_DID_RE= DIRECT_DEFAULT_GATEWAY);
}

+

+/**
+ * check whether an IPv6 host address is covered by a given route_ip= v6
+ * @param network= the network address
= + * @param bits the network mask
+ * @param host the host address to be checked if it is contain= ed by the network
+ *=
+ * @return true if = the host address is covered by the network with the given
+ * network mask by bits
+ */
+bool
+route_ipv6_match_host(const struct in6_addr *network, un= signed int bits, const struct in6_addr *host);
+
#endif /* ifndef ROUTE_H */

To view, visit change 1191. To unsubscribe, o= r for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ief1495b52ea81cac35d78e40264= 372d3869423f1
Gerrit-Change-Number: 1191
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: d12fk <heiko@...515...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: d12fk <heiko@...515...>= ;
Gerrit-MessageType: newpatchset
--5/g3NlyiVbg=--