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
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
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
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(-)
20 --- a/include/linux/netdevice.h
21 +++ b/include/linux/netdevice.h
22 @@ -1682,6 +1682,10 @@ enum netdev_priv_flags {
23 IFF_TX_SKB_NO_LINEAR = BIT_ULL(31),
26 +enum netdev_extra_priv_flags {
27 + IFF_NO_IP_ALIGN = 1<<0,
30 #define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
31 #define IFF_EBRIDGE IFF_EBRIDGE
32 #define IFF_BONDING IFF_BONDING
33 @@ -1713,6 +1717,7 @@ enum netdev_priv_flags {
34 #define IFF_FAILOVER_SLAVE IFF_FAILOVER_SLAVE
35 #define IFF_L3MDEV_RX_HANDLER IFF_L3MDEV_RX_HANDLER
36 #define IFF_TX_SKB_NO_LINEAR IFF_TX_SKB_NO_LINEAR
37 +#define IFF_NO_IP_ALIGN IFF_NO_IP_ALIGN
39 /* Specifies the type of the struct net_device::ml_priv pointer */
40 enum netdev_ml_priv_type {
41 @@ -2013,6 +2018,7 @@ struct net_device {
42 /* Read-mostly cache-line for fast-path access */
44 unsigned int priv_flags;
45 + unsigned int extra_priv_flags;
46 const struct net_device_ops *netdev_ops;
48 unsigned short gflags;
49 @@ -2073,6 +2079,11 @@ struct net_device {
50 const struct tlsdev_ops *tlsdev_ops;
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);
58 const struct header_ops *header_ops;
60 unsigned char operstate;
61 @@ -2144,6 +2155,10 @@ struct net_device {
62 struct mctp_dev __rcu *mctp_ptr;
65 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
66 + void *phy_ptr; /* PHY device specific data */
70 * Cache lines mostly used on receive path (including eth_type_trans())
72 --- a/include/linux/skbuff.h
73 +++ b/include/linux/skbuff.h
74 @@ -2855,6 +2855,10 @@ static inline int pskb_trim(struct sk_bu
75 return (len < skb->len) ? __pskb_trim(skb, len) : 0;
78 +extern struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
79 + unsigned int length, gfp_t gfp);
83 * pskb_trim_unique - remove end from a paged unique (not cloned) buffer
84 * @skb: buffer to alter
85 @@ -3005,16 +3009,6 @@ static inline struct sk_buff *dev_alloc_
89 -static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
90 - unsigned int length, gfp_t gfp)
92 - struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
94 - if (NET_IP_ALIGN && skb)
95 - skb_reserve(skb, NET_IP_ALIGN);
99 static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
104 @@ -26,6 +26,12 @@ menuconfig NET
108 +config ETHERNET_PACKET_MANGLE
111 + This option can be selected by phy drivers that need to mangle
112 + packets going in or out of an ethernet device.
114 config WANT_COMPAT_NETLINK_MESSAGES
119 @@ -3600,6 +3600,11 @@ static int xmit_one(struct sk_buff *skb,
120 if (dev_nit_active(dev))
121 dev_queue_xmit_nit(skb, dev);
123 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
124 + if (dev->eth_mangle_tx && !(skb = dev->eth_mangle_tx(dev, skb)))
125 + return NETDEV_TX_OK;
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
134 #include <linux/if_vlan.h>
135 #include <linux/mpls.h>
136 #include <linux/kcov.h>
137 +#include <linux/if.h>
139 #include <net/protocol.h>
141 @@ -602,6 +603,22 @@ skb_fail:
143 EXPORT_SYMBOL(__napi_alloc_skb);
145 +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
146 + unsigned int length, gfp_t gfp)
148 + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
150 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
151 + if (dev && (dev->extra_priv_flags & IFF_NO_IP_ALIGN))
155 + if (NET_IP_ALIGN && skb)
156 + skb_reserve(skb, NET_IP_ALIGN);
159 +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
161 void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
162 int size, unsigned int truesize)
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;
171 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
172 + if (dev->eth_mangle_rx)
173 + dev->eth_mangle_rx(dev, skb);
176 skb_reset_mac_header(skb);
178 eth = (struct ethhdr *)skb->data;