net: introduce vlan_vid_[add/del] and use them instead of direct [add/kill]_vid ndo...
[deliverable/linux.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>
1da177e4 6
22d1ba74
PM
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;
9bb8582e 16 u16 vlan_qos;
22d1ba74
PM
17 struct vlan_priority_tci_mapping *next;
18};
19
9793241f
ED
20
21/**
4af429d2 22 * struct vlan_pcpu_stats - VLAN percpu rx/tx stats
9793241f
ED
23 * @rx_packets: number of received packets
24 * @rx_bytes: number of received bytes
9618e2ff 25 * @rx_multicast: number of received multicast packets
4af429d2
ED
26 * @tx_packets: number of transmitted packets
27 * @tx_bytes: number of transmitted bytes
9618e2ff 28 * @syncp: synchronization point for 64bit counters
4af429d2
ED
29 * @rx_errors: number of rx errors
30 * @tx_dropped: number of tx drops
9793241f 31 */
4af429d2 32struct vlan_pcpu_stats {
9618e2ff
ED
33 u64 rx_packets;
34 u64 rx_bytes;
35 u64 rx_multicast;
4af429d2
ED
36 u64 tx_packets;
37 u64 tx_bytes;
9618e2ff 38 struct u64_stats_sync syncp;
4af429d2
ED
39 u32 rx_errors;
40 u32 tx_dropped;
9793241f
ED
41};
42
22d1ba74 43/**
7da82c06 44 * struct vlan_dev_priv - VLAN private device data
22d1ba74
PM
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
4af429d2 54 * @vlan_pcpu_stats: ptr to percpu rx stats
22d1ba74 55 */
7da82c06 56struct vlan_dev_priv {
22d1ba74
PM
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
9bb8582e
PM
62 u16 vlan_id;
63 u16 flags;
22d1ba74
PM
64
65 struct net_device *real_dev;
66 unsigned char real_dev_addr[ETH_ALEN];
67
68 struct proc_dir_entry *dent;
4af429d2 69 struct vlan_pcpu_stats __percpu *vlan_pcpu_stats;
22d1ba74
PM
70};
71
7da82c06 72static inline struct vlan_dev_priv *vlan_dev_priv(const struct net_device *dev)
22d1ba74
PM
73{
74 return netdev_priv(dev);
75}
76
536d1d4a
JP
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
69ecca86
DL
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
1da177e4 108/* found in vlan_dev.c */
c17d8874 109void vlan_dev_set_ingress_priority(const struct net_device *dev,
9bb8582e 110 u32 skb_prio, u16 vlan_prio);
c17d8874 111int vlan_dev_set_egress_priority(const struct net_device *dev,
9bb8582e 112 u32 skb_prio, u16 vlan_prio);
b3ce0325 113int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
c17d8874 114void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
1da177e4 115
9bb8582e 116int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id);
07b5b17e
PM
117void vlan_setup(struct net_device *dev);
118int register_vlan_dev(struct net_device *dev);
23289a37 119void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
07b5b17e 120
7750f403 121static inline u32 vlan_get_ingress_priority(struct net_device *dev,
9bb8582e 122 u16 vlan_tci)
7750f403 123{
7da82c06 124 struct vlan_dev_priv *vip = vlan_dev_priv(dev);
7750f403 125
05423b24 126 return vip->ingress_priority_map[(vlan_tci >> VLAN_PRIO_SHIFT) & 0x7];
7750f403
PM
127}
128
70c03b49
PM
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
b3020061
SH
145extern const char vlan_fullname[];
146extern const char vlan_version[];
147extern int vlan_netlink_init(void);
148extern void vlan_netlink_fini(void);
07b5b17e
PM
149
150extern struct rtnl_link_ops vlan_link_ops;
151
d9ed0f0e
PE
152extern int vlan_net_id;
153
a59a8c1c
PE
154struct proc_dir_entry;
155
d9ed0f0e 156struct vlan_net {
a59a8c1c
PE
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;
7a17a2f7
PE
161 /* Determines interface naming scheme. */
162 unsigned short name_type;
d9ed0f0e
PE
163};
164
1da177e4 165#endif /* !(__BEN_VLAN_802_1Q_INC__) */
This page took 1.135162 seconds and 5 git commands to generate.