blob: 7c8b20b120eac680f27e3cd1e99630b1fe521799 [file] [log] [blame]
Patrick McHardyb863ceb2007-07-14 18:55:06 -07001#ifndef _LINUX_IF_MACVLAN_H
2#define _LINUX_IF_MACVLAN_H
3
Arnd Bergmannfc0663d2010-01-30 12:23:40 +00004#include <linux/if_link.h>
Li RongQingcdf3e272014-01-04 14:22:34 +08005#include <linux/if_vlan.h>
Arnd Bergmannfc0663d2010-01-30 12:23:40 +00006#include <linux/list.h>
7#include <linux/netdevice.h>
8#include <linux/netlink.h>
9#include <net/netlink.h>
Eric Dumazetbc661542010-06-24 00:54:21 +000010#include <linux/u64_stats_sync.h>
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000011
Jason Wang1d2f41e2013-06-05 23:54:35 +000012#if IS_ENABLED(CONFIG_MACVTAP)
Arnd Bergmann501c7742010-02-18 05:46:50 +000013struct 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
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000025struct macvlan_port;
26struct macvtap_queue;
27
Krishna Kumar1565c7c2010-08-04 06:15:59 +000028/*
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 */
Jason Wangf0afce02013-06-05 23:54:37 +000032#define MAX_MACVTAP_QUEUES 16
Krishna Kumar1565c7c2010-08-04 06:15:59 +000033
Eric Dumazetcd431e72013-02-05 20:22:50 +000034#define MACVLAN_MC_FILTER_BITS 8
35#define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
36
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000037struct 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;
John Fastabenda6cc0cf2013-11-06 09:54:46 -080043 void *fwd_priv;
Li RongQingcdf3e272014-01-04 14:22:34 +080044 struct vlan_pcpu_stats __percpu *pcpu_stats;
Eric Dumazetcd431e72013-02-05 20:22:50 +000045
46 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
47
Vlad Yasevich2be5c762013-06-25 16:04:21 -040048 netdev_features_t set_features;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000049 enum macvlan_mode mode;
John Fastabenddf8ef8f2012-04-15 06:44:37 +000050 u16 flags;
Jason Wang815f2362013-06-05 23:54:39 +000051 /* This array tracks active taps. */
Jason Wangd9a90a32013-06-13 14:23:35 +080052 struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES];
Jason Wang815f2362013-06-05 23:54:39 +000053 /* This list tracks all taps (both enabled and disabled) */
54 struct list_head queue_list;
Krishna Kumar1565c7c2010-08-04 06:15:59 +000055 int numvtaps;
Jason Wang815f2362013-06-05 23:54:39 +000056 int numqueues;
Vlad Yasevich2be5c762013-06-25 16:04:21 -040057 netdev_features_t tap_features;
Eric W. Biedermane09eff72011-10-20 04:29:24 +000058 int minor;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000059};
60
61static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
62 unsigned int len, bool success,
63 bool multicast)
64{
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000065 if (likely(success)) {
Li RongQingcdf3e272014-01-04 14:22:34 +080066 struct vlan_pcpu_stats *pcpu_stats;
Eric Dumazet8ffab512010-11-10 21:14:04 +000067
68 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
69 u64_stats_update_begin(&pcpu_stats->syncp);
70 pcpu_stats->rx_packets++;
71 pcpu_stats->rx_bytes += len;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000072 if (multicast)
Eric Dumazet8ffab512010-11-10 21:14:04 +000073 pcpu_stats->rx_multicast++;
74 u64_stats_update_end(&pcpu_stats->syncp);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000075 } else {
Eric Dumazet8ffab512010-11-10 21:14:04 +000076 this_cpu_inc(vlan->pcpu_stats->rx_errors);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000077 }
78}
79
Herbert Xu8a357472010-07-21 21:44:31 +000080extern void macvlan_common_setup(struct net_device *dev);
81
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000082extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
Vlad Yasevich2f6a1b62013-12-11 13:27:11 -050083 struct nlattr *tb[], struct nlattr *data[]);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000084
85extern void macvlan_count_rx(const struct macvlan_dev *vlan,
86 unsigned int len, bool success,
87 bool multicast);
88
89extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
90
91extern int macvlan_link_register(struct rtnl_link_ops *ops);
92
Michal Kubečekbe9eac42013-11-15 06:18:40 +010093#if IS_ENABLED(CONFIG_MACVLAN)
94static inline struct net_device *
95macvlan_dev_real_dev(const struct net_device *dev)
96{
97 struct macvlan_dev *macvlan = netdev_priv(dev);
98
99 return macvlan->lowerdev;
100}
101#else
102static inline struct net_device *
103macvlan_dev_real_dev(const struct net_device *dev)
104{
105 BUG();
106 return NULL;
107}
108#endif
109
Patrick McHardyb863ceb2007-07-14 18:55:06 -0700110#endif /* _LINUX_IF_MACVLAN_H */