vlan_core.c 3.2 KB

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