]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/if_macvlan.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-bionic-kernel.git] / include / linux / if_macvlan.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_IF_MACVLAN_H
3 #define _LINUX_IF_MACVLAN_H
4
5 #include <linux/if_link.h>
6 #include <linux/if_vlan.h>
7 #include <linux/list.h>
8 #include <linux/netdevice.h>
9 #include <linux/netlink.h>
10 #include <net/netlink.h>
11 #include <linux/u64_stats_sync.h>
12
13 struct macvlan_port;
14 struct macvtap_queue;
15
16 /*
17 * Maximum times a macvtap device can be opened. This can be used to
18 * configure the number of receive queue, e.g. for multiqueue virtio.
19 */
20 #define MAX_TAP_QUEUES 256
21
22 #define MACVLAN_MC_FILTER_BITS 8
23 #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
24
25 struct macvlan_dev {
26 struct net_device *dev;
27 struct list_head list;
28 struct hlist_node hlist;
29 struct macvlan_port *port;
30 struct net_device *lowerdev;
31 void *fwd_priv;
32 struct vlan_pcpu_stats __percpu *pcpu_stats;
33
34 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
35
36 netdev_features_t set_features;
37 enum macvlan_mode mode;
38 u16 flags;
39 /* This array tracks active taps. */
40 struct tap_queue __rcu *taps[MAX_TAP_QUEUES];
41 /* This list tracks all taps (both enabled and disabled) */
42 struct list_head queue_list;
43 int numvtaps;
44 int numqueues;
45 netdev_features_t tap_features;
46 int minor;
47 int nest_level;
48 #ifdef CONFIG_NET_POLL_CONTROLLER
49 struct netpoll *netpoll;
50 #endif
51 unsigned int macaddr_count;
52 };
53
54 static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
55 unsigned int len, bool success,
56 bool multicast)
57 {
58 if (likely(success)) {
59 struct vlan_pcpu_stats *pcpu_stats;
60
61 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
62 u64_stats_update_begin(&pcpu_stats->syncp);
63 pcpu_stats->rx_packets++;
64 pcpu_stats->rx_bytes += len;
65 if (multicast)
66 pcpu_stats->rx_multicast++;
67 u64_stats_update_end(&pcpu_stats->syncp);
68 } else {
69 this_cpu_inc(vlan->pcpu_stats->rx_errors);
70 }
71 }
72
73 extern void macvlan_common_setup(struct net_device *dev);
74
75 extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
76 struct nlattr *tb[], struct nlattr *data[]);
77
78 extern void macvlan_count_rx(const struct macvlan_dev *vlan,
79 unsigned int len, bool success,
80 bool multicast);
81
82 extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
83
84 extern int macvlan_link_register(struct rtnl_link_ops *ops);
85
86 #if IS_ENABLED(CONFIG_MACVLAN)
87 static inline struct net_device *
88 macvlan_dev_real_dev(const struct net_device *dev)
89 {
90 struct macvlan_dev *macvlan = netdev_priv(dev);
91
92 return macvlan->lowerdev;
93 }
94 #else
95 static inline struct net_device *
96 macvlan_dev_real_dev(const struct net_device *dev)
97 {
98 BUG();
99 return NULL;
100 }
101 #endif
102
103 #endif /* _LINUX_IF_MACVLAN_H */