From: "cron2 (Code Review)" Date: Fri, 5 Sep 2025 17:55:31 +0000 References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., ralf@...2726... Message-ID: <10f37f463ab311b896662ceb5966c233b8a9e480-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="OUQfPoy/5c4="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[release/2.6]: dco: backport OS-independent part of peer float support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel , ralf_lici --OUQfPoy/5c4= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos, ralf_lici. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1169?usp=3Demail to review the following change. Change subject: dco: backport OS-independent part of peer float support ...................................................................... dco: backport OS-independent part of peer float support This is a backport of commit cb8a0f6f5741d102b667d98370ab4d553503d0b5, which introduces float support for DCO linux, Windows, and the OS-independent parts. DCO linux/windows in 2.6 has no float support kernel-side, so this ignores all OS dependent parts, backporting just enough to add FreeBSD support in the next patch. One notable difference in the backport is that 2.6 has no multi-socket support, so all the "link_sockets[0]" occurances need to be changed back to "link_socket". Change-Id: Ib748e726eb84dcbe8a48b297d165dec80c0e578d Signed-off-by: Ralf Lici Signed-off-by: Gert Doering (cherry picked from commit cb8a0f6f5741d102b667d98370ab4d553503d0b5) --- M src/openvpn/forward.c M src/openvpn/forward.h M src/openvpn/multi.c 3 files changed, 73 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/69/1169/1 diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 0f2ec07..ab5ebda 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1234,6 +1234,41 @@ perf_pop(); } +void +extract_dco_float_peer_addr(const sa_family_t socket_family, + struct openvpn_sockaddr *out_osaddr, + const struct sockaddr *float_sa) +{ + if (float_sa->sa_family =3D=3D AF_INET) + { + struct sockaddr_in *float4 =3D (struct sockaddr_in *)float_sa; + /* DCO treats IPv4-mapped IPv6 addresses as pure IPv4. However, on= a + * dual-stack socket, we need to preserve the mapping otherwise op= envpn + * will not be able to find the peer by its transport address. + */ + if (socket_family =3D=3D AF_INET6) + { + out_osaddr->addr.in6.sin6_family =3D AF_INET6; + out_osaddr->addr.in6.sin6_port =3D float4->sin_port; + + memset(&out_osaddr->addr.in6.sin6_addr.s6_addr, 0, 10); + out_osaddr->addr.in6.sin6_addr.s6_addr[10] =3D 0xff; + out_osaddr->addr.in6.sin6_addr.s6_addr[11] =3D 0xff; + memcpy(&out_osaddr->addr.in6.sin6_addr.s6_addr[12], + &float4->sin_addr.s_addr, sizeof(in_addr_t)); + } + else + { + memcpy(&out_osaddr->addr.in4, float4, sizeof(struct sockaddr_i= n)); + } + } + else + { + struct sockaddr_in6 *float6 =3D (struct sockaddr_in6 *)float_sa; + memcpy(&out_osaddr->addr.in6, float6, sizeof(struct sockaddr_in6)); + } +} + static void process_incoming_dco(struct context *c) { diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h index 245a802..3d0abd5 100644 --- a/src/openvpn/forward.h +++ b/src/openvpn/forward.h @@ -189,6 +189,21 @@ void process_incoming_link_part2(struct context *c, struct link_socket_inf= o *lsi, const uint8_t *orig_buf); /** + * Transfers \c float_sa data extracted from an incoming DCO + * PEER_FLOAT_NTF to \c out_osaddr for later processing. + * + * @param socket_family - The address family of the socket + * @param out_osaddr - openvpn_sockaddr struct that will be filled the new + * address data + * @param float_sa - The sockaddr struct containing the data received from= the + * DCO notification + */ +void +extract_dco_float_peer_addr(sa_family_t socket_family, + struct openvpn_sockaddr *out_osaddr, + const struct sockaddr *float_sa); + +/** * Write a packet to the external network interface. * @ingroup external_multiplexer * diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 199f655..eb5f932 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -3169,6 +3169,18 @@ goto done; } + /* It doesn't make sense to let a peer float to the address it alr= eady + * has, so we disallow it. This can happen if a DCO netlink notifi= cation + * gets lost and we miss a floating step. + */ + if (m1->peer_id =3D=3D m2->peer_id) + { + msg(M_WARN, "disallowing peer %" PRIu32 " (%s) from floating t= o " + "its own address (%s)", + m1->peer_id, tls_common_name(mi->context.c2.tls_multi, fal= se), + mroute_addr_print(&mi->real, &gc)); + goto done; + } msg(D_MULTI_MEDIUM, "closing instance %s", multi_instance_string(e= x_mi, false, &gc)); multi_close_instance(m, ex_mi, false); } @@ -3301,6 +3313,17 @@ { process_incoming_del_peer(m, mi, dco); } +#if 0 + else if (dco->dco_message_type =3D=3D OVPN_CMD_FLOAT_PEER) + { + ASSERT(mi->context.c2.link_socket); + extract_dco_float_peer_addr(mi->context.c2.link_socket->info.a= f, + &m->top.c2.from.dest, + (struct sockaddr *)&dco->dco_float= _peer_ss); + multi_process_float(m, mi); + CLEAR(dco->dco_float_peer_ss); + } +#endif /* if defined(TARGET_LINUX) || defined(TARGET_WIN32) */ else if (dco->dco_message_type =3D=3D OVPN_CMD_SWAP_KEYS) { tls_session_soft_reset(mi->context.c2.tls_multi); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1169?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: release/2.6 Gerrit-Change-Id: Ib748e726eb84dcbe8a48b297d165dec80c0e578d Gerrit-Change-Number: 1169 Gerrit-PatchSet: 1 Gerrit-Owner: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: ralf_lici Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: ralf_lici Gerrit-MessageType: newchange --OUQfPoy/5c4= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos, ralf_lic= i.

