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