kernel: split patches folder up into backport, pending and hack folders
[openwrt/openwrt.git] / target / linux / generic / hack-4.9 / 721-phy_packets.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 patch
5
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 ---
8 include/linux/netdevice.h | 11 +++++++++++
9 include/linux/skbuff.h | 14 ++++----------
10 net/Kconfig | 6 ++++++
11 net/core/dev.c | 18 ++++++++++++++----
12 net/core/skbuff.c | 17 +++++++++++++++++
13 net/ethernet/eth.c | 6 ++++++
14 6 files changed, 58 insertions(+), 14 deletions(-)
15
16 Index: linux-4.9.34/include/linux/netdevice.h
17 ===================================================================
18 --- linux-4.9.34.orig/include/linux/netdevice.h
19 +++ linux-4.9.34/include/linux/netdevice.h
20 @@ -1398,6 +1398,7 @@ enum netdev_priv_flags {
21 IFF_RXFH_CONFIGURED = 1<<25,
22 IFF_PHONY_HEADROOM = 1<<26,
23 IFF_MACSEC = 1<<27,
24 + IFF_NO_IP_ALIGN = 1<<28,
25 };
26
27 #define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
28 @@ -1427,6 +1428,7 @@ enum netdev_priv_flags {
29 #define IFF_TEAM IFF_TEAM
30 #define IFF_RXFH_CONFIGURED IFF_RXFH_CONFIGURED
31 #define IFF_MACSEC IFF_MACSEC
32 +#define IFF_NO_IP_ALIGN IFF_NO_IP_ALIGN
33
34 /**
35 * struct net_device - The DEVICE structure.
36 @@ -1713,6 +1715,11 @@ struct net_device {
37 const struct ndisc_ops *ndisc_ops;
38 #endif
39
40 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
41 + void (*eth_mangle_rx)(struct net_device *dev, struct sk_buff *skb);
42 + struct sk_buff *(*eth_mangle_tx)(struct net_device *dev, struct sk_buff *skb);
43 +#endif
44 +
45 const struct header_ops *header_ops;
46
47 unsigned int flags;
48 @@ -1780,6 +1787,10 @@ struct net_device {
49 struct mpls_dev __rcu *mpls_ptr;
50 #endif
51
52 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
53 + void *phy_ptr; /* PHY device specific data */
54 +#endif
55 +
56 /*
57 * Cache lines mostly used on receive path (including eth_type_trans())
58 */
59 Index: linux-4.9.34/include/linux/skbuff.h
60 ===================================================================
61 --- linux-4.9.34.orig/include/linux/skbuff.h
62 +++ linux-4.9.34/include/linux/skbuff.h
63 @@ -2334,6 +2334,10 @@ static inline int pskb_trim(struct sk_bu
64 return (len < skb->len) ? __pskb_trim(skb, len) : 0;
65 }
66
67 +extern struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
68 + unsigned int length, gfp_t gfp);
69 +
70 +
71 /**
72 * pskb_trim_unique - remove end from a paged unique (not cloned) buffer
73 * @skb: buffer to alter
74 @@ -2454,16 +2458,6 @@ static inline struct sk_buff *dev_alloc_
75 }
76
77
78 -static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
79 - unsigned int length, gfp_t gfp)
80 -{
81 - struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
82 -
83 - if (NET_IP_ALIGN && skb)
84 - skb_reserve(skb, NET_IP_ALIGN);
85 - return skb;
86 -}
87 -
88 static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
89 unsigned int length)
90 {
91 Index: linux-4.9.34/net/Kconfig
92 ===================================================================
93 --- linux-4.9.34.orig/net/Kconfig
94 +++ linux-4.9.34/net/Kconfig
95 @@ -25,6 +25,12 @@ menuconfig NET
96
97 if NET
98
99 +config ETHERNET_PACKET_MANGLE
100 + bool
101 + help
102 + This option can be selected by phy drivers that need to mangle
103 + packets going in or out of an ethernet device.
104 +
105 config WANT_COMPAT_NETLINK_MESSAGES
106 bool
107 help
108 Index: linux-4.9.34/net/core/dev.c
109 ===================================================================
110 --- linux-4.9.34.orig/net/core/dev.c
111 +++ linux-4.9.34/net/core/dev.c
112 @@ -2931,10 +2931,20 @@ static int xmit_one(struct sk_buff *skb,
113 if (!list_empty(&ptype_all) || !list_empty(&dev->ptype_all))
114 dev_queue_xmit_nit(skb, dev);
115
116 - len = skb->len;
117 - trace_net_dev_start_xmit(skb, dev);
118 - rc = netdev_start_xmit(skb, dev, txq, more);
119 - trace_net_dev_xmit(skb, rc, dev, len);
120 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
121 + if (!dev->eth_mangle_tx ||
122 + (skb = dev->eth_mangle_tx(dev, skb)) != NULL)
123 +#else
124 + if (1)
125 +#endif
126 + {
127 + len = skb->len;
128 + trace_net_dev_start_xmit(skb, dev);
129 + rc = netdev_start_xmit(skb, dev, txq, more);
130 + trace_net_dev_xmit(skb, rc, dev, len);
131 + } else {
132 + rc = NETDEV_TX_OK;
133 + }
134
135 return rc;
136 }
137 Index: linux-4.9.34/net/core/skbuff.c
138 ===================================================================
139 --- linux-4.9.34.orig/net/core/skbuff.c
140 +++ linux-4.9.34/net/core/skbuff.c
141 @@ -64,6 +64,7 @@
142 #include <linux/errqueue.h>
143 #include <linux/prefetch.h>
144 #include <linux/if_vlan.h>
145 +#include <linux/if.h>
146
147 #include <net/protocol.h>
148 #include <net/dst.h>
149 @@ -529,6 +530,22 @@ skb_fail:
150 }
151 EXPORT_SYMBOL(__napi_alloc_skb);
152
153 +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
154 + unsigned int length, gfp_t gfp)
155 +{
156 + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
157 +
158 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
159 + if (dev && (dev->priv_flags & IFF_NO_IP_ALIGN))
160 + return skb;
161 +#endif
162 +
163 + if (NET_IP_ALIGN && skb)
164 + skb_reserve(skb, NET_IP_ALIGN);
165 + return skb;
166 +}
167 +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
168 +
169 void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
170 int size, unsigned int truesize)
171 {
172 Index: linux-4.9.34/net/ethernet/eth.c
173 ===================================================================
174 --- linux-4.9.34.orig/net/ethernet/eth.c
175 +++ linux-4.9.34/net/ethernet/eth.c
176 @@ -171,6 +171,12 @@ __be16 eth_type_trans(struct sk_buff *sk
177 const struct ethhdr *eth;
178
179 skb->dev = dev;
180 +
181 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
182 + if (dev->eth_mangle_rx)
183 + dev->eth_mangle_rx(dev, skb);
184 +#endif
185 +
186 skb_reset_mac_header(skb);
187
188 eth = (struct ethhdr *)skb->data;