blob: ddd33fd5904dbb32d428c449543ecc6e3dc8a010 [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
Jason Wang1d2f41e2013-06-05 23:54:35 +000011#if IS_ENABLED(CONFIG_MACVTAP)
Arnd Bergmann501c7742010-02-18 05:46:50 +000012struct 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 */
Jason Wangf0afce02013-06-05 23:54:37 +000053#define MAX_MACVTAP_QUEUES 16
Krishna Kumar1565c7c2010-08-04 06:15:59 +000054
Eric Dumazetcd431e72013-02-05 20:22:50 +000055#define MACVLAN_MC_FILTER_BITS 8
56#define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
57
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000058struct 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;
Eric Dumazet8ffab512010-11-10 21:14:04 +000064 struct macvlan_pcpu_stats __percpu *pcpu_stats;
Eric Dumazetcd431e72013-02-05 20:22:50 +000065
66 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
67
Vlad Yasevich2be5c762013-06-25 16:04:21 -040068 netdev_features_t set_features;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000069 enum macvlan_mode mode;
John Fastabenddf8ef8f2012-04-15 06:44:37 +000070 u16 flags;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000071 int (*receive)(struct sk_buff *skb);
72 int (*forward)(struct net_device *dev, struct sk_buff *skb);
Jason Wang815f2362013-06-05 23:54:39 +000073 /* This array tracks active taps. */
Jason Wangd9a90a32013-06-13 14:23:35 +080074 struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES];
Jason Wang815f2362013-06-05 23:54:39 +000075 /* This list tracks all taps (both enabled and disabled) */
76 struct list_head queue_list;
Krishna Kumar1565c7c2010-08-04 06:15:59 +000077 int numvtaps;
Jason Wang815f2362013-06-05 23:54:39 +000078 int numqueues;
Vlad Yasevich2be5c762013-06-25 16:04:21 -040079 netdev_features_t tap_features;
Eric W. Biedermane09eff72011-10-20 04:29:24 +000080 int minor;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000081};
82
83static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
84 unsigned int len, bool success,
85 bool multicast)
86{
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000087 if (likely(success)) {
Eric Dumazet8ffab512010-11-10 21:14:04 +000088 struct macvlan_pcpu_stats *pcpu_stats;
89
90 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
91 u64_stats_update_begin(&pcpu_stats->syncp);
92 pcpu_stats->rx_packets++;
93 pcpu_stats->rx_bytes += len;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000094 if (multicast)
Eric Dumazet8ffab512010-11-10 21:14:04 +000095 pcpu_stats->rx_multicast++;
96 u64_stats_update_end(&pcpu_stats->syncp);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000097 } else {
Eric Dumazet8ffab512010-11-10 21:14:04 +000098 this_cpu_inc(vlan->pcpu_stats->rx_errors);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000099 }
100}
101
Herbert Xu8a357472010-07-21 21:44:31 +0000102extern void macvlan_common_setup(struct net_device *dev);
103
Arnd Bergmannfc0663d2010-01-30 12:23:40 +0000104extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
105 struct nlattr *tb[], struct nlattr *data[],
106 int (*receive)(struct sk_buff *skb),
107 int (*forward)(struct net_device *dev,
108 struct sk_buff *skb));
109
110extern void macvlan_count_rx(const struct macvlan_dev *vlan,
111 unsigned int len, bool success,
112 bool multicast);
113
114extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
115
116extern int macvlan_link_register(struct rtnl_link_ops *ops);
117
118extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
119 struct net_device *dev);
120
Patrick McHardyb863ceb2007-07-14 18:55:06 -0700121#endif /* _LINUX_IF_MACVLAN_H */