blob: 4cb7aeeafce03df846188fb936b6bd2ee6b0417f [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;
Krishna Kumar1565c7c2010-08-04 06:15:59 +000014
Eric Dumazetcd431e72013-02-05 20:22:50 +000015#define MACVLAN_MC_FILTER_BITS 8
16#define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
17
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000018struct macvlan_dev {
19 struct net_device *dev;
20 struct list_head list;
21 struct hlist_node hlist;
22 struct macvlan_port *port;
23 struct net_device *lowerdev;
John Fastabenda6cc0cf2013-11-06 09:54:46 -080024 void *fwd_priv;
Li RongQingcdf3e272014-01-04 14:22:34 +080025 struct vlan_pcpu_stats __percpu *pcpu_stats;
Eric Dumazetcd431e72013-02-05 20:22:50 +000026
27 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
28
Vlad Yasevich2be5c762013-06-25 16:04:21 -040029 netdev_features_t set_features;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000030 enum macvlan_mode mode;
John Fastabenddf8ef8f2012-04-15 06:44:37 +000031 u16 flags;
Vlad Yasevichc674ac32014-05-16 17:04:56 -040032 int nest_level;
Girish Moodalbail5e54b3c2017-12-08 06:03:26 -080033 unsigned int macaddr_count;
dingtianhong688cea82014-05-30 16:00:56 +080034#ifdef CONFIG_NET_POLL_CONTROLLER
35 struct netpoll *netpoll;
36#endif
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000037};
38
39static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
40 unsigned int len, bool success,
41 bool multicast)
42{
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000043 if (likely(success)) {
Li RongQingcdf3e272014-01-04 14:22:34 +080044 struct vlan_pcpu_stats *pcpu_stats;
Eric Dumazet8ffab512010-11-10 21:14:04 +000045
46 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
47 u64_stats_update_begin(&pcpu_stats->syncp);
48 pcpu_stats->rx_packets++;
49 pcpu_stats->rx_bytes += len;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000050 if (multicast)
Eric Dumazet8ffab512010-11-10 21:14:04 +000051 pcpu_stats->rx_multicast++;
52 u64_stats_update_end(&pcpu_stats->syncp);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000053 } else {
Eric Dumazet8ffab512010-11-10 21:14:04 +000054 this_cpu_inc(vlan->pcpu_stats->rx_errors);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000055 }
56}
57
Herbert Xu8a357472010-07-21 21:44:31 +000058extern void macvlan_common_setup(struct net_device *dev);
59
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000060extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
David Ahern42ab19e2017-10-04 17:48:47 -070061 struct nlattr *tb[], struct nlattr *data[],
62 struct netlink_ext_ack *extack);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000063
64extern void macvlan_count_rx(const struct macvlan_dev *vlan,
65 unsigned int len, bool success,
66 bool multicast);
67
68extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
69
70extern int macvlan_link_register(struct rtnl_link_ops *ops);
71
Michal Kubečekbe9eac42013-11-15 06:18:40 +010072#if IS_ENABLED(CONFIG_MACVLAN)
73static inline struct net_device *
74macvlan_dev_real_dev(const struct net_device *dev)
75{
76 struct macvlan_dev *macvlan = netdev_priv(dev);
77
78 return macvlan->lowerdev;
79}
80#else
81static inline struct net_device *
82macvlan_dev_real_dev(const struct net_device *dev)
83{
84 BUG();
85 return NULL;
86}
87#endif
88
Patrick McHardyb863ceb2007-07-14 18:55:06 -070089#endif /* _LINUX_IF_MACVLAN_H */