if_macvlan.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. void *accel_priv;
  21. struct vlan_pcpu_stats __percpu *pcpu_stats;
  22. DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
  23. netdev_features_t set_features;
  24. enum macvlan_mode mode;
  25. u16 flags;
  26. unsigned int macaddr_count;
  27. #ifdef CONFIG_NET_POLL_CONTROLLER
  28. struct netpoll *netpoll;
  29. #endif
  30. };
  31. static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
  32. unsigned int len, bool success,
  33. bool multicast)
  34. {
  35. if (likely(success)) {
  36. struct vlan_pcpu_stats *pcpu_stats;
  37. pcpu_stats = get_cpu_ptr(vlan->pcpu_stats);
  38. u64_stats_update_begin(&pcpu_stats->syncp);
  39. pcpu_stats->rx_packets++;
  40. pcpu_stats->rx_bytes += len;
  41. if (multicast)
  42. pcpu_stats->rx_multicast++;
  43. u64_stats_update_end(&pcpu_stats->syncp);
  44. put_cpu_ptr(vlan->pcpu_stats);
  45. } else {
  46. this_cpu_inc(vlan->pcpu_stats->rx_errors);
  47. }
  48. }
  49. extern void macvlan_common_setup(struct net_device *dev);
  50. extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
  51. struct nlattr *tb[], struct nlattr *data[],
  52. struct netlink_ext_ack *extack);
  53. extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
  54. extern int macvlan_link_register(struct rtnl_link_ops *ops);
  55. #if IS_ENABLED(CONFIG_MACVLAN)
  56. static inline struct net_device *
  57. macvlan_dev_real_dev(const struct net_device *dev)
  58. {
  59. struct macvlan_dev *macvlan = netdev_priv(dev);
  60. return macvlan->lowerdev;
  61. }
  62. #else
  63. static inline struct net_device *
  64. macvlan_dev_real_dev(const struct net_device *dev)
  65. {
  66. BUG();
  67. return NULL;
  68. }
  69. #endif
  70. static inline void *macvlan_accel_priv(struct net_device *dev)
  71. {
  72. struct macvlan_dev *macvlan = netdev_priv(dev);
  73. return macvlan->accel_priv;
  74. }
  75. static inline bool macvlan_supports_dest_filter(struct net_device *dev)
  76. {
  77. struct macvlan_dev *macvlan = netdev_priv(dev);
  78. return macvlan->mode == MACVLAN_MODE_PRIVATE ||
  79. macvlan->mode == MACVLAN_MODE_VEPA ||
  80. macvlan->mode == MACVLAN_MODE_BRIDGE;
  81. }
  82. static inline int macvlan_release_l2fw_offload(struct net_device *dev)
  83. {
  84. struct macvlan_dev *macvlan = netdev_priv(dev);
  85. macvlan->accel_priv = NULL;
  86. return dev_uc_add(macvlan->lowerdev, dev->dev_addr);
  87. }
  88. #endif /* _LINUX_IF_MACVLAN_H */