vlan_core.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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(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(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 =
  72. p->dev == skb->dev && !compare_ether_header(
  73. skb_mac_header(p), skb_gro_mac_header(skb));
  74. NAPI_GRO_CB(p)->flush = 0;
  75. }
  76. return dev_gro_receive(napi, skb);
  77. drop:
  78. return 2;
  79. }
  80. int vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
  81. unsigned int vlan_tci, struct sk_buff *skb)
  82. {
  83. skb_gro_reset_offset(skb);
  84. return napi_skb_finish(vlan_gro_common(napi, grp, vlan_tci, skb), skb);
  85. }
  86. EXPORT_SYMBOL(vlan_gro_receive);
  87. int vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
  88. unsigned int vlan_tci, struct napi_gro_fraginfo *info)
  89. {
  90. struct sk_buff *skb = napi_fraginfo_skb(napi, info);
  91. if (!skb)
  92. return NET_RX_DROP;
  93. return napi_frags_finish(napi, skb,
  94. vlan_gro_common(napi, grp, vlan_tci, skb));
  95. }
  96. EXPORT_SYMBOL(vlan_gro_frags);