1 #ifndef __BEN_VLAN_802_1Q_INC__
2 #define __BEN_VLAN_802_1Q_INC__
4 #include <linux/if_vlan.h>
5 #include <linux/u64_stats_sync.h>
6 #include <linux/list.h>
8 /* if this changes, algorithm will have to be reworked because this
9 * depends on completely exhausting the VLAN identifier space. Thus
10 * it gives constant time look-up, but in many cases it wastes memory.
12 #define VLAN_GROUP_ARRAY_SPLIT_PARTS 8
13 #define VLAN_GROUP_ARRAY_PART_LEN (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS)
22 unsigned int nr_vlan_devs;
23 struct hlist_node hlist; /* linked list */
24 struct net_device **vlan_devices_arrays[VLAN_PROTO_NUM]
25 [VLAN_GROUP_ARRAY_SPLIT_PARTS];
29 struct net_device *real_dev; /* The ethernet(like) device
30 * the vlan is attached to.
32 struct vlan_group grp;
33 struct list_head vid_list;
38 static inline unsigned int vlan_proto_idx(__be16 proto)
41 case __constant_htons(ETH_P_8021Q):
42 return VLAN_PROTO_8021Q;
43 case __constant_htons(ETH_P_8021AD):
44 return VLAN_PROTO_8021AD;
51 static inline struct net_device *__vlan_group_get_device(struct vlan_group *vg,
55 struct net_device **array;
57 array = vg->vlan_devices_arrays[pidx]
58 [vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
59 return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
62 static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
66 return __vlan_group_get_device(vg, vlan_proto_idx(vlan_proto), vlan_id);
69 static inline void vlan_group_set_device(struct vlan_group *vg,
70 __be16 vlan_proto, u16 vlan_id,
71 struct net_device *dev)
73 struct net_device **array;
76 array = vg->vlan_devices_arrays[vlan_proto_idx(vlan_proto)]
77 [vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
78 array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
81 /* Must be invoked with rcu_read_lock or with RTNL. */
82 static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
83 __be16 vlan_proto, u16 vlan_id)
85 struct vlan_info *vlan_info = rcu_dereference_rtnl(real_dev->vlan_info);
88 return vlan_group_get_device(&vlan_info->grp,
94 #define vlan_group_for_each_dev(grp, i, dev) \
95 for ((i) = 0; i < VLAN_PROTO_NUM * VLAN_N_VID; i++) \
96 if (((dev) = __vlan_group_get_device((grp), (i) / VLAN_N_VID, \
99 /* found in vlan_dev.c */
100 void vlan_dev_set_ingress_priority(const struct net_device *dev,
101 u32 skb_prio, u16 vlan_prio);
102 int vlan_dev_set_egress_priority(const struct net_device *dev,
103 u32 skb_prio, u16 vlan_prio);
104 int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
105 void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
107 int vlan_check_real_dev(struct net_device *real_dev,
108 __be16 protocol, u16 vlan_id);
109 void vlan_setup(struct net_device *dev);
110 int register_vlan_dev(struct net_device *dev);
111 void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
113 static inline u32 vlan_get_ingress_priority(struct net_device *dev,
116 struct vlan_dev_priv *vip = vlan_dev_priv(dev);
118 return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
121 #ifdef CONFIG_VLAN_8021Q_GVRP
122 int vlan_gvrp_request_join(const struct net_device *dev);
123 void vlan_gvrp_request_leave(const struct net_device *dev);
124 int vlan_gvrp_init_applicant(struct net_device *dev);
125 void vlan_gvrp_uninit_applicant(struct net_device *dev);
126 int vlan_gvrp_init(void);
127 void vlan_gvrp_uninit(void);
129 static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
130 static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
131 static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
132 static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
133 static inline int vlan_gvrp_init(void) { return 0; }
134 static inline void vlan_gvrp_uninit(void) {}
137 #ifdef CONFIG_VLAN_8021Q_MVRP
138 int vlan_mvrp_request_join(const struct net_device *dev);
139 void vlan_mvrp_request_leave(const struct net_device *dev);
140 int vlan_mvrp_init_applicant(struct net_device *dev);
141 void vlan_mvrp_uninit_applicant(struct net_device *dev);
142 int vlan_mvrp_init(void);
143 void vlan_mvrp_uninit(void);
145 static inline int vlan_mvrp_request_join(const struct net_device *dev) { return 0; }
146 static inline void vlan_mvrp_request_leave(const struct net_device *dev) {}
147 static inline int vlan_mvrp_init_applicant(struct net_device *dev) { return 0; }
148 static inline void vlan_mvrp_uninit_applicant(struct net_device *dev) {}
149 static inline int vlan_mvrp_init(void) { return 0; }
150 static inline void vlan_mvrp_uninit(void) {}
153 extern const char vlan_fullname[];
154 extern const char vlan_version[];
155 int vlan_netlink_init(void);
156 void vlan_netlink_fini(void);
158 extern struct rtnl_link_ops vlan_link_ops;
160 extern int vlan_net_id;
162 struct proc_dir_entry;
166 struct proc_dir_entry *proc_vlan_dir;
167 /* /proc/net/vlan/config */
168 struct proc_dir_entry *proc_vlan_conf;
169 /* Determines interface naming scheme. */
170 unsigned short name_type;
173 #endif /* !(__BEN_VLAN_802_1Q_INC__) */