Patrick McHardy | b863ceb | 2007-07-14 18:55:06 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_IF_MACVLAN_H |
| 2 | #define _LINUX_IF_MACVLAN_H |
| 3 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 4 | #include <linux/if_link.h> |
Li RongQing | cdf3e27 | 2014-01-04 14:22:34 +0800 | [diff] [blame] | 5 | #include <linux/if_vlan.h> |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 6 | #include <linux/list.h> |
| 7 | #include <linux/netdevice.h> |
| 8 | #include <linux/netlink.h> |
| 9 | #include <net/netlink.h> |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 10 | #include <linux/u64_stats_sync.h> |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 11 | |
| 12 | struct macvlan_port; |
| 13 | struct macvtap_queue; |
| 14 | |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 15 | /* |
| 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 Grandhi | 635b8c8 | 2017-02-10 16:03:47 -0800 | [diff] [blame] | 19 | #define MAX_TAP_QUEUES 256 |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 20 | |
Eric Dumazet | cd431e7 | 2013-02-05 20:22:50 +0000 | [diff] [blame] | 21 | #define MACVLAN_MC_FILTER_BITS 8 |
| 22 | #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS) |
| 23 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 24 | struct 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 Fastabend | a6cc0cf | 2013-11-06 09:54:46 -0800 | [diff] [blame] | 30 | void *fwd_priv; |
Li RongQing | cdf3e27 | 2014-01-04 14:22:34 +0800 | [diff] [blame] | 31 | struct vlan_pcpu_stats __percpu *pcpu_stats; |
Eric Dumazet | cd431e7 | 2013-02-05 20:22:50 +0000 | [diff] [blame] | 32 | |
| 33 | DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ); |
| 34 | |
Vlad Yasevich | 2be5c76 | 2013-06-25 16:04:21 -0400 | [diff] [blame] | 35 | netdev_features_t set_features; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 36 | enum macvlan_mode mode; |
John Fastabend | df8ef8f | 2012-04-15 06:44:37 +0000 | [diff] [blame] | 37 | u16 flags; |
Jason Wang | 815f236 | 2013-06-05 23:54:39 +0000 | [diff] [blame] | 38 | /* This array tracks active taps. */ |
Sainath Grandhi | 635b8c8 | 2017-02-10 16:03:47 -0800 | [diff] [blame] | 39 | struct tap_queue __rcu *taps[MAX_TAP_QUEUES]; |
Jason Wang | 815f236 | 2013-06-05 23:54:39 +0000 | [diff] [blame] | 40 | /* This list tracks all taps (both enabled and disabled) */ |
| 41 | struct list_head queue_list; |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 42 | int numvtaps; |
Jason Wang | 815f236 | 2013-06-05 23:54:39 +0000 | [diff] [blame] | 43 | int numqueues; |
Vlad Yasevich | 2be5c76 | 2013-06-25 16:04:21 -0400 | [diff] [blame] | 44 | netdev_features_t tap_features; |
Eric W. Biederman | e09eff7 | 2011-10-20 04:29:24 +0000 | [diff] [blame] | 45 | int minor; |
Vlad Yasevich | c674ac3 | 2014-05-16 17:04:56 -0400 | [diff] [blame] | 46 | int nest_level; |
dingtianhong | 688cea8 | 2014-05-30 16:00:56 +0800 | [diff] [blame] | 47 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 48 | struct netpoll *netpoll; |
| 49 | #endif |
Michael Braun | 79cf79a | 2014-09-25 16:31:08 +0200 | [diff] [blame] | 50 | unsigned int macaddr_count; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | static inline void macvlan_count_rx(const struct macvlan_dev *vlan, |
| 54 | unsigned int len, bool success, |
| 55 | bool multicast) |
| 56 | { |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 57 | if (likely(success)) { |
Li RongQing | cdf3e27 | 2014-01-04 14:22:34 +0800 | [diff] [blame] | 58 | struct vlan_pcpu_stats *pcpu_stats; |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 59 | |
| 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 Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 64 | if (multicast) |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 65 | pcpu_stats->rx_multicast++; |
| 66 | u64_stats_update_end(&pcpu_stats->syncp); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 67 | } else { |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 68 | this_cpu_inc(vlan->pcpu_stats->rx_errors); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Herbert Xu | 8a35747 | 2010-07-21 21:44:31 +0000 | [diff] [blame] | 72 | extern void macvlan_common_setup(struct net_device *dev); |
| 73 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 74 | extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev, |
Vlad Yasevich | 2f6a1b6 | 2013-12-11 13:27:11 -0500 | [diff] [blame] | 75 | struct nlattr *tb[], struct nlattr *data[]); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 76 | |
| 77 | extern void macvlan_count_rx(const struct macvlan_dev *vlan, |
| 78 | unsigned int len, bool success, |
| 79 | bool multicast); |
| 80 | |
| 81 | extern void macvlan_dellink(struct net_device *dev, struct list_head *head); |
| 82 | |
| 83 | extern int macvlan_link_register(struct rtnl_link_ops *ops); |
| 84 | |
Michal Kubeček | be9eac4 | 2013-11-15 06:18:40 +0100 | [diff] [blame] | 85 | #if IS_ENABLED(CONFIG_MACVLAN) |
| 86 | static inline struct net_device * |
| 87 | macvlan_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 |
| 94 | static inline struct net_device * |
| 95 | macvlan_dev_real_dev(const struct net_device *dev) |
| 96 | { |
| 97 | BUG(); |
| 98 | return NULL; |
| 99 | } |
| 100 | #endif |
| 101 | |
Patrick McHardy | b863ceb | 2007-07-14 18:55:06 -0700 | [diff] [blame] | 102 | #endif /* _LINUX_IF_MACVLAN_H */ |