721-phy_packets.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. --- a/include/linux/netdevice.h
  2. +++ b/include/linux/netdevice.h
  3. @@ -1078,6 +1078,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. @@ -1134,6 +1139,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/linux/if.h
  23. +++ b/include/linux/if.h
  24. @@ -80,6 +80,7 @@
  25. * skbs on transmit */
  26. #define IFF_UNICAST_FLT 0x20000 /* Supports unicast filtering */
  27. #define IFF_TEAM_PORT 0x40000 /* device used as team port */
  28. +#define IFF_NO_IP_ALIGN 0x80000 /* do not ip-align allocated rx pkts */
  29. #define IF_GET_IFACE 0x0001 /* for querying only */
  30. #define IF_GET_PROTO 0x0002
  31. --- a/include/linux/skbuff.h
  32. +++ b/include/linux/skbuff.h
  33. @@ -1661,6 +1661,10 @@ extern struct sk_buff *dev_alloc_skb(uns
  34. extern struct sk_buff *__netdev_alloc_skb(struct net_device *dev,
  35. unsigned int length, gfp_t gfp_mask);
  36. +extern struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  37. + unsigned int length, gfp_t gfp);
  38. +
  39. +
  40. /**
  41. * netdev_alloc_skb - allocate an skbuff for rx on a specific device
  42. * @dev: network device to receive on
  43. @@ -1680,16 +1684,6 @@ static inline struct sk_buff *netdev_all
  44. return __netdev_alloc_skb(dev, length, GFP_ATOMIC);
  45. }
  46. -static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  47. - unsigned int length, gfp_t gfp)
  48. -{
  49. - struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  50. -
  51. - if (NET_IP_ALIGN && skb)
  52. - skb_reserve(skb, NET_IP_ALIGN);
  53. - return skb;
  54. -}
  55. -
  56. static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
  57. unsigned int length)
  58. {
  59. --- a/net/Kconfig
  60. +++ b/net/Kconfig
  61. @@ -23,6 +23,12 @@ menuconfig NET
  62. if NET
  63. +config ETHERNET_PACKET_MANGLE
  64. + bool
  65. + help
  66. + This option can be selected by phy drivers that need to mangle
  67. + packets going in or out of an ethernet device.
  68. +
  69. config WANT_COMPAT_NETLINK_MESSAGES
  70. bool
  71. help
  72. --- a/net/core/dev.c
  73. +++ b/net/core/dev.c
  74. @@ -2267,9 +2267,19 @@ int dev_hard_start_xmit(struct sk_buff *
  75. }
  76. }
  77. - skb_len = skb->len;
  78. - rc = ops->ndo_start_xmit(skb, dev);
  79. - trace_net_dev_xmit(skb, rc, dev, skb_len);
  80. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  81. + if (!dev->eth_mangle_tx ||
  82. + (skb = dev->eth_mangle_tx(dev, skb)) != NULL)
  83. +#else
  84. + if (1)
  85. +#endif
  86. + {
  87. + skb_len = skb->len;
  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. @@ -2289,9 +2299,19 @@ gso:
  97. if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
  98. skb_dst_drop(nskb);
  99. - skb_len = nskb->len;
  100. - rc = ops->ndo_start_xmit(nskb, dev);
  101. - trace_net_dev_xmit(nskb, rc, dev, skb_len);
  102. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  103. + if (!dev->eth_mangle_tx ||
  104. + (nskb = dev->eth_mangle_tx(dev, nskb)) != NULL)
  105. +#else
  106. + if (1)
  107. +#endif
  108. + {
  109. + skb_len = nskb->len;
  110. + rc = ops->ndo_start_xmit(nskb, dev);
  111. + trace_net_dev_xmit(nskb, rc, dev, skb_len);
  112. + } else {
  113. + rc = NETDEV_TX_OK;
  114. + }
  115. if (unlikely(rc != NETDEV_TX_OK)) {
  116. if (rc & ~NETDEV_TX_MASK)
  117. goto out_kfree_gso_skb;
  118. --- a/net/core/skbuff.c
  119. +++ b/net/core/skbuff.c
  120. @@ -58,6 +58,7 @@
  121. #include <linux/scatterlist.h>
  122. #include <linux/errqueue.h>
  123. #include <linux/prefetch.h>
  124. +#include <linux/if.h>
  125. #include <net/protocol.h>
  126. #include <net/dst.h>
  127. @@ -320,6 +321,22 @@ struct sk_buff *__netdev_alloc_skb(struc
  128. }
  129. EXPORT_SYMBOL(__netdev_alloc_skb);
  130. +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  131. + unsigned int length, gfp_t gfp)
  132. +{
  133. + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  134. +
  135. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  136. + if (dev && (dev->priv_flags & IFF_NO_IP_ALIGN))
  137. + return skb;
  138. +#endif
  139. +
  140. + if (NET_IP_ALIGN && skb)
  141. + skb_reserve(skb, NET_IP_ALIGN);
  142. + return skb;
  143. +}
  144. +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
  145. +
  146. void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
  147. int size)
  148. {
  149. --- a/net/ethernet/eth.c
  150. +++ b/net/ethernet/eth.c
  151. @@ -160,6 +160,12 @@ __be16 eth_type_trans(struct sk_buff *sk
  152. struct ethhdr *eth;
  153. skb->dev = dev;
  154. +
  155. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  156. + if (dev->eth_mangle_rx)
  157. + dev->eth_mangle_rx(dev, skb);
  158. +#endif
  159. +
  160. skb_reset_mac_header(skb);
  161. skb_pull_inline(skb, ETH_HLEN);
  162. eth = eth_hdr(skb);