vlan_core.c 3.0 KB

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