blob: 84ba5ac39e039f80da563305155800cd1332782c [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;
John Fastabenda6cc0cf2013-11-06 09:54:46 -080064 void *fwd_priv;
Eric Dumazet8ffab512010-11-10 21:14:04 +000065 struct macvlan_pcpu_stats __percpu *pcpu_stats;
Eric Dumazetcd431e72013-02-05 20:22:50 +000066
67 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
68
Vlad Yasevich2be5c762013-06-25 16:04:21 -040069 netdev_features_t set_features;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000070 enum macvlan_mode mode;
John Fastabenddf8ef8f2012-04-15 06:44:37 +000071 u16 flags;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000072 int (*receive)(struct sk_buff *skb);
73 int (*forward)(struct net_device *dev, struct sk_buff *skb);
Jason Wang815f2362013-06-05 23:54:39 +000074 /* This array tracks active taps. */
Jason Wangd9a90a32013-06-13 14:23:35 +080075 struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES];
Jason Wang815f2362013-06-05 23:54:39 +000076 /* This list tracks all taps (both enabled and disabled) */
77 struct list_head queue_list;
Krishna Kumar1565c7c2010-08-04 06:15:59 +000078 int numvtaps;
Jason Wang815f2362013-06-05 23:54:39 +000079 int numqueues;
Vlad Yasevich2be5c762013-06-25 16:04:21 -040080 netdev_features_t tap_features;
Eric W. Biedermane09eff72011-10-20 04:29:24 +000081 int minor;
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000082};
83
84static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
85 unsigned int len, bool success,
86 bool multicast)
87{
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000088 if (likely(success)) {
Eric Dumazet8ffab512010-11-10 21:14:04 +000089 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 Bergmannfc0663d2010-01-30 12:23:40 +000095 if (multicast)
Eric Dumazet8ffab512010-11-10 21:14:04 +000096 pcpu_stats->rx_multicast++;
97 u64_stats_update_end(&pcpu_stats->syncp);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +000098 } else {
Eric Dumazet8ffab512010-11-10 21:14:04 +000099 this_cpu_inc(vlan->pcpu_stats->rx_errors);
Arnd Bergmannfc0663d2010-01-30 12:23:40 +0000100 }
101}
102
Herbert Xu8a357472010-07-21 21:44:31 +0000103extern void macvlan_common_setup(struct net_device *dev);
104
Arnd Bergmannfc0663d2010-01-30 12:23:40 +0000105extern 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
111extern void macvlan_count_rx(const struct macvlan_dev *vlan,
112 unsigned int len, bool success,
113 bool multicast);
114
115extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
116
117extern int macvlan_link_register(struct rtnl_link_ops *ops);
118
119extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
120 struct net_device *dev);
121
Michal Kubečekbe9eac42013-11-15 06:18:40 +0100122#if IS_ENABLED(CONFIG_MACVLAN)
123static inline struct net_device *
124macvlan_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
131static inline struct net_device *
132macvlan_dev_real_dev(const struct net_device *dev)
133{
134 BUG();
135 return NULL;
136}
137#endif
138
Patrick McHardyb863ceb2007-07-14 18:55:06 -0700139#endif /* _LINUX_IF_MACVLAN_H */