mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-27 21:03:32 +00:00
ethernet: Add helper for assigning packet type when dest address does not match device address
[ Upstream commit 6e159fd653
]
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>
This commit is contained in:
parent
51fcea1b7c
commit
3d63a6c77b
2 changed files with 26 additions and 11 deletions
|
@ -543,6 +543,31 @@ static inline void eth_hw_addr_gen(struct net_device *dev, const u8 *base_addr,
|
||||||
eth_hw_addr_set(dev, addr);
|
eth_hw_addr_set(dev, 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
|
* eth_skb_pad - Pad buffer to mininum number of octets for Ethernet frame
|
||||||
* @skb: Buffer to pad
|
* @skb: Buffer to pad
|
||||||
|
|
|
@ -165,17 +165,7 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
|
||||||
eth = (struct ethhdr *)skb->data;
|
eth = (struct ethhdr *)skb->data;
|
||||||
skb_pull_inline(skb, ETH_HLEN);
|
skb_pull_inline(skb, ETH_HLEN);
|
||||||
|
|
||||||
if (unlikely(!ether_addr_equal_64bits(eth->h_dest,
|
eth_skb_pkt_type(skb, dev);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some variants of DSA tagging don't have an ethertype field
|
* Some variants of DSA tagging don't have an ethertype field
|
||||||
|
|
Loading…
Reference in a new issue