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> |
| 5 | #include <linux/list.h> |
| 6 | #include <linux/netdevice.h> |
| 7 | #include <linux/netlink.h> |
| 8 | #include <net/netlink.h> |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 9 | #include <linux/u64_stats_sync.h> |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 10 | |
Jason Wang | 1d2f41e | 2013-06-05 23:54:35 +0000 | [diff] [blame] | 11 | #if IS_ENABLED(CONFIG_MACVTAP) |
Arnd Bergmann | 501c774 | 2010-02-18 05:46:50 +0000 | [diff] [blame] | 12 | struct socket *macvtap_get_socket(struct file *); |
| 13 | #else |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/errno.h> |
| 16 | struct file; |
| 17 | struct socket; |
| 18 | static inline struct socket *macvtap_get_socket(struct file *f) |
| 19 | { |
| 20 | return ERR_PTR(-EINVAL); |
| 21 | } |
| 22 | #endif /* CONFIG_MACVTAP */ |
| 23 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 24 | struct macvlan_port; |
| 25 | struct macvtap_queue; |
| 26 | |
| 27 | /** |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 28 | * struct macvlan_pcpu_stats - MACVLAN percpu stats |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 29 | * @rx_packets: number of received packets |
| 30 | * @rx_bytes: number of received bytes |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 31 | * @rx_multicast: number of received multicast packets |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 32 | * @tx_packets: number of transmitted packets |
| 33 | * @tx_bytes: number of transmitted bytes |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 34 | * @syncp: synchronization point for 64bit counters |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 35 | * @rx_errors: number of rx errors |
| 36 | * @tx_dropped: number of tx dropped packets |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 37 | */ |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 38 | struct macvlan_pcpu_stats { |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 39 | u64 rx_packets; |
| 40 | u64 rx_bytes; |
| 41 | u64 rx_multicast; |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 42 | u64 tx_packets; |
| 43 | u64 tx_bytes; |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 44 | struct u64_stats_sync syncp; |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 45 | u32 rx_errors; |
| 46 | u32 tx_dropped; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 49 | /* |
| 50 | * Maximum times a macvtap device can be opened. This can be used to |
| 51 | * configure the number of receive queue, e.g. for multiqueue virtio. |
| 52 | */ |
Jason Wang | f0afce0 | 2013-06-05 23:54:37 +0000 | [diff] [blame] | 53 | #define MAX_MACVTAP_QUEUES 16 |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 54 | |
Eric Dumazet | cd431e7 | 2013-02-05 20:22:50 +0000 | [diff] [blame] | 55 | #define MACVLAN_MC_FILTER_BITS 8 |
| 56 | #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS) |
| 57 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 58 | struct macvlan_dev { |
| 59 | struct net_device *dev; |
| 60 | struct list_head list; |
| 61 | struct hlist_node hlist; |
| 62 | struct macvlan_port *port; |
| 63 | struct net_device *lowerdev; |
John Fastabend | a6cc0cf | 2013-11-06 09:54:46 -0800 | [diff] [blame] | 64 | void *fwd_priv; |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 65 | struct macvlan_pcpu_stats __percpu *pcpu_stats; |
Eric Dumazet | cd431e7 | 2013-02-05 20:22:50 +0000 | [diff] [blame] | 66 | |
| 67 | DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ); |
| 68 | |
Vlad Yasevich | 2be5c76 | 2013-06-25 16:04:21 -0400 | [diff] [blame] | 69 | netdev_features_t set_features; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 70 | enum macvlan_mode mode; |
John Fastabend | df8ef8f | 2012-04-15 06:44:37 +0000 | [diff] [blame] | 71 | u16 flags; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 72 | int (*receive)(struct sk_buff *skb); |
| 73 | int (*forward)(struct net_device *dev, struct sk_buff *skb); |
Jason Wang | 815f236 | 2013-06-05 23:54:39 +0000 | [diff] [blame] | 74 | /* This array tracks active taps. */ |
Jason Wang | d9a90a3 | 2013-06-13 14:23:35 +0800 | [diff] [blame] | 75 | struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES]; |
Jason Wang | 815f236 | 2013-06-05 23:54:39 +0000 | [diff] [blame] | 76 | /* This list tracks all taps (both enabled and disabled) */ |
| 77 | struct list_head queue_list; |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 78 | int numvtaps; |
Jason Wang | 815f236 | 2013-06-05 23:54:39 +0000 | [diff] [blame] | 79 | int numqueues; |
Vlad Yasevich | 2be5c76 | 2013-06-25 16:04:21 -0400 | [diff] [blame] | 80 | netdev_features_t tap_features; |
Eric W. Biederman | e09eff7 | 2011-10-20 04:29:24 +0000 | [diff] [blame] | 81 | int minor; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | static inline void macvlan_count_rx(const struct macvlan_dev *vlan, |
| 85 | unsigned int len, bool success, |
| 86 | bool multicast) |
| 87 | { |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 88 | if (likely(success)) { |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 89 | struct macvlan_pcpu_stats *pcpu_stats; |
| 90 | |
| 91 | pcpu_stats = this_cpu_ptr(vlan->pcpu_stats); |
| 92 | u64_stats_update_begin(&pcpu_stats->syncp); |
| 93 | pcpu_stats->rx_packets++; |
| 94 | pcpu_stats->rx_bytes += len; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 95 | if (multicast) |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 96 | pcpu_stats->rx_multicast++; |
| 97 | u64_stats_update_end(&pcpu_stats->syncp); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 98 | } else { |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 99 | this_cpu_inc(vlan->pcpu_stats->rx_errors); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Herbert Xu | 8a35747 | 2010-07-21 21:44:31 +0000 | [diff] [blame] | 103 | extern void macvlan_common_setup(struct net_device *dev); |
| 104 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 105 | extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev, |
| 106 | struct nlattr *tb[], struct nlattr *data[], |
| 107 | int (*receive)(struct sk_buff *skb), |
| 108 | int (*forward)(struct net_device *dev, |
| 109 | struct sk_buff *skb)); |
| 110 | |
| 111 | extern void macvlan_count_rx(const struct macvlan_dev *vlan, |
| 112 | unsigned int len, bool success, |
| 113 | bool multicast); |
| 114 | |
| 115 | extern void macvlan_dellink(struct net_device *dev, struct list_head *head); |
| 116 | |
| 117 | extern int macvlan_link_register(struct rtnl_link_ops *ops); |
| 118 | |
| 119 | extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb, |
| 120 | struct net_device *dev); |
| 121 | |
Michal Kubeček | be9eac4 | 2013-11-15 06:18:40 +0100 | [diff] [blame^] | 122 | #if IS_ENABLED(CONFIG_MACVLAN) |
| 123 | static inline struct net_device * |
| 124 | macvlan_dev_real_dev(const struct net_device *dev) |
| 125 | { |
| 126 | struct macvlan_dev *macvlan = netdev_priv(dev); |
| 127 | |
| 128 | return macvlan->lowerdev; |
| 129 | } |
| 130 | #else |
| 131 | static inline struct net_device * |
| 132 | macvlan_dev_real_dev(const struct net_device *dev) |
| 133 | { |
| 134 | BUG(); |
| 135 | return NULL; |
| 136 | } |
| 137 | #endif |
| 138 | |
Patrick McHardy | b863ceb | 2007-07-14 18:55:06 -0700 | [diff] [blame] | 139 | #endif /* _LINUX_IF_MACVLAN_H */ |