vlan_core.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include <linux/skbuff.h>
  2. #include <linux/netdevice.h>
  3. #include <linux/if_vlan.h>
  4. #include <linux/netpoll.h>
  5. #include "vlan.h"
  6. /* VLAN rx hw acceleration helper. This acts like netif_{rx,receive_skb}(). */
  7. int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
  8. u16 vlan_tci, int polling)
  9. {
  10. if (netpoll_rx(skb))
  11. return NET_RX_DROP;
  12. if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
  13. goto drop;
  14. skb->skb_iif = skb->dev->ifindex;
  15. __vlan_hwaccel_put_tag(skb, vlan_tci);
  16. skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
  17. if (!skb->dev)
  18. goto drop;
  19. return (polling ? netif_receive_skb(skb) : netif_rx(skb));
  20. drop:
  21. dev_kfree_skb_any(skb);
  22. return NET_RX_DROP;
  23. }
  24. EXPORT_SYMBOL(__vlan_hwaccel_rx);
  25. int vlan_hwaccel_do_receive(struct sk_buff *skb)
  26. {
  27. struct net_device *dev = skb->dev;
  28. struct vlan_rx_stats *rx_stats;
  29. skb->dev = vlan_dev_info(dev)->real_dev;
  30. netif_nit_deliver(skb);
  31. skb->dev = dev;
  32. skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci);
  33. skb->vlan_tci = 0;
  34. rx_stats = per_cpu_ptr(vlan_dev_info(dev)->vlan_rx_stats,
  35. smp_processor_id());
  36. rx_stats->rx_packets++;
  37. rx_stats->rx_bytes += skb->len;
  38. switch (skb->pkt_type) {
  39. case PACKET_BROADCAST:
  40. break;
  41. case PACKET_MULTICAST:
  42. rx_stats->multicast++;
  43. break;
  44. case PACKET_OTHERHOST:
  45. /* Our lower layer thinks this is not local, let's make sure.
  46. * This allows the VLAN to have a different MAC than the
  47. * underlying device, and still route correctly. */
  48. if (!compare_ether_addr(eth_hdr(skb)->h_dest,
  49. dev->dev_addr))
  50. skb->pkt_type = PACKET_HOST;
  51. break;
  52. };
  53. return 0;
  54. }
  55. struct net_device *vlan_dev_real_dev(const struct net_device *dev)
  56. {
  57. return vlan_dev_info(dev)->real_dev;
  58. }
  59. EXPORT_SYMBOL(vlan_dev_real_dev);
  60. u16 vlan_dev_vlan_id(const struct net_device *dev)
  61. {
  62. return vlan_dev_info(dev)->vlan_id;
  63. }
  64. EXPORT_SYMBOL(vlan_dev_vlan_id);
  65. static gro_result_t
  66. vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
  67. unsigned int vlan_tci, struct sk_buff *skb)
  68. {
  69. struct sk_buff *p;
  70. if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
  71. goto drop;
  72. skb->skb_iif = skb->dev->ifindex;
  73. __vlan_hwaccel_put_tag(skb, vlan_tci);
  74. skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
  75. if (!skb->dev)
  76. goto drop;
  77. for (p = napi->gro_list; p; p = p->next) {
  78. NAPI_GRO_CB(p)->same_flow =
  79. p->dev == skb->dev && !compare_ether_header(
  80. skb_mac_header(p), skb_gro_mac_header(skb));
  81. NAPI_GRO_CB(p)->flush = 0;
  82. }
  83. return dev_gro_receive(napi, skb);
  84. drop:
  85. return GRO_DROP;
  86. }
  87. gro_result_t vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
  88. unsigned int vlan_tci, struct sk_buff *skb)
  89. {
  90. if (netpoll_rx_on(skb))
  91. return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
  92. ? GRO_DROP : GRO_NORMAL;
  93. skb_gro_reset_offset(skb);
  94. return napi_skb_finish(vlan_gro_common(napi, grp, vlan_tci, skb), skb);
  95. }
  96. EXPORT_SYMBOL(vlan_gro_receive);
  97. gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
  98. unsigned int vlan_tci)
  99. {
  100. struct sk_buff *skb = napi_frags_skb(napi);
  101. if (!skb)
  102. return GRO_DROP;
  103. if (netpoll_rx_on(skb)) {
  104. skb->protocol = eth_type_trans(skb, skb->dev);
  105. return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
  106. ? GRO_DROP : GRO_NORMAL;
  107. }
  108. return napi_frags_finish(napi, skb,
  109. vlan_gro_common(napi, grp, vlan_tci, skb));
  110. }
  111. EXPORT_SYMBOL(vlan_gro_frags);