if_macvlan.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. void *fwd_priv;
  58. struct macvlan_pcpu_stats __percpu *pcpu_stats;
  59. DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
  60. netdev_features_t set_features;
  61. enum macvlan_mode mode;
  62. u16 flags;
  63. int (*receive)(struct sk_buff *skb);
  64. int (*forward)(struct net_device *dev, struct sk_buff *skb);
  65. /* This array tracks active taps. */
  66. struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES];
  67. /* This list tracks all taps (both enabled and disabled) */
  68. struct list_head queue_list;
  69. int numvtaps;
  70. int numqueues;
  71. netdev_features_t tap_features;
  72. int minor;
  73. };
  74. static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
  75. unsigned int len, bool success,
  76. bool multicast)
  77. {
  78. if (likely(success)) {
  79. struct macvlan_pcpu_stats *pcpu_stats;
  80. pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
  81. u64_stats_update_begin(&pcpu_stats->syncp);
  82. pcpu_stats->rx_packets++;
  83. pcpu_stats->rx_bytes += len;
  84. if (multicast)
  85. pcpu_stats->rx_multicast++;
  86. u64_stats_update_end(&pcpu_stats->syncp);
  87. } else {
  88. this_cpu_inc(vlan->pcpu_stats->rx_errors);
  89. }
  90. }
  91. extern void macvlan_common_setup(struct net_device *dev);
  92. extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
  93. struct nlattr *tb[], struct nlattr *data[],
  94. int (*receive)(struct sk_buff *skb),
  95. int (*forward)(struct net_device *dev,
  96. struct sk_buff *skb));
  97. extern void macvlan_count_rx(const struct macvlan_dev *vlan,
  98. unsigned int len, bool success,
  99. bool multicast);
  100. extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
  101. extern int macvlan_link_register(struct rtnl_link_ops *ops);
  102. extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
  103. struct net_device *dev);
  104. #endif /* _LINUX_IF_MACVLAN_H */