if_macvlan.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 defined(CONFIG_MACVTAP) || defined(CONFIG_MACVTAP_MODULE)
  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 (NR_CPUS < 16 ? NR_CPUS : 16)
  49. struct macvlan_dev {
  50. struct net_device *dev;
  51. struct list_head list;
  52. struct hlist_node hlist;
  53. struct macvlan_port *port;
  54. struct net_device *lowerdev;
  55. struct macvlan_pcpu_stats __percpu *pcpu_stats;
  56. enum macvlan_mode mode;
  57. int (*receive)(struct sk_buff *skb);
  58. int (*forward)(struct net_device *dev, struct sk_buff *skb);
  59. struct macvtap_queue *taps[MAX_MACVTAP_QUEUES];
  60. int numvtaps;
  61. int minor;
  62. };
  63. static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
  64. unsigned int len, bool success,
  65. bool multicast)
  66. {
  67. if (likely(success)) {
  68. struct macvlan_pcpu_stats *pcpu_stats;
  69. pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
  70. u64_stats_update_begin(&pcpu_stats->syncp);
  71. pcpu_stats->rx_packets++;
  72. pcpu_stats->rx_bytes += len;
  73. if (multicast)
  74. pcpu_stats->rx_multicast++;
  75. u64_stats_update_end(&pcpu_stats->syncp);
  76. } else {
  77. this_cpu_inc(vlan->pcpu_stats->rx_errors);
  78. }
  79. }
  80. extern void macvlan_common_setup(struct net_device *dev);
  81. extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
  82. struct nlattr *tb[], struct nlattr *data[],
  83. int (*receive)(struct sk_buff *skb),
  84. int (*forward)(struct net_device *dev,
  85. struct sk_buff *skb));
  86. extern void macvlan_count_rx(const struct macvlan_dev *vlan,
  87. unsigned int len, bool success,
  88. bool multicast);
  89. extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
  90. extern int macvlan_link_register(struct rtnl_link_ops *ops);
  91. extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
  92. struct net_device *dev);
  93. #endif /* _LINUX_IF_MACVLAN_H */