Loading...
1#ifndef __BEN_VLAN_802_1Q_INC__
2#define __BEN_VLAN_802_1Q_INC__
3
4#include <linux/if_vlan.h>
5#include <linux/u64_stats_sync.h>
6#include <linux/list.h>
7
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
15enum vlan_protos {
16 VLAN_PROTO_8021Q = 0,
17 VLAN_PROTO_8021AD,
18 VLAN_PROTO_NUM,
19};
20
21struct vlan_group {
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];
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
38static inline unsigned int vlan_proto_idx(__be16 proto)
39{
40 switch (proto) {
41 case htons(ETH_P_8021Q):
42 return VLAN_PROTO_8021Q;
43 case htons(ETH_P_8021AD):
44 return VLAN_PROTO_8021AD;
45 default:
46 BUG();
47 return 0;
48 }
49}
50
51static inline struct net_device *__vlan_group_get_device(struct vlan_group *vg,
52 unsigned int pidx,
53 u16 vlan_id)
54{
55 struct net_device **array;
56
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;
60}
61
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
69static inline void vlan_group_set_device(struct vlan_group *vg,
70 __be16 vlan_proto, u16 vlan_id,
71 struct net_device *dev)
72{
73 struct net_device **array;
74 if (!vg)
75 return;
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;
79}
80
81/* Must be invoked with rcu_read_lock or with RTNL. */
82static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
83 __be16 vlan_proto, u16 vlan_id)
84{
85 struct vlan_info *vlan_info = rcu_dereference_rtnl(real_dev->vlan_info);
86
87 if (vlan_info)
88 return vlan_group_get_device(&vlan_info->grp,
89 vlan_proto, vlan_id);
90
91 return NULL;
92}
93
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
99/* found in vlan_dev.c */
100void vlan_dev_set_ingress_priority(const struct net_device *dev,
101 u32 skb_prio, u16 vlan_prio);
102int vlan_dev_set_egress_priority(const struct net_device *dev,
103 u32 skb_prio, u16 vlan_prio);
104int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
105void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
106
107int vlan_check_real_dev(struct net_device *real_dev,
108 __be16 protocol, u16 vlan_id);
109void vlan_setup(struct net_device *dev);
110int register_vlan_dev(struct net_device *dev);
111void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
112
113static inline u32 vlan_get_ingress_priority(struct net_device *dev,
114 u16 vlan_tci)
115{
116 struct vlan_dev_priv *vip = vlan_dev_priv(dev);
117
118 return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
119}
120
121#ifdef CONFIG_VLAN_8021Q_GVRP
122int vlan_gvrp_request_join(const struct net_device *dev);
123void vlan_gvrp_request_leave(const struct net_device *dev);
124int vlan_gvrp_init_applicant(struct net_device *dev);
125void vlan_gvrp_uninit_applicant(struct net_device *dev);
126int vlan_gvrp_init(void);
127void vlan_gvrp_uninit(void);
128#else
129static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
130static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
131static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
132static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
133static inline int vlan_gvrp_init(void) { return 0; }
134static inline void vlan_gvrp_uninit(void) {}
135#endif
136
137#ifdef CONFIG_VLAN_8021Q_MVRP
138int vlan_mvrp_request_join(const struct net_device *dev);
139void vlan_mvrp_request_leave(const struct net_device *dev);
140int vlan_mvrp_init_applicant(struct net_device *dev);
141void vlan_mvrp_uninit_applicant(struct net_device *dev);
142int vlan_mvrp_init(void);
143void vlan_mvrp_uninit(void);
144#else
145static inline int vlan_mvrp_request_join(const struct net_device *dev) { return 0; }
146static inline void vlan_mvrp_request_leave(const struct net_device *dev) {}
147static inline int vlan_mvrp_init_applicant(struct net_device *dev) { return 0; }
148static inline void vlan_mvrp_uninit_applicant(struct net_device *dev) {}
149static inline int vlan_mvrp_init(void) { return 0; }
150static inline void vlan_mvrp_uninit(void) {}
151#endif
152
153extern const char vlan_fullname[];
154extern const char vlan_version[];
155int vlan_netlink_init(void);
156void vlan_netlink_fini(void);
157
158extern struct rtnl_link_ops vlan_link_ops;
159
160extern int vlan_net_id;
161
162struct proc_dir_entry;
163
164struct vlan_net {
165 /* /proc/net/vlan */
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;
171};
172
173#endif /* !(__BEN_VLAN_802_1Q_INC__) */
1#ifndef __BEN_VLAN_802_1Q_INC__
2#define __BEN_VLAN_802_1Q_INC__
3
4#include <linux/if_vlan.h>
5#include <linux/u64_stats_sync.h>
6
7
8/**
9 * struct vlan_priority_tci_mapping - vlan egress priority mappings
10 * @priority: skb priority
11 * @vlan_qos: vlan priority: (skb->priority << 13) & 0xE000
12 * @next: pointer to next struct
13 */
14struct vlan_priority_tci_mapping {
15 u32 priority;
16 u16 vlan_qos;
17 struct vlan_priority_tci_mapping *next;
18};
19
20
21/**
22 * struct vlan_pcpu_stats - VLAN percpu rx/tx stats
23 * @rx_packets: number of received packets
24 * @rx_bytes: number of received bytes
25 * @rx_multicast: number of received multicast packets
26 * @tx_packets: number of transmitted packets
27 * @tx_bytes: number of transmitted bytes
28 * @syncp: synchronization point for 64bit counters
29 * @rx_errors: number of rx errors
30 * @tx_dropped: number of tx drops
31 */
32struct vlan_pcpu_stats {
33 u64 rx_packets;
34 u64 rx_bytes;
35 u64 rx_multicast;
36 u64 tx_packets;
37 u64 tx_bytes;
38 struct u64_stats_sync syncp;
39 u32 rx_errors;
40 u32 tx_dropped;
41};
42
43/**
44 * struct vlan_dev_info - VLAN private device data
45 * @nr_ingress_mappings: number of ingress priority mappings
46 * @ingress_priority_map: ingress priority mappings
47 * @nr_egress_mappings: number of egress priority mappings
48 * @egress_priority_map: hash of egress priority mappings
49 * @vlan_id: VLAN identifier
50 * @flags: device flags
51 * @real_dev: underlying netdevice
52 * @real_dev_addr: address of underlying netdevice
53 * @dent: proc dir entry
54 * @vlan_pcpu_stats: ptr to percpu rx stats
55 */
56struct vlan_dev_info {
57 unsigned int nr_ingress_mappings;
58 u32 ingress_priority_map[8];
59 unsigned int nr_egress_mappings;
60 struct vlan_priority_tci_mapping *egress_priority_map[16];
61
62 u16 vlan_id;
63 u16 flags;
64
65 struct net_device *real_dev;
66 unsigned char real_dev_addr[ETH_ALEN];
67
68 struct proc_dir_entry *dent;
69 struct vlan_pcpu_stats __percpu *vlan_pcpu_stats;
70};
71
72static inline struct vlan_dev_info *vlan_dev_info(const struct net_device *dev)
73{
74 return netdev_priv(dev);
75}
76
77static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
78 u16 vlan_id)
79{
80 struct net_device **array;
81 array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
82 return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
83}
84
85static inline void vlan_group_set_device(struct vlan_group *vg,
86 u16 vlan_id,
87 struct net_device *dev)
88{
89 struct net_device **array;
90 if (!vg)
91 return;
92 array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
93 array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
94}
95
96/* Must be invoked with rcu_read_lock or with RTNL. */
97static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
98 u16 vlan_id)
99{
100 struct vlan_group *grp = rcu_dereference_rtnl(real_dev->vlgrp);
101
102 if (grp)
103 return vlan_group_get_device(grp, vlan_id);
104
105 return NULL;
106}
107
108/* found in vlan_dev.c */
109void vlan_dev_set_ingress_priority(const struct net_device *dev,
110 u32 skb_prio, u16 vlan_prio);
111int vlan_dev_set_egress_priority(const struct net_device *dev,
112 u32 skb_prio, u16 vlan_prio);
113int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
114void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
115
116int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id);
117void vlan_setup(struct net_device *dev);
118int register_vlan_dev(struct net_device *dev);
119void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
120
121static inline u32 vlan_get_ingress_priority(struct net_device *dev,
122 u16 vlan_tci)
123{
124 struct vlan_dev_info *vip = vlan_dev_info(dev);
125
126 return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
127}
128
129#ifdef CONFIG_VLAN_8021Q_GVRP
130extern int vlan_gvrp_request_join(const struct net_device *dev);
131extern void vlan_gvrp_request_leave(const struct net_device *dev);
132extern int vlan_gvrp_init_applicant(struct net_device *dev);
133extern void vlan_gvrp_uninit_applicant(struct net_device *dev);
134extern int vlan_gvrp_init(void);
135extern void vlan_gvrp_uninit(void);
136#else
137static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
138static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
139static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
140static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
141static inline int vlan_gvrp_init(void) { return 0; }
142static inline void vlan_gvrp_uninit(void) {}
143#endif
144
145extern const char vlan_fullname[];
146extern const char vlan_version[];
147extern int vlan_netlink_init(void);
148extern void vlan_netlink_fini(void);
149
150extern struct rtnl_link_ops vlan_link_ops;
151
152extern int vlan_net_id;
153
154struct proc_dir_entry;
155
156struct 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
165#endif /* !(__BEN_VLAN_802_1Q_INC__) */