vlan.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #ifndef __BEN_VLAN_802_1Q_INC__
  2. #define __BEN_VLAN_802_1Q_INC__
  3. #include <linux/if_vlan.h>
  4. #include <linux/u64_stats_sync.h>
  5. /**
  6. * struct vlan_priority_tci_mapping - vlan egress priority mappings
  7. * @priority: skb priority
  8. * @vlan_qos: vlan priority: (skb->priority << 13) & 0xE000
  9. * @next: pointer to next struct
  10. */
  11. struct vlan_priority_tci_mapping {
  12. u32 priority;
  13. u16 vlan_qos;
  14. struct vlan_priority_tci_mapping *next;
  15. };
  16. /**
  17. * struct vlan_rx_stats - VLAN percpu rx stats
  18. * @rx_packets: number of received packets
  19. * @rx_bytes: number of received bytes
  20. * @rx_multicast: number of received multicast packets
  21. * @syncp: synchronization point for 64bit counters
  22. * @rx_errors: number of errors
  23. */
  24. struct vlan_rx_stats {
  25. u64 rx_packets;
  26. u64 rx_bytes;
  27. u64 rx_multicast;
  28. struct u64_stats_sync syncp;
  29. unsigned long rx_errors;
  30. };
  31. /**
  32. * struct vlan_dev_info - VLAN private device data
  33. * @nr_ingress_mappings: number of ingress priority mappings
  34. * @ingress_priority_map: ingress priority mappings
  35. * @nr_egress_mappings: number of egress priority mappings
  36. * @egress_priority_map: hash of egress priority mappings
  37. * @vlan_id: VLAN identifier
  38. * @flags: device flags
  39. * @real_dev: underlying netdevice
  40. * @real_dev_addr: address of underlying netdevice
  41. * @dent: proc dir entry
  42. * @cnt_inc_headroom_on_tx: statistic - number of skb expansions on TX
  43. * @cnt_encap_on_xmit: statistic - number of skb encapsulations on TX
  44. * @vlan_rx_stats: ptr to percpu rx stats
  45. */
  46. struct vlan_dev_info {
  47. unsigned int nr_ingress_mappings;
  48. u32 ingress_priority_map[8];
  49. unsigned int nr_egress_mappings;
  50. struct vlan_priority_tci_mapping *egress_priority_map[16];
  51. u16 vlan_id;
  52. u16 flags;
  53. struct net_device *real_dev;
  54. unsigned char real_dev_addr[ETH_ALEN];
  55. struct proc_dir_entry *dent;
  56. unsigned long cnt_inc_headroom_on_tx;
  57. unsigned long cnt_encap_on_xmit;
  58. struct vlan_rx_stats __percpu *vlan_rx_stats;
  59. };
  60. static inline struct vlan_dev_info *vlan_dev_info(const struct net_device *dev)
  61. {
  62. return netdev_priv(dev);
  63. }
  64. #define VLAN_GRP_HASH_SHIFT 5
  65. #define VLAN_GRP_HASH_SIZE (1 << VLAN_GRP_HASH_SHIFT)
  66. #define VLAN_GRP_HASH_MASK (VLAN_GRP_HASH_SIZE - 1)
  67. /* Find a VLAN device by the MAC address of its Ethernet device, and
  68. * it's VLAN ID. The default configuration is to have VLAN's scope
  69. * to be box-wide, so the MAC will be ignored. The mac will only be
  70. * looked at if we are configured to have a separate set of VLANs per
  71. * each MAC addressable interface. Note that this latter option does
  72. * NOT follow the spec for VLANs, but may be useful for doing very
  73. * large quantities of VLAN MUX/DEMUX onto FrameRelay or ATM PVCs.
  74. *
  75. * Must be invoked with rcu_read_lock (ie preempt disabled)
  76. * or with RTNL.
  77. */
  78. struct net_device *__find_vlan_dev(struct net_device *real_dev, u16 vlan_id);
  79. /* found in vlan_dev.c */
  80. int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
  81. struct packet_type *ptype, struct net_device *orig_dev);
  82. void vlan_dev_set_ingress_priority(const struct net_device *dev,
  83. u32 skb_prio, u16 vlan_prio);
  84. int vlan_dev_set_egress_priority(const struct net_device *dev,
  85. u32 skb_prio, u16 vlan_prio);
  86. int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
  87. void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
  88. int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id);
  89. void vlan_setup(struct net_device *dev);
  90. int register_vlan_dev(struct net_device *dev);
  91. void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
  92. static inline u32 vlan_get_ingress_priority(struct net_device *dev,
  93. u16 vlan_tci)
  94. {
  95. struct vlan_dev_info *vip = vlan_dev_info(dev);
  96. return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
  97. }
  98. #ifdef CONFIG_VLAN_8021Q_GVRP
  99. extern int vlan_gvrp_request_join(const struct net_device *dev);
  100. extern void vlan_gvrp_request_leave(const struct net_device *dev);
  101. extern int vlan_gvrp_init_applicant(struct net_device *dev);
  102. extern void vlan_gvrp_uninit_applicant(struct net_device *dev);
  103. extern int vlan_gvrp_init(void);
  104. extern void vlan_gvrp_uninit(void);
  105. #else
  106. static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
  107. static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
  108. static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
  109. static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
  110. static inline int vlan_gvrp_init(void) { return 0; }
  111. static inline void vlan_gvrp_uninit(void) {}
  112. #endif
  113. extern const char vlan_fullname[];
  114. extern const char vlan_version[];
  115. extern int vlan_netlink_init(void);
  116. extern void vlan_netlink_fini(void);
  117. extern struct rtnl_link_ops vlan_link_ops;
  118. static inline int is_vlan_dev(struct net_device *dev)
  119. {
  120. return dev->priv_flags & IFF_802_1Q_VLAN;
  121. }
  122. extern int vlan_net_id;
  123. struct proc_dir_entry;
  124. struct vlan_net {
  125. /* /proc/net/vlan */
  126. struct proc_dir_entry *proc_vlan_dir;
  127. /* /proc/net/vlan/config */
  128. struct proc_dir_entry *proc_vlan_conf;
  129. /* Determines interface naming scheme. */
  130. unsigned short name_type;
  131. };
  132. #endif /* !(__BEN_VLAN_802_1Q_INC__) */