1#ifndef _LINUX_IF_MACVLAN_H
2#define _LINUX_IF_MACVLAN_H
3
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>
11
12#if IS_ENABLED(CONFIG_MACVTAP)
13struct socket *macvtap_get_socket(struct file *);
14#else
15#include <linux/err.h>
16#include <linux/errno.h>
17struct file;
18struct socket;
19static inline struct socket *macvtap_get_socket(struct file *f)
20{
21 return ERR_PTR(-EINVAL);
22}
23#endif
24
25struct macvlan_port;
26struct macvtap_queue;
27
28
29
30
31
32#define MAX_MACVTAP_QUEUES 16
33
34#define MACVLAN_MC_FILTER_BITS 8
35#define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
36
37struct macvlan_dev {
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;
43 void *fwd_priv;
44 struct vlan_pcpu_stats __percpu *pcpu_stats;
45
46 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
47
48 netdev_features_t set_features;
49 enum macvlan_mode mode;
50 u16 flags;
51
52 struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES];
53
54 struct list_head queue_list;
55 int numvtaps;
56 int numqueues;
57 netdev_features_t tap_features;
58 int minor;
59 int nest_level;
60};
61
62static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
63 unsigned int len, bool success,
64 bool multicast)
65{
66 if (likely(success)) {
67 struct vlan_pcpu_stats *pcpu_stats;
68
69 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
70 u64_stats_update_begin(&pcpu_stats->syncp);
71 pcpu_stats->rx_packets++;
72 pcpu_stats->rx_bytes += len;
73 if (multicast)
74 pcpu_stats->rx_multicast++;
75 u64_stats_update_end(&pcpu_stats->syncp);
76 } else {
77 this_cpu_inc(vlan->pcpu_stats->rx_errors);
78 }
79}
80
81extern void macvlan_common_setup(struct net_device *dev);
82
83extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
84 struct nlattr *tb[], struct nlattr *data[]);
85
86extern void macvlan_count_rx(const struct macvlan_dev *vlan,
87 unsigned int len, bool success,
88 bool multicast);
89
90extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
91
92extern int macvlan_link_register(struct rtnl_link_ops *ops);
93
94#if IS_ENABLED(CONFIG_MACVLAN)
95static inline struct net_device *
96macvlan_dev_real_dev(const struct net_device *dev)
97{
98 struct macvlan_dev *macvlan = netdev_priv(dev);
99
100 return macvlan->lowerdev;
101}
102#else
103static inline struct net_device *
104macvlan_dev_real_dev(const struct net_device *dev)
105{
106 BUG();
107 return NULL;
108}
109#endif
110
111#endif
112