Skip to contentSkip to conversation

dco: properly re-initialize dco_del_peer_reason

PATCH In review Antonio Quartulli 3 participants 9 messages Jan 3, 2023 – Jan 7, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 dco: properly re-initialize dco_del_peer_reason

After processing a message, all fields of the dco object should be re-initialized so that future processings are not affected by stale values.

This includes dco_del_peer_reason.

Since its values can start at 0, re-initialize it with -1.

---
 src/openvpn/multi.c | 1 +
 1 file changed, 1 insertion(+)
src/openvpn/multi.c +1 -0
index 3658e1d5..27676de5 100644
@@ -3301,6 +3301,7 @@ multi_process_incoming_dco(struct multi_context *m)
 
     dco->dco_message_type = 0;
     dco->dco_message_peer_id = -1;
+    dco->dco_del_peer_reason = -1;
     dco->dco_read_bytes = 0;
     dco->dco_write_bytes = 0;
     return ret > 0;
Signature · 1 line
2.38.2
#1 lore raw

PATCH 2/3 dco: bail out when no peer-specific message is delivered

multi_process_incoming_dco() is currently partly processing messages that were actually discarded. This results in a bogus message being printed:

"Received packet for peer-id unknown to OpenVPN: -1, type 0, reason 2"

Change the flow so that we bail out immediately when we know that no message was truly delivered by DCO.
Currently this can be verified by chacking that the peed_is is greater than -1.

---
 src/openvpn/multi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/openvpn/multi.c +9 -1
index 27676de5..b10a6d8d 100644
@@ -3270,7 +3270,15 @@ multi_process_incoming_dco(struct multi_context *m)
 
     int peer_id = dco->dco_message_peer_id;
 
-    if ((peer_id >= 0) && (peer_id < m->max_clients) && (m->instances[peer_id]))
+    /* no peer-specific message delivered -> nothing to process.
+     * bail out right away
+     */
+    if (peer_id < 0)
+    {
+        return ret > 0;
+    }
+
+    if ((peer_id < m->max_clients) && (m->instances[peer_id]))
     {
         mi = m->instances[peer_id];
         if (dco->dco_message_type == OVPN_CMD_PACKET)
Signature · 1 line
2.38.2
#4 lore raw

PATCH 3/3 dco: improve comment about hidden debug message

In reply to Antonio Quartulli

While at it also improve the debug message itself
to be more self-explanatory.

---
 src/openvpn/multi.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
src/openvpn/multi.c +9 -4
index b10a6d8d..8facc66f 100644
@@ -3296,12 +3296,17 @@ multi_process_incoming_dco(struct multi_context *m)
         if (dco->dco_message_type == OVPN_CMD_DEL_PEER
             && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
         {
-            /* we get notified after we kill the peer ourselves and probably
-             * have already forgotten about it. This is expected */
+            /* we receive OVPN_CMD_DEL_PEER message with reason USERSPACE
+             * after we kill the peer ourselves. This peer may have already
+             * been deleted, so we end up here.
+             * In this case, print the following debug message with DCO_DEBUG
+             * level only to avoid polluting the standard DCO level with this
+             * harmless event.
+             */
             msglevel = D_DCO_DEBUG;
         }
-        msg(msglevel, "Received packet for peer-id unknown to OpenVPN: %d, "
-            "type %d, reason %d", peer_id, dco->dco_message_type,
+        msg(msglevel, "Received DCO message for unknown peer-id: %d, "
+            "type %d, del_peer_reason %d", peer_id, dco->dco_message_type,
             dco->dco_del_peer_reason);
         /* Also clear the buffer if this was incoming packet for a dropped peer */
         buf_init(&dco->dco_packet_in, 0);
Signature · 1 line
2.38.2
Acked-by on v1 1/3
#7 lore raw
In reply to Antonio Quartulli

Am 03.01.23 um 21:23 schrieb Antonio Quartulli:

Quoted 7 lines

After processing a message, all fields of the dco object should be re-initialized so that future processings are not affected by stale values.

This includes dco_del_peer_reason.

Since its values can start at 0, re-initialize it with -1.

The place we do the reinitialisation is weird but for now just fix it.

ARne

Acked-by on v1 2/3
#2 lore raw

Re: [Openvpn-devel] [PATCH 2/3] dco: bail out when no peer-specific message is delivered

In reply to Antonio Quartulli

Am 03.01.23 um 21:23 schrieb Antonio Quartulli:

Quoted 10 lines

multi_process_incoming_dco() is currently partly processing messages that were actually discarded. This results in a bogus message being printed:

"Received packet for peer-id unknown to OpenVPN: -1, type 0, reason 2"

Change the flow so that we bail out immediately when we know that no message was truly delivered by DCO.
Currently this can be verified by chacking that the peed_is is greater than -1.

I think we should somewhere properly document that peer-id = -1 has this meaning.

Arne

Acked-by on v1 3/3
#5 lore raw

Re: [Openvpn-devel] [PATCH 3/3] dco: improve comment about hidden debug message

In reply to Antonio Quartulli

Am 03.01.23 um 21:23 schrieb Antonio Quartulli:

Quoted 24 lines

While at it also improve the debug message itself
to be more self-explanatory.

---
  src/openvpn/multi.c | 13 +++++++++----
  1 file changed, 9 insertions(+), 4 deletions(-)
src/openvpn/multi.c +6 -2
index b10a6d8d..8facc66f 100644
@@ -3296,12 +3296,17 @@ multi_process_incoming_dco(struct multi_context *m)
          if (dco->dco_message_type == OVPN_CMD_DEL_PEER
              && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
          {
-            /* we get notified after we kill the peer ourselves and probably
-             * have already forgotten about it. This is expected */
+            /* we receive OVPN_CMD_DEL_PEER message with reason USERSPACE
+             * after we kill the peer ourselves. This peer may have already
+             * been deleted, so we end up here.
+             * In this case, print the following debug message with DCO_DEBUG
+             * level only to avoid polluting the standard DCO level with this
+             * harmless event.

src/openvpn/multi.c multi_process_incoming_dco(struct multi_context *m) · line 3312

Quoted 10 lines
src/openvpn/multi.c +3 -2
+             */
              msglevel = D_DCO_DEBUG;
          }
-        msg(msglevel, "Received packet for peer-id unknown to OpenVPN: %d, "
-            "type %d, reason %d", peer_id, dco->dco_message_type,
+        msg(msglevel, "Received DCO message for unknown peer-id: %d, "
+            "type %d, del_peer_reason %d", peer_id, dco->dco_message_type,
              dco->dco_del_peer_reason);
          /* Also clear the buffer if this was incoming packet for a dropped peer */
          buf_init(&dco->dco_packet_in, 0);
#8 lore raw
In reply to Antonio Quartulli

I've done a bit of stare-at-code, and it's nicely trivial :-) - but let me repeat what I said on IRC, better coding style would be to do proper initialization *before* calling dco_do_read(), not as an afterthought at the end of the function (which also breaks "early return").

I have not tested this patch on its own (just compile-tested), as it's trivial enough and has an ACK already.

For now this is fine, but we should come back here.

Your patch has been applied to the master branch.

commit e9889016fb7269d025a2dbba5f7079ee87e39520 (master) commit aaccf88431eb146231a600971227a8a6c395b349 (release/2.6)

Author: Antonio Quartulli
Date:   Tue Jan 3 21:23:28 2023 +0100
     dco: properly re-initialize dco_del_peer_reason

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg25881.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#3 lore raw

[Openvpn-devel] [PATCH applied] Re: dco: bail out when no peer-specific message is delivered

In reply to Antonio Quartulli

I've done a bit of commit message grammar ("chacking that the peed_is") and actually tested this one. Without the check, my DCO test server has quite a lot of these...

Jan  7 07:24:06 ubuntu2004 tun-udp-p2mp-topology-subnet[2441339]: Received packet for peer-id unknown to OpenVPN: -1, type 0, reason 2
Jan  7 07:24:06 ubuntu2004 tun-tcp-p2mp[2441317]: Received packet for peer-id unknown to OpenVPN: -1, type 0, reason 1

with the patch these are gone. Very welcome de-noisification of my logs :-)

We do still have a bit of "logging redundancy" here... for every client connect to instance A, p2p instance B logs 3 lines (on D_DCO_DEBUG)

Jan  7 18:35:35 ubuntu2004 tun-udp-p2p-tls-sha256[2463894]: dco_do_read
Jan  7 18:35:35 ubuntu2004 tun-udp-p2p-tls-sha256[2463894]: ovpn-dco: ignoring message (type=3) for foreign ifindex 34074
Jan  7 18:35:35 ubuntu2004 tun-udp-p2p-tls-sha256[2463894]: process_incoming_dco: received message of type 0 - ignoring

.. this is coming from forward.c::process_incoming_dco(), which I assume is only called in the p2p case, and the first message is coming from ovpn_handle_msg() (which is not using the __func__ paradigm... why?) - so if we can assert that "there is no message, there is nothing to see (and nothing to log!)" in the multi_process_incoming_dco() case - maybe we can apply this (unwritten) function contract here as well...

Stare-at-code also agrees that if the function contract says "if (peer_id < 0) there is no valid packet, ever", early exit is a good way out - see my note about un-initializing the dco-> fields at the *end* of the function for 1/3, though - in this case, no un-init... and also Arne's comment about "is this documented anywhere?")

Your patch has been applied to the master and release/2.6 branch.

commit 388e032019ec3674b8294c856039b96fe35e5f32 (master) commit b0dee39c353ae9479fd19e66ae07cb336d57eef8 (release/2.6)

Author: Antonio Quartulli
Date:   Tue Jan 3 21:23:29 2023 +0100
     dco: bail out when no peer-specific message is delivered

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg25882.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw

[Openvpn-devel] [PATCH applied] Re: dco: improve comment about hidden debug message

In reply to Antonio Quartulli

Not sure about the message rewording ("I can understand both variants just fine"), but - as discussed - the comment is helpful for readers foreign to these code paths.

Not tested beyond "does it compile?" - trivial enough.

Your patch has been applied to the master and release/2.6 branch.

commit b20daf274304ee30daa839910e633c96307a4744 (master) commit fce1e72f18aea303056967f6a2e6be9324a9ca4e (release/2.6)

Author: Antonio Quartulli
Date:   Tue Jan 3 21:23:30 2023 +0100
     dco: improve comment about hidden debug message

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg25883.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering