1 #ifndef _LINUX_IF_MACVLAN_H
2 #define _LINUX_IF_MACVLAN_H
4 #include <linux/if_link.h>
5 #include <linux/if_vlan.h>
6 #include <linux/list.h>
7 #include <linux/netdevice.h>
8 #include <linux/netlink.h>
9 #include <net/netlink.h>
10 #include <linux/u64_stats_sync.h>
12 #if IS_ENABLED(CONFIG_MACVTAP)
13 struct socket *macvtap_get_socket(struct file *);
15 #include <linux/err.h>
16 #include <linux/errno.h>
19 static inline struct socket *macvtap_get_socket(struct file *f)
21 return ERR_PTR(-EINVAL);
23 #endif /* CONFIG_MACVTAP */
29 * Maximum times a macvtap device can be opened. This can be used to
30 * configure the number of receive queue, e.g. for multiqueue virtio.
32 #define MAX_MACVTAP_QUEUES 16
34 #define MACVLAN_MC_FILTER_BITS 8
35 #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
38 struct net_device *dev;
39 struct list_head list;
40 struct hlist_node hlist;
41 struct macvlan_port *port;
42 struct net_device *lowerdev;
44 struct vlan_pcpu_stats __percpu *pcpu_stats;
46 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
48 netdev_features_t set_features;
49 enum macvlan_mode mode;
51 /* This array tracks active taps. */
52 struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES];
53 /* This list tracks all taps (both enabled and disabled) */
54 struct list_head queue_list;
57 netdev_features_t tap_features;
60 #ifdef CONFIG_NET_POLL_CONTROLLER
61 struct netpoll *netpoll;
65 static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
66 unsigned int len, bool success,
69 if (likely(success)) {
70 struct vlan_pcpu_stats *pcpu_stats;
72 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
73 u64_stats_update_begin(&pcpu_stats->syncp);
74 pcpu_stats->rx_packets++;
75 pcpu_stats->rx_bytes += len;
77 pcpu_stats->rx_multicast++;
78 u64_stats_update_end(&pcpu_stats->syncp);
80 this_cpu_inc(vlan->pcpu_stats->rx_errors);
84 extern void macvlan_common_setup(struct net_device *dev);
86 extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
87 struct nlattr *tb[], struct nlattr *data[]);
89 extern void macvlan_count_rx(const struct macvlan_dev *vlan,
90 unsigned int len, bool success,
93 extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
95 extern int macvlan_link_register(struct rtnl_link_ops *ops);
97 #if IS_ENABLED(CONFIG_MACVLAN)
98 static inline struct net_device *
99 macvlan_dev_real_dev(const struct net_device *dev)
101 struct macvlan_dev *macvlan = netdev_priv(dev);
103 return macvlan->lowerdev;
106 static inline struct net_device *
107 macvlan_dev_real_dev(const struct net_device *dev)
114 #endif /* _LINUX_IF_MACVLAN_H */