1 #ifndef _LINUX_IF_MACVLAN_H 2 #define _LINUX_IF_MACVLAN_H 3 4 #include <linux/if_link.h> 5 #include <linux/if_vlan.h> 6 #include <linux/list.h> 7 #include <linux/netdevice.h> 8 #include <linux/netlink.h> 9 #include <net/netlink.h> 10 #include <linux/u64_stats_sync.h> 11 12 struct macvlan_port; 13 struct macvtap_queue; 14 15 /* 16 * Maximum times a macvtap device can be opened. This can be used to 17 * configure the number of receive queue, e.g. for multiqueue virtio. 18 */ 19 #define MAX_TAP_QUEUES 256 20 21 #define MACVLAN_MC_FILTER_BITS 8 22 #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS) 23 24 struct macvlan_dev { 25 struct net_device *dev; 26 struct list_head list; 27 struct hlist_node hlist; 28 struct macvlan_port *port; 29 struct net_device *lowerdev; 30 void *fwd_priv; 31 struct vlan_pcpu_stats __percpu *pcpu_stats; 32 33 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ); 34 35 netdev_features_t set_features; 36 enum macvlan_mode mode; 37 u16 flags; 38 /* This array tracks active taps. */ 39 struct tap_queue __rcu *taps[MAX_TAP_QUEUES]; 40 /* This list tracks all taps (both enabled and disabled) */ 41 struct list_head queue_list; 42 int numvtaps; 43 int numqueues; 44 netdev_features_t tap_features; 45 int minor; 46 int nest_level; 47 #ifdef CONFIG_NET_POLL_CONTROLLER 48 struct netpoll *netpoll; 49 #endif 50 unsigned int macaddr_count; 51 }; 52 53 static inline void macvlan_count_rx(const struct macvlan_dev *vlan, 54 unsigned int len, bool success, 55 bool multicast) 56 { 57 if (likely(success)) { 58 struct vlan_pcpu_stats *pcpu_stats; 59 60 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats); 61 u64_stats_update_begin(&pcpu_stats->syncp); 62 pcpu_stats->rx_packets++; 63 pcpu_stats->rx_bytes += len; 64 if (multicast) 65 pcpu_stats->rx_multicast++; 66 u64_stats_update_end(&pcpu_stats->syncp); 67 } else { 68 this_cpu_inc(vlan->pcpu_stats->rx_errors); 69 } 70 } 71 72 extern void macvlan_common_setup(struct net_device *dev); 73 74 extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev, 75 struct nlattr *tb[], struct nlattr *data[], 76 struct netlink_ext_ack *extack); 77 78 extern void macvlan_count_rx(const struct macvlan_dev *vlan, 79 unsigned int len, bool success, 80 bool multicast); 81 82 extern void macvlan_dellink(struct net_device *dev, struct list_head *head); 83 84 extern int macvlan_link_register(struct rtnl_link_ops *ops); 85 86 #if IS_ENABLED(CONFIG_MACVLAN) 87 static inline struct net_device * 88 macvlan_dev_real_dev(const struct net_device *dev) 89 { 90 struct macvlan_dev *macvlan = netdev_priv(dev); 91 92 return macvlan->lowerdev; 93 } 94 #else 95 static inline struct net_device * 96 macvlan_dev_real_dev(const struct net_device *dev) 97 { 98 BUG(); 99 return NULL; 100 } 101 #endif 102 103 #endif /* _LINUX_IF_MACVLAN_H */ 104