vlan.h 5.7 KB

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