cron2 would like plaisthos and flichtenheld to review t= his change.

V= iew Change

dco: backport OS-independent part of peer float support
<= br>This is a backport of commit cb8a0f6f5741d102b667d98370ab4d553503d0b5,which introduces float support for DCO linux, Windows, and the
OS-inde= pendent parts.

DCO linux/windows in 2.6 has no float support kernel-= side, so this
ignores all OS dependent parts, backporting just enough to= add
FreeBSD support in the next patch.

One notable difference in= the backport is that 2.6 has no multi-socket
support, so all the "= link_sockets[0]" occurances need to be changed back
to "link_s= ocket".

Change-Id: Ib748e726eb84dcbe8a48b297d165dec80c0e578dSigned-off-by: Ralf Lici <ralf@...2726...>
Signed-off-by: Gert Do= ering <gert@...1296...>
(cherry picked from commit cb8a0f6f5741d10= 2b667d98370ab4d553503d0b5)
---
M src/openvpn/forward.c
M src/openv= pn/forward.h
M src/openvpn/multi.c
3 files changed, 73 insertions(+),= 0 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn r=
efs/changes/69/1169/1
diff --git a/src/openvpn/forward.c b/src/open=
vpn/forward.c
index 0f2ec07..ab5ebda 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -1234,6 +1234,41 @@
perf_pop();

}

