From: Linus Walleij <linus.walleij@linaro.org>
To: Hans Ulli Kroll <ulli.kroll@googlemail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, Linus Walleij <linus.walleij@linaro.org>,
Maxime Chevallier <maxime.chevallier@bootlin.com>
Subject: [PATCH net v3 2/3] if_ether: Add an accessor to read the raw ethertype
Date: Thu, 21 Dec 2023 01:02:21 +0100 [thread overview]
Message-ID: <20231221-new-gemini-ethernet-regression-v3-2-a96b4374bfe8@linaro.org> (raw)
In-Reply-To: <20231221-new-gemini-ethernet-regression-v3-0-a96b4374bfe8@linaro.org>
There are circumstances where the skb->protocol can not be
trusted, such as when using DSA switches that add a custom
ethertype to the ethernet packet, which is later on supposed
to be stripped by the switch hardware connected to the
conduit ethernet interface.
Since ethernet drivers transmitting such frames with alien
ethertypes can have hardware that will get confused by
custom ethertypes they need a way to retrieve and act
on any such type.
The new eth_skb_raw_ethertype() helper will extract the
ethertype directly from the skb->data using the ethernet
and (if necessary) VLAN helper functions, and return the
ethertype actually found inside the raw buffer.
Suggested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
include/linux/if_ether.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/include/linux/if_ether.h b/include/linux/if_ether.h
index 8a9792a6427a..6bf265979757 100644
--- a/include/linux/if_ether.h
+++ b/include/linux/if_ether.h
@@ -37,6 +37,22 @@ static inline struct ethhdr *inner_eth_hdr(const struct sk_buff *skb)
return (struct ethhdr *)skb_inner_mac_header(skb);
}
+/* This determines the ethertype incoded into the skb data without
+ * relying on skb->protocol which is not always identical.
+ */
+static inline u16 skb_eth_raw_ethertype(struct sk_buff *skb)
+{
+ struct ethhdr *hdr;
+
+ /* If we can't extract a header, return invalid type */
+ if (!pskb_may_pull(skb, ETH_HLEN))
+ return 0x0000U;
+
+ hdr = skb_eth_hdr(skb);
+
+ return ntohs(hdr->h_proto);
+}
+
int eth_header_parse(const struct sk_buff *skb, unsigned char *haddr);
extern ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len);
--
2.34.1
next prev parent reply other threads:[~2023-12-21 0:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-21 0:02 [PATCH net v3 0/3] Fix a regression in the Gemini ethernet controller Linus Walleij
2023-12-21 0:02 ` [PATCH net v3 1/3] net: ethernet: cortina: Drop software checksum and TSO Linus Walleij
2023-12-21 8:47 ` Eric Dumazet
2023-12-21 0:02 ` Linus Walleij [this message]
2023-12-21 0:02 ` [PATCH net v3 3/3] net: ethernet: cortina: Bypass checksumming engine of alien ethertypes Linus Walleij
2023-12-21 8:50 ` Eric Dumazet
2023-12-21 18:04 ` Simon Horman
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=20231221-new-gemini-ethernet-regression-v3-2-a96b4374bfe8@linaro.org \
--to=linus.walleij@linaro.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ulli.kroll@googlemail.com \
/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;
as well as URLs for NNTP newsgroup(s).