vlan_core.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. struct net_device_stats *stats;
  10. if (skb_bond_should_drop(skb)) {
  11. dev_kfree_skb_any(skb);
  12. return NET_RX_DROP;
  13. }
  14. skb->vlan_tci = vlan_tci;
  15. netif_nit_deliver(skb);
  16. skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
  17. if (skb->dev == NULL) {
  18. dev_kfree_skb_any(skb);
  19. /* Not NET_RX_DROP, this is not being dropped
  20. * due to congestion. */
  21. return NET_RX_SUCCESS;
  22. }
  23. skb->vlan_tci = 0;
  24. stats = &skb->dev->stats;
  25. stats->rx_packets++;
  26. stats->rx_bytes += skb->len;
  27. skb->priority = vlan_get_ingress_priority(skb->dev, vlan_tci);
  28. switch (skb->pkt_type) {
  29. case PACKET_BROADCAST:
  30. break;
  31. case PACKET_MULTICAST:
  32. stats->multicast++;
  33. break;
  34. case PACKET_OTHERHOST:
  35. /* Our lower layer thinks this is not local, let's make sure.
  36. * This allows the VLAN to have a different MAC than the
  37. * underlying device, and still route correctly. */
  38. if (!compare_ether_addr(eth_hdr(skb)->h_dest,
  39. skb->dev->dev_addr))
  40. skb->pkt_type = PACKET_HOST;
  41. break;
  42. };
  43. return (polling ? netif_receive_skb(skb) : netif_rx(skb));
  44. }
  45. EXPORT_SYMBOL(__vlan_hwaccel_rx);
  46. struct net_device *vlan_dev_real_dev(const struct net_device *dev)
  47. {
  48. return vlan_dev_info(dev)->real_dev;
  49. }
  50. EXPORT_SYMBOL_GPL(vlan_dev_real_dev);
  51. u16 vlan_dev_vlan_id(const struct net_device *dev)
  52. {
  53. return vlan_dev_info(dev)->vlan_id;
  54. }
  55. EXPORT_SYMBOL_GPL(vlan_dev_vlan_id);