1 From: Felix Fietkau <nbd@nbd.name>
2 Subject: net: replace GRO optimization patch with a new one that supports VLANs/bridges with different MAC addresses
4 Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 include/linux/netdevice.h | 2 ++
7 include/linux/skbuff.h | 3 ++-
8 net/core/dev.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++
9 net/ethernet/eth.c | 18 +++++++++++++++++-
10 4 files changed, 69 insertions(+), 2 deletions(-)
12 --- a/include/linux/netdevice.h
13 +++ b/include/linux/netdevice.h
14 @@ -1752,6 +1752,8 @@ struct net_device {
15 struct netdev_hw_addr_list mc;
16 struct netdev_hw_addr_list dev_addrs;
18 + unsigned char local_addr_mask[MAX_ADDR_LEN];
21 struct kset *queues_kset;
23 --- a/include/linux/skbuff.h
24 +++ b/include/linux/skbuff.h
25 @@ -747,7 +747,8 @@ struct sk_buff {
26 #ifdef CONFIG_NET_SWITCHDEV
27 __u8 offload_fwd_mark:1;
29 - /* 2, 4 or 5 bit hole */
31 + /* 1, 3 or 4 bit hole */
33 #ifdef CONFIG_NET_SCHED
34 __u16 tc_index; /* traffic control index */
37 @@ -4572,6 +4572,9 @@ static enum gro_result dev_gro_receive(s
44 if (!(skb->dev->features & NETIF_F_GRO))
47 @@ -5867,6 +5870,48 @@ static void __netdev_adjacent_dev_unlink
48 &upper_dev->adj_list.lower);
51 +static void __netdev_addr_mask(unsigned char *mask, const unsigned char *addr,
52 + struct net_device *dev)
56 + for (i = 0; i < dev->addr_len; i++)
57 + mask[i] |= addr[i] ^ dev->dev_addr[i];
60 +static void __netdev_upper_mask(unsigned char *mask, struct net_device *dev,
61 + struct net_device *lower)
63 + struct net_device *cur;
64 + struct list_head *iter;
66 + netdev_for_each_upper_dev_rcu(dev, cur, iter) {
67 + __netdev_addr_mask(mask, cur->dev_addr, lower);
68 + __netdev_upper_mask(mask, cur, lower);
72 +static void __netdev_update_addr_mask(struct net_device *dev)
74 + unsigned char mask[MAX_ADDR_LEN];
75 + struct net_device *cur;
76 + struct list_head *iter;
78 + memset(mask, 0, sizeof(mask));
79 + __netdev_upper_mask(mask, dev, dev);
80 + memcpy(dev->local_addr_mask, mask, dev->addr_len);
82 + netdev_for_each_lower_dev(dev, cur, iter)
83 + __netdev_update_addr_mask(cur);
86 +static void netdev_update_addr_mask(struct net_device *dev)
89 + __netdev_update_addr_mask(dev);
93 static int __netdev_upper_dev_link(struct net_device *dev,
94 struct net_device *upper_dev, bool master,
95 void *upper_priv, void *upper_info)
96 @@ -5939,6 +5984,7 @@ static int __netdev_upper_dev_link(struc
97 goto rollback_lower_mesh;
100 + netdev_update_addr_mask(dev);
101 ret = call_netdevice_notifiers_info(NETDEV_CHANGEUPPER, dev,
102 &changeupper_info.info);
103 ret = notifier_to_errno(ret);
104 @@ -6065,6 +6111,7 @@ void netdev_upper_dev_unlink(struct net_
105 list_for_each_entry(i, &upper_dev->all_adj_list.upper, list)
106 __netdev_adjacent_dev_unlink(dev, i->dev, i->ref_nr);
108 + netdev_update_addr_mask(dev);
109 call_netdevice_notifiers_info(NETDEV_CHANGEUPPER, dev,
110 &changeupper_info.info);
112 @@ -6667,6 +6714,7 @@ int dev_set_mac_address(struct net_devic
115 dev->addr_assign_type = NET_ADDR_SET;
116 + netdev_update_addr_mask(dev);
117 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
118 add_device_randomness(dev->dev_addr, dev->addr_len);
120 --- a/net/ethernet/eth.c
121 +++ b/net/ethernet/eth.c
122 @@ -143,6 +143,18 @@ u32 eth_get_headlen(void *data, unsigned
124 EXPORT_SYMBOL(eth_get_headlen);
127 +eth_check_local_mask(const void *addr1, const void *addr2, const void *mask)
129 + const u16 *a1 = addr1;
130 + const u16 *a2 = addr2;
131 + const u16 *m = mask;
133 + return (((a1[0] ^ a2[0]) & ~m[0]) |
134 + ((a1[1] ^ a2[1]) & ~m[1]) |
135 + ((a1[2] ^ a2[2]) & ~m[2]));
139 * eth_type_trans - determine the packet's protocol ID.
140 * @skb: received socket data
141 @@ -171,8 +183,12 @@ __be16 eth_type_trans(struct sk_buff *sk
142 skb->pkt_type = PACKET_MULTICAST;
144 else if (unlikely(!ether_addr_equal_64bits(eth->h_dest,
147 skb->pkt_type = PACKET_OTHERHOST;
148 + if (eth_check_local_mask(eth->h_dest, dev->dev_addr,
149 + dev->local_addr_mask))
154 * Some variants of DSA tagging don't have an ethertype field