721-phy_packets.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. --- a/include/linux/netdevice.h
  2. +++ b/include/linux/netdevice.h
  3. @@ -1227,6 +1227,11 @@ struct net_device {
  4. const struct ethtool_ops *ethtool_ops;
  5. const struct forwarding_accel_ops *fwd_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. @@ -1292,6 +1297,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. @@ -84,6 +84,7 @@
  25. #define IFF_LIVE_ADDR_CHANGE 0x100000 /* device supports hardware address
  26. * change when it's running */
  27. #define IFF_MACVLAN 0x200000 /* Macvlan device */
  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. @@ -1776,6 +1776,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. @@ -1902,16 +1906,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. @@ -24,6 +24,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. @@ -2606,10 +2606,20 @@ 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. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  78. + if (!dev->eth_mangle_tx ||
  79. + (skb = dev->eth_mangle_tx(dev, skb)) != NULL)
  80. +#else
  81. + if (1)
  82. +#endif
  83. + {
  84. + skb_len = skb->len;
  85. + rc = ops->ndo_start_xmit(skb, dev);
  86. - trace_net_dev_xmit(skb, rc, dev, skb_len);
  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. --- a/net/core/skbuff.c
  95. +++ b/net/core/skbuff.c
  96. @@ -62,6 +62,7 @@
  97. #include <linux/scatterlist.h>
  98. #include <linux/errqueue.h>
  99. #include <linux/prefetch.h>
  100. +#include <linux/if.h>
  101. #include <net/protocol.h>
  102. #include <net/dst.h>
  103. @@ -438,6 +439,22 @@ struct sk_buff *__netdev_alloc_skb(struc
  104. }
  105. EXPORT_SYMBOL(__netdev_alloc_skb);
  106. +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  107. + unsigned int length, gfp_t gfp)
  108. +{
  109. + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  110. +
  111. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  112. + if (dev && (dev->priv_flags & IFF_NO_IP_ALIGN))
  113. + return skb;
  114. +#endif
  115. +
  116. + if (NET_IP_ALIGN && skb)
  117. + skb_reserve(skb, NET_IP_ALIGN);
  118. + return skb;
  119. +}
  120. +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
  121. +
  122. void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
  123. int size, unsigned int truesize)
  124. {
  125. --- a/net/ethernet/eth.c
  126. +++ b/net/ethernet/eth.c
  127. @@ -159,6 +159,12 @@ __be16 eth_type_trans(struct sk_buff *sk
  128. 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);