1 #ifndef _LINUX_IF_MACVLAN_H
2 #define _LINUX_IF_MACVLAN_H
4 #include <linux/if_link.h>
5 #include <linux/list.h>
6 #include <linux/netdevice.h>
7 #include <linux/netlink.h>
8 #include <net/netlink.h>
9 #include <linux/u64_stats_sync.h>
11 #if defined(CONFIG_MACVTAP) || defined(CONFIG_MACVTAP_MODULE)
12 struct socket *macvtap_get_socket(struct file *);
14 #include <linux/err.h>
15 #include <linux/errno.h>
18 static inline struct socket *macvtap_get_socket(struct file *f)
20 return ERR_PTR(-EINVAL);
22 #endif /* CONFIG_MACVTAP */
28 * struct macvlan_pcpu_stats - MACVLAN percpu stats
29 * @rx_packets: number of received packets
30 * @rx_bytes: number of received bytes
31 * @rx_multicast: number of received multicast packets
32 * @tx_packets: number of transmitted packets
33 * @tx_bytes: number of transmitted bytes
34 * @syncp: synchronization point for 64bit counters
35 * @rx_errors: number of rx errors
36 * @tx_dropped: number of tx dropped packets
38 struct macvlan_pcpu_stats {
44 struct u64_stats_sync syncp;
50 * Maximum times a macvtap device can be opened. This can be used to
51 * configure the number of receive queue, e.g. for multiqueue virtio.
53 #define MAX_MACVTAP_QUEUES (NR_CPUS < 16 ? NR_CPUS : 16)
56 struct net_device *dev;
57 struct list_head list;
58 struct hlist_node hlist;
59 struct macvlan_port *port;
60 struct net_device *lowerdev;
61 struct macvlan_pcpu_stats __percpu *pcpu_stats;
62 enum macvlan_mode mode;
63 int (*receive)(struct sk_buff *skb);
64 int (*forward)(struct net_device *dev, struct sk_buff *skb);
65 struct macvtap_queue *taps[MAX_MACVTAP_QUEUES];
69 static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
70 unsigned int len, bool success,
73 if (likely(success)) {
74 struct macvlan_pcpu_stats *pcpu_stats;
76 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
77 u64_stats_update_begin(&pcpu_stats->syncp);
78 pcpu_stats->rx_packets++;
79 pcpu_stats->rx_bytes += len;
81 pcpu_stats->rx_multicast++;
82 u64_stats_update_end(&pcpu_stats->syncp);
84 this_cpu_inc(vlan->pcpu_stats->rx_errors);
88 extern void macvlan_common_setup(struct net_device *dev);
90 extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
91 struct nlattr *tb[], struct nlattr *data[],
92 int (*receive)(struct sk_buff *skb),
93 int (*forward)(struct net_device *dev,
94 struct sk_buff *skb));
96 extern void macvlan_count_rx(const struct macvlan_dev *vlan,
97 unsigned int len, bool success,
100 extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
102 extern int macvlan_link_register(struct rtnl_link_ops *ops);
104 extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
105 struct net_device *dev);
107 #endif /* _LINUX_IF_MACVLAN_H */