From: "plaisthos (Code Review)" Date: Mon, 15 Sep 2025 17:39:07 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="8K9RfWI7ovg="; 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: openvpn-devel --8K9RfWI7ovg= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1191?usp=3Demail to review the following change. 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(+), 11 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/91/1191/1 diff --git a/src/openvpn/route.c b/src/openvpn/route.c index e504485..8be3f65 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -710,25 +710,23 @@ return ret; } -/* check whether an IPv6 host address is covered by a given route_ipv6 +/** + * 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; - 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 +737,9 @@ return true; } - mask =3D 0xff << (8 - bits); + unsigned 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 +828,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: 1 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --8K9RfWI7ovg= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos would like flichtenheld to review this change.

V= iew Change

Allow route_ipv6_match_host to be used outside of route.c
Also adjust style a bit to C99

Change-Id: Ief1495b52ea81cac35d7= 8e40264372d3869423f1
Signed-off-by: Arne Schwabe <arne@...1227...>=
---
M src/openvpn/route.c
M src/openvpn/route.h
2 files change= d, 23 insertions(+), 11 deletions(-)

git pull ssh://gerrit.openvp=
n.net:29418/openvpn refs/changes/91/1191/1
diff --git a/src/openvpn=
/route.c b/src/openvpn/route.c
index e504485..8be3f65 10064= 4
--- a/src/openvpn/route.c
+++ b/src/openv= pn/route.c
@@ -710,25 +710,23 @@
retur= n ret;
}

-/* check whether an IPv6 host address is covered by a= given route_ipv6
+/*= *
+ * check whether a= n IPv6 host address is covered by a given route_ipv6
* (n= ot the most beautiful implementation in the world, but portable and<= br> * "good enough")
*/
-static bool
-route_ipv6_match_host(const struct route_ipv6 *r= 6, const struct in6_addr *host)
+bool
+rou= te_ipv6_match_host(const struct in6_addr *network, unsigned int bits, const= struct in6_addr *host)
{
- unsigned int bits =3D r6->netbits;
- int i;
- unsigned int mask;
-
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_a= ddr[i])
+ if (= network->s6_addr[i] !=3D host->s6_addr[i])
{=
return false;
}
@@ -739,9 +737,9 @@
return true;
}

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

+ = if ((network->s6_addr[i] & mask) =3D=3D (host->s6_addr[i] & m= ask))
{
return true; }
@@ -830,7 +828,8 @@
= * avoiding routing loops, so ignore this part and let
<= span> * need_remote_ipv6_route always evaluate to false

*/
- if (remote_host_ipv6 && route_ipv6_mat= ch_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,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,1= 7 @@
return rl && BOOL_CAST(rl->iflags &= ; RL_DID_REDIRECT_DEFAULT_GATEWAY);
}

+
+/**
+ * check whether an IPv6 host address is covered by a giv= en route_ipv6
+ * @pa= ram network the network address
+ * @param bits the network mask
+ * @param host the host address to be checked if it= is contained by the network
+ *
+ * @retu= rn 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, unsigned int bits, const struct in6_addr *host);
+
#endif /* ifndef RO= UTE_H */

To view, visit change 1191. To uns= ubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ief1495b52ea81cac35d78e40264= 372d3869423f1
Gerrit-Change-Number: 1191
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--8K9RfWI7ovg=--