Skip to content

Commit 6e159fd

Browse files
Binary-Eaterkuba-moo
authored andcommitted
ethernet: Add helper for assigning packet type when dest address does not match device address
Enable reuse of logic in eth_type_trans for determining packet type. Suggested-by: Sabrina Dubroca <[email protected]> Cc: [email protected] Signed-off-by: Rahul Rameshbabu <[email protected]> Reviewed-by: Sabrina Dubroca <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 475747a commit 6e159fd

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

include/linux/etherdevice.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,31 @@ static inline void eth_hw_addr_gen(struct net_device *dev, const u8 *base_addr,
607607
eth_hw_addr_set(dev, addr);
608608
}
609609

610+
/**
611+
* eth_skb_pkt_type - Assign packet type if destination address does not match
612+
* @skb: Assigned a packet type if address does not match @dev address
613+
* @dev: Network device used to compare packet address against
614+
*
615+
* If the destination MAC address of the packet does not match the network
616+
* device address, assign an appropriate packet type.
617+
*/
618+
static inline void eth_skb_pkt_type(struct sk_buff *skb,
619+
const struct net_device *dev)
620+
{
621+
const struct ethhdr *eth = eth_hdr(skb);
622+
623+
if (unlikely(!ether_addr_equal_64bits(eth->h_dest, dev->dev_addr))) {
624+
if (unlikely(is_multicast_ether_addr_64bits(eth->h_dest))) {
625+
if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
626+
skb->pkt_type = PACKET_BROADCAST;
627+
else
628+
skb->pkt_type = PACKET_MULTICAST;
629+
} else {
630+
skb->pkt_type = PACKET_OTHERHOST;
631+
}
632+
}
633+
}
634+
610635
/**
611636
* eth_skb_pad - Pad buffer to mininum number of octets for Ethernet frame
612637
* @skb: Buffer to pad

net/ethernet/eth.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,7 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
164164
eth = (struct ethhdr *)skb->data;
165165
skb_pull_inline(skb, ETH_HLEN);
166166

167-
if (unlikely(!ether_addr_equal_64bits(eth->h_dest,
168-
dev->dev_addr))) {
169-
if (unlikely(is_multicast_ether_addr_64bits(eth->h_dest))) {
170-
if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
171-
skb->pkt_type = PACKET_BROADCAST;
172-
else
173-
skb->pkt_type = PACKET_MULTICAST;
174-
} else {
175-
skb->pkt_type = PACKET_OTHERHOST;
176-
}
177-
}
167+
eth_skb_pkt_type(skb, dev);
178168

179169
/*
180170
* Some variants of DSA tagging don't have an ethertype field

0 commit comments

Comments
 (0)