Skip to content

Commit d35fb16

Browse files
Binary-Eatergregkh
authored andcommitted
ethernet: Add helper for assigning packet type when dest address does not match device address
commit 6e159fd upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5dbdbe1 commit d35fb16

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

include/linux/etherdevice.h

+25
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,31 @@ static inline unsigned long compare_ether_header(const void *a, const void *b)
542542
#endif
543543
}
544544

545+
/**
546+
* eth_skb_pkt_type - Assign packet type if destination address does not match
547+
* @skb: Assigned a packet type if address does not match @dev address
548+
* @dev: Network device used to compare packet address against
549+
*
550+
* If the destination MAC address of the packet does not match the network
551+
* device address, assign an appropriate packet type.
552+
*/
553+
static inline void eth_skb_pkt_type(struct sk_buff *skb,
554+
const struct net_device *dev)
555+
{
556+
const struct ethhdr *eth = eth_hdr(skb);
557+
558+
if (unlikely(!ether_addr_equal_64bits(eth->h_dest, dev->dev_addr))) {
559+
if (unlikely(is_multicast_ether_addr_64bits(eth->h_dest))) {
560+
if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
561+
skb->pkt_type = PACKET_BROADCAST;
562+
else
563+
skb->pkt_type = PACKET_MULTICAST;
564+
} else {
565+
skb->pkt_type = PACKET_OTHERHOST;
566+
}
567+
}
568+
}
569+
545570
/**
546571
* eth_skb_pad - Pad buffer to mininum number of octets for Ethernet frame
547572
* @skb: Buffer to pad

net/ethernet/eth.c

+1-11
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,7 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
163163
eth = (struct ethhdr *)skb->data;
164164
skb_pull_inline(skb, ETH_HLEN);
165165

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

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

0 commit comments

Comments
 (0)