blob: 35280b302290459ff20293b2e4bcafd5aa6b9b2a [file] [log] [blame]
Patrick McHardyb863ceb2007-07-14 18:55:06 -07001#ifndef _LINUX_IF_MACVLAN_H
2#define _LINUX_IF_MACVLAN_H
3
Arnd Bergmannfc0663d2010-01-30 12:23:40 +00004#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 Dumazetbc661542010-06-24 00:54:21 +00009#include <linux/u64_stats_sync.h>
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000010
Arnd Bergmann501c7742010-02-18 05:46:50 +000011#if defined(CONFIG_MACVTAP) || defined(CONFIG_MACVTAP_MODULE)
12struct socket *macvtap_get_socket(struct file *);
13#else
14#include <linux/err.h>
15#include <linux/errno.h>
16struct file;
17struct socket;
18static inline struct socket *macvtap_get_socket(struct file *f)
19{
20 return ERR_PTR(-EINVAL);
21}
22#endif /* CONFIG_MACVTAP */
23
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000024struct macvlan_port;
25struct 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 Dumazetbc661542010-06-24 00:54:21 +000031 * @rx_multicast: number of received multicast packets
32 * @syncp: synchronization point for 64bit counters
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000033 * @rx_errors: number of errors
34 */
35struct macvlan_rx_stats {
Eric Dumazetbc661542010-06-24 00:54:21 +000036 u64 rx_packets;
37 u64 rx_bytes;
38 u64 rx_multicast;
39 struct u64_stats_sync syncp;
40 unsigned long rx_errors;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000041};
42
43struct macvlan_dev {
44 struct net_device *dev;
45 struct list_head list;
46 struct hlist_node hlist;
47 struct macvlan_port *port;
48 struct net_device *lowerdev;
Tejun Heo47d74272010-02-16 15:21:08 +000049 struct macvlan_rx_stats __percpu *rx_stats;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000050 enum macvlan_mode mode;
51 int (*receive)(struct sk_buff *skb);
52 int (*forward)(struct net_device *dev, struct sk_buff *skb);
Arnd Bergmann20d29d72010-01-30 12:24:26 +000053 struct macvtap_queue *tap;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000054};
55
56static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
57 unsigned int len, bool success,
58 bool multicast)
59{
60 struct macvlan_rx_stats *rx_stats;
61
Eric Dumazetbc661542010-06-24 00:54:21 +000062 rx_stats = this_cpu_ptr(vlan->rx_stats);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000063 if (likely(success)) {
Eric Dumazetbc661542010-06-24 00:54:21 +000064 u64_stats_update_begin(&rx_stats->syncp);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000065 rx_stats->rx_packets++;;
66 rx_stats->rx_bytes += len;
67 if (multicast)
Eric Dumazetbc661542010-06-24 00:54:21 +000068 rx_stats->rx_multicast++;
69 u64_stats_update_end(&rx_stats->syncp);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000070 } else {
71 rx_stats->rx_errors++;
72 }
73}
74
Herbert Xu8a357472010-07-21 21:44:31 +000075extern void macvlan_common_setup(struct net_device *dev);
76
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000077extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
78 struct nlattr *tb[], struct nlattr *data[],
79 int (*receive)(struct sk_buff *skb),
80 int (*forward)(struct net_device *dev,
81 struct sk_buff *skb));
82
83extern void macvlan_count_rx(const struct macvlan_dev *vlan,
84 unsigned int len, bool success,
85 bool multicast);
86
87extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
88
89extern int macvlan_link_register(struct rtnl_link_ops *ops);
90
91extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
92 struct net_device *dev);
93
Patrick McHardyb863ceb2007-07-14 18:55:06 -070094#endif /* _LINUX_IF_MACVLAN_H */