721-phy_packets.patch 4.7 KB

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