summaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorRahul Rameshbabu <rrameshbabu@nvidia.com>2024-04-23 11:13:03 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-05-17 11:42:37 +0200
commit3d63a6c77b51c1a7cef2987a7f70ec9d91b04d95 (patch)
treec9a8995e7a674287fd2e28a34237a9549851579a /include/linux
parent51fcea1b7c52abc3ff5af354e199731582a34ebf (diff)
downloadlinux-stable-3d63a6c77b51c1a7cef2987a7f70ec9d91b04d95.tar.gz
linux-stable-3d63a6c77b51c1a7cef2987a7f70ec9d91b04d95.tar.bz2
linux-stable-3d63a6c77b51c1a7cef2987a7f70ec9d91b04d95.zip
ethernet: Add helper for assigning packet type when dest address does not match device address
[ Upstream commit 6e159fd653d7ebf6290358e0330a0cb8a75cf73b ] Enable reuse of logic in eth_type_trans for determining packet type. Suggested-by: Sabrina Dubroca <sd@queasysnail.net> Cc: stable@vger.kernel.org Signed-off-by: Rahul Rameshbabu <rrameshbabu@nvidia.com> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net> Link: https://lore.kernel.org/r/20240423181319.115860-3-rrameshbabu@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/etherdevice.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index fef4bb77f759..267b3cbc7ae1 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -544,6 +544,31 @@ static inline void eth_hw_addr_gen(struct net_device *dev, const u8 *base_addr,
}
/**
+ * eth_skb_pkt_type - Assign packet type if destination address does not match
+ * @skb: Assigned a packet type if address does not match @dev address
+ * @dev: Network device used to compare packet address against
+ *
+ * If the destination MAC address of the packet does not match the network
+ * device address, assign an appropriate packet type.
+ */
+static inline void eth_skb_pkt_type(struct sk_buff *skb,
+ const struct net_device *dev)
+{
+ const struct ethhdr *eth = eth_hdr(skb);
+
+ if (unlikely(!ether_addr_equal_64bits(eth->h_dest, dev->dev_addr))) {
+ if (unlikely(is_multicast_ether_addr_64bits(eth->h_dest))) {
+ if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
+ skb->pkt_type = PACKET_BROADCAST;
+ else
+ skb->pkt_type = PACKET_MULTICAST;
+ } else {
+ skb->pkt_type = PACKET_OTHERHOST;
+ }
+ }
+}
+
+/**
* eth_skb_pad - Pad buffer to mininum number of octets for Ethernet frame
* @skb: Buffer to pad
*