History

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.

Rahul Rameshbabu committed 2 years ago

Commit 6e159fd1 parent 475747a2 files · +26 −11Browse files

Unified · Split

2 files
  1. include/linux/etherdevice.h +25 −0
  2. net/ethernet/eth.c +1 −11
include/linux/etherdevice.h+25−0
@@ -607,6 +607,31 @@ static inline void eth_hw_addr_gen(struct net_device *dev, const u8 *base_addr, · 606 unmodified lines
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+1−11
@@ -164,17 +164,7 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev) · 163 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t