vlan.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. #include <linux/list.h>
  6. /**
  7. * struct vlan_priority_tci_mapping - vlan egress priority mappings
  8. * @priority: skb priority
  9. * @vlan_qos: vlan priority: (skb->priority << 13) & 0xE000
  10. * @next: pointer to next struct
  11. */
  12. struct vlan_priority_tci_mapping {
  13. u32 priority;
  14. u16 vlan_qos;
  15. struct vlan_priority_tci_mapping *next;
  16. };
  17. /**
  18. * struct vlan_pcpu_stats - VLAN percpu rx/tx stats
  19. * @rx_packets: number of received packets
  20. * @rx_bytes: number of received bytes
  21. * @rx_multicast: number of received multicast packets
  22. * @tx_packets: number of transmitted packets
  23. * @tx_bytes: number of transmitted bytes
  24. * @syncp: synchronization point for 64bit counters
  25. * @rx_errors: number of rx errors
  26. * @tx_dropped: number of tx drops
  27. */
  28. struct vlan_pcpu_stats {
  29. u64 rx_packets;
  30. u64 rx_bytes;
  31. u64 rx_multicast;
  32. u64 tx_packets;
  33. u64 tx_bytes;
  34. struct u64_stats_sync syncp;
  35. u32 rx_errors;
  36. u32 tx_dropped;
  37. };
  38. /**
  39. * struct vlan_dev_priv - VLAN private device data
  40. * @nr_ingress_mappings: number of ingress priority mappings
  41. * @ingress_priority_map: ingress priority mappings
  42. * @nr_egress_mappings: number of egress priority mappings
  43. * @egress_priority_map: hash of egress priority mappings
  44. * @vlan_id: VLAN identifier
  45. * @flags: device flags
  46. * @real_dev: underlying netdevice
  47. * @real_dev_addr: address of underlying netdevice
  48. * @dent: proc dir entry
  49. * @vlan_pcpu_stats: ptr to percpu rx stats
  50. */
  51. struct vlan_dev_priv {
  52. unsigned int nr_ingress_mappings;
  53. u32 ingress_priority_map[8];
  54. unsigned int nr_egress_mappings;
  55. struct vlan_priority_tci_mapping *egress_priority_map[16];
  56. u16 vlan_id;
  57. u16 flags;
  58. struct net_device *real_dev;
  59. unsigned char real_dev_addr[ETH_ALEN];
  60. struct proc_dir_entry *dent;
  61. struct vlan_pcpu_stats __percpu *vlan_pcpu_stats;
  62. };
  63. static inline struct vlan_dev_priv *vlan_dev_priv(const struct net_device *dev)
  64. {
  65. return netdev_priv(dev);
  66. }
  67. /* if this changes, algorithm will have to be reworked because this
  68. * depends on completely exhausting the VLAN identifier space. Thus
  69. * it gives constant time look-up, but in many cases it wastes memory.
  70. */
  71. #define VLAN_GROUP_ARRAY_SPLIT_PARTS 8
  72. #define VLAN_GROUP_ARRAY_PART_LEN (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS)
  73. struct vlan_group {
  74. unsigned int nr_vlan_devs;
  75. struct hlist_node hlist; /* linked list */
  76. struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS];
  77. };
  78. struct vlan_info {
  79. struct net_device *real_dev; /* The ethernet(like) device
  80. * the vlan is attached to.
  81. */
  82. struct vlan_group grp;
  83. struct list_head vid_list;
  84. unsigned int nr_vids;
  85. struct rcu_head rcu;
  86. };
  87. static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
  88. u16 vlan_id)
  89. {
  90. struct net_device **array;
  91. array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
  92. return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
  93. }
  94. static inline void vlan_group_set_device(struct vlan_group *vg,
  95. u16 vlan_id,
  96. struct net_device *dev)
  97. {
  98. struct net_device **array;
  99. if (!vg)
  100. return;
  101. array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
  102. array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
  103. }
  104. /* Must be invoked with rcu_read_lock or with RTNL. */
  105. static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
  106. u16 vlan_id)
  107. {
  108. struct vlan_info *vlan_info = rcu_dereference_rtnl(real_dev->vlan_info);
  109. if (vlan_info)
  110. return vlan_group_get_device(&vlan_info->grp, vlan_id);
  111. return NULL;
  112. }
  113. /* found in vlan_dev.c */
  114. void vlan_dev_set_ingress_priority(const struct net_device *dev,
  115. u32 skb_prio, u16 vlan_prio);
  116. int vlan_dev_set_egress_priority(const struct net_device *dev,
  117. u32 skb_prio, u16 vlan_prio);
  118. int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
  119. void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
  120. int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id);
  121. void vlan_setup(struct net_device *dev);
  122. int register_vlan_dev(struct net_device *dev);
  123. void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
  124. static inline u32 vlan_get_ingress_priority(struct net_device *dev,
  125. u16 vlan_tci)
  126. {
  127. struct vlan_dev_priv *vip = vlan_dev_priv(dev);
  128. return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
  129. }
  130. #ifdef CONFIG_VLAN_8021Q_GVRP
  131. extern int vlan_gvrp_request_join(const struct net_device *dev);
  132. extern void vlan_gvrp_request_leave(const struct net_device *dev);
  133. extern int vlan_gvrp_init_applicant(struct net_device *dev);
  134. extern void vlan_gvrp_uninit_applicant(struct net_device *dev);
  135. extern int vlan_gvrp_init(void);
  136. extern void vlan_gvrp_uninit(void);
  137. #else
  138. static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
  139. static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
  140. static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
  141. static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
  142. static inline int vlan_gvrp_init(void) { return 0; }
  143. static inline void vlan_gvrp_uninit(void) {}
  144. #endif
  145. extern const char vlan_fullname[];
  146. extern const char vlan_version[];
  147. extern int vlan_netlink_init(void);
  148. extern void vlan_netlink_fini(void);
  149. extern struct rtnl_link_ops vlan_link_ops;
  150. extern int vlan_net_id;
  151. struct proc_dir_entry;
  152. struct vlan_net {
  153. /* /proc/net/vlan */
  154. struct proc_dir_entry *proc_vlan_dir;
  155. /* /proc/net/vlan/config */
  156. struct proc_dir_entry *proc_vlan_conf;
  157. /* Determines interface naming scheme. */
  158. unsigned short name_type;
  159. };
  160. #endif /* !(__BEN_VLAN_802_1Q_INC__) */