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 IS_ENABLED(CONFIG_MACVTAP)
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 16
55 #define MACVLAN_MC_FILTER_BITS 8
56 #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
59 struct net_device
*dev
;
60 struct list_head list
;
61 struct hlist_node hlist
;
62 struct macvlan_port
*port
;
63 struct net_device
*lowerdev
;
65 struct macvlan_pcpu_stats __percpu
*pcpu_stats
;
67 DECLARE_BITMAP(mc_filter
, MACVLAN_MC_FILTER_SZ
);
69 netdev_features_t set_features
;
70 enum macvlan_mode mode
;
72 int (*receive
)(struct sk_buff
*skb
);
73 int (*forward
)(struct net_device
*dev
, struct sk_buff
*skb
);
74 /* This array tracks active taps. */
75 struct macvtap_queue __rcu
*taps
[MAX_MACVTAP_QUEUES
];
76 /* This list tracks all taps (both enabled and disabled) */
77 struct list_head queue_list
;
80 netdev_features_t tap_features
;
84 static inline void macvlan_count_rx(const struct macvlan_dev
*vlan
,
85 unsigned int len
, bool success
,
88 if (likely(success
)) {
89 struct macvlan_pcpu_stats
*pcpu_stats
;
91 pcpu_stats
= this_cpu_ptr(vlan
->pcpu_stats
);
92 u64_stats_update_begin(&pcpu_stats
->syncp
);
93 pcpu_stats
->rx_packets
++;
94 pcpu_stats
->rx_bytes
+= len
;
96 pcpu_stats
->rx_multicast
++;
97 u64_stats_update_end(&pcpu_stats
->syncp
);
99 this_cpu_inc(vlan
->pcpu_stats
->rx_errors
);
103 extern void macvlan_common_setup(struct net_device
*dev
);
105 extern int macvlan_common_newlink(struct net
*src_net
, struct net_device
*dev
,
106 struct nlattr
*tb
[], struct nlattr
*data
[],
107 int (*receive
)(struct sk_buff
*skb
),
108 int (*forward
)(struct net_device
*dev
,
109 struct sk_buff
*skb
));
111 extern void macvlan_count_rx(const struct macvlan_dev
*vlan
,
112 unsigned int len
, bool success
,
115 extern void macvlan_dellink(struct net_device
*dev
, struct list_head
*head
);
117 extern int macvlan_link_register(struct rtnl_link_ops
*ops
);
119 extern netdev_tx_t
macvlan_start_xmit(struct sk_buff
*skb
,
120 struct net_device
*dev
);
122 #if IS_ENABLED(CONFIG_MACVLAN)
123 static inline struct net_device
*
124 macvlan_dev_real_dev(const struct net_device
*dev
)
126 struct macvlan_dev
*macvlan
= netdev_priv(dev
);
128 return macvlan
->lowerdev
;
131 static inline struct net_device
*
132 macvlan_dev_real_dev(const struct net_device
*dev
)
139 #endif /* _LINUX_IF_MACVLAN_H */