721-phy_packets.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. --- a/include/linux/netdevice.h
  2. +++ b/include/linux/netdevice.h
  3. @@ -1228,6 +1228,7 @@ enum netdev_priv_flags {
  4. IFF_LIVE_ADDR_CHANGE = 1<<20,
  5. IFF_MACVLAN = 1<<21,
  6. IFF_XMIT_DST_RELEASE_PERM = 1<<22,
  7. + IFF_NO_IP_ALIGN = 1<<23,
  8. };
  9. #define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
  10. @@ -1253,6 +1254,7 @@ enum netdev_priv_flags {
  11. #define IFF_LIVE_ADDR_CHANGE IFF_LIVE_ADDR_CHANGE
  12. #define IFF_MACVLAN IFF_MACVLAN
  13. #define IFF_XMIT_DST_RELEASE_PERM IFF_XMIT_DST_RELEASE_PERM
  14. +#define IFF_NO_IP_ALIGN IFF_NO_IP_ALIGN
  15. /**
  16. * struct net_device - The DEVICE structure.
  17. @@ -1523,6 +1525,11 @@ struct net_device {
  18. const struct ethtool_ops *ethtool_ops;
  19. const struct forwarding_accel_ops *fwd_ops;
  20. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  21. + void (*eth_mangle_rx)(struct net_device *dev, struct sk_buff *skb);
  22. + struct sk_buff *(*eth_mangle_tx)(struct net_device *dev, struct sk_buff *skb);
  23. +#endif
  24. +
  25. const struct header_ops *header_ops;
  26. unsigned int flags;
  27. @@ -1587,6 +1594,10 @@ struct net_device {
  28. void *ax25_ptr;
  29. struct wireless_dev *ieee80211_ptr;
  30. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  31. + void *phy_ptr; /* PHY device specific data */
  32. +#endif
  33. +
  34. /*
  35. * Cache lines mostly used on receive path (including eth_type_trans())
  36. */
  37. --- a/include/linux/skbuff.h
  38. +++ b/include/linux/skbuff.h
  39. @@ -2054,6 +2054,10 @@ static inline int pskb_trim(struct sk_bu
  40. return (len < skb->len) ? __pskb_trim(skb, len) : 0;
  41. }
  42. +extern struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  43. + unsigned int length, gfp_t gfp);
  44. +
  45. +
  46. /**
  47. * pskb_trim_unique - remove end from a paged unique (not cloned) buffer
  48. * @skb: buffer to alter
  49. @@ -2180,16 +2184,6 @@ static inline struct sk_buff *dev_alloc_
  50. }
  51. -static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  52. - unsigned int length, gfp_t gfp)
  53. -{
  54. - struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  55. -
  56. - if (NET_IP_ALIGN && skb)
  57. - skb_reserve(skb, NET_IP_ALIGN);
  58. - return skb;
  59. -}
  60. -
  61. static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
  62. unsigned int length)
  63. {
  64. --- a/net/Kconfig
  65. +++ b/net/Kconfig
  66. @@ -25,6 +25,12 @@ menuconfig NET
  67. if NET
  68. +config ETHERNET_PACKET_MANGLE
  69. + bool
  70. + help
  71. + This option can be selected by phy drivers that need to mangle
  72. + packets going in or out of an ethernet device.
  73. +
  74. config WANT_COMPAT_NETLINK_MESSAGES
  75. bool
  76. help
  77. --- a/net/core/dev.c
  78. +++ b/net/core/dev.c
  79. @@ -2623,10 +2623,20 @@ static int xmit_one(struct sk_buff *skb,
  80. if (!list_empty(&ptype_all))
  81. dev_queue_xmit_nit(skb, dev);
  82. - len = skb->len;
  83. - trace_net_dev_start_xmit(skb, dev);
  84. - rc = netdev_start_xmit(skb, dev, txq, more);
  85. - trace_net_dev_xmit(skb, rc, dev, len);
  86. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  87. + if (!dev->eth_mangle_tx ||
  88. + (skb = dev->eth_mangle_tx(dev, skb)) != NULL)
  89. +#else
  90. + if (1)
  91. +#endif
  92. + {
  93. + len = skb->len;
  94. + trace_net_dev_start_xmit(skb, dev);
  95. + rc = netdev_start_xmit(skb, dev, txq, more);
  96. + trace_net_dev_xmit(skb, rc, dev, len);
  97. + } else {
  98. + rc = NETDEV_TX_OK;
  99. + }
  100. return rc;
  101. }
  102. --- a/net/core/skbuff.c
  103. +++ b/net/core/skbuff.c
  104. @@ -63,6 +63,7 @@
  105. #include <linux/errqueue.h>
  106. #include <linux/prefetch.h>
  107. #include <linux/if_vlan.h>
  108. +#include <linux/if.h>
  109. #include <net/protocol.h>
  110. #include <net/dst.h>
  111. @@ -469,6 +470,22 @@ struct sk_buff *__netdev_alloc_skb(struc
  112. }
  113. EXPORT_SYMBOL(__netdev_alloc_skb);
  114. +struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
  115. + unsigned int length, gfp_t gfp)
  116. +{
  117. + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp);
  118. +
  119. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  120. + if (dev && (dev->priv_flags & IFF_NO_IP_ALIGN))
  121. + return skb;
  122. +#endif
  123. +
  124. + if (NET_IP_ALIGN && skb)
  125. + skb_reserve(skb, NET_IP_ALIGN);
  126. + return skb;
  127. +}
  128. +EXPORT_SYMBOL(__netdev_alloc_skb_ip_align);
  129. +
  130. void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
  131. int size, unsigned int truesize)
  132. {
  133. --- a/net/ethernet/eth.c
  134. +++ b/net/ethernet/eth.c
  135. @@ -200,6 +200,12 @@ __be16 eth_type_trans(struct sk_buff *sk
  136. const struct ethhdr *eth;
  137. skb->dev = dev;
  138. +
  139. +#ifdef CONFIG_ETHERNET_PACKET_MANGLE
  140. + if (dev->eth_mangle_rx)
  141. + dev->eth_mangle_rx(dev, skb);
  142. +#endif
  143. +
  144. skb_reset_mac_header(skb);
  145. skb_pull_inline(skb, ETH_HLEN);
  146. eth = eth_hdr(skb);