if_macvlan.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. struct macvtap_queue *taps[MAX_MACVTAP_QUEUES];
  64. int numvtaps;
  65. int minor;
  66. };
  67. static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
  68. unsigned int len, bool success,
  69. bool multicast)
  70. {
  71. if (likely(success)) {
  72. struct macvlan_pcpu_stats *pcpu_stats;
  73. pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
  74. u64_stats_update_begin(&pcpu_stats->syncp);
  75. pcpu_stats->rx_packets++;
  76. pcpu_stats->rx_bytes += len;
  77. if (multicast)
  78. pcpu_stats->rx_multicast++;
  79. u64_stats_update_end(&pcpu_stats->syncp);
  80. } else {
  81. this_cpu_inc(vlan->pcpu_stats->rx_errors);
  82. }
  83. }
  84. extern void macvlan_common_setup(struct net_device *dev);
  85. extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
  86. struct nlattr *tb[], struct nlattr *data[],
  87. int (*receive)(struct sk_buff *skb),
  88. int (*forward)(struct net_device *dev,
  89. struct sk_buff *skb));
  90. extern void macvlan_count_rx(const struct macvlan_dev *vlan,
  91. unsigned int len, bool success,
  92. bool multicast);
  93. extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
  94. extern int macvlan_link_register(struct rtnl_link_ops *ops);
  95. extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
  96. struct net_device *dev);
  97. #endif /* _LINUX_IF_MACVLAN_H */