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 | |
Jason Wang | 1d2f41e | 2013-06-05 23:54:35 +0000 | [diff] [blame] | 12 | #if IS_ENABLED(CONFIG_MACVTAP) |
Arnd Bergmann | 501c774 | 2010-02-18 05:46:50 +0000 | [diff] [blame] | 13 | struct socket *macvtap_get_socket(struct file *); |
| 14 | #else |
| 15 | #include <linux/err.h> |
| 16 | #include <linux/errno.h> |
| 17 | struct file; |
| 18 | struct socket; |
| 19 | static inline struct socket *macvtap_get_socket(struct file *f) |
| 20 | { |
| 21 | return ERR_PTR(-EINVAL); |
| 22 | } |
| 23 | #endif /* CONFIG_MACVTAP */ |
| 24 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 25 | struct macvlan_port; |
| 26 | struct macvtap_queue; |
| 27 | |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 28 | /* |
| 29 | * Maximum times a macvtap device can be opened. This can be used to |
| 30 | * configure the number of receive queue, e.g. for multiqueue virtio. |
| 31 | */ |
Pankaj Gupta | dfe816c | 2015-06-19 19:47:53 +0530 | [diff] [blame] | 32 | #define MAX_MACVTAP_QUEUES 256 |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 33 | |
Eric Dumazet | cd431e7 | 2013-02-05 20:22:50 +0000 | [diff] [blame] | 34 | #define MACVLAN_MC_FILTER_BITS 8 |
| 35 | #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS) |
| 36 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 37 | struct macvlan_dev { |
| 38 | struct net_device *dev; |
| 39 | struct list_head list; |
| 40 | struct hlist_node hlist; |
| 41 | struct macvlan_port *port; |
| 42 | struct net_device *lowerdev; |
John Fastabend | a6cc0cf | 2013-11-06 09:54:46 -0800 | [diff] [blame] | 43 | void *fwd_priv; |
Li RongQing | cdf3e27 | 2014-01-04 14:22:34 +0800 | [diff] [blame] | 44 | struct vlan_pcpu_stats __percpu *pcpu_stats; |
Eric Dumazet | cd431e7 | 2013-02-05 20:22:50 +0000 | [diff] [blame] | 45 | |
| 46 | DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ); |
| 47 | |
Vlad Yasevich | 2be5c76 | 2013-06-25 16:04:21 -0400 | [diff] [blame] | 48 | netdev_features_t set_features; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 49 | enum macvlan_mode mode; |
John Fastabend | df8ef8f | 2012-04-15 06:44:37 +0000 | [diff] [blame] | 50 | u16 flags; |
Jason Wang | 815f236 | 2013-06-05 23:54:39 +0000 | [diff] [blame] | 51 | /* This array tracks active taps. */ |
Jason Wang | d9a90a3 | 2013-06-13 14:23:35 +0800 | [diff] [blame] | 52 | struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES]; |
Jason Wang | 815f236 | 2013-06-05 23:54:39 +0000 | [diff] [blame] | 53 | /* This list tracks all taps (both enabled and disabled) */ |
| 54 | struct list_head queue_list; |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 55 | int numvtaps; |
Jason Wang | 815f236 | 2013-06-05 23:54:39 +0000 | [diff] [blame] | 56 | int numqueues; |
Vlad Yasevich | 2be5c76 | 2013-06-25 16:04:21 -0400 | [diff] [blame] | 57 | netdev_features_t tap_features; |
Eric W. Biederman | e09eff7 | 2011-10-20 04:29:24 +0000 | [diff] [blame] | 58 | int minor; |
Vlad Yasevich | c674ac3 | 2014-05-16 17:04:56 -0400 | [diff] [blame] | 59 | int nest_level; |
dingtianhong | 688cea8 | 2014-05-30 16:00:56 +0800 | [diff] [blame] | 60 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 61 | struct netpoll *netpoll; |
| 62 | #endif |
Michael Braun | 79cf79a | 2014-09-25 16:31:08 +0200 | [diff] [blame] | 63 | unsigned int macaddr_count; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | static inline void macvlan_count_rx(const struct macvlan_dev *vlan, |
| 67 | unsigned int len, bool success, |
| 68 | bool multicast) |
| 69 | { |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 70 | if (likely(success)) { |
Li RongQing | cdf3e27 | 2014-01-04 14:22:34 +0800 | [diff] [blame] | 71 | struct vlan_pcpu_stats *pcpu_stats; |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 72 | |
| 73 | pcpu_stats = this_cpu_ptr(vlan->pcpu_stats); |
| 74 | u64_stats_update_begin(&pcpu_stats->syncp); |
| 75 | pcpu_stats->rx_packets++; |
| 76 | pcpu_stats->rx_bytes += len; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 77 | if (multicast) |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 78 | pcpu_stats->rx_multicast++; |
| 79 | u64_stats_update_end(&pcpu_stats->syncp); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 80 | } else { |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 81 | this_cpu_inc(vlan->pcpu_stats->rx_errors); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Herbert Xu | 8a35747 | 2010-07-21 21:44:31 +0000 | [diff] [blame] | 85 | extern void macvlan_common_setup(struct net_device *dev); |
| 86 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 87 | 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] | 88 | struct nlattr *tb[], struct nlattr *data[]); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 89 | |
| 90 | extern void macvlan_count_rx(const struct macvlan_dev *vlan, |
| 91 | unsigned int len, bool success, |
| 92 | bool multicast); |
| 93 | |
| 94 | extern void macvlan_dellink(struct net_device *dev, struct list_head *head); |
| 95 | |
| 96 | extern int macvlan_link_register(struct rtnl_link_ops *ops); |
| 97 | |
Michal Kubeček | be9eac4 | 2013-11-15 06:18:40 +0100 | [diff] [blame] | 98 | #if IS_ENABLED(CONFIG_MACVLAN) |
| 99 | static inline struct net_device * |
| 100 | macvlan_dev_real_dev(const struct net_device *dev) |
| 101 | { |
| 102 | struct macvlan_dev *macvlan = netdev_priv(dev); |
| 103 | |
| 104 | return macvlan->lowerdev; |
| 105 | } |
| 106 | #else |
| 107 | static inline struct net_device * |
| 108 | macvlan_dev_real_dev(const struct net_device *dev) |
| 109 | { |
| 110 | BUG(); |
| 111 | return NULL; |
| 112 | } |
| 113 | #endif |
| 114 | |
Patrick McHardy | b863ceb | 2007-07-14 18:55:06 -0700 | [diff] [blame] | 115 | #endif /* _LINUX_IF_MACVLAN_H */ |