]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
b863ceb7 PM |
2 | #ifndef _LINUX_IF_MACVLAN_H |
3 | #define _LINUX_IF_MACVLAN_H | |
4 | ||
fc0663d6 | 5 | #include <linux/if_link.h> |
cdf3e274 | 6 | #include <linux/if_vlan.h> |
fc0663d6 AB |
7 | #include <linux/list.h> |
8 | #include <linux/netdevice.h> | |
9 | #include <linux/netlink.h> | |
10 | #include <net/netlink.h> | |
bc66154e | 11 | #include <linux/u64_stats_sync.h> |
fc0663d6 AB |
12 | |
13 | struct macvlan_port; | |
14 | struct macvtap_queue; | |
15 | ||
1565c7c1 KK |
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 | */ | |
635b8c8e | 20 | #define MAX_TAP_QUEUES 256 |
1565c7c1 | 21 | |
cd431e73 ED |
22 | #define MACVLAN_MC_FILTER_BITS 8 |
23 | #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS) | |
24 | ||
fc0663d6 AB |
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; | |
a6cc0cfa | 31 | void *fwd_priv; |
cdf3e274 | 32 | struct vlan_pcpu_stats __percpu *pcpu_stats; |
cd431e73 ED |
33 | |
34 | DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ); | |
35 | ||
2be5c767 | 36 | netdev_features_t set_features; |
fc0663d6 | 37 | enum macvlan_mode mode; |
df8ef8f3 | 38 | u16 flags; |
815f236d | 39 | /* This array tracks active taps. */ |
635b8c8e | 40 | struct tap_queue __rcu *taps[MAX_TAP_QUEUES]; |
815f236d JW |
41 | /* This list tracks all taps (both enabled and disabled) */ |
42 | struct list_head queue_list; | |
1565c7c1 | 43 | int numvtaps; |
815f236d | 44 | int numqueues; |
2be5c767 | 45 | netdev_features_t tap_features; |
e09eff7f | 46 | int minor; |
c674ac30 | 47 | int nest_level; |
688cea83 | 48 | #ifdef CONFIG_NET_POLL_CONTROLLER |
49 | struct netpoll *netpoll; | |
50 | #endif | |
79cf79ab | 51 | unsigned int macaddr_count; |
fc0663d6 AB |
52 | }; |
53 | ||
54 | static inline void macvlan_count_rx(const struct macvlan_dev *vlan, | |
55 | unsigned int len, bool success, | |
56 | bool multicast) | |
57 | { | |
fc0663d6 | 58 | if (likely(success)) { |
cdf3e274 | 59 | struct vlan_pcpu_stats *pcpu_stats; |
8ffab51b ED |
60 | |
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; | |
fc0663d6 | 65 | if (multicast) |
8ffab51b ED |
66 | pcpu_stats->rx_multicast++; |
67 | u64_stats_update_end(&pcpu_stats->syncp); | |
fc0663d6 | 68 | } else { |
8ffab51b | 69 | this_cpu_inc(vlan->pcpu_stats->rx_errors); |
fc0663d6 AB |
70 | } |
71 | } | |
72 | ||
8a35747a HX |
73 | extern void macvlan_common_setup(struct net_device *dev); |
74 | ||
fc0663d6 | 75 | extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev, |
2f6a1b66 | 76 | struct nlattr *tb[], struct nlattr *data[]); |
fc0663d6 AB |
77 | |
78 | extern void macvlan_count_rx(const struct macvlan_dev *vlan, | |
79 | unsigned int len, bool success, | |
80 | bool multicast); | |
81 | ||
82 | extern void macvlan_dellink(struct net_device *dev, struct list_head *head); | |
83 | ||
84 | extern int macvlan_link_register(struct rtnl_link_ops *ops); | |
85 | ||
be9eac48 MK |
86 | #if IS_ENABLED(CONFIG_MACVLAN) |
87 | static inline struct net_device * | |
88 | macvlan_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 | |
95 | static inline struct net_device * | |
96 | macvlan_dev_real_dev(const struct net_device *dev) | |
97 | { | |
98 | BUG(); | |
99 | return NULL; | |
100 | } | |
101 | #endif | |
102 | ||
b863ceb7 | 103 | #endif /* _LINUX_IF_MACVLAN_H */ |