kernel: bump 5.15 to 5.15.100
[openwrt/openwrt.git] / target / linux / generic / hack-5.15 / 721-net-add-packet-mangeling.patch
1 From ffe387740bbe88dd88bbe04d6375902708003d6e Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@nbd.name>
3 Date: Fri, 7 Jul 2017 17:25:00 +0200
4 Subject: net: add packet mangeling
5
6 ar8216 switches have a hardware bug, which renders normal 802.1q support
7 unusable. Packet mangling is required to fix up the vlan for incoming
8 packets.
9
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 ---
12 include/linux/netdevice.h | 11 +++++++++++
13 include/linux/skbuff.h | 14 ++++----------
14 net/Kconfig | 6 ++++++
15 net/core/dev.c | 20 +++++++++++++++-----
16 net/core/skbuff.c | 17 +++++++++++++++++
17 net/ethernet/eth.c | 6 ++++++
18 6 files changed, 59 insertions(+), 15 deletions(-)
19
20 --- a/include/linux/netdevice.h
21 +++ b/include/linux/netdevice.h
22 @@ -1676,6 +1676,10 @@ enum netdev_priv_flags {
23 IFF_TX_SKB_NO_LINEAR = BIT_ULL(31),
24 };
25
26 +enum netdev_extra_priv_flags {
27 + IFF_NO_IP_ALIGN = 1<<0,
28 +};
29 +
30 #define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
31 #define IFF_EBRIDGE IFF_EBRIDGE
32 #define IFF_BONDING IFF_BONDING
33 @@ -1708,6 +1712,7 @@ enum netdev_priv_flags {
34 #define IFF_L3MDEV_RX_HANDLER IFF_L3MDEV_RX_HANDLER
35 #define IFF_LIVE_RENAME_OK IFF_LIVE_RENAME_OK
36 #define IFF_TX_SKB_NO_LINEAR IFF_TX_SKB_NO_LINEAR
37 +#define IFF_NO_IP_ALIGN IFF_NO_IP_ALIGN
38
39 /* Specifies the type of the struct net_device::ml_priv pointer */
40 enum netdev_ml_priv_type {
41 @@ -2009,6 +2014,7 @@ struct net_device {
42 /* Read-mostly cache-line for fast-path access */
43 unsigned int flags;
44 unsigned int priv_flags;
45 + unsigned int extra_priv_flags;
46 const struct net_device_ops *netdev_ops;
47 int ifindex;
48 unsigned short gflags;
49 @@ -2069,6 +2075,11 @@ struct net_device {
50 const struct tlsdev_ops *tlsdev_ops;
51 #endif
52
53 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
54 + void (*eth_mangle_rx)(struct net_device *dev, struct sk_buff *skb);
55 + struct sk_buff *(*eth_mangle_tx)(struct net_device *dev, struct sk_buff *skb);
56 +#endif
57 +
58 const struct header_ops *header_ops;
59
60 unsigned char operstate;
61 @@ -2143,6 +2154,10 @@ struct net_device {
62 struct mctp_dev __rcu *mctp_ptr;
63 #endif
64
65 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
66 + void *phy_ptr; /* PHY device specific data */
67 +#endif
68 +
69 /*
70 * Cache lines mostly used on receive path (including eth_type_trans())
71 */
72 --- a/include/linux/skbuff.h
73 +++ b/include/linux/skbuff.h
74 @@ -2854,6 +2854,10 @@ static inline int pskb_trim(struct sk_bu
75 return (len < skb->len) ? __pskb_trim(skb, len) : 0;
76 }
77
78 +extern struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
79 + unsigned int length, gfp_t gfp);
80 +
81 +
82 /**
83 * pskb_trim_unique - remove end from a paged unique (not cloned) buffer
84 * @skb: buffer to alter
85 @@ -3004,16 +3008,6 @@ static inline struct sk_buff *dev_alloc_
86 }
87
88
89 -static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
90 - unsigned int length, gfp_t gfp)
91 -{
92 - struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
93 -
94 - if (NET_IP_ALIGN && skb)
95 - skb_reserve(skb, NET_IP_ALIGN);
96 - return skb;
97 -}
98 -
99 static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
100 unsigned int length)
101 {
102 --- a/net/Kconfig
103 +++ b/net/Kconfig
104 @@ -26,6 +26,12 @@ menuconfig NET
105
106 if NET
107
108 +config ETHERNET_PACKET_MANGLE
109 + bool
110 + help
111 + This option can be selected by phy drivers that need to mangle
112 + packets going in or out of an ethernet device.
113 +
114 config WANT_COMPAT_NETLINK_MESSAGES
115 bool
116 help
117 --- a/net/core/dev.c
118 +++ b/net/core/dev.c
119 @@ -3590,6 +3590,11 @@ static int xmit_one(struct sk_buff *skb,
120 if (dev_nit_active(dev))
121 dev_queue_xmit_nit(skb, dev);
122
123 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
124 + if (dev->eth_mangle_tx && !(skb = dev->eth_mangle_tx(dev, skb)))
125 + return NETDEV_TX_OK;
126 +#endif
127 +
128 len = skb->len;
129 PRANDOM_ADD_NOISE(skb, dev, txq, len + jiffies);
130 trace_net_dev_start_xmit(skb, dev);
131 --- a/net/core/skbuff.c
132 +++ b/net/core/skbuff.c
133 @@ -61,6 +61,7 @@
134 #include <linux/if_vlan.h>
135 #include <linux/mpls.h>
136 #include <linux/kcov.h>
137 +#include <linux/if.h>
138
139 #include <net/protocol.h>
140 #include <net/dst.h>
141 @@ -602,6 +603,22 @@ skb_fail:
142 }
143 EXPORT_SYMBOL(__napi_alloc_skb);
144
145 +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
146 + unsigned int length, gfp_t gfp)
147 +{
148 + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
149 +
150 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
151 + if (dev && (dev->extra_priv_flags & IFF_NO_IP_ALIGN))
152 + return skb;
153 +#endif
154 +
155 + if (NET_IP_ALIGN && skb)
156 + skb_reserve(skb, NET_IP_ALIGN);
157 + return skb;
158 +}
159 +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
160 +
161 void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
162 int size, unsigned int truesize)
163 {
164 --- a/net/ethernet/eth.c
165 +++ b/net/ethernet/eth.c
166 @@ -170,6 +170,12 @@ __be16 eth_type_trans(struct sk_buff *sk
167 const struct ethhdr *eth;
168
169 skb->dev = dev;
170 +
171 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
172 + if (dev->eth_mangle_rx)
173 + dev->eth_mangle_rx(dev, skb);
174 +#endif
175 +
176 skb_reset_mac_header(skb);
177
178 eth = (struct ethhdr *)skb->data;