GNU Linux-libre 4.14.313-gnu1
[releases.git] / include / linux / if_macvlan.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_IF_MACVLAN_H
3 #define _LINUX_IF_MACVLAN_H
4
5 #include <linux/if_link.h>
6 #include <linux/if_vlan.h>
7 #include <linux/list.h>
8 #include <linux/netdevice.h>
9 #include <linux/netlink.h>
10 #include <net/netlink.h>
11 #include <linux/u64_stats_sync.h>
12
13 struct macvlan_port;
14 struct macvtap_queue;
15
16 /*
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  */
20 #define MAX_TAP_QUEUES  256
21
22 #define MACVLAN_MC_FILTER_BITS  8
23 #define MACVLAN_MC_FILTER_SZ    (1 << MACVLAN_MC_FILTER_BITS)
24
25 struct 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;
31         void                    *fwd_priv;
32         struct vlan_pcpu_stats __percpu *pcpu_stats;
33
34         DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
35
36         netdev_features_t       set_features;
37         enum macvlan_mode       mode;
38         u16                     flags;
39         /* This array tracks active taps. */
40         struct tap_queue        __rcu *taps[MAX_TAP_QUEUES];
41         /* This list tracks all taps (both enabled and disabled) */
42         struct list_head        queue_list;
43         int                     numvtaps;
44         int                     numqueues;
45         netdev_features_t       tap_features;
46         int                     minor;
47         int                     nest_level;
48 #ifdef CONFIG_NET_POLL_CONTROLLER
49         struct netpoll          *netpoll;
50 #endif
51         unsigned int            macaddr_count;
52 };
53
54 static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
55                                     unsigned int len, bool success,
56                                     bool multicast)
57 {
58         if (likely(success)) {
59                 struct vlan_pcpu_stats *pcpu_stats;
60
61                 pcpu_stats = get_cpu_ptr(vlan->pcpu_stats);
62                 u64_stats_update_begin(&pcpu_stats->syncp);
63                 pcpu_stats->rx_packets++;
64                 pcpu_stats->rx_bytes += len;
65                 if (multicast)
66                         pcpu_stats->rx_multicast++;
67                 u64_stats_update_end(&pcpu_stats->syncp);
68                 put_cpu_ptr(vlan->pcpu_stats);
69         } else {
70                 this_cpu_inc(vlan->pcpu_stats->rx_errors);
71         }
72 }
73
74 extern void macvlan_common_setup(struct net_device *dev);
75
76 extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
77                                   struct nlattr *tb[], struct nlattr *data[]);
78
79 extern void macvlan_count_rx(const struct macvlan_dev *vlan,
80                              unsigned int len, bool success,
81                              bool multicast);
82
83 extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
84
85 extern int macvlan_link_register(struct rtnl_link_ops *ops);
86
87 #if IS_ENABLED(CONFIG_MACVLAN)
88 static inline struct net_device *
89 macvlan_dev_real_dev(const struct net_device *dev)
90 {
91         struct macvlan_dev *macvlan = netdev_priv(dev);
92
93         return macvlan->lowerdev;
94 }
95 #else
96 static inline struct net_device *
97 macvlan_dev_real_dev(const struct net_device *dev)
98 {
99         BUG();
100         return NULL;
101 }
102 #endif
103
104 #endif /* _LINUX_IF_MACVLAN_H */