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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 | 10 ++++++++++
  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, 58 insertions(+), 15 deletions(-)
  17. --- a/include/linux/netdevice.h
  18. +++ b/include/linux/netdevice.h
  19. @@ -1687,6 +1687,7 @@ enum netdev_priv_flags {
  20. IFF_L3MDEV_RX_HANDLER = 1<<29,
  21. IFF_NO_ADDRCONF = BIT_ULL(30),
  22. IFF_TX_SKB_NO_LINEAR = BIT_ULL(31),
  23. + IFF_NO_IP_ALIGN = BIT_ULL(32),
  24. };
  25. /* Specifies the type of the struct net_device::ml_priv pointer */
  26. @@ -2168,6 +2169,11 @@ struct net_device {
  27. const struct tlsdev_ops *tlsdev_ops;
  28. #endif
  29. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  30. + void (*eth_mangle_rx)(struct net_device *dev, struct sk_buff *skb);
  31. + struct sk_buff *(*eth_mangle_tx)(struct net_device *dev, struct sk_buff *skb);
  32. +#endif
  33. +
  34. unsigned int operstate;
  35. unsigned char link_mode;
  36. @@ -2237,6 +2243,10 @@ struct net_device {
  37. struct mctp_dev __rcu *mctp_ptr;
  38. #endif
  39. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  40. + void *phy_ptr; /* PHY device specific data */
  41. +#endif
  42. +
  43. /*
  44. * Cache lines mostly used on receive path (including eth_type_trans())
  45. */
  46. --- a/include/linux/skbuff.h
  47. +++ b/include/linux/skbuff.h
  48. @@ -3213,6 +3213,10 @@ static inline int pskb_trim(struct sk_bu
  49. return (len < skb->len) ? __pskb_trim(skb, len) : 0;
  50. }
  51. +extern struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  52. + unsigned int length, gfp_t gfp);
  53. +
  54. +
  55. /**
  56. * pskb_trim_unique - remove end from a paged unique (not cloned) buffer
  57. * @skb: buffer to alter
  58. @@ -3378,16 +3382,6 @@ static inline struct sk_buff *dev_alloc_
  59. }
  60. -static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  61. - unsigned int length, gfp_t gfp)
  62. -{
  63. - struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  64. -
  65. - if (NET_IP_ALIGN && skb)
  66. - skb_reserve(skb, NET_IP_ALIGN);
  67. - return skb;
  68. -}
  69. -
  70. static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
  71. unsigned int length)
  72. {
  73. --- a/net/Kconfig
  74. +++ b/net/Kconfig
  75. @@ -26,6 +26,12 @@ menuconfig NET
  76. if NET
  77. +config ETHERNET_PACKET_MANGLE
  78. + bool
  79. + help
  80. + This option can be selected by phy drivers that need to mangle
  81. + packets going in or out of an ethernet device.
  82. +
  83. config WANT_COMPAT_NETLINK_MESSAGES
  84. bool
  85. help
  86. --- a/net/core/dev.c
  87. +++ b/net/core/dev.c
  88. @@ -3646,6 +3646,11 @@ static int xmit_one(struct sk_buff *skb,
  89. if (dev_nit_active(dev))
  90. dev_queue_xmit_nit(skb, dev);
  91. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  92. + if (dev->eth_mangle_tx && !(skb = dev->eth_mangle_tx(dev, skb)))
  93. + return NETDEV_TX_OK;
  94. +#endif
  95. +
  96. len = skb->len;
  97. trace_net_dev_start_xmit(skb, dev);
  98. rc = netdev_start_xmit(skb, dev, txq, more);
  99. --- a/net/core/skbuff.c
  100. +++ b/net/core/skbuff.c
  101. @@ -64,6 +64,7 @@
  102. #include <linux/mpls.h>
  103. #include <linux/kcov.h>
  104. #include <linux/iov_iter.h>
  105. +#include <linux/if.h>
  106. #include <net/protocol.h>
  107. #include <net/dst.h>
  108. @@ -326,6 +327,22 @@ void *__napi_alloc_frag_align(unsigned i
  109. }
  110. EXPORT_SYMBOL(__napi_alloc_frag_align);
  111. +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  112. + unsigned int length, gfp_t gfp)
  113. +{
  114. + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  115. +
  116. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  117. + if (dev && (dev->priv_flags & IFF_NO_IP_ALIGN))
  118. + return skb;
  119. +#endif
  120. +
  121. + if (NET_IP_ALIGN && skb)
  122. + skb_reserve(skb, NET_IP_ALIGN);
  123. + return skb;
  124. +}
  125. +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
  126. +
  127. void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask)
  128. {
  129. void *data;
  130. --- a/net/ethernet/eth.c
  131. +++ b/net/ethernet/eth.c
  132. @@ -159,6 +159,12 @@ __be16 eth_type_trans(struct sk_buff *sk
  133. const struct ethhdr *eth;
  134. skb->dev = dev;
  135. +
  136. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  137. + if (dev->eth_mangle_rx)
  138. + dev->eth_mangle_rx(dev, skb);
  139. +#endif
  140. +
  141. skb_reset_mac_header(skb);
  142. eth = eth_skb_pull_mac(skb);