721-net-add-packet-mangeling.patch 4.9 KB

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