From: Sven Eckelmann <sven@narfation.org>
To: Eric Biggers <ebiggers@kernel.org>
Cc: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org,
b.a.t.m.a.n@lists.open-mesh.org
Subject: Re: [PATCH net-next 3/4] batman-adv: keep skb crc32 helper local in BLA
Date: Sun, 28 Sep 2025 10:45:12 +0200 [thread overview]
Message-ID: <2878689.BEx9A2HvPv@sven-desktop> (raw)
In-Reply-To: <20250927205552.GD9798@quark>
[-- Attachment #1: Type: text/plain, Size: 5125 bytes --]
On Saturday, 27 September 2025 22:55:52 CEST Eric Biggers wrote:
> Hi,
>
> On Tue, Sep 16, 2025 at 02:24:40PM +0200, Simon Wunderlich wrote:
> > +static __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
> > +{
> > + unsigned int to = skb->len;
> > + unsigned int consumed = 0;
> > + struct skb_seq_state st;
> > + unsigned int from;
> > + unsigned int len;
> > + const u8 *data;
> > + u32 crc = 0;
> > +
> > + from = (unsigned int)(payload_ptr - skb->data);
> > +
> > + skb_prepare_seq_read(skb, from, to, &st);
> > + while ((len = skb_seq_read(consumed, &data, &st)) != 0) {
> > + crc = crc32c(crc, data, len);
> > + consumed += len;
> > + }
> > +
> > + return htonl(crc);
> > +}
>
> Has using skb_crc32c() been considered here?
No. At the time this was written (v3.8), skb_crc32c (v6.16) didnt exist. Also
its predecessor __skb_checksum only started its existence in v3.13. And no one
noticed it as candidate to replace batadv_skb_crc32 with
And this patch here was just moving the function between two places - so not
introducing new code.
Do you want to submit a patch to integrate your new function in batman-adv? I
only performed a quick-and-dirty test to see if it returns the same results
and it seemed to do its job fine.
diff --git c/net/batman-adv/Kconfig w/net/batman-adv/Kconfig
index c299e2bc..58c408b7 100644
--- c/net/batman-adv/Kconfig
+++ w/net/batman-adv/Kconfig
@@ -35,6 +35,7 @@ config BATMAN_ADV_BLA
bool "Bridge Loop Avoidance"
depends on BATMAN_ADV && INET
select CRC16
+ select NET_CRC32C
default y
help
This option enables BLA (Bridge Loop Avoidance), a mechanism
diff --git c/net/batman-adv/bridge_loop_avoidance.c w/net/batman-adv/bridge_loop_avoidance.c
index b992ba12..eef40b6f 100644
--- c/net/batman-adv/bridge_loop_avoidance.c
+++ w/net/batman-adv/bridge_loop_avoidance.c
@@ -12,7 +12,6 @@
#include <linux/compiler.h>
#include <linux/container_of.h>
#include <linux/crc16.h>
-#include <linux/crc32.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
@@ -1585,45 +1584,11 @@ int batadv_bla_init(struct batadv_priv *bat_priv)
return 0;
}
-/**
- * batadv_skb_crc32() - calculate CRC32 of the whole packet and skip bytes in
- * the header
- * @skb: skb pointing to fragmented socket buffers
- * @payload_ptr: Pointer to position inside the head buffer of the skb
- * marking the start of the data to be CRC'ed
- *
- * payload_ptr must always point to an address in the skb head buffer and not to
- * a fragment.
- *
- * Return: big endian crc32c of the checksummed data
- */
-static __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
-{
- unsigned int to = skb->len;
- unsigned int consumed = 0;
- struct skb_seq_state st;
- unsigned int from;
- unsigned int len;
- const u8 *data;
- u32 crc = 0;
-
- from = (unsigned int)(payload_ptr - skb->data);
-
- skb_prepare_seq_read(skb, from, to, &st);
- while ((len = skb_seq_read(consumed, &data, &st)) != 0) {
- crc = crc32c(crc, data, len);
- consumed += len;
- }
-
- return htonl(crc);
-}
-
/**
* batadv_bla_check_duplist() - Check if a frame is in the broadcast dup.
* @bat_priv: the bat priv with all the mesh interface information
* @skb: contains the multicast packet to be checked
- * @payload_ptr: pointer to position inside the head buffer of the skb
- * marking the start of the data to be CRC'ed
+ * @payload_offset: offset in the skb, marking the start of the data to be CRC'ed
* @orig: originator mac address, NULL if unknown
*
* Check if it is on our broadcast list. Another gateway might have sent the
@@ -1638,16 +1603,18 @@ static __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
* Return: true if a packet is in the duplicate list, false otherwise.
*/
static bool batadv_bla_check_duplist(struct batadv_priv *bat_priv,
- struct sk_buff *skb, u8 *payload_ptr,
+ struct sk_buff *skb, int payload_offset,
const u8 *orig)
{
struct batadv_bcast_duplist_entry *entry;
bool ret = false;
+ int payload_len;
int i, curr;
__be32 crc;
/* calculate the crc ... */
- crc = batadv_skb_crc32(skb, payload_ptr);
+ payload_len = skb->len - payload_offset;
+ crc = htonl(skb_crc32c(skb, payload_offset, payload_len, 0));
spin_lock_bh(&bat_priv->bla.bcast_duplist_lock);
@@ -1727,7 +1694,7 @@ static bool batadv_bla_check_duplist(struct batadv_priv *bat_priv,
static bool batadv_bla_check_ucast_duplist(struct batadv_priv *bat_priv,
struct sk_buff *skb)
{
- return batadv_bla_check_duplist(bat_priv, skb, (u8 *)skb->data, NULL);
+ return batadv_bla_check_duplist(bat_priv, skb, 0, NULL);
}
/**
@@ -1745,12 +1712,10 @@ bool batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
struct sk_buff *skb)
{
struct batadv_bcast_packet *bcast_packet;
- u8 *payload_ptr;
bcast_packet = (struct batadv_bcast_packet *)skb->data;
- payload_ptr = (u8 *)(bcast_packet + 1);
- return batadv_bla_check_duplist(bat_priv, skb, payload_ptr,
+ return batadv_bla_check_duplist(bat_priv, skb, sizeof(*bcast_packet),
bcast_packet->orig);
}
Regards,
Sven
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: Sven Eckelmann <sven@narfation.org>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Simon Wunderlich <sw@simonwunderlich.de>,
kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org,
b.a.t.m.a.n@lists.open-mesh.org
Subject: Re: [PATCH net-next 3/4] batman-adv: keep skb crc32 helper local in BLA
Date: Sun, 28 Sep 2025 10:45:12 +0200 [thread overview]
Message-ID: <2878689.BEx9A2HvPv@sven-desktop> (raw)
In-Reply-To: <20250927205552.GD9798@quark>
[-- Attachment #1: Type: text/plain, Size: 5125 bytes --]
On Saturday, 27 September 2025 22:55:52 CEST Eric Biggers wrote:
> Hi,
>
> On Tue, Sep 16, 2025 at 02:24:40PM +0200, Simon Wunderlich wrote:
> > +static __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
> > +{
> > + unsigned int to = skb->len;
> > + unsigned int consumed = 0;
> > + struct skb_seq_state st;
> > + unsigned int from;
> > + unsigned int len;
> > + const u8 *data;
> > + u32 crc = 0;
> > +
> > + from = (unsigned int)(payload_ptr - skb->data);
> > +
> > + skb_prepare_seq_read(skb, from, to, &st);
> > + while ((len = skb_seq_read(consumed, &data, &st)) != 0) {
> > + crc = crc32c(crc, data, len);
> > + consumed += len;
> > + }
> > +
> > + return htonl(crc);
> > +}
>
> Has using skb_crc32c() been considered here?
No. At the time this was written (v3.8), skb_crc32c (v6.16) didnt exist. Also
its predecessor __skb_checksum only started its existence in v3.13. And no one
noticed it as candidate to replace batadv_skb_crc32 with
And this patch here was just moving the function between two places - so not
introducing new code.
Do you want to submit a patch to integrate your new function in batman-adv? I
only performed a quick-and-dirty test to see if it returns the same results
and it seemed to do its job fine.
diff --git c/net/batman-adv/Kconfig w/net/batman-adv/Kconfig
index c299e2bc..58c408b7 100644
--- c/net/batman-adv/Kconfig
+++ w/net/batman-adv/Kconfig
@@ -35,6 +35,7 @@ config BATMAN_ADV_BLA
bool "Bridge Loop Avoidance"
depends on BATMAN_ADV && INET
select CRC16
+ select NET_CRC32C
default y
help
This option enables BLA (Bridge Loop Avoidance), a mechanism
diff --git c/net/batman-adv/bridge_loop_avoidance.c w/net/batman-adv/bridge_loop_avoidance.c
index b992ba12..eef40b6f 100644
--- c/net/batman-adv/bridge_loop_avoidance.c
+++ w/net/batman-adv/bridge_loop_avoidance.c
@@ -12,7 +12,6 @@
#include <linux/compiler.h>
#include <linux/container_of.h>
#include <linux/crc16.h>
-#include <linux/crc32.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
@@ -1585,45 +1584,11 @@ int batadv_bla_init(struct batadv_priv *bat_priv)
return 0;
}
-/**
- * batadv_skb_crc32() - calculate CRC32 of the whole packet and skip bytes in
- * the header
- * @skb: skb pointing to fragmented socket buffers
- * @payload_ptr: Pointer to position inside the head buffer of the skb
- * marking the start of the data to be CRC'ed
- *
- * payload_ptr must always point to an address in the skb head buffer and not to
- * a fragment.
- *
- * Return: big endian crc32c of the checksummed data
- */
-static __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
-{
- unsigned int to = skb->len;
- unsigned int consumed = 0;
- struct skb_seq_state st;
- unsigned int from;
- unsigned int len;
- const u8 *data;
- u32 crc = 0;
-
- from = (unsigned int)(payload_ptr - skb->data);
-
- skb_prepare_seq_read(skb, from, to, &st);
- while ((len = skb_seq_read(consumed, &data, &st)) != 0) {
- crc = crc32c(crc, data, len);
- consumed += len;
- }
-
- return htonl(crc);
-}
-
/**
* batadv_bla_check_duplist() - Check if a frame is in the broadcast dup.
* @bat_priv: the bat priv with all the mesh interface information
* @skb: contains the multicast packet to be checked
- * @payload_ptr: pointer to position inside the head buffer of the skb
- * marking the start of the data to be CRC'ed
+ * @payload_offset: offset in the skb, marking the start of the data to be CRC'ed
* @orig: originator mac address, NULL if unknown
*
* Check if it is on our broadcast list. Another gateway might have sent the
@@ -1638,16 +1603,18 @@ static __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
* Return: true if a packet is in the duplicate list, false otherwise.
*/
static bool batadv_bla_check_duplist(struct batadv_priv *bat_priv,
- struct sk_buff *skb, u8 *payload_ptr,
+ struct sk_buff *skb, int payload_offset,
const u8 *orig)
{
struct batadv_bcast_duplist_entry *entry;
bool ret = false;
+ int payload_len;
int i, curr;
__be32 crc;
/* calculate the crc ... */
- crc = batadv_skb_crc32(skb, payload_ptr);
+ payload_len = skb->len - payload_offset;
+ crc = htonl(skb_crc32c(skb, payload_offset, payload_len, 0));
spin_lock_bh(&bat_priv->bla.bcast_duplist_lock);
@@ -1727,7 +1694,7 @@ static bool batadv_bla_check_duplist(struct batadv_priv *bat_priv,
static bool batadv_bla_check_ucast_duplist(struct batadv_priv *bat_priv,
struct sk_buff *skb)
{
- return batadv_bla_check_duplist(bat_priv, skb, (u8 *)skb->data, NULL);
+ return batadv_bla_check_duplist(bat_priv, skb, 0, NULL);
}
/**
@@ -1745,12 +1712,10 @@ bool batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
struct sk_buff *skb)
{
struct batadv_bcast_packet *bcast_packet;
- u8 *payload_ptr;
bcast_packet = (struct batadv_bcast_packet *)skb->data;
- payload_ptr = (u8 *)(bcast_packet + 1);
- return batadv_bla_check_duplist(bat_priv, skb, payload_ptr,
+ return batadv_bla_check_duplist(bat_priv, skb, sizeof(*bcast_packet),
bcast_packet->orig);
}
Regards,
Sven
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2025-09-28 8:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-16 12:24 [PATCH net-next 0/4] pull request for net-next: batman-adv 2025-09-16 Simon Wunderlich
2025-09-16 12:24 ` Simon Wunderlich
2025-09-16 12:24 ` [PATCH net-next 1/4] batman-adv: Start new development cycle Simon Wunderlich
2025-09-16 12:24 ` Simon Wunderlich
2025-09-17 0:40 ` patchwork-bot+netdevbpf
2025-09-16 12:24 ` [PATCH net-next 2/4] batman-adv: remove network coding support Simon Wunderlich
2025-09-16 12:24 ` Simon Wunderlich
2025-09-16 12:24 ` [PATCH net-next 3/4] batman-adv: keep skb crc32 helper local in BLA Simon Wunderlich
2025-09-16 12:24 ` Simon Wunderlich
2025-09-27 20:55 ` Eric Biggers
2025-09-27 20:55 ` Eric Biggers
2025-09-28 8:45 ` Sven Eckelmann [this message]
2025-09-28 8:45 ` Sven Eckelmann
2025-09-28 17:17 ` Eric Biggers
2025-09-28 17:17 ` Eric Biggers
2025-09-16 12:24 ` [PATCH net-next 4/4] batman-adv: remove includes for extern declarations Simon Wunderlich
2025-09-16 12:24 ` Simon Wunderlich
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=2878689.BEx9A2HvPv@sven-desktop \
--to=sven@narfation.org \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=ebiggers@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.