Netdev List
 help / color / mirror / Atom feed
From: Simon Wunderlich <sw@simonwunderlich.de>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	b.a.t.m.a.n@lists.open-mesh.org,
	Sven Eckelmann <sven@narfation.org>,
	Simon Wunderlich <sw@simonwunderlich.de>
Subject: [PATCH net-next 02/10] batman-adv: tvlv: handle negative tvlv processing return codes
Date: Wed,  5 Aug 2026 16:27:16 +0200	[thread overview]
Message-ID: <20260805143200.722098-3-sw@simonwunderlich.de> (raw)
In-Reply-To: <20260805143200.722098-1-sw@simonwunderlich.de>

From: Sven Eckelmann <sven@narfation.org>

batadv_tvlv_containers_process() was implemented with only two return codes
from the handlers in mind:

* NET_RX_SUCCESS (0)
* NET_RX_DROP (1)

The multicast handlers broke this convention and are also returning
negative return codes. But the processing code was never updated to
correctly aggregate them.

To handle negative return codes for non-OGM(2) handlers, they are now
aggregated to:

* NET_RX_SUCCESS when no handlers returned a different return code
* the last negative return code when at least one handler returned a
  negative return code
* NET_RX_DROP otherwise

With the current callers, the old implementation is not triggering any
unexpected behavior. The behavior is only adjusted for new code which might
need more reliable return values.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/routing.c |  4 +++-
 net/batman-adv/tvlv.c    | 22 ++++++++++++++--------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index bbd40fe3a8e59..a9d657f2a831a 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -1334,7 +1334,9 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
  * contents of its TVLV forwards it and/or decapsulates it to hand it to the
  * mesh interface.
  *
- * Return: NET_RX_DROP if the skb is not consumed, NET_RX_SUCCESS otherwise.
+ * Return: NET_RX_SUCCESS if the skb was locally received, NET_RX_DROP otherwise
+ * or a negative errno code when the multicast tracker TVLV could not be
+ * processed
  */
 int batadv_recv_mcast_packet(struct sk_buff *skb,
 			     struct batadv_hard_iface *recv_if)
diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
index 49bf2ed9ecdc3..cc14a76582b5a 100644
--- a/net/batman-adv/tvlv.c
+++ b/net/batman-adv/tvlv.c
@@ -383,8 +383,9 @@ int batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,
  * @tvlv_value: tvlv content
  * @tvlv_value_len: tvlv content length
  *
- * Return: success if the handler was not found or the return value of the
- * handler callback.
+ * Return: NET_RX_SUCCESS if the handler was not found or the return value of
+ * the handler callback. The latter is NET_RX_SUCCESS or NET_RX_DROP for the
+ * unicast handler and additionally a negative errno code for the mcast handler.
  */
 static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv,
 				    struct batadv_tvlv_handler *tvlv_handler,
@@ -524,8 +525,9 @@ static bool batadv_tvlv_containers_contain(void *tvlv_value,
  * @tvlv_value: tvlv content
  * @tvlv_value_len: tvlv content length
  *
- * Return: success when processing an OGM or the return value of all called
- * handler callbacks.
+ * Return: NET_RX_SUCCESS when processing an OGM or the combined return value of
+ * all called handler callbacks. The latter is NET_RX_SUCCESS, NET_RX_DROP or,
+ * for BATADV_MCAST packets, a negative errno code.
  */
 int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
 				   u8 packet_type,
@@ -540,6 +542,7 @@ int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
 	u16 tvlv_value_cont_len;
 	u8 cifnotfound = BATADV_TVLV_HANDLER_OGM_CIFNOTFND;
 	int ret = NET_RX_SUCCESS;
+	int res;
 
 	while ((tvlv_hdr = batadv_tvlv_hdr_next(&tvlv_value, &tvlv_value_len))) {
 		tvlv_value_cont_len = ntohs(tvlv_hdr->len);
@@ -548,10 +551,13 @@ int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
 						       tvlv_hdr->type,
 						       tvlv_hdr->version);
 
-		ret |= batadv_tvlv_call_handler(bat_priv, tvlv_handler,
-						packet_type, orig_node, skb,
-						tvlv_hdr + 1,
-						tvlv_value_cont_len);
+		res = batadv_tvlv_call_handler(bat_priv, tvlv_handler,
+					       packet_type, orig_node, skb,
+					       tvlv_hdr + 1,
+					       tvlv_value_cont_len);
+		if (ret == NET_RX_SUCCESS || res < 0)
+			ret = res;
+
 		batadv_tvlv_handler_put(tvlv_handler);
 	}
 
-- 
2.47.3


  parent reply	other threads:[~2026-08-05 14:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 14:27 [PATCH net-next 00/10] pull request for net-next: batman-adv 2026-08-05 Simon Wunderlich
2026-08-05 14:27 ` [PATCH net-next 01/10] batman-adv: dat: drop non-4addr backwards compatibility Simon Wunderlich
2026-08-06 15:03   ` Sven Eckelmann
2026-08-05 14:27 ` Simon Wunderlich [this message]
2026-08-06 15:36   ` [PATCH net-next 02/10] batman-adv: tvlv: handle negative tvlv processing return codes Sven Eckelmann
2026-08-05 14:27 ` [PATCH net-next 03/10] batman-adv: add missing kernel-doc comments Simon Wunderlich
2026-08-06 16:02   ` Sven Eckelmann
2026-08-06 18:25   ` Sven Eckelmann
2026-08-05 14:27 ` [PATCH net-next 04/10] batman-adv: fix kernel-doc for functions holding skb ownership Simon Wunderlich
2026-08-05 14:27 ` [PATCH net-next 05/10] batman-adv: annotate functions which may reallocate the skbuff Simon Wunderlich
2026-08-06 16:13   ` Sven Eckelmann
2026-08-05 14:27 ` [PATCH net-next 06/10] batman-adv: split multiple declarations per line Simon Wunderlich
2026-08-05 14:27 ` [PATCH net-next 07/10] batman-adv: switch var declarations to reverse x-mas tree order Simon Wunderlich
2026-08-05 14:27 ` [PATCH net-next 08/10] batman-adv: handle errors in batadv_init() Simon Wunderlich
2026-08-05 14:27 ` [PATCH net-next 09/10] batman-adv: correct NET_RX_* NET_XMIT_* confusion Simon Wunderlich
2026-08-05 14:27 ` [PATCH net-next 10/10] batman-adv: remove negative returns for batadv_send_skb_unicast Simon Wunderlich
2026-08-06 16:26   ` Sven Eckelmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260805143200.722098-3-sw@simonwunderlich.de \
    --to=sw@simonwunderlich.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sven@narfation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox