721-phy_packets.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. --- a/include/linux/netdevice.h
  2. +++ b/include/linux/netdevice.h
  3. @@ -1245,6 +1245,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. @@ -1313,6 +1318,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. @@ -1858,6 +1858,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. @@ -1984,16 +1988,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. @@ -2607,10 +2607,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. - trace_net_dev_start_xmit(skb, dev);
  77. - rc = ops->ndo_start_xmit(skb, dev);
  78. - trace_net_dev_xmit(skb, rc, dev, skb_len);
  79. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  80. + if (!dev->eth_mangle_tx ||
  81. + (skb = dev->eth_mangle_tx(dev, skb)) != NULL)
  82. +#else
  83. + if (1)
  84. +#endif
  85. + {
  86. + skb_len = skb->len;
  87. + trace_net_dev_start_xmit(skb, dev);
  88. + rc = ops->ndo_start_xmit(skb, dev);
  89. + trace_net_dev_xmit(skb, rc, dev, skb_len);
  90. + } else {
  91. + rc = NETDEV_TX_OK;
  92. + }
  93. if (rc == NETDEV_TX_OK)
  94. txq_trans_update(txq);
  95. return rc;
  96. --- a/net/core/skbuff.c
  97. +++ b/net/core/skbuff.c
  98. @@ -62,6 +62,7 @@
  99. #include <linux/scatterlist.h>
  100. #include <linux/errqueue.h>
  101. #include <linux/prefetch.h>
  102. +#include <linux/if.h>
  103. #include <net/protocol.h>
  104. #include <net/dst.h>
  105. @@ -439,6 +440,22 @@ struct sk_buff *__netdev_alloc_skb(struc
  106. }
  107. EXPORT_SYMBOL(__netdev_alloc_skb);
  108. +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  109. + unsigned int length, gfp_t gfp)
  110. +{
  111. + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  112. +
  113. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  114. + if (dev && (dev->priv_flags & IFF_NO_IP_ALIGN))
  115. + return skb;
  116. +#endif
  117. +
  118. + if (NET_IP_ALIGN && skb)
  119. + skb_reserve(skb, NET_IP_ALIGN);
  120. + return skb;
  121. +}
  122. +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
  123. +
  124. void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
  125. int size, unsigned int truesize)
  126. {
  127. --- a/net/ethernet/eth.c
  128. +++ b/net/ethernet/eth.c
  129. @@ -161,6 +161,12 @@ __be16 eth_type_trans(struct sk_buff *sk
  130. const struct ethhdr *eth;
  131. skb->dev = dev;
  132. +
  133. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  134. + if (dev->eth_mangle_rx)
  135. + dev->eth_mangle_rx(dev, skb);
  136. +#endif
  137. +
  138. skb_reset_mac_header(skb);
  139. skb_pull_inline(skb, ETH_HLEN);
  140. eth = eth_hdr(skb);