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

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

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