1 Subject: NET: skip GRO for foreign MAC addresses
3 For network drivers using napi_gro_receive, packets are run through GRO,
4 even when the destination MAC address does not match, and they're supposed
5 to be delivered to another host behind a different bridge port.
7 This can be very expensive, because for drivers without TSO or scatter-
8 gather, this can only be undone by copying the skb and checksumming it
11 To be able to track foreign MAC addresses in an inexpensive way, create
12 a mask of changed bits in MAC addresses of upper devices. This allows
13 handling VLANs and bridge devices with different addresses (as long as
14 they are not too different).
16 Signed-off-by: Felix Fietkau <nbd@nbd.name>
20 @@ -4271,6 +4271,9 @@ static enum gro_result dev_gro_receive(s
27 if (!(skb->dev->features & NETIF_F_GRO))
30 @@ -5437,6 +5440,48 @@ static void __netdev_adjacent_dev_unlink
31 &upper_dev->adj_list.lower);
34 +static void __netdev_addr_mask(unsigned char *mask, const unsigned char *addr,
35 + struct net_device *dev)
39 + for (i = 0; i < dev->addr_len; i++)
40 + mask[i] |= addr[i] ^ dev->dev_addr[i];
43 +static void __netdev_upper_mask(unsigned char *mask, struct net_device *dev,
44 + struct net_device *lower)
46 + struct net_device *cur;
47 + struct list_head *iter;
49 + netdev_for_each_upper_dev_rcu(dev, cur, iter) {
50 + __netdev_addr_mask(mask, cur->dev_addr, lower);
51 + __netdev_upper_mask(mask, cur, lower);
55 +static void __netdev_update_addr_mask(struct net_device *dev)
57 + unsigned char mask[MAX_ADDR_LEN];
58 + struct net_device *cur;
59 + struct list_head *iter;
61 + memset(mask, 0, sizeof(mask));
62 + __netdev_upper_mask(mask, dev, dev);
63 + memcpy(dev->local_addr_mask, mask, dev->addr_len);
65 + netdev_for_each_lower_dev(dev, cur, iter)
66 + __netdev_update_addr_mask(cur);
69 +static void netdev_update_addr_mask(struct net_device *dev)
72 + __netdev_update_addr_mask(dev);
76 static int __netdev_upper_dev_link(struct net_device *dev,
77 struct net_device *upper_dev, bool master,
79 @@ -5508,6 +5553,7 @@ static int __netdev_upper_dev_link(struc
80 goto rollback_lower_mesh;
83 + netdev_update_addr_mask(dev);
84 call_netdevice_notifiers_info(NETDEV_CHANGEUPPER, dev,
85 &changeupper_info.info);
87 @@ -5634,6 +5680,7 @@ void netdev_upper_dev_unlink(struct net_
88 list_for_each_entry(i, &upper_dev->all_adj_list.upper, list)
89 __netdev_adjacent_dev_unlink(dev, i->dev, i->ref_nr);
91 + netdev_update_addr_mask(dev);
92 call_netdevice_notifiers_info(NETDEV_CHANGEUPPER, dev,
93 &changeupper_info.info);
95 @@ -6174,6 +6221,7 @@ int dev_set_mac_address(struct net_devic
98 dev->addr_assign_type = NET_ADDR_SET;
99 + netdev_update_addr_mask(dev);
100 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
101 add_device_randomness(dev->dev_addr, dev->addr_len);
103 --- a/include/linux/netdevice.h
104 +++ b/include/linux/netdevice.h
105 @@ -1639,6 +1639,8 @@ struct net_device {
106 struct netdev_hw_addr_list mc;
107 struct netdev_hw_addr_list dev_addrs;
109 + unsigned char local_addr_mask[MAX_ADDR_LEN];
112 struct kset *queues_kset;
114 --- a/include/linux/skbuff.h
115 +++ b/include/linux/skbuff.h
116 @@ -642,7 +642,8 @@ struct sk_buff {
117 __u8 ipvs_property:1;
118 __u8 inner_protocol_type:1;
119 __u8 remcsum_offload:1;
120 - /* 3 or 5 bit hole */
122 + /* 2 or 4 bit hole */
124 #ifdef CONFIG_NET_SCHED
125 __u16 tc_index; /* traffic control index */
126 --- a/net/ethernet/eth.c
127 +++ b/net/ethernet/eth.c
128 @@ -140,6 +140,18 @@ u32 eth_get_headlen(void *data, unsigned
130 EXPORT_SYMBOL(eth_get_headlen);
133 +eth_check_local_mask(const void *addr1, const void *addr2, const void *mask)
135 + const u16 *a1 = addr1;
136 + const u16 *a2 = addr2;
137 + const u16 *m = mask;
139 + return (((a1[0] ^ a2[0]) & ~m[0]) |
140 + ((a1[1] ^ a2[1]) & ~m[1]) |
141 + ((a1[2] ^ a2[2]) & ~m[2]));
145 * eth_type_trans - determine the packet's protocol ID.
146 * @skb: received socket data
147 @@ -168,8 +180,12 @@ __be16 eth_type_trans(struct sk_buff *sk
148 skb->pkt_type = PACKET_MULTICAST;
150 else if (unlikely(!ether_addr_equal_64bits(eth->h_dest,
153 skb->pkt_type = PACKET_OTHERHOST;
154 + if (eth_check_local_mask(eth->h_dest, dev->dev_addr,
155 + dev->local_addr_mask))
160 * Some variants of DSA tagging don't have an ethertype field