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 @@ -2133,6 +2133,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 @@ -972,6 +972,7 @@ struct sk_buff {
26 #ifdef CONFIG_IPV6_NDISC_NODETYPE
27 __u8 ndisc_nodetype:2;
32 __u8 inner_protocol_type:1;
35 @@ -491,6 +491,9 @@ static enum gro_result dev_gro_receive(s
42 if (netif_elide_gro(skb->dev))
47 @@ -7593,6 +7593,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 @@ -7644,6 +7686,7 @@ static int __netdev_upper_dev_link(struc
100 + netdev_update_addr_mask(dev);
101 ret = call_netdevice_notifiers_info(NETDEV_CHANGEUPPER,
102 &changeupper_info.info);
103 ret = notifier_to_errno(ret);
104 @@ -7740,6 +7783,7 @@ static void __netdev_upper_dev_unlink(st
106 __netdev_adjacent_dev_unlink_neighbour(dev, upper_dev);
108 + netdev_update_addr_mask(dev);
109 call_netdevice_notifiers_info(NETDEV_CHANGEUPPER,
110 &changeupper_info.info);
112 @@ -8792,6 +8836,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(const struct net_dev
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 @@ -174,6 +186,10 @@ __be16 eth_type_trans(struct sk_buff *sk
143 skb->pkt_type = PACKET_OTHERHOST;
146 + if (eth_check_local_mask(eth->h_dest, dev->dev_addr,
147 + dev->local_addr_mask))