721-phy_packets.patch 5.4 KB

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