1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_IF_MACVLAN_H
3 #define _LINUX_IF_MACVLAN_H
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>
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.
20 #define MAX_TAP_QUEUES 256
22 #define MACVLAN_MC_FILTER_BITS 8
23 #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
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
;
32 struct vlan_pcpu_stats __percpu
*pcpu_stats
;
34 DECLARE_BITMAP(mc_filter
, MACVLAN_MC_FILTER_SZ
);
36 netdev_features_t set_features
;
37 enum macvlan_mode mode
;
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
;
45 netdev_features_t tap_features
;
48 #ifdef CONFIG_NET_POLL_CONTROLLER
49 struct netpoll
*netpoll
;
51 unsigned int macaddr_count
;
54 static inline void macvlan_count_rx(const struct macvlan_dev
*vlan
,
55 unsigned int len
, bool success
,
58 if (likely(success
)) {
59 struct vlan_pcpu_stats
*pcpu_stats
;
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
;
66 pcpu_stats
->rx_multicast
++;
67 u64_stats_update_end(&pcpu_stats
->syncp
);
69 this_cpu_inc(vlan
->pcpu_stats
->rx_errors
);
73 extern void macvlan_common_setup(struct net_device
*dev
);
75 extern int macvlan_common_newlink(struct net
*src_net
, struct net_device
*dev
,
76 struct nlattr
*tb
[], struct nlattr
*data
[]);
78 extern void macvlan_count_rx(const struct macvlan_dev
*vlan
,
79 unsigned int len
, bool success
,
82 extern void macvlan_dellink(struct net_device
*dev
, struct list_head
*head
);
84 extern int macvlan_link_register(struct rtnl_link_ops
*ops
);
86 #if IS_ENABLED(CONFIG_MACVLAN)
87 static inline struct net_device
*
88 macvlan_dev_real_dev(const struct net_device
*dev
)
90 struct macvlan_dev
*macvlan
= netdev_priv(dev
);
92 return macvlan
->lowerdev
;
95 static inline struct net_device
*
96 macvlan_dev_real_dev(const struct net_device
*dev
)
103 #endif /* _LINUX_IF_MACVLAN_H */