blob: f65e8d250f7e78c8d483ddedd29c3fe5bf94bc30 [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/**
Eric Dumazet8ffab512010-11-10 21:14:04 +000028 * struct macvlan_pcpu_stats - MACVLAN percpu stats
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000029 * @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
Eric Dumazet8ffab512010-11-10 21:14:04 +000032 * @tx_packets: number of transmitted packets
33 * @tx_bytes: number of transmitted bytes
Eric Dumazetbc661542010-06-24 00:54:21 +000034 * @syncp: synchronization point for 64bit counters
Eric Dumazet8ffab512010-11-10 21:14:04 +000035 * @rx_errors: number of rx errors
36 * @tx_dropped: number of tx dropped packets
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000037 */
Eric Dumazet8ffab512010-11-10 21:14:04 +000038struct macvlan_pcpu_stats {
Eric Dumazetbc661542010-06-24 00:54:21 +000039 u64 rx_packets;
40 u64 rx_bytes;
41 u64 rx_multicast;
Eric Dumazet8ffab512010-11-10 21:14:04 +000042 u64 tx_packets;
43 u64 tx_bytes;
Eric Dumazetbc661542010-06-24 00:54:21 +000044 struct u64_stats_sync syncp;
Eric Dumazet8ffab512010-11-10 21:14:04 +000045 u32 rx_errors;
46 u32 tx_dropped;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000047};
48
Krishna Kumar1565c7c2010-08-04 06:15:59 +000049/*
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 */
53#define MAX_MACVTAP_QUEUES (NR_CPUS < 16 ? NR_CPUS : 16)
54
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000055struct macvlan_dev {
56 struct net_device *dev;
57 struct list_head list;
58 struct hlist_node hlist;
59 struct macvlan_port *port;
60 struct net_device *lowerdev;
Eric Dumazet8ffab512010-11-10 21:14:04 +000061 struct macvlan_pcpu_stats __percpu *pcpu_stats;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000062 enum macvlan_mode mode;
John Fastabenddf8ef8f2012-04-15 06:44:37 +000063 u16 flags;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000064 int (*receive)(struct sk_buff *skb);
65 int (*forward)(struct net_device *dev, struct sk_buff *skb);
Krishna Kumar1565c7c2010-08-04 06:15:59 +000066 struct macvtap_queue *taps[MAX_MACVTAP_QUEUES];
67 int numvtaps;
Eric W. Biedermane09eff72011-10-20 04:29:24 +000068 int minor;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000069};
70
71static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
72 unsigned int len, bool success,
73 bool multicast)
74{
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000075 if (likely(success)) {
Eric Dumazet8ffab512010-11-10 21:14:04 +000076 struct macvlan_pcpu_stats *pcpu_stats;
77
78 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
79 u64_stats_update_begin(&pcpu_stats->syncp);
80 pcpu_stats->rx_packets++;
81 pcpu_stats->rx_bytes += len;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000082 if (multicast)
Eric Dumazet8ffab512010-11-10 21:14:04 +000083 pcpu_stats->rx_multicast++;
84 u64_stats_update_end(&pcpu_stats->syncp);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000085 } else {
Eric Dumazet8ffab512010-11-10 21:14:04 +000086 this_cpu_inc(vlan->pcpu_stats->rx_errors);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000087 }
88}
89
Herbert Xu8a357472010-07-21 21:44:31 +000090extern void macvlan_common_setup(struct net_device *dev);
91
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000092extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
93 struct nlattr *tb[], struct nlattr *data[],
94 int (*receive)(struct sk_buff *skb),
95 int (*forward)(struct net_device *dev,
96 struct sk_buff *skb));
97
98extern void macvlan_count_rx(const struct macvlan_dev *vlan,
99 unsigned int len, bool success,
100 bool multicast);
101
102extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
103
104extern int macvlan_link_register(struct rtnl_link_ops *ops);
105
106extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
107 struct net_device *dev);
108
Patrick McHardyb863ceb2007-07-14 18:55:06 -0700109#endif /* _LINUX_IF_MACVLAN_H */