if_bridge.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Linux ethernet bridge
  4. *
  5. * Authors:
  6. * Lennert Buytenhek <[email protected]>
  7. */
  8. #ifndef _LINUX_IF_BRIDGE_H
  9. #define _LINUX_IF_BRIDGE_H
  10. #include <linux/netdevice.h>
  11. #include <uapi/linux/if_bridge.h>
  12. #include <linux/bitops.h>
  13. struct br_ip {
  14. union {
  15. __be32 ip4;
  16. #if IS_ENABLED(CONFIG_IPV6)
  17. struct in6_addr ip6;
  18. #endif
  19. } src;
  20. union {
  21. __be32 ip4;
  22. #if IS_ENABLED(CONFIG_IPV6)
  23. struct in6_addr ip6;
  24. #endif
  25. unsigned char mac_addr[ETH_ALEN];
  26. } dst;
  27. __be16 proto;
  28. __u16 vid;
  29. };
  30. struct br_ip_list {
  31. struct list_head list;
  32. struct br_ip addr;
  33. };
  34. #define BR_HAIRPIN_MODE BIT(0)
  35. #define BR_BPDU_GUARD BIT(1)
  36. #define BR_ROOT_BLOCK BIT(2)
  37. #define BR_MULTICAST_FAST_LEAVE BIT(3)
  38. #define BR_ADMIN_COST BIT(4)
  39. #define BR_LEARNING BIT(5)
  40. #define BR_FLOOD BIT(6)
  41. #define BR_AUTO_MASK (BR_FLOOD | BR_LEARNING)
  42. #define BR_PROMISC BIT(7)
  43. #define BR_PROXYARP BIT(8)
  44. #define BR_LEARNING_SYNC BIT(9)
  45. #define BR_PROXYARP_WIFI BIT(10)
  46. #define BR_MCAST_FLOOD BIT(11)
  47. #define BR_MULTICAST_TO_UNICAST BIT(12)
  48. #define BR_VLAN_TUNNEL BIT(13)
  49. #define BR_BCAST_FLOOD BIT(14)
  50. #define BR_NEIGH_SUPPRESS BIT(15)
  51. #define BR_ISOLATED BIT(16)
  52. #define BR_MRP_AWARE BIT(17)
  53. #define BR_MRP_LOST_CONT BIT(18)
  54. #define BR_MRP_LOST_IN_CONT BIT(19)
  55. #define BR_TX_FWD_OFFLOAD BIT(20)
  56. #define BR_PORT_LOCKED BIT(21)
  57. #define BR_DEFAULT_AGEING_TIME (300 * HZ)
  58. struct net_bridge;
  59. void brioctl_set(int (*hook)(struct net *net, struct net_bridge *br,
  60. unsigned int cmd, struct ifreq *ifr,
  61. void __user *uarg));
  62. int br_ioctl_call(struct net *net, struct net_bridge *br, unsigned int cmd,
  63. struct ifreq *ifr, void __user *uarg);
  64. #if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_IGMP_SNOOPING)
  65. int br_multicast_list_adjacent(struct net_device *dev,
  66. struct list_head *br_ip_list);
  67. bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto);
  68. bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto);
  69. bool br_multicast_has_router_adjacent(struct net_device *dev, int proto);
  70. bool br_multicast_enabled(const struct net_device *dev);
  71. bool br_multicast_router(const struct net_device *dev);
  72. #else
  73. static inline int br_multicast_list_adjacent(struct net_device *dev,
  74. struct list_head *br_ip_list)
  75. {
  76. return 0;
  77. }
  78. static inline bool br_multicast_has_querier_anywhere(struct net_device *dev,
  79. int proto)
  80. {
  81. return false;
  82. }
  83. static inline bool br_multicast_has_querier_adjacent(struct net_device *dev,
  84. int proto)
  85. {
  86. return false;
  87. }
  88. static inline bool br_multicast_has_router_adjacent(struct net_device *dev,
  89. int proto)
  90. {
  91. return true;
  92. }
  93. static inline bool br_multicast_enabled(const struct net_device *dev)
  94. {
  95. return false;
  96. }
  97. static inline bool br_multicast_router(const struct net_device *dev)
  98. {
  99. return false;
  100. }
  101. #endif
  102. #if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_VLAN_FILTERING)
  103. bool br_vlan_enabled(const struct net_device *dev);
  104. int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid);
  105. int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid);
  106. int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto);
  107. int br_vlan_get_info(const struct net_device *dev, u16 vid,
  108. struct bridge_vlan_info *p_vinfo);
  109. int br_vlan_get_info_rcu(const struct net_device *dev, u16 vid,
  110. struct bridge_vlan_info *p_vinfo);
  111. bool br_mst_enabled(const struct net_device *dev);
  112. int br_mst_get_info(const struct net_device *dev, u16 msti, unsigned long *vids);
  113. int br_mst_get_state(const struct net_device *dev, u16 msti, u8 *state);
  114. #else
  115. static inline bool br_vlan_enabled(const struct net_device *dev)
  116. {
  117. return false;
  118. }
  119. static inline int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid)
  120. {
  121. return -EINVAL;
  122. }
  123. static inline int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto)
  124. {
  125. return -EINVAL;
  126. }
  127. static inline int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid)
  128. {
  129. return -EINVAL;
  130. }
  131. static inline int br_vlan_get_info(const struct net_device *dev, u16 vid,
  132. struct bridge_vlan_info *p_vinfo)
  133. {
  134. return -EINVAL;
  135. }
  136. static inline int br_vlan_get_info_rcu(const struct net_device *dev, u16 vid,
  137. struct bridge_vlan_info *p_vinfo)
  138. {
  139. return -EINVAL;
  140. }
  141. static inline bool br_mst_enabled(const struct net_device *dev)
  142. {
  143. return false;
  144. }
  145. static inline int br_mst_get_info(const struct net_device *dev, u16 msti,
  146. unsigned long *vids)
  147. {
  148. return -EINVAL;
  149. }
  150. static inline int br_mst_get_state(const struct net_device *dev, u16 msti,
  151. u8 *state)
  152. {
  153. return -EINVAL;
  154. }
  155. #endif
  156. #if IS_ENABLED(CONFIG_BRIDGE)
  157. struct net_device *br_fdb_find_port(const struct net_device *br_dev,
  158. const unsigned char *addr,
  159. __u16 vid);
  160. void br_fdb_clear_offload(const struct net_device *dev, u16 vid);
  161. bool br_port_flag_is_set(const struct net_device *dev, unsigned long flag);
  162. u8 br_port_get_stp_state(const struct net_device *dev);
  163. clock_t br_get_ageing_time(const struct net_device *br_dev);
  164. #else
  165. static inline struct net_device *
  166. br_fdb_find_port(const struct net_device *br_dev,
  167. const unsigned char *addr,
  168. __u16 vid)
  169. {
  170. return NULL;
  171. }
  172. static inline void br_fdb_clear_offload(const struct net_device *dev, u16 vid)
  173. {
  174. }
  175. static inline bool
  176. br_port_flag_is_set(const struct net_device *dev, unsigned long flag)
  177. {
  178. return false;
  179. }
  180. static inline u8 br_port_get_stp_state(const struct net_device *dev)
  181. {
  182. return BR_STATE_DISABLED;
  183. }
  184. static inline clock_t br_get_ageing_time(const struct net_device *br_dev)
  185. {
  186. return 0;
  187. }
  188. #endif
  189. #endif