Blame view

include/linux/if_macvlan.h 2.83 KB
b863ceb7d   Patrick McHardy   [NET]: Add macvla...
1
2
  #ifndef _LINUX_IF_MACVLAN_H
  #define _LINUX_IF_MACVLAN_H
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
3
  #include <linux/if_link.h>
cdf3e274c   Li RongQing   macvlan: unify ma...
4
  #include <linux/if_vlan.h>
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
5
6
7
8
  #include <linux/list.h>
  #include <linux/netdevice.h>
  #include <linux/netlink.h>
  #include <net/netlink.h>
bc66154ef   Eric Dumazet   macvlan: 64 bit r...
9
  #include <linux/u64_stats_sync.h>
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
10

1d2f41ed2   Jason Wang   macvlan: switch t...
11
  #if IS_ENABLED(CONFIG_MACVTAP)
501c774cb   Arnd Bergmann   net/macvtap: add ...
12
13
14
15
16
17
18
19
20
21
22
  struct socket *macvtap_get_socket(struct file *);
  #else
  #include <linux/err.h>
  #include <linux/errno.h>
  struct file;
  struct socket;
  static inline struct socket *macvtap_get_socket(struct file *f)
  {
  	return ERR_PTR(-EINVAL);
  }
  #endif /* CONFIG_MACVTAP */
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
23
24
  struct macvlan_port;
  struct macvtap_queue;
1565c7c1c   Krishna Kumar   macvtap: Implemen...
25
26
27
28
  /*
   * Maximum times a macvtap device can be opened. This can be used to
   * configure the number of receive queue, e.g. for multiqueue virtio.
   */
f0afce01a   Jason Wang   macvlan: change t...
29
  #define MAX_MACVTAP_QUEUES	16
1565c7c1c   Krishna Kumar   macvtap: Implemen...
30

cd431e738   Eric Dumazet   macvlan: add mult...
31
32
  #define MACVLAN_MC_FILTER_BITS	8
  #define MACVLAN_MC_FILTER_SZ	(1 << MACVLAN_MC_FILTER_BITS)
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
33
34
35
36
37
38
  struct macvlan_dev {
  	struct net_device	*dev;
  	struct list_head	list;
  	struct hlist_node	hlist;
  	struct macvlan_port	*port;
  	struct net_device	*lowerdev;
a6cc0cfa7   John Fastabend   net: Add layer 2 ...
39
  	void			*fwd_priv;
cdf3e274c   Li RongQing   macvlan: unify ma...
40
  	struct vlan_pcpu_stats __percpu *pcpu_stats;
cd431e738   Eric Dumazet   macvlan: add mult...
41
42
  
  	DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
2be5c7679   Vlad Yasevich   macvtap: Let TUNS...
43
  	netdev_features_t	set_features;
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
44
  	enum macvlan_mode	mode;
df8ef8f3a   John Fastabend   macvlan: add FDB ...
45
  	u16			flags;
815f236d6   Jason Wang   macvtap: add TUNS...
46
  	/* This array tracks active taps. */
d9a90a310   Jason Wang   macvtap: slient s...
47
  	struct macvtap_queue	__rcu *taps[MAX_MACVTAP_QUEUES];
815f236d6   Jason Wang   macvtap: add TUNS...
48
49
  	/* This list tracks all taps (both enabled and disabled) */
  	struct list_head	queue_list;
1565c7c1c   Krishna Kumar   macvtap: Implemen...
50
  	int			numvtaps;
815f236d6   Jason Wang   macvtap: add TUNS...
51
  	int			numqueues;
2be5c7679   Vlad Yasevich   macvtap: Let TUNS...
52
  	netdev_features_t	tap_features;
e09eff7fc   Eric W. Biederman   macvtap: Fix the ...
53
  	int			minor;
c674ac30c   Vlad Yasevich   macvlan: Fix lock...
54
  	int			nest_level;
688cea83f   dingtianhong   macvlan: add netp...
55
56
57
  #ifdef CONFIG_NET_POLL_CONTROLLER
  	struct netpoll		*netpoll;
  #endif
79cf79abc   Michael Braun   macvlan: add sour...
58
  	unsigned int		macaddr_count;
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
59
60
61
62
63
64
  };
  
  static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
  				    unsigned int len, bool success,
  				    bool multicast)
  {
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
65
  	if (likely(success)) {
cdf3e274c   Li RongQing   macvlan: unify ma...
66
  		struct vlan_pcpu_stats *pcpu_stats;
8ffab51b3   Eric Dumazet   macvlan: lockless...
67
68
69
70
71
  
  		pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
  		u64_stats_update_begin(&pcpu_stats->syncp);
  		pcpu_stats->rx_packets++;
  		pcpu_stats->rx_bytes += len;
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
72
  		if (multicast)
8ffab51b3   Eric Dumazet   macvlan: lockless...
73
74
  			pcpu_stats->rx_multicast++;
  		u64_stats_update_end(&pcpu_stats->syncp);
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
75
  	} else {
8ffab51b3   Eric Dumazet   macvlan: lockless...
76
  		this_cpu_inc(vlan->pcpu_stats->rx_errors);
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
77
78
  	}
  }
8a35747a5   Herbert Xu   macvtap: Limit pa...
79
  extern void macvlan_common_setup(struct net_device *dev);
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
80
  extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
2f6a1b660   Vlad Yasevich   macvlan: Remove c...
81
  				  struct nlattr *tb[], struct nlattr *data[]);
fc0663d6b   Arnd Bergmann   macvlan: allow mu...
82
83
84
85
86
87
88
89
  
  extern void macvlan_count_rx(const struct macvlan_dev *vlan,
  			     unsigned int len, bool success,
  			     bool multicast);
  
  extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
  
  extern int macvlan_link_register(struct rtnl_link_ops *ops);
be9eac482   Michal Kubeček   macvlan: introduc...
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  #if IS_ENABLED(CONFIG_MACVLAN)
  static inline struct net_device *
  macvlan_dev_real_dev(const struct net_device *dev)
  {
  	struct macvlan_dev *macvlan = netdev_priv(dev);
  
  	return macvlan->lowerdev;
  }
  #else
  static inline struct net_device *
  macvlan_dev_real_dev(const struct net_device *dev)
  {
  	BUG();
  	return NULL;
  }
  #endif
b863ceb7d   Patrick McHardy   [NET]: Add macvla...
106
  #endif /* _LINUX_IF_MACVLAN_H */