Repository : ssh://git@diktynna/batman-adv On branches: main,main
commit b097e63c8549d9a1311adf8e2597f63fbb80291a Author: Vladimir Oltean vladimir.oltean@nxp.com Date: Fri Apr 21 01:55:54 2023 +0300
batman-adv: introduce skb_vlan_eth_hdr()
Similar to skb_eth_hdr() introduced in commit 96cc4b69581d ("macvlan: do not assume mac_header is set in macvlan_broadcast()"), let's introduce a skb_vlan_eth_hdr() helper which can be used in TX-only code paths to get to the VLAN header based on skb->data rather than based on the skb_mac_header(skb).
We also consolidate the drivers that dereference skb->data to go through this helper.
Signed-off-by: Vladimir Oltean vladimir.oltean@nxp.com Reviewed-by: Eric Dumazet edumazet@google.com Reviewed-by: Simon Horman simon.horman@corigine.com Reviewed-by: Florian Fainelli f.fainelli@gmail.com Signed-off-by: David S. Miller davem@davemloft.net [sven@narfation.org: add compat code] Signed-off-by: Sven Eckelmann sven@narfation.org
b097e63c8549d9a1311adf8e2597f63fbb80291a compat-include/linux/if_vlan.h | 28 ++++++++++++++++++++++++++++ net/batman-adv/soft-interface.c | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/compat-include/linux/if_vlan.h b/compat-include/linux/if_vlan.h new file mode 100644 index 00000000..eb15e060 --- /dev/null +++ b/compat-include/linux/if_vlan.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_IF_VLAN_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_IF_VLAN_H_ + +#include <linux/version.h> +#include_next <linux/if_vlan.h> + +#if LINUX_VERSION_IS_LESS(6, 4, 0) + +/* Prefer this version in TX path, instead of + * skb_reset_mac_header() + vlan_eth_hdr() + */ +static inline struct vlan_ethhdr *skb_vlan_eth_hdr(const struct sk_buff *skb) +{ + return (struct vlan_ethhdr *)skb->data; +} + +#endif /* LINUX_VERSION_IS_LESS(6, 4, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_IF_VLAN_H_ */ diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c index 125f4628..d3fdf822 100644 --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c @@ -439,7 +439,7 @@ void batadv_interface_rx(struct net_device *soft_iface, if (!pskb_may_pull(skb, VLAN_ETH_HLEN)) goto dropped;
- vhdr = (struct vlan_ethhdr *)skb->data; + vhdr = skb_vlan_eth_hdr(skb);
/* drop batman-in-batman packets to prevent loops */ if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN))