0018-net-allow-PHY-drivers-to-insert-packet-mangle-hooks.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. diff -Nur linux-4.1.6.orig/include/linux/netdevice.h linux-4.1.6/include/linux/netdevice.h
  2. --- linux-4.1.6.orig/include/linux/netdevice.h 2015-09-13 22:24:50.977669635 +0200
  3. +++ linux-4.1.6/include/linux/netdevice.h 2015-09-13 22:25:26.259637337 +0200
  4. @@ -1270,6 +1270,7 @@
  5. IFF_XMIT_DST_RELEASE_PERM = 1<<22,
  6. IFF_IPVLAN_MASTER = 1<<23,
  7. IFF_IPVLAN_SLAVE = 1<<24,
  8. + IFF_NO_IP_ALIGN = 1<<25,
  9. };
  10. #define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
  11. @@ -1297,6 +1298,7 @@
  12. #define IFF_XMIT_DST_RELEASE_PERM IFF_XMIT_DST_RELEASE_PERM
  13. #define IFF_IPVLAN_MASTER IFF_IPVLAN_MASTER
  14. #define IFF_IPVLAN_SLAVE IFF_IPVLAN_SLAVE
  15. +#define IFF_NO_IP_ALIGN IFF_NO_IP_ALIGN
  16. /**
  17. * struct net_device - The DEVICE structure.
  18. @@ -1567,6 +1569,11 @@
  19. const struct swdev_ops *swdev_ops;
  20. #endif
  21. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  22. + void (*eth_mangle_rx)(struct net_device *dev, struct sk_buff *skb);
  23. + struct sk_buff *(*eth_mangle_tx)(struct net_device *dev, struct sk_buff *skb);
  24. +#endif
  25. +
  26. const struct header_ops *header_ops;
  27. unsigned int flags;
  28. @@ -1631,6 +1638,10 @@
  29. struct mpls_dev __rcu *mpls_ptr;
  30. #endif
  31. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  32. + void *phy_ptr; /* PHY device specific data */
  33. +#endif
  34. +
  35. /*
  36. * Cache lines mostly used on receive path (including eth_type_trans())
  37. */
  38. diff -Nur linux-4.1.6.orig/include/linux/skbuff.h linux-4.1.6/include/linux/skbuff.h
  39. --- linux-4.1.6.orig/include/linux/skbuff.h 2015-09-13 22:24:50.981669405 +0200
  40. +++ linux-4.1.6/include/linux/skbuff.h 2015-09-13 22:25:26.267636876 +0200
  41. @@ -2068,6 +2068,10 @@
  42. return (len < skb->len) ? __pskb_trim(skb, len) : 0;
  43. }
  44. +extern struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  45. + unsigned int length, gfp_t gfp);
  46. +
  47. +
  48. /**
  49. * pskb_trim_unique - remove end from a paged unique (not cloned) buffer
  50. * @skb: buffer to alter
  51. @@ -2176,16 +2180,6 @@
  52. }
  53. -static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  54. - unsigned int length, gfp_t gfp)
  55. -{
  56. - struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  57. -
  58. - if (NET_IP_ALIGN && skb)
  59. - skb_reserve(skb, NET_IP_ALIGN);
  60. - return skb;
  61. -}
  62. -
  63. static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
  64. unsigned int length)
  65. {
  66. diff -Nur linux-4.1.6.orig/net/core/dev.c linux-4.1.6/net/core/dev.c
  67. --- linux-4.1.6.orig/net/core/dev.c 2015-09-13 22:24:51.109662032 +0200
  68. +++ linux-4.1.6/net/core/dev.c 2015-09-13 22:25:26.267636876 +0200
  69. @@ -2657,10 +2657,20 @@
  70. if (!list_empty(&ptype_all) || !list_empty(&dev->ptype_all))
  71. dev_queue_xmit_nit(skb, dev);
  72. - len = skb->len;
  73. - trace_net_dev_start_xmit(skb, dev);
  74. - rc = netdev_start_xmit(skb, dev, txq, more);
  75. - trace_net_dev_xmit(skb, rc, dev, len);
  76. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  77. + if (!dev->eth_mangle_tx ||
  78. + (skb = dev->eth_mangle_tx(dev, skb)) != NULL)
  79. +#else
  80. + if (1)
  81. +#endif
  82. + {
  83. + len = skb->len;
  84. + trace_net_dev_start_xmit(skb, dev);
  85. + rc = netdev_start_xmit(skb, dev, txq, more);
  86. + trace_net_dev_xmit(skb, rc, dev, len);
  87. + } else {
  88. + rc = NETDEV_TX_OK;
  89. + }
  90. return rc;
  91. }
  92. diff -Nur linux-4.1.6.orig/net/core/skbuff.c linux-4.1.6/net/core/skbuff.c
  93. --- linux-4.1.6.orig/net/core/skbuff.c 2015-09-13 22:24:51.113661802 +0200
  94. +++ linux-4.1.6/net/core/skbuff.c 2015-09-13 22:25:49.410303821 +0200
  95. @@ -63,6 +63,7 @@
  96. #include <linux/errqueue.h>
  97. #include <linux/prefetch.h>
  98. #include <linux/if_vlan.h>
  99. +#include <linux/if.h>
  100. #include <linux/locallock.h>
  101. #include <net/protocol.h>
  102. @@ -570,6 +571,22 @@
  103. }
  104. EXPORT_SYMBOL(__napi_alloc_skb);
  105. +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  106. + unsigned int length, gfp_t gfp)
  107. +{
  108. + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  109. +
  110. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  111. + if (dev && (dev->priv_flags & IFF_NO_IP_ALIGN))
  112. + return skb;
  113. +#endif
  114. +
  115. + if (NET_IP_ALIGN && skb)
  116. + skb_reserve(skb, NET_IP_ALIGN);
  117. + return skb;
  118. +}
  119. +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
  120. +
  121. void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
  122. int size, unsigned int truesize)
  123. {
  124. diff -Nur linux-4.1.6.orig/net/ethernet/eth.c linux-4.1.6/net/ethernet/eth.c
  125. --- linux-4.1.6.orig/net/ethernet/eth.c 2015-08-17 05:52:51.000000000 +0200
  126. +++ linux-4.1.6/net/ethernet/eth.c 2015-09-13 22:25:26.271636646 +0200
  127. @@ -155,6 +155,12 @@
  128. const struct ethhdr *eth;
  129. skb->dev = dev;
  130. +
  131. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  132. + if (dev->eth_mangle_rx)
  133. + dev->eth_mangle_rx(dev, skb);
  134. +#endif
  135. +
  136. skb_reset_mac_header(skb);
  137. skb_pull_inline(skb, ETH_HLEN);
  138. eth = eth_hdr(skb);
  139. diff -Nur linux-4.1.6.orig/net/Kconfig linux-4.1.6/net/Kconfig
  140. --- linux-4.1.6.orig/net/Kconfig 2015-08-17 05:52:51.000000000 +0200
  141. +++ linux-4.1.6/net/Kconfig 2015-09-13 22:25:26.279636185 +0200
  142. @@ -25,6 +25,12 @@
  143. if NET
  144. +config ETHERNET_PACKET_MANGLE
  145. + bool
  146. + help
  147. + This option can be selected by phy drivers that need to mangle
  148. + packets going in or out of an ethernet device.
  149. +
  150. config WANT_COMPAT_NETLINK_MESSAGES
  151. bool
  152. help