]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/if_macvlan.h
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
[mirror_ubuntu-bionic-kernel.git] / include / linux / if_macvlan.h
CommitLineData
b863ceb7
PM
1#ifndef _LINUX_IF_MACVLAN_H
2#define _LINUX_IF_MACVLAN_H
3
fc0663d6 4#include <linux/if_link.h>
cdf3e274 5#include <linux/if_vlan.h>
fc0663d6
AB
6#include <linux/list.h>
7#include <linux/netdevice.h>
8#include <linux/netlink.h>
9#include <net/netlink.h>
bc66154e 10#include <linux/u64_stats_sync.h>
fc0663d6 11
1d2f41ed 12#if IS_ENABLED(CONFIG_MACVTAP)
501c774c
AB
13struct socket *macvtap_get_socket(struct file *);
14#else
15#include <linux/err.h>
16#include <linux/errno.h>
17struct file;
18struct socket;
19static inline struct socket *macvtap_get_socket(struct file *f)
20{
21 return ERR_PTR(-EINVAL);
22}
23#endif /* CONFIG_MACVTAP */
24
fc0663d6
AB
25struct macvlan_port;
26struct macvtap_queue;
27
1565c7c1
KK
28/*
29 * Maximum times a macvtap device can be opened. This can be used to
30 * configure the number of receive queue, e.g. for multiqueue virtio.
31 */
f0afce01 32#define MAX_MACVTAP_QUEUES 16
1565c7c1 33
cd431e73
ED
34#define MACVLAN_MC_FILTER_BITS 8
35#define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
36
fc0663d6
AB
37struct macvlan_dev {
38 struct net_device *dev;
39 struct list_head list;
40 struct hlist_node hlist;
41 struct macvlan_port *port;
42 struct net_device *lowerdev;
a6cc0cfa 43 void *fwd_priv;
cdf3e274 44 struct vlan_pcpu_stats __percpu *pcpu_stats;
cd431e73
ED
45
46 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
47
2be5c767 48 netdev_features_t set_features;
fc0663d6 49 enum macvlan_mode mode;
df8ef8f3 50 u16 flags;
815f236d 51 /* This array tracks active taps. */
d9a90a31 52 struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES];
815f236d
JW
53 /* This list tracks all taps (both enabled and disabled) */
54 struct list_head queue_list;
1565c7c1 55 int numvtaps;
815f236d 56 int numqueues;
2be5c767 57 netdev_features_t tap_features;
e09eff7f 58 int minor;
c674ac30 59 int nest_level;
688cea83 60#ifdef CONFIG_NET_POLL_CONTROLLER
61 struct netpoll *netpoll;
62#endif
fc0663d6
AB
63};
64
65static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
66 unsigned int len, bool success,
67 bool multicast)
68{
fc0663d6 69 if (likely(success)) {
cdf3e274 70 struct vlan_pcpu_stats *pcpu_stats;
8ffab51b
ED
71
72 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
73 u64_stats_update_begin(&pcpu_stats->syncp);
74 pcpu_stats->rx_packets++;
75 pcpu_stats->rx_bytes += len;
fc0663d6 76 if (multicast)
8ffab51b
ED
77 pcpu_stats->rx_multicast++;
78 u64_stats_update_end(&pcpu_stats->syncp);
fc0663d6 79 } else {
8ffab51b 80 this_cpu_inc(vlan->pcpu_stats->rx_errors);
fc0663d6
AB
81 }
82}
83
8a35747a
HX
84extern void macvlan_common_setup(struct net_device *dev);
85
fc0663d6 86extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
2f6a1b66 87 struct nlattr *tb[], struct nlattr *data[]);
fc0663d6
AB
88
89extern void macvlan_count_rx(const struct macvlan_dev *vlan,
90 unsigned int len, bool success,
91 bool multicast);
92
93extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
94
95extern int macvlan_link_register(struct rtnl_link_ops *ops);
96
be9eac48
MK
97#if IS_ENABLED(CONFIG_MACVLAN)
98static inline struct net_device *
99macvlan_dev_real_dev(const struct net_device *dev)
100{
101 struct macvlan_dev *macvlan = netdev_priv(dev);
102
103 return macvlan->lowerdev;
104}
105#else
106static inline struct net_device *
107macvlan_dev_real_dev(const struct net_device *dev)
108{
109 BUG();
110 return NULL;
111}
112#endif
113
b863ceb7 114#endif /* _LINUX_IF_MACVLAN_H */