if_macvlan.h 3.2 KB

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