]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/8021q/vlan.h
Merge tag 'pm-4.13-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[mirror_ubuntu-artful-kernel.git] / net / 8021q / vlan.h
CommitLineData
1da177e4
LT
1#ifndef __BEN_VLAN_802_1Q_INC__
2#define __BEN_VLAN_802_1Q_INC__
3
4#include <linux/if_vlan.h>
9618e2ff 5#include <linux/u64_stats_sync.h>
5b9ea6e0 6#include <linux/list.h>
1da177e4 7
5b9ea6e0
JP
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.
11 */
12#define VLAN_GROUP_ARRAY_SPLIT_PARTS 8
13#define VLAN_GROUP_ARRAY_PART_LEN (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS)
14
1fd9b1fc
PM
15enum vlan_protos {
16 VLAN_PROTO_8021Q = 0,
8ad227ff 17 VLAN_PROTO_8021AD,
1fd9b1fc
PM
18 VLAN_PROTO_NUM,
19};
20
5b9ea6e0
JP
21struct vlan_group {
22 unsigned int nr_vlan_devs;
23 struct hlist_node hlist; /* linked list */
1fd9b1fc
PM
24 struct net_device **vlan_devices_arrays[VLAN_PROTO_NUM]
25 [VLAN_GROUP_ARRAY_SPLIT_PARTS];
5b9ea6e0
JP
26};
27
28struct vlan_info {
29 struct net_device *real_dev; /* The ethernet(like) device
30 * the vlan is attached to.
31 */
32 struct vlan_group grp;
33 struct list_head vid_list;
34 unsigned int nr_vids;
35 struct rcu_head rcu;
36};
37
1fd9b1fc
PM
38static inline unsigned int vlan_proto_idx(__be16 proto)
39{
40 switch (proto) {
f0e78826 41 case htons(ETH_P_8021Q):
1fd9b1fc 42 return VLAN_PROTO_8021Q;
f0e78826 43 case htons(ETH_P_8021AD):
8ad227ff 44 return VLAN_PROTO_8021AD;
1fd9b1fc
PM
45 default:
46 BUG();
8da63a65 47 return 0;
1fd9b1fc
PM
48 }
49}
50
51static inline struct net_device *__vlan_group_get_device(struct vlan_group *vg,
52 unsigned int pidx,
53 u16 vlan_id)
536d1d4a
JP
54{
55 struct net_device **array;
1fd9b1fc
PM
56
57 array = vg->vlan_devices_arrays[pidx]
58 [vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
536d1d4a
JP
59 return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
60}
61
1fd9b1fc
PM
62static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
63 __be16 vlan_proto,
64 u16 vlan_id)
65{
66 return __vlan_group_get_device(vg, vlan_proto_idx(vlan_proto), vlan_id);
67}
68
536d1d4a 69static inline void vlan_group_set_device(struct vlan_group *vg,
1fd9b1fc 70 __be16 vlan_proto, u16 vlan_id,
536d1d4a
JP
71 struct net_device *dev)
72{
73 struct net_device **array;
74 if (!vg)
75 return;
1fd9b1fc
PM
76 array = vg->vlan_devices_arrays[vlan_proto_idx(vlan_proto)]
77 [vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
536d1d4a
JP
78 array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
79}
80
69ecca86
DL
81/* Must be invoked with rcu_read_lock or with RTNL. */
82static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
1fd9b1fc 83 __be16 vlan_proto, u16 vlan_id)
69ecca86 84{
5b9ea6e0 85 struct vlan_info *vlan_info = rcu_dereference_rtnl(real_dev->vlan_info);
69ecca86 86
5b9ea6e0 87 if (vlan_info)
1fd9b1fc
PM
88 return vlan_group_get_device(&vlan_info->grp,
89 vlan_proto, vlan_id);
69ecca86
DL
90
91 return NULL;
92}
93
1fd9b1fc
PM
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, \
97 (i) % VLAN_N_VID)))
98
1da177e4 99/* found in vlan_dev.c */
c17d8874 100void vlan_dev_set_ingress_priority(const struct net_device *dev,
9bb8582e 101 u32 skb_prio, u16 vlan_prio);
c17d8874 102int vlan_dev_set_egress_priority(const struct net_device *dev,
9bb8582e 103 u32 skb_prio, u16 vlan_prio);
b3ce0325 104int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
c17d8874 105void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
1da177e4 106
1fd9b1fc
PM
107int vlan_check_real_dev(struct net_device *real_dev,
108 __be16 protocol, u16 vlan_id);
07b5b17e
PM
109void vlan_setup(struct net_device *dev);
110int register_vlan_dev(struct net_device *dev);
23289a37 111void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
308453aa
MM
112bool vlan_dev_inherit_address(struct net_device *dev,
113 struct net_device *real_dev);
07b5b17e 114
7750f403 115static inline u32 vlan_get_ingress_priority(struct net_device *dev,
9bb8582e 116 u16 vlan_tci)
7750f403 117{
7da82c06 118 struct vlan_dev_priv *vip = vlan_dev_priv(dev);
7750f403 119
05423b24 120 return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
7750f403
PM
121}
122
70c03b49 123#ifdef CONFIG_VLAN_8021Q_GVRP
348662a1
JP
124int vlan_gvrp_request_join(const struct net_device *dev);
125void vlan_gvrp_request_leave(const struct net_device *dev);
126int vlan_gvrp_init_applicant(struct net_device *dev);
127void vlan_gvrp_uninit_applicant(struct net_device *dev);
128int vlan_gvrp_init(void);
129void vlan_gvrp_uninit(void);
70c03b49
PM
130#else
131static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
132static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
133static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
134static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
135static inline int vlan_gvrp_init(void) { return 0; }
136static inline void vlan_gvrp_uninit(void) {}
137#endif
138
86fbe9bb 139#ifdef CONFIG_VLAN_8021Q_MVRP
348662a1
JP
140int vlan_mvrp_request_join(const struct net_device *dev);
141void vlan_mvrp_request_leave(const struct net_device *dev);
142int vlan_mvrp_init_applicant(struct net_device *dev);
143void vlan_mvrp_uninit_applicant(struct net_device *dev);
144int vlan_mvrp_init(void);
145void vlan_mvrp_uninit(void);
86fbe9bb
DW
146#else
147static inline int vlan_mvrp_request_join(const struct net_device *dev) { return 0; }
148static inline void vlan_mvrp_request_leave(const struct net_device *dev) {}
149static inline int vlan_mvrp_init_applicant(struct net_device *dev) { return 0; }
150static inline void vlan_mvrp_uninit_applicant(struct net_device *dev) {}
151static inline int vlan_mvrp_init(void) { return 0; }
152static inline void vlan_mvrp_uninit(void) {}
153#endif
154
b3020061
SH
155extern const char vlan_fullname[];
156extern const char vlan_version[];
348662a1
JP
157int vlan_netlink_init(void);
158void vlan_netlink_fini(void);
07b5b17e
PM
159
160extern struct rtnl_link_ops vlan_link_ops;
161
c7d03a00 162extern unsigned int vlan_net_id;
d9ed0f0e 163
a59a8c1c
PE
164struct proc_dir_entry;
165
d9ed0f0e 166struct vlan_net {
a59a8c1c
PE
167 /* /proc/net/vlan */
168 struct proc_dir_entry *proc_vlan_dir;
169 /* /proc/net/vlan/config */
170 struct proc_dir_entry *proc_vlan_conf;
7a17a2f7
PE
171 /* Determines interface naming scheme. */
172 unsigned short name_type;
d9ed0f0e
PE
173};
174
1da177e4 175#endif /* !(__BEN_VLAN_802_1Q_INC__) */