Blame view

net/8021q/vlan.h 5.48 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
  #ifndef __BEN_VLAN_802_1Q_INC__
  #define __BEN_VLAN_802_1Q_INC__
  
  #include <linux/if_vlan.h>
9618e2ffd   Eric Dumazet   vlan: 64 bit rx c...
6
  #include <linux/u64_stats_sync.h>
5b9ea6e02   Jiri Pirko   vlan: introduce v...
7
  #include <linux/list.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8

5b9ea6e02   Jiri Pirko   vlan: introduce v...
9
10
11
12
13
14
  /* if this changes, algorithm will have to be reworked because this
   * depends on completely exhausting the VLAN identifier space.  Thus
   * it gives constant time look-up, but in many cases it wastes memory.
   */
  #define VLAN_GROUP_ARRAY_SPLIT_PARTS  8
  #define VLAN_GROUP_ARRAY_PART_LEN     (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS)
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
15
16
  enum vlan_protos {
  	VLAN_PROTO_8021Q	= 0,
8ad227ff8   Patrick McHardy   net: vlan: add 80...
17
  	VLAN_PROTO_8021AD,
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
18
19
  	VLAN_PROTO_NUM,
  };
5b9ea6e02   Jiri Pirko   vlan: introduce v...
20
21
22
  struct vlan_group {
  	unsigned int		nr_vlan_devs;
  	struct hlist_node	hlist;	/* linked list */
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
23
24
  	struct net_device **vlan_devices_arrays[VLAN_PROTO_NUM]
  					       [VLAN_GROUP_ARRAY_SPLIT_PARTS];
5b9ea6e02   Jiri Pirko   vlan: introduce v...
25
26
27
28
29
30
31
32
33
34
35
  };
  
  struct vlan_info {
  	struct net_device	*real_dev; /* The ethernet(like) device
  					    * the vlan is attached to.
  					    */
  	struct vlan_group	grp;
  	struct list_head	vid_list;
  	unsigned int		nr_vids;
  	struct rcu_head		rcu;
  };
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
36
37
38
  static inline unsigned int vlan_proto_idx(__be16 proto)
  {
  	switch (proto) {
f0e78826e   Joe Perches   8021q: Convert us...
39
  	case htons(ETH_P_8021Q):
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
40
  		return VLAN_PROTO_8021Q;
f0e78826e   Joe Perches   8021q: Convert us...
41
  	case htons(ETH_P_8021AD):
8ad227ff8   Patrick McHardy   net: vlan: add 80...
42
  		return VLAN_PROTO_8021AD;
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
43
44
  	default:
  		BUG();
8da63a655   Patrick McHardy   net: vlan: fix up...
45
  		return 0;
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
46
47
48
49
50
51
  	}
  }
  
  static inline struct net_device *__vlan_group_get_device(struct vlan_group *vg,
  							 unsigned int pidx,
  							 u16 vlan_id)
536d1d4a0   Jiri Pirko   vlan: move vlan_g...
52
53
  {
  	struct net_device **array;
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
54
55
56
  
  	array = vg->vlan_devices_arrays[pidx]
  				       [vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
536d1d4a0   Jiri Pirko   vlan: move vlan_g...
57
58
  	return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
  }
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
59
60
61
62
63
64
  static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
  						       __be16 vlan_proto,
  						       u16 vlan_id)
  {
  	return __vlan_group_get_device(vg, vlan_proto_idx(vlan_proto), vlan_id);
  }
536d1d4a0   Jiri Pirko   vlan: move vlan_g...
65
  static inline void vlan_group_set_device(struct vlan_group *vg,
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
66
  					 __be16 vlan_proto, u16 vlan_id,
536d1d4a0   Jiri Pirko   vlan: move vlan_g...
67
68
69
70
71
  					 struct net_device *dev)
  {
  	struct net_device **array;
  	if (!vg)
  		return;
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
72
73
  	array = vg->vlan_devices_arrays[vlan_proto_idx(vlan_proto)]
  				       [vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
536d1d4a0   Jiri Pirko   vlan: move vlan_g...
74
75
  	array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
  }
69ecca86d   David Lamparter   net: vlan, qlcnic...
76
77
  /* Must be invoked with rcu_read_lock or with RTNL. */
  static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
78
  					       __be16 vlan_proto, u16 vlan_id)
69ecca86d   David Lamparter   net: vlan, qlcnic...
79
  {
5b9ea6e02   Jiri Pirko   vlan: introduce v...
80
  	struct vlan_info *vlan_info = rcu_dereference_rtnl(real_dev->vlan_info);
69ecca86d   David Lamparter   net: vlan, qlcnic...
81

5b9ea6e02   Jiri Pirko   vlan: introduce v...
82
  	if (vlan_info)
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
83
84
  		return vlan_group_get_device(&vlan_info->grp,
  					     vlan_proto, vlan_id);
69ecca86d   David Lamparter   net: vlan, qlcnic...
85
86
87
  
  	return NULL;
  }
1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
88
89
90
91
  #define vlan_group_for_each_dev(grp, i, dev) \
  	for ((i) = 0; i < VLAN_PROTO_NUM * VLAN_N_VID; i++) \
  		if (((dev) = __vlan_group_get_device((grp), (i) / VLAN_N_VID, \
  							    (i) % VLAN_N_VID)))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
  /* found in vlan_dev.c */
c17d8874f   Patrick McHardy   [VLAN]: Convert n...
93
  void vlan_dev_set_ingress_priority(const struct net_device *dev,
9bb8582ef   Patrick McHardy   vlan: TCI related...
94
  				   u32 skb_prio, u16 vlan_prio);