+void
+ext= ract_dco_float_peer_addr(const sa_family_t socket_family,
+ struct op= envpn_sockaddr *out_osaddr,
+ const struct sockaddr *float_sa)=
+{
+ if (float_sa->sa_family =3D=3D AF_INE= T)
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ struct sockaddr_in *flo= at4 =3D (struct sockaddr_in *)float_sa;
+ /* DCO treats IPv4-mapped IPv6 addresses as pur= e IPv4. However, on a
+ * dual-stack socket, we need to preserve the mapping otherwise o= penvpn
+ * wi= ll not be able to find the peer by its transport address.
+ */
+ if (socket_family =3D=3D AF_INET6)
+ {
+ out_osaddr->addr.= in6.sin6_family =3D AF_INET6;

+ out_osaddr->addr.in6.sin6_port =3D float4->sin_= port;
+
+ memset(&out_osadd= r->addr.in6.sin6_addr.s6_addr, 0, 10);
+ out_osaddr->addr.in6.sin6_addr.s6_addr= [10] =3D 0xff;
+ = out_osaddr->addr.in6.sin6_addr.s6_addr[11] =3D 0xff;
+ memcpy(&out_osad= dr->addr.in6.sin6_addr.s6_addr[12],
+ &float4->sin_addr.s_addr, size= of(in_addr_t));
+ = }
+ else
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ memcpy(&out_osa= ddr->addr.in4, float4, sizeof(struct sockaddr_in));

+ }
+ }
+ else
+= {
+ struct= sockaddr_in6 *float6 =3D (struct sockaddr_in6 *)float_sa;
+ memcpy(&out_osaddr->a= ddr.in6, float6, sizeof(struct sockaddr_in6));
+ }
+}
+
static void
process_incoming_dco(struct conte= xt *c)
{
diff --git a/src/openvpn/forward.= h b/src/openvpn/forward.h
index 245a802..3d0abd5 100644

--- a/src/openvpn/forward.h
+++ b/src/openvpn/= forward.h
@@ -189,6 +189,21 @@
void proces= s_incoming_link_part2(struct context *c, struct link_socket_info *lsi, cons= t uint8_t *orig_buf);

/**
+ * Transfers \c float_sa data extr= acted from an incoming DCO
+ * PEER_FLOAT_NTF to \c out_osaddr for later processing.
<= span style=3D"color: hsl(120, 100%, 40%);">+ *
+ * @param socket_family - The address family of = the socket
+ * @param= out_osaddr - openvpn_sockaddr struct that will be filled the new+ * address data+ * @param float_sa - The soc= kaddr struct containing the data received from the
+ * DCO notification
+ */
+void
+extract_dco_float_peer_addr(sa_family_t socket_family,
+ struct = openvpn_sockaddr *out_osaddr,
+ const struct sockaddr *float_sa);
+
+/**
* Write a packet to= the external network interface.
* @ingroup external_mult= iplexer
*
diff --git a/src/openvpn/multi.= c b/src/openvpn/multi.c
index 199f655..eb5f932 100644

--- a/src/openvpn/multi.c
+++ b/src/openvpn/mult= i.c
@@ -3169,6 +3169,18 @@
got= o done;
}

+ /* It doesn't make sense to l= et a peer float to the address it already
+ * has, so we disallow it. This can happen if= a DCO netlink notification
+ * gets lost and we miss a floating step.
+ */
+ if (m1->peer_id =3D=3D m2->peer= _id)
+ {
+ msg(M_WARN, &= quot;disallowing peer %" PRIu32 " (%s) from floating to "
+ "= its own address (%s)",
+ m1->peer_id, tls_common_name(mi->context.c2.t= ls_multi, false),
+ = mroute_addr_print(&mi->real, &gc));
+ goto done;

<= span style=3D"color: hsl(120, 100%, 40%);">+ }

= msg(D_MULTI_MEDIUM, "closing instance %s", multi_instance_str= ing(ex_mi, false, &gc));
multi_close_instance(= m, ex_mi, false);
}
@@ -3301,6 +3313,1= 7 @@
{
process_incomi= ng_del_peer(m, mi, dco);
}
+#if 0
+ else if (dco->dco_message_type =3D=3D OVPN_C= MD_FLOAT_PEER)
+ = {
+ ASS= ERT(mi->context.c2.link_socket);
+ extract_dco_float_peer_addr(mi->context.c2.l= ink_socket->info.af,
+ &m->top.c2.from.dest,
+ = (struct sockaddr *)&dco->dco_float_peer_ss);
+ multi_process= _float(m, mi);
+ = CLEAR(dco->dco_float_peer_ss);
+ }
+#endif /* if defined(TARGET_LINUX) || defined(TARGET_WIN32) */
else if (dco->dco_message_type =3D=3D OVPN_CMD_S= WAP_KEYS)
{
tls_sessi= on_soft_reset(mi->context.c2.tls_multi);

To view, visit change 1169. To unsubscribe, or for help writing mail filte= rs, visit settings.

<= div itemscope itemtype=3D"http://schema.org/EmailMessage">
<= meta itemprop=3D"name" content=3D"View Change"/>
Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: Ib748e726eb84dcbe8a48b297d16= 5dec80c0e578d
Gerrit-Change-Number: 1169
Gerrit-PatchSet: 1
Gerrit-Owner: cron2 <gert@...1296...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-Reviewer: ralf_lici <ralf@...2726...= >
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: ralf_lici <ralf@...2804...= .>
Gerrit-MessageType: newchange
--OUQfPoy/5c4=--