721-phy_packets.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. --- a/include/linux/netdevice.h
  2. +++ b/include/linux/netdevice.h
  3. @@ -1297,6 +1297,7 @@ enum netdev_priv_flags {
  4. IFF_NO_QUEUE = 1<<21,
  5. IFF_OPENVSWITCH = 1<<22,
  6. IFF_L3MDEV_SLAVE = 1<<23,
  7. + IFF_NO_IP_ALIGN = 1<<24,
  8. };
  9. #define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
  10. @@ -1323,6 +1324,7 @@ enum netdev_priv_flags {
  11. #define IFF_NO_QUEUE IFF_NO_QUEUE
  12. #define IFF_OPENVSWITCH IFF_OPENVSWITCH
  13. #define IFF_L3MDEV_SLAVE IFF_L3MDEV_SLAVE
  14. +#define IFF_NO_IP_ALIGN IFF_NO_IP_ALIGN
  15. /**
  16. * struct net_device - The DEVICE structure.
  17. @@ -1603,6 +1605,11 @@ struct net_device {
  18. const struct l3mdev_ops *l3mdev_ops;
  19. #endif
  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. @@ -1670,6 +1677,10 @@ struct net_device {
  28. struct mpls_dev __rcu *mpls_ptr;
  29. #endif
  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. @@ -2208,6 +2208,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. @@ -2312,16 +2316,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. @@ -2747,10 +2747,20 @@ static int xmit_one(struct sk_buff *skb,
  80. if (!list_empty(&ptype_all) || !list_empty(&dev->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. @@ -520,6 +521,22 @@ skb_fail:
  112. }
  113. EXPORT_SYMBOL(__napi_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. @@ -168,6 +168,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. eth = (struct ethhdr *)skb->data;