fec1839a41585ee4fbe2496caca7cc7e7ac2325b
[openwrt/openwrt.git] / target / linux / generic / patches-3.14 / 721-phy_packets.patch
1 --- a/include/linux/netdevice.h
2 +++ b/include/linux/netdevice.h
3 @@ -1245,6 +1245,11 @@ struct net_device {
4 const struct ethtool_ops *ethtool_ops;
5 const struct forwarding_accel_ops *fwd_ops;
6
7 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
8 + void (*eth_mangle_rx)(struct net_device *dev, struct sk_buff *skb);
9 + struct sk_buff *(*eth_mangle_tx)(struct net_device *dev, struct sk_buff *skb);
10 +#endif
11 +
12 /* Hardware header description */
13 const struct header_ops *header_ops;
14
15 @@ -1313,6 +1318,9 @@ struct net_device {
16 void *ax25_ptr; /* AX.25 specific data */
17 struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
18 assign before registering */
19 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
20 + void *phy_ptr; /* PHY device specific data */
21 +#endif
22
23 /*
24 * Cache lines mostly used on receive path (including eth_type_trans())
25 --- a/include/uapi/linux/if.h
26 +++ b/include/uapi/linux/if.h
27 @@ -84,6 +84,7 @@
28 #define IFF_LIVE_ADDR_CHANGE 0x100000 /* device supports hardware address
29 * change when it's running */
30 #define IFF_MACVLAN 0x200000 /* Macvlan device */
31 +#define IFF_NO_IP_ALIGN 0x400000 /* do not ip-align allocated rx pkts */
32
33
34 #define IF_GET_IFACE 0x0001 /* for querying only */
35 --- a/include/linux/skbuff.h
36 +++ b/include/linux/skbuff.h
37 @@ -1858,6 +1858,10 @@ static inline int pskb_trim(struct sk_bu
38 return (len < skb->len) ? __pskb_trim(skb, len) : 0;
39 }
40
41 +extern struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
42 + unsigned int length, gfp_t gfp);
43 +
44 +
45 /**
46 * pskb_trim_unique - remove end from a paged unique (not cloned) buffer
47 * @skb: buffer to alter
48 @@ -1984,16 +1988,6 @@ static inline struct sk_buff *dev_alloc_
49 }
50
51
52 -static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
53 - unsigned int length, gfp_t gfp)
54 -{
55 - struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
56 -
57 - if (NET_IP_ALIGN && skb)
58 - skb_reserve(skb, NET_IP_ALIGN);
59 - return skb;
60 -}
61 -
62 static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
63 unsigned int length)
64 {
65 --- a/net/Kconfig
66 +++ b/net/Kconfig
67 @@ -24,6 +24,12 @@ menuconfig NET
68
69 if NET
70
71 +config ETHERNET_PACKET_MANGLE
72 + bool
73 + help
74 + This option can be selected by phy drivers that need to mangle
75 + packets going in or out of an ethernet device.
76 +
77 config WANT_COMPAT_NETLINK_MESSAGES
78 bool
79 help
80 --- a/net/core/dev.c
81 +++ b/net/core/dev.c
82 @@ -2618,10 +2618,20 @@ int dev_hard_start_xmit(struct sk_buff *
83 if (!list_empty(&ptype_all))
84 dev_queue_xmit_nit(skb, dev);
85
86 - skb_len = skb->len;
87 - trace_net_dev_start_xmit(skb, dev);
88 - rc = ops->ndo_start_xmit(skb, dev);
89 - trace_net_dev_xmit(skb, rc, dev, skb_len);
90 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
91 + if (!dev->eth_mangle_tx ||
92 + (skb = dev->eth_mangle_tx(dev, skb)) != NULL)
93 +#else
94 + if (1)
95 +#endif
96 + {
97 + skb_len = skb->len;
98 + trace_net_dev_start_xmit(skb, dev);
99 + rc = ops->ndo_start_xmit(skb, dev);
100 + trace_net_dev_xmit(skb, rc, dev, skb_len);
101 + } else {
102 + rc = NETDEV_TX_OK;
103 + }
104 if (rc == NETDEV_TX_OK)
105 txq_trans_update(txq);
106 return rc;
107 --- a/net/core/skbuff.c
108 +++ b/net/core/skbuff.c
109 @@ -63,6 +63,7 @@
110 #include <linux/errqueue.h>
111 #include <linux/prefetch.h>
112 #include <linux/if_vlan.h>
113 +#include <linux/if.h>
114
115 #include <net/protocol.h>
116 #include <net/dst.h>
117 @@ -440,6 +441,22 @@ struct sk_buff *__netdev_alloc_skb(struc
118 }
119 EXPORT_SYMBOL(__netdev_alloc_skb);
120
121 +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
122 + unsigned int length, gfp_t gfp)
123 +{
124 + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
125 +
126 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
127 + if (dev && (dev->priv_flags & IFF_NO_IP_ALIGN))
128 + return skb;
129 +#endif
130 +
131 + if (NET_IP_ALIGN && skb)
132 + skb_reserve(skb, NET_IP_ALIGN);
133 + return skb;
134 +}
135 +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
136 +
137 void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
138 int size, unsigned int truesize)
139 {
140 --- a/net/ethernet/eth.c
141 +++ b/net/ethernet/eth.c
142 @@ -161,6 +161,12 @@ __be16 eth_type_trans(struct sk_buff *sk
143 const struct ethhdr *eth;
144
145 skb->dev = dev;
146 +
147 +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
148 + if (dev->eth_mangle_rx)
149 + dev->eth_mangle_rx(dev, skb);
150 +#endif
151 +
152 skb_reset_mac_header(skb);
153 skb_pull_inline(skb, ETH_HLEN);
154 eth = eth_hdr(skb);