blob: c9ec1343d1879cc463ffe50afcee143623350b5d [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
12struct macvlan_port;
13struct macvtap_queue;
14
Krishna Kumar1565c7c2010-08-04 06:15:59 +000015/*
16 * Maximum times a macvtap device can be opened. This can be used to
17 * configure the number of receive queue, e.g. for multiqueue virtio.
18 */
Sainath Grandhi635b8c82017-02-10 16:03:47 -080019#define MAX_TAP_QUEUES 256
Krishna Kumar1565c7c2010-08-04 06:15:59 +000020
Eric Dumazetcd431e72013-02-05 20:22:50 +000021#define MACVLAN_MC_FILTER_BITS 8
22#define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
23
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000024struct macvlan_dev {
25 struct net_device *dev;
26 struct list_head list;
27 struct hlist_node hlist;
28 struct macvlan_port *port;
29 struct net_device *lowerdev;
John Fastabenda6cc0cf2013-11-06 09:54:46 -080030 void *fwd_priv;
Li RongQingcdf3e272014-01-04 14:22:34 +080031 struct vlan_pcpu_stats __percpu *pcpu_stats;
Eric Dumazetcd431e72013-02-05 20:22:50 +000032
33 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
34
Vlad Yasevich2be5c762013-06-25 16:04:21 -040035 netdev_features_t set_features;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000036 enum macvlan_mode mode;
John Fastabenddf8ef8f2012-04-15 06:44:37 +000037 u16 flags;
Jason Wang815f2362013-06-05 23:54:39 +000038 /* This array tracks active taps. */
Sainath Grandhi635b8c82017-02-10 16:03:47 -080039 struct tap_queue __rcu *taps[MAX_TAP_QUEUES];
Jason Wang815f2362013-06-05 23:54:39 +000040 /* This list tracks all taps (both enabled and disabled) */
41 struct list_head queue_list;
Krishna Kumar1565c7c2010-08-04 06:15:59 +000042 int numvtaps;
Jason Wang815f2362013-06-05 23:54:39 +000043 int numqueues;
Vlad Yasevich2be5c762013-06-25 16:04:21 -040044 netdev_features_t tap_features;
Eric W. Biedermane09eff72011-10-20 04:29:24 +000045 int minor;
Vlad Yasevichc674ac32014-05-16 17:04:56 -040046 int nest_level;
dingtianhong688cea82014-05-30 16:00:56 +080047#ifdef CONFIG_NET_POLL_CONTROLLER
48 struct netpoll *netpoll;
49#endif
Michael Braun79cf79a2014-09-25 16:31:08 +020050 unsigned int macaddr_count;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000051};
52
53static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
54 unsigned int len, bool success,
55 bool multicast)
56{
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000057 if (likely(success)) {
Li RongQingcdf3e272014-01-04 14:22:34 +080058 struct vlan_pcpu_stats *pcpu_stats;
Eric Dumazet8ffab512010-11-10 21:14:04 +000059
60 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
61 u64_stats_update_begin(&pcpu_stats->syncp);
62 pcpu_stats->rx_packets++;
63 pcpu_stats->rx_bytes += len;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000064 if (multicast)
Eric Dumazet8ffab512010-11-10 21:14:04 +000065 pcpu_stats->rx_multicast++;
66 u64_stats_update_end(&pcpu_stats->syncp);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000067 } else {
Eric Dumazet8ffab512010-11-10 21:14:04 +000068 this_cpu_inc(vlan->pcpu_stats->rx_errors);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000069 }
70}
71
Herbert Xu8a357472010-07-21 21:44:31 +000072extern void macvlan_common_setup(struct net_device *dev);
73
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000074extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
Vlad Yasevich2f6a1b62013-12-11 13:27:11 -050075 struct nlattr *tb[], struct nlattr *data[]);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000076
77extern void macvlan_count_rx(const struct macvlan_dev *vlan,
78 unsigned int len, bool success,
79 bool multicast);
80
81extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
82
83extern int macvlan_link_register(struct rtnl_link_ops *ops);
84
Michal Kubečekbe9eac42013-11-15 06:18:40 +010085#if IS_ENABLED(CONFIG_MACVLAN)
86static inline struct net_device *
87macvlan_dev_real_dev(const struct net_device *dev)
88{
89 struct macvlan_dev *macvlan = netdev_priv(dev);
90
91 return macvlan->lowerdev;
92}
93#else
94static inline struct net_device *
95macvlan_dev_real_dev(const struct net_device *dev)
96{
97 BUG();
98 return NULL;
99}
100#endif
101
Patrick McHardyb863ceb2007-07-14 18:55:06 -0700102#endif /* _LINUX_IF_MACVLAN_H */