c17d8874f   Patrick McHardy   [VLAN]: Convert n...
95
  int vlan_dev_set_egress_priority(const struct net_device *dev,
9bb8582ef   Patrick McHardy   vlan: TCI related...
96
  				 u32 skb_prio, u16 vlan_prio);
b3ce0325f   Patrick McHardy   vlan: Change vlan...
97
  int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
c17d8874f   Patrick McHardy   [VLAN]: Convert n...
98
  void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99

1fd9b1fc3   Patrick McHardy   net: vlan: prepar...
100
101
  int vlan_check_real_dev(struct net_device *real_dev,
  			__be16 protocol, u16 vlan_id);
07b5b17e1   Patrick McHardy   [VLAN]: Use rtnl_...
102
103
  void vlan_setup(struct net_device *dev);
  int register_vlan_dev(struct net_device *dev);
23289a37e   Eric Dumazet   net: add a list_h...
104
  void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
308453aa9   Mike Manning   vlan: Propagate M...
105
106
  bool vlan_dev_inherit_address(struct net_device *dev,
  			      struct net_device *real_dev);
07b5b17e1   Patrick McHardy   [VLAN]: Use rtnl_...
107

7750f403c   Patrick McHardy   vlan: uninline __...
108
  static inline u32 vlan_get_ingress_priority(struct net_device *dev,
9bb8582ef   Patrick McHardy   vlan: TCI related...
109
  					    u16 vlan_tci)
7750f403c   Patrick McHardy   vlan: uninline __...
110
  {
7da82c06d   Jiri Pirko   vlan: rename vlan...
111
  	struct vlan_dev_priv *vip = vlan_dev_priv(dev);
7750f403c   Patrick McHardy   vlan: uninline __...
112

05423b241   Eric Dumazet   vlan: allow null ...
113
  	return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
7750f403c   Patrick McHardy   vlan: uninline __...
114
  }
70c03b49b   Patrick McHardy   vlan: Add GVRP su...
115
  #ifdef CONFIG_VLAN_8021Q_GVRP
348662a14   Joe Perches   net: 8021q/blueto...
116
117
118
119
120
121
  int vlan_gvrp_request_join(const struct net_device *dev);
  void vlan_gvrp_request_leave(const struct net_device *dev);
  int vlan_gvrp_init_applicant(struct net_device *dev);
  void vlan_gvrp_uninit_applicant(struct net_device *dev);
  int vlan_gvrp_init(void);
  void vlan_gvrp_uninit(void);
70c03b49b   Patrick McHardy   vlan: Add GVRP su...
122
123
124
125
126
127
128
129
  #else
  static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
  static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
  static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
  static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
  static inline int vlan_gvrp_init(void) { return 0; }
  static inline void vlan_gvrp_uninit(void) {}
  #endif
86fbe9bb5   David Ward   net/8021q: Implem...
130
  #ifdef CONFIG_VLAN_8021Q_MVRP
348662a14   Joe Perches   net: 8021q/blueto...
131
132
133
134
135
136
  int vlan_mvrp_request_join(const struct net_device *dev);
  void vlan_mvrp_request_leave(const struct net_device *dev);
  int vlan_mvrp_init_applicant(struct net_device *dev);
  void vlan_mvrp_uninit_applicant(struct net_device *dev);
  int vlan_mvrp_init(void);
  void vlan_mvrp_uninit(void);
86fbe9bb5   David Ward   net/8021q: Implem...
137
138
139
140
141
142
143
144
  #else
  static inline int vlan_mvrp_request_join(const struct net_device *dev) { return 0; }
  static inline void vlan_mvrp_request_leave(const struct net_device *dev) {}
  static inline int vlan_mvrp_init_applicant(struct net_device *dev) { return 0; }
  static inline void vlan_mvrp_uninit_applicant(struct net_device *dev) {}
  static inline int vlan_mvrp_init(void) { return 0; }
  static inline void vlan_mvrp_uninit(void) {}
  #endif
b30200616   Stephen Hemminger   vlan: propogate e...
145
146
  extern const char vlan_fullname[];
  extern const char vlan_version[];
348662a14   Joe Perches   net: 8021q/blueto...
147
148
  int vlan_netlink_init(void);
  void vlan_netlink_fini(void);
07b5b17e1   Patrick McHardy   [VLAN]: Use rtnl_...
149
150
  
  extern struct rtnl_link_ops vlan_link_ops;
c7d03a00b   Alexey Dobriyan   netns: make struc...
151
  extern unsigned int vlan_net_id;
d9ed0f0e2   Pavel Emelyanov   [VLAN]: Introduce...
152

a59a8c1c8   Pavel Emelyanov   [VLAN]: Create pr...
153
  struct proc_dir_entry;
d9ed0f0e2   Pavel Emelyanov   [VLAN]: Introduce...
154
  struct vlan_net {
a59a8c1c8   Pavel Emelyanov   [VLAN]: Create pr...
155
156
157
158
  	/* /proc/net/vlan */
  	struct proc_dir_entry *proc_vlan_dir;
  	/* /proc/net/vlan/config */
  	struct proc_dir_entry *proc_vlan_conf;
7a17a2f79   Pavel Emelyanov   [VLAN]: Make the ...
159
160
  	/* Determines interface naming scheme. */
  	unsigned short name_type;
d9ed0f0e2   Pavel Emelyanov   [VLAN]: Introduce...
161
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
  #endif /* !(__BEN_VLAN_802_1Q_INC__) */