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 | |
Arnd Bergmann | 501c774 | 2010-02-18 05:46:50 +0000 | [diff] [blame] | 11 | #if defined(CONFIG_MACVTAP) || defined(CONFIG_MACVTAP_MODULE) |
| 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 | /** |
| 28 | * struct macvlan_rx_stats - MACVLAN percpu rx stats |
| 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 |
| 32 | * @syncp: synchronization point for 64bit counters |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 33 | * @rx_errors: number of errors |
| 34 | */ |
| 35 | struct macvlan_rx_stats { |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 36 | u64 rx_packets; |
| 37 | u64 rx_bytes; |
| 38 | u64 rx_multicast; |
| 39 | struct u64_stats_sync syncp; |
| 40 | unsigned long rx_errors; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 43 | /* |
| 44 | * Maximum times a macvtap device can be opened. This can be used to |
| 45 | * configure the number of receive queue, e.g. for multiqueue virtio. |
| 46 | */ |
| 47 | #define MAX_MACVTAP_QUEUES (NR_CPUS < 16 ? NR_CPUS : 16) |
| 48 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 49 | struct macvlan_dev { |
| 50 | struct net_device *dev; |
| 51 | struct list_head list; |
| 52 | struct hlist_node hlist; |
| 53 | struct macvlan_port *port; |
| 54 | struct net_device *lowerdev; |
Tejun Heo | 47d7427 | 2010-02-16 15:21:08 +0000 | [diff] [blame] | 55 | struct macvlan_rx_stats __percpu *rx_stats; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 56 | enum macvlan_mode mode; |
| 57 | int (*receive)(struct sk_buff *skb); |
| 58 | int (*forward)(struct net_device *dev, struct sk_buff *skb); |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 59 | struct macvtap_queue *taps[MAX_MACVTAP_QUEUES]; |
| 60 | int numvtaps; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | static inline void macvlan_count_rx(const struct macvlan_dev *vlan, |
| 64 | unsigned int len, bool success, |
| 65 | bool multicast) |
| 66 | { |
| 67 | struct macvlan_rx_stats *rx_stats; |
| 68 | |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 69 | rx_stats = this_cpu_ptr(vlan->rx_stats); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 70 | if (likely(success)) { |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 71 | u64_stats_update_begin(&rx_stats->syncp); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 72 | rx_stats->rx_packets++;; |
| 73 | rx_stats->rx_bytes += len; |
| 74 | if (multicast) |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 75 | rx_stats->rx_multicast++; |
| 76 | u64_stats_update_end(&rx_stats->syncp); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 77 | } else { |
| 78 | rx_stats->rx_errors++; |
| 79 | } |
| 80 | } |
| 81 | |
Herbert Xu | 8a35747 | 2010-07-21 21:44:31 +0000 | [diff] [blame] | 82 | extern void macvlan_common_setup(struct net_device *dev); |
| 83 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 84 | extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev, |
| 85 | struct nlattr *tb[], struct nlattr *data[], |
| 86 | int (*receive)(struct sk_buff *skb), |
| 87 | int (*forward)(struct net_device *dev, |
| 88 | struct sk_buff *skb)); |
| 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 | |
| 98 | extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb, |
| 99 | struct net_device *dev); |
| 100 | |
Patrick McHardy | b863ceb | 2007-07-14 18:55:06 -0700 | [diff] [blame] | 101 | #endif /* _LINUX_IF_MACVLAN_H */ |