if_macvlan.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_IF_MACVLAN_H
  3. #define _LINUX_IF_MACVLAN_H
  4. #include <linux/if_link.h>
  5. #include <linux/if_vlan.h>
  6. #include <linux/list.h>
  7. #include <linux/netdevice.h>
  8. #include <linux/netlink.h>
  9. #include <net/netlink.h>
  10. #include <linux/u64_stats_sync.h>
  11. struct macvlan_port;
  12. #define MACVLAN_MC_FILTER_BITS 8
  13. #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
  14. struct macvlan_dev {
  15. struct net_device *dev;
  16. struct list_head list;
  17. struct hlist_node hlist;
  18. struct macvlan_port *port;
  19. struct net_device *lowerdev;
  20. netdevice_tracker dev_tracker;
  21. void *accel_priv;
  22. struct vlan_pcpu_stats __percpu *pcpu_stats;
  23. DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
  24. netdev_features_t set_features;
  25. enum macvlan_mode mode;
  26. u16 flags;
  27. unsigned int macaddr_count;
  28. u32 bc_queue_len_req;
  29. #ifdef CONFIG_NET_POLL_CONTROLLER
  30. struct netpoll *netpoll;
  31. #endif
  32. };
  33. static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
  34. unsigned int len, bool success,
  35. bool multicast)
  36. {
  37. if (likely(success)) {
  38. struct vlan_pcpu_stats *pcpu_stats;
  39. pcpu_stats = get_cpu_ptr(vlan->pcpu_stats);
  40. u64_stats_update_begin(&pcpu_stats->syncp);
  41. u64_stats_inc(&pcpu_stats->rx_packets);
  42. u64_stats_add(&pcpu_stats->rx_bytes, len);
  43. if (multicast)
  44. u64_stats_inc(&pcpu_stats->rx_multicast);
  45. u64_stats_update_end(&pcpu_stats->syncp);
  46. put_cpu_ptr(vlan->pcpu_stats);
  47. } else {
  48. this_cpu_inc(vlan->pcpu_stats->rx_errors);
  49. }
  50. }
  51. extern void macvlan_common_setup(struct net_device *dev);
  52. extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
  53. struct nlattr *tb[], struct nlattr *data[],
  54. struct netlink_ext_ack *extack);
  55. extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
  56. extern int macvlan_link_register(struct rtnl_link_ops *ops);
  57. #if IS_ENABLED(CONFIG_MACVLAN)
  58. static inline struct net_device *
  59. macvlan_dev_real_dev(const struct net_device *dev)
  60. {
  61. struct macvlan_dev *macvlan = netdev_priv(dev);
  62. return macvlan->lowerdev;
  63. }
  64. #else
  65. static inline struct net_device *
  66. macvlan_dev_real_dev(const struct net_device *dev)
  67. {
  68. BUG();
  69. return NULL;
  70. }
  71. #endif
  72. static inline void *macvlan_accel_priv(struct net_device *dev)
  73. {
  74. struct macvlan_dev *macvlan = netdev_priv(dev);
  75. return macvlan->accel_priv;
  76. }
  77. static inline bool macvlan_supports_dest_filter(struct net_device *dev)
  78. {
  79. struct macvlan_dev *macvlan = netdev_priv(dev);
  80. return macvlan->mode == MACVLAN_MODE_PRIVATE ||
  81. macvlan->mode == MACVLAN_MODE_VEPA ||
  82. macvlan->mode == MACVLAN_MODE_BRIDGE;
  83. }
  84. static inline int macvlan_release_l2fw_offload(struct net_device *dev)
  85. {
  86. struct macvlan_dev *macvlan = netdev_priv(dev);
  87. macvlan->accel_priv = NULL;
  88. return dev_uc_add(macvlan->lowerdev, dev->dev_addr);
  89. }
  90. #endif /* _LINUX_IF_MACVLAN_H */