vlan.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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_pcpu_stats - VLAN percpu rx/tx stats
  18. * @rx_packets: number of received packets
  19. * @rx_bytes: number of received bytes
  20. * @rx_multicast: number of received multicast packets
  21. * @tx_packets: number of transmitted packets
  22. * @tx_bytes: number of transmitted bytes
  23. * @syncp: synchronization point for 64bit counters
  24. * @rx_errors: number of rx errors
  25. * @tx_dropped: number of tx drops
  26. */
  27. struct vlan_pcpu_stats {
  28. u64 rx_packets;
  29. u64 rx_bytes;
  30. u64 rx_multicast;
  31. u64 tx_packets;
  32. u64 tx_bytes;
  33. struct u64_stats_sync syncp;
  34. u32 rx_errors;
  35. u32 tx_dropped;
  36. };
  37. /**
  38. * struct vlan_dev_info - VLAN private device data
  39. * @nr_ingress_mappings: number of ingress priority mappings
  40. * @ingress_priority_map: ingress priority mappings
  41. * @nr_egress_mappings: number of egress priority mappings
  42. * @egress_priority_map: hash of egress priority mappings
  43. * @vlan_id: VLAN identifier
  44. * @flags: device flags
  45. * @real_dev: underlying netdevice
  46. * @real_dev_addr: address of underlying netdevice
  47. * @dent: proc dir entry
  48. * @vlan_pcpu_stats: ptr to percpu rx stats
  49. */
  50. struct vlan_dev_info {
  51. unsigned int nr_ingress_mappings;
  52. u32 ingress_priority_map[8];
  53. unsigned int nr_egress_mappings;
  54. struct vlan_priority_tci_mapping *egress_priority_map[16];
  55. u16 vlan_id;
  56. u16 flags;
  57. struct net_device *real_dev;
  58. unsigned char real_dev_addr[ETH_ALEN];
  59. struct proc_dir_entry *dent;
  60. struct vlan_pcpu_stats __percpu *vlan_pcpu_stats;
  61. };
  62. static inline struct vlan_dev_info *vlan_dev_info(const struct net_device *dev)
  63. {
  64. return netdev_priv(dev);
  65. }
  66. static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
  67. u16 vlan_id)
  68. {
  69. struct net_device **array;
  70. array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
  71. return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
  72. }
  73. static inline void vlan_group_set_device(struct vlan_group *vg,
  74. u16 vlan_id,
  75. struct net_device *dev)
  76. {
  77. struct net_device **array;
  78. if (!vg)
  79. return;
  80. array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
  81. array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
  82. }
  83. /* Must be invoked with rcu_read_lock or with RTNL. */
  84. static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
  85. u16 vlan_id)
  86. {
  87. struct vlan_group *grp = rcu_dereference_rtnl(real_dev->vlgrp);
  88. if (grp)
  89. return vlan_group_get_device(grp, vlan_id);
  90. return NULL;
  91. }
  92. /* found in vlan_dev.c */
  93. void vlan_dev_set_ingress_priority(const struct net_device *dev,
  94. u32 skb_prio, u16 vlan_prio);
  95. int vlan_dev_set_egress_priority(const struct net_device *dev,
  96. u32 skb_prio, u16 vlan_prio);
  97. int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
  98. void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
  99. int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id);
  100. void vlan_setup(struct net_device *dev);
  101. int register_vlan_dev(struct net_device *dev);
  102. void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
  103. static inline u32 vlan_get_ingress_priority(struct net_device *dev,
  104. u16 vlan_tci)
  105. {
  106. struct vlan_dev_info *vip = vlan_dev_info(dev);
  107. return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
  108. }
  109. #ifdef CONFIG_VLAN_8021Q_GVRP
  110. extern int vlan_gvrp_request_join(const struct net_device *dev);
  111. extern void vlan_gvrp_request_leave(const struct net_device *dev);
  112. extern int vlan_gvrp_init_applicant(struct net_device *dev);
  113. extern void vlan_gvrp_uninit_applicant(struct net_device *dev);
  114. extern int vlan_gvrp_init(void);
  115. extern void vlan_gvrp_uninit(void);
  116. #else
  117. static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
  118. static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
  119. static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
  120. static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
  121. static inline int vlan_gvrp_init(void) { return 0; }
  122. static inline void vlan_gvrp_uninit(void) {}
  123. #endif
  124. extern const char vlan_fullname[];
  125. extern const char vlan_version[];
  126. extern int vlan_netlink_init(void);
  127. extern void vlan_netlink_fini(void);
  128. extern struct rtnl_link_ops vlan_link_ops;
  129. extern int vlan_net_id;
  130. struct proc_dir_entry;
  131. struct vlan_net {
  132. /* /proc/net/vlan */
  133. struct proc_dir_entry *proc_vlan_dir;
  134. /* /proc/net/vlan/config */
  135. struct proc_dir_entry *proc_vlan_conf;
  136. /* Determines interface naming scheme. */
  137. unsigned short name_type;
  138. };
  139. #endif /* !(__BEN_VLAN_802_1Q_INC__) */