721-phy_packets.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. --- a/include/linux/netdevice.h
  2. +++ b/include/linux/netdevice.h
  3. @@ -1093,6 +1093,11 @@ struct net_device {
  4. const struct net_device_ops *netdev_ops;
  5. const struct ethtool_ops *ethtool_ops;
  6. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  7. + void (*eth_mangle_rx)(struct net_device *dev, struct sk_buff *skb);
  8. + struct sk_buff *(*eth_mangle_tx)(struct net_device *dev, struct sk_buff *skb);
  9. +#endif
  10. +
  11. /* Hardware header description */
  12. const struct header_ops *header_ops;
  13. @@ -1149,6 +1154,9 @@ struct net_device {
  14. void *ax25_ptr; /* AX.25 specific data */
  15. struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
  16. assign before registering */
  17. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  18. + void *phy_ptr; /* PHY device specific data */
  19. +#endif
  20. /*
  21. * Cache lines mostly used on receive path (including eth_type_trans())
  22. --- a/include/uapi/linux/if.h
  23. +++ b/include/uapi/linux/if.h
  24. @@ -83,6 +83,7 @@
  25. #define IFF_SUPP_NOFCS 0x80000 /* device supports sending custom FCS */
  26. #define IFF_LIVE_ADDR_CHANGE 0x100000 /* device supports hardware address
  27. * change when it's running */
  28. +#define IFF_NO_IP_ALIGN 0x200000 /* do not ip-align allocated rx pkts */
  29. #define IF_GET_IFACE 0x0001 /* for querying only */
  30. --- a/include/linux/skbuff.h
  31. +++ b/include/linux/skbuff.h
  32. @@ -1757,6 +1757,10 @@ static inline int pskb_trim(struct sk_bu
  33. return (len < skb->len) ? __pskb_trim(skb, len) : 0;
  34. }
  35. +extern struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  36. + unsigned int length, gfp_t gfp);
  37. +
  38. +
  39. /**
  40. * pskb_trim_unique - remove end from a paged unique (not cloned) buffer
  41. * @skb: buffer to alter
  42. @@ -1877,16 +1881,6 @@ static inline struct sk_buff *dev_alloc_
  43. }
  44. -static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  45. - unsigned int length, gfp_t gfp)
  46. -{
  47. - struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  48. -
  49. - if (NET_IP_ALIGN && skb)
  50. - skb_reserve(skb, NET_IP_ALIGN);
  51. - return skb;
  52. -}
  53. -
  54. static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
  55. unsigned int length)
  56. {
  57. --- a/net/Kconfig
  58. +++ b/net/Kconfig
  59. @@ -23,6 +23,12 @@ menuconfig NET
  60. if NET
  61. +config ETHERNET_PACKET_MANGLE
  62. + bool
  63. + help
  64. + This option can be selected by phy drivers that need to mangle
  65. + packets going in or out of an ethernet device.
  66. +
  67. config WANT_COMPAT_NETLINK_MESSAGES
  68. bool
  69. help
  70. --- a/net/core/dev.c
  71. +++ b/net/core/dev.c
  72. @@ -2364,9 +2364,19 @@ int dev_hard_start_xmit(struct sk_buff *
  73. if (!list_empty(&ptype_all))
  74. dev_queue_xmit_nit(skb, dev);
  75. - skb_len = skb->len;
  76. - rc = ops->ndo_start_xmit(skb, dev);
  77. - trace_net_dev_xmit(skb, rc, dev, skb_len);
  78. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  79. + if (!dev->eth_mangle_tx ||
  80. + (skb = dev->eth_mangle_tx(dev, skb)) != NULL)
  81. +#else
  82. + if (1)
  83. +#endif
  84. + {
  85. + skb_len = skb->len;
  86. + rc = ops->ndo_start_xmit(skb, dev);
  87. + trace_net_dev_xmit(skb, rc, dev, skb_len);
  88. + } else {
  89. + rc = NETDEV_TX_OK;
  90. + }
  91. if (rc == NETDEV_TX_OK)
  92. txq_trans_update(txq);
  93. return rc;
  94. @@ -2389,9 +2399,19 @@ gso:
  95. if (!list_empty(&ptype_all))
  96. dev_queue_xmit_nit(nskb, dev);
  97. - skb_len = nskb->len;
  98. - rc = ops->ndo_start_xmit(nskb, dev);
  99. - trace_net_dev_xmit(nskb, rc, dev, skb_len);
  100. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  101. + if (!dev->eth_mangle_tx ||
  102. + (nskb = dev->eth_mangle_tx(dev, nskb)) != NULL)
  103. +#else
  104. + if (1)
  105. +#endif
  106. + {
  107. + skb_len = nskb->len;
  108. + rc = ops->ndo_start_xmit(nskb, dev);
  109. + trace_net_dev_xmit(nskb, rc, dev, skb_len);
  110. + } else {
  111. + rc = NETDEV_TX_OK;
  112. + }
  113. if (unlikely(rc != NETDEV_TX_OK)) {
  114. if (rc & ~NETDEV_TX_MASK)
  115. goto out_kfree_gso_skb;
  116. --- a/net/core/skbuff.c
  117. +++ b/net/core/skbuff.c
  118. @@ -60,6 +60,7 @@
  119. #include <linux/scatterlist.h>
  120. #include <linux/errqueue.h>
  121. #include <linux/prefetch.h>
  122. +#include <linux/if.h>
  123. #include <net/protocol.h>
  124. #include <net/dst.h>
  125. @@ -455,6 +456,22 @@ struct sk_buff *__netdev_alloc_skb(struc
  126. }
  127. EXPORT_SYMBOL(__netdev_alloc_skb);
  128. +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  129. + unsigned int length, gfp_t gfp)
  130. +{
  131. + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  132. +
  133. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  134. + if (dev && (dev->priv_flags & IFF_NO_IP_ALIGN))
  135. + return skb;
  136. +#endif
  137. +
  138. + if (NET_IP_ALIGN && skb)
  139. + skb_reserve(skb, NET_IP_ALIGN);
  140. + return skb;
  141. +}
  142. +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
  143. +
  144. void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
  145. int size, unsigned int truesize)
  146. {
  147. --- a/net/ethernet/eth.c
  148. +++ b/net/ethernet/eth.c
  149. @@ -159,6 +159,12 @@ __be16 eth_type_trans(struct sk_buff *sk
  150. struct ethhdr *eth;
  151. skb->dev = dev;
  152. +
  153. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  154. + if (dev->eth_mangle_rx)
  155. + dev->eth_mangle_rx(dev, skb);
  156. +#endif
  157. +
  158. skb_reset_mac_header(skb);
  159. skb_pull_inline(skb, ETH_HLEN);
  160. eth = eth_hdr(skb);