vlan_core.c 3.0 KB

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