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>
16 * Maximum times a macvtap device can be opened. This can be used to
17 * configure the number of receive queue, e.g. for multiqueue virtio.
19 #define MAX_TAP_QUEUES 256
21 #define MACVLAN_MC_FILTER_BITS 8
22 #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
25 struct net_device
*dev
;
26 struct list_head list
;
27 struct hlist_node hlist
;
28 struct macvlan_port
*port
;
29 struct net_device
*lowerdev
;
31 struct vlan_pcpu_stats __percpu
*pcpu_stats
;
33 DECLARE_BITMAP(mc_filter
, MACVLAN_MC_FILTER_SZ
);
35 netdev_features_t set_features
;
36 enum macvlan_mode mode
;
38 /* This array tracks active taps. */
39 struct tap_queue __rcu
*taps
[MAX_TAP_QUEUES
];
40 /* This list tracks all taps (both enabled and disabled) */
41 struct list_head queue_list
;
44 netdev_features_t tap_features
;
47 #ifdef CONFIG_NET_POLL_CONTROLLER
48 struct netpoll
*netpoll
;
50 unsigned int macaddr_count
;
53 static inline void macvlan_count_rx(const struct macvlan_dev
*vlan
,
54 unsigned int len
, bool success
,
57 if (likely(success
)) {
58 struct vlan_pcpu_stats
*pcpu_stats
;
60 pcpu_stats
= this_cpu_ptr(vlan
->pcpu_stats
);
61 u64_stats_update_begin(&pcpu_stats
->syncp
);
62 pcpu_stats
->rx_packets
++;
63 pcpu_stats
->rx_bytes
+= len
;
65 pcpu_stats
->rx_multicast
++;
66 u64_stats_update_end(&pcpu_stats
->syncp
);
68 this_cpu_inc(vlan
->pcpu_stats
->rx_errors
);
72 extern void macvlan_common_setup(struct net_device
*dev
);
74 extern int macvlan_common_newlink(struct net
*src_net
, struct net_device
*dev
,
75 struct nlattr
*tb
[], struct nlattr
*data
[]);
77 extern void macvlan_count_rx(const struct macvlan_dev
*vlan
,
78 unsigned int len
, bool success
,
81 extern void macvlan_dellink(struct net_device
*dev
, struct list_head
*head
);
83 extern int macvlan_link_register(struct rtnl_link_ops
*ops
);
85 #if IS_ENABLED(CONFIG_MACVLAN)
86 static inline struct net_device
*
87 macvlan_dev_real_dev(const struct net_device
*dev
)
89 struct macvlan_dev
*macvlan
= netdev_priv(dev
);
91 return macvlan
->lowerdev
;
94 static inline struct net_device
*
95 macvlan_dev_real_dev(const struct net_device
*dev
)
102 #endif /* _LINUX_IF_MACVLAN_H */