blob: 0e2c60efad2def3c70ce43758bed23e90030fce3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Patrick McHardyb863ceb2007-07-14 18:55:06 -07002#ifndef _LINUX_IF_MACVLAN_H
3#define _LINUX_IF_MACVLAN_H
4
Arnd Bergmannfc0663d2010-01-30 12:23:40 +00005#include <linux/if_link.h>
Li RongQingcdf3e272014-01-04 14:22:34 +08006#include <linux/if_vlan.h>
Arnd Bergmannfc0663d2010-01-30 12:23:40 +00007#include <linux/list.h>
8#include <linux/netdevice.h>
9#include <linux/netlink.h>
10#include <net/netlink.h>
Eric Dumazetbc661542010-06-24 00:54:21 +000011#include <linux/u64_stats_sync.h>
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000012
13struct macvlan_port;
14struct macvtap_queue;
15
Krishna Kumar1565c7c2010-08-04 06:15:59 +000016/*
17 * Maximum times a macvtap device can be opened. This can be used to
18 * configure the number of receive queue, e.g. for multiqueue virtio.
19 */
Sainath Grandhi635b8c82017-02-10 16:03:47 -080020#define MAX_TAP_QUEUES 256
Krishna Kumar1565c7c2010-08-04 06:15:59 +000021
Eric Dumazetcd431e72013-02-05 20:22:50 +000022#define MACVLAN_MC_FILTER_BITS 8
23#define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
24
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000025struct macvlan_dev {
26 struct net_device *dev;
27 struct list_head list;
28 struct hlist_node hlist;
29 struct macvlan_port *port;
30 struct net_device *lowerdev;
John Fastabenda6cc0cf2013-11-06 09:54:46 -080031 void *fwd_priv;
Li RongQingcdf3e272014-01-04 14:22:34 +080032 struct vlan_pcpu_stats __percpu *pcpu_stats;
Eric Dumazetcd431e72013-02-05 20:22:50 +000033
34 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
35
Vlad Yasevich2be5c762013-06-25 16:04:21 -040036 netdev_features_t set_features;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000037 enum macvlan_mode mode;
John Fastabenddf8ef8f2012-04-15 06:44:37 +000038 u16 flags;
Jason Wang815f2362013-06-05 23:54:39 +000039 /* This array tracks active taps. */
Sainath Grandhi635b8c82017-02-10 16:03:47 -080040 struct tap_queue __rcu *taps[MAX_TAP_QUEUES];
Jason Wang815f2362013-06-05 23:54:39 +000041 /* This list tracks all taps (both enabled and disabled) */
42 struct list_head queue_list;
Krishna Kumar1565c7c2010-08-04 06:15:59 +000043 int numvtaps;
Jason Wang815f2362013-06-05 23:54:39 +000044 int numqueues;
Vlad Yasevich2be5c762013-06-25 16:04:21 -040045 netdev_features_t tap_features;
Eric W. Biedermane09eff72011-10-20 04:29:24 +000046 int minor;
Vlad Yasevichc674ac32014-05-16 17:04:56 -040047 int nest_level;
dingtianhong688cea82014-05-30 16:00:56 +080048#ifdef CONFIG_NET_POLL_CONTROLLER
49 struct netpoll *netpoll;
50#endif
Michael Braun79cf79a2014-09-25 16:31:08 +020051 unsigned int macaddr_count;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000052};
53
54static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
55 unsigned int len, bool success,
56 bool multicast)
57{
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000058 if (likely(success)) {
Li RongQingcdf3e272014-01-04 14:22:34 +080059 struct vlan_pcpu_stats *pcpu_stats;
Eric Dumazet8ffab512010-11-10 21:14:04 +000060
61 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
62 u64_stats_update_begin(&pcpu_stats->syncp);
63 pcpu_stats->rx_packets++;
64 pcpu_stats->rx_bytes += len;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000065 if (multicast)
Eric Dumazet8ffab512010-11-10 21:14:04 +000066 pcpu_stats->rx_multicast++;
67 u64_stats_update_end(&pcpu_stats->syncp);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000068 } else {
Eric Dumazet8ffab512010-11-10 21:14:04 +000069 this_cpu_inc(vlan->pcpu_stats->rx_errors);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000070 }
71}
72
Herbert Xu8a357472010-07-21 21:44:31 +000073extern void macvlan_common_setup(struct net_device *dev);
74
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000075extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
Vlad Yasevich2f6a1b62013-12-11 13:27:11 -050076 struct nlattr *tb[], struct nlattr *data[]);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000077
78extern void macvlan_count_rx(const struct macvlan_dev *vlan,
79 unsigned int len, bool success,
80 bool multicast);
81
82extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
83
84extern int macvlan_link_register(struct rtnl_link_ops *ops);
85
Michal Kubečekbe9eac42013-11-15 06:18:40 +010086#if IS_ENABLED(CONFIG_MACVLAN)
87static inline struct net_device *
88macvlan_dev_real_dev(const struct net_device *dev)
89{
90 struct macvlan_dev *macvlan = netdev_priv(dev);
91
92 return macvlan->lowerdev;
93}
94#else
95static inline struct net_device *
96macvlan_dev_real_dev(const struct net_device *dev)
97{
98 BUG();
99 return NULL;
100}
101#endif
102
Patrick McHardyb863ceb2007-07-14 18:55:06 -0700103#endif /* _LINUX_IF_MACVLAN_H */