if_macvlan.h 2.8 KB

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