xref: /linux/include/linux/if_bridge.h (revision 87020def2529ec26fc9077e889fa1c34f53f1f83)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *	Linux ethernet bridge
4  *
5  *	Authors:
6  *	Lennert Buytenhek		<buytenh@gnu.org>
7  */
8 #ifndef _LINUX_IF_BRIDGE_H
9 #define _LINUX_IF_BRIDGE_H
10 
11 
12 #include <linux/netdevice.h>
13 #include <uapi/linux/if_bridge.h>
14 #include <linux/bitops.h>
15 
16 struct br_ip {
17 	union {
18 		__be32	ip4;
19 #if IS_ENABLED(CONFIG_IPV6)
20 		struct in6_addr ip6;
21 #endif
22 	} src;
23 	union {
24 		__be32	ip4;
25 #if IS_ENABLED(CONFIG_IPV6)
26 		struct in6_addr ip6;
27 #endif
28 		unsigned char	mac_addr[ETH_ALEN];
29 	} dst;
30 	__be16		proto;
31 	__u16           vid;
32 };
33 
34 struct br_ip_list {
35 	struct list_head list;
36 	struct br_ip addr;
37 };
38 
39 enum bridge_flags_bit {
40 	BR_HAIRPIN_MODE_BIT,
41 	BR_BPDU_GUARD_BIT,
42 	BR_ROOT_BLOCK_BIT,
43 	BR_MULTICAST_FAST_LEAVE_BIT,
44 	BR_ADMIN_COST_BIT,
45 	BR_LEARNING_BIT,
46 	BR_FLOOD_BIT,
47 	BR_PROMISC_BIT,
48 	BR_PROXYARP_BIT,
49 	BR_LEARNING_SYNC_BIT,
50 	BR_PROXYARP_WIFI_BIT,
51 	BR_MCAST_FLOOD_BIT,
52 	BR_MULTICAST_TO_UNICAST_BIT,
53 	BR_VLAN_TUNNEL_BIT,
54 	BR_BCAST_FLOOD_BIT,
55 	BR_NEIGH_SUPPRESS_BIT,
56 	BR_ISOLATED_BIT,
57 	BR_MRP_AWARE_BIT,
58 	BR_MRP_LOST_CONT_BIT,
59 	BR_MRP_LOST_IN_CONT_BIT,
60 	BR_TX_FWD_OFFLOAD_BIT,
61 	BR_PORT_LOCKED_BIT,
62 	BR_PORT_MAB_BIT,
63 	BR_NEIGH_VLAN_SUPPRESS_BIT,
64 	BR_NEIGH_FORWARD_GRAT_BIT,
65 };
66 
67 #define BR_HAIRPIN_MODE		BIT(BR_HAIRPIN_MODE_BIT)
68 #define BR_BPDU_GUARD		BIT(BR_BPDU_GUARD_BIT)
69 #define BR_ROOT_BLOCK		BIT(BR_ROOT_BLOCK_BIT)
70 #define BR_MULTICAST_FAST_LEAVE	BIT(BR_MULTICAST_FAST_LEAVE_BIT)
71 #define BR_ADMIN_COST		BIT(BR_ADMIN_COST_BIT)
72 #define BR_LEARNING		BIT(BR_LEARNING_BIT)
73 #define BR_FLOOD		BIT(BR_FLOOD_BIT)
74 #define BR_AUTO_MASK		(BR_FLOOD | BR_LEARNING)
75 #define BR_PROMISC		BIT(BR_PROMISC_BIT)
76 #define BR_PROXYARP		BIT(BR_PROXYARP_BIT)
77 #define BR_LEARNING_SYNC	BIT(BR_LEARNING_SYNC_BIT)
78 #define BR_PROXYARP_WIFI	BIT(BR_PROXYARP_WIFI_BIT)
79 #define BR_MCAST_FLOOD		BIT(BR_MCAST_FLOOD_BIT)
80 #define BR_MULTICAST_TO_UNICAST	BIT(BR_MULTICAST_TO_UNICAST_BIT)
81 #define BR_VLAN_TUNNEL		BIT(BR_VLAN_TUNNEL_BIT)
82 #define BR_BCAST_FLOOD		BIT(BR_BCAST_FLOOD_BIT)
83 #define BR_NEIGH_SUPPRESS	BIT(BR_NEIGH_SUPPRESS_BIT)
84 #define BR_ISOLATED		BIT(BR_ISOLATED_BIT)
85 #define BR_MRP_AWARE		BIT(BR_MRP_AWARE_BIT)
86 #define BR_MRP_LOST_CONT	BIT(BR_MRP_LOST_CONT_BIT)
87 #define BR_MRP_LOST_IN_CONT	BIT(BR_MRP_LOST_IN_CONT_BIT)
88 #define BR_TX_FWD_OFFLOAD	BIT(BR_TX_FWD_OFFLOAD_BIT)
89 #define BR_PORT_LOCKED		BIT(BR_PORT_LOCKED_BIT)
90 #define BR_PORT_MAB		BIT(BR_PORT_MAB_BIT)
91 #define BR_NEIGH_VLAN_SUPPRESS	BIT(BR_NEIGH_VLAN_SUPPRESS_BIT)
92 #define BR_NEIGH_FORWARD_GRAT	BIT(BR_NEIGH_FORWARD_GRAT_BIT)
93 
94 #define BR_DEFAULT_AGEING_TIME	(300 * HZ)
95 
96 struct net_bridge;
97 void brioctl_set(int (*hook)(struct net *net, unsigned int cmd,
98 			     void __user *uarg));
99 int br_ioctl_call(struct net *net, unsigned int cmd, void __user *uarg);
100 
101 #if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_IGMP_SNOOPING)
102 int br_multicast_list_adjacent(struct net_device *dev,
103 			       struct list_head *br_ip_list);
104 bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto);
105 bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto);
106 bool br_multicast_has_router_adjacent(struct net_device *dev, int proto);
107 bool br_multicast_enabled(const struct net_device *dev);
108 bool br_multicast_router(const struct net_device *dev);
109 #else
110 static inline int br_multicast_list_adjacent(struct net_device *dev,
111 					     struct list_head *br_ip_list)
112 {
113 	return 0;
114 }
115 static inline bool br_multicast_has_querier_anywhere(struct net_device *dev,
116 						     int proto)
117 {
118 	return false;
119 }
120 static inline bool br_multicast_has_querier_adjacent(struct net_device *dev,
121 						     int proto)
122 {
123 	return false;
124 }
125 
126 static inline bool br_multicast_has_router_adjacent(struct net_device *dev,
127 						    int proto)
128 {
129 	return true;
130 }
131 
132 static inline bool br_multicast_enabled(const struct net_device *dev)
133 {
134 	return false;
135 }
136 static inline bool br_multicast_router(const struct net_device *dev)
137 {
138 	return false;
139 }
140 #endif
141 
142 #if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_VLAN_FILTERING)
143 bool br_vlan_enabled(const struct net_device *dev);
144 int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid);
145 int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid);
146 int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto);
147 int br_vlan_get_info(const struct net_device *dev, u16 vid,
148 		     struct bridge_vlan_info *p_vinfo);
149 int br_vlan_get_info_rcu(const struct net_device *dev, u16 vid,
150 			 struct bridge_vlan_info *p_vinfo);
151 bool br_mst_enabled(const struct net_device *dev);
152 int br_mst_get_info(const struct net_device *dev, u16 msti, unsigned long *vids);
153 int br_mst_get_state(const struct net_device *dev, u16 msti, u8 *state);
154 #else
155 static inline bool br_vlan_enabled(const struct net_device *dev)
156 {
157 	return false;
158 }
159 
160 static inline int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid)
161 {
162 	return -EINVAL;
163 }
164 
165 static inline int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto)
166 {
167 	return -EINVAL;
168 }
169 
170 static inline int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid)
171 {
172 	return -EINVAL;
173 }
174 
175 static inline int br_vlan_get_info(const struct net_device *dev, u16 vid,
176 				   struct bridge_vlan_info *p_vinfo)
177 {
178 	return -EINVAL;
179 }
180 
181 static inline int br_vlan_get_info_rcu(const struct net_device *dev, u16 vid,
182 				       struct bridge_vlan_info *p_vinfo)
183 {
184 	return -EINVAL;
185 }
186 
187 static inline bool br_mst_enabled(const struct net_device *dev)
188 {
189 	return false;
190 }
191 
192 static inline int br_mst_get_info(const struct net_device *dev, u16 msti,
193 				  unsigned long *vids)
194 {
195 	return -EINVAL;
196 }
197 static inline int br_mst_get_state(const struct net_device *dev, u16 msti,
198 				   u8 *state)
199 {
200 	return -EINVAL;
201 }
202 #endif
203 
204 #if IS_ENABLED(CONFIG_BRIDGE)
205 struct net_device *br_fdb_find_port(const struct net_device *br_dev,
206 				    const unsigned char *addr,
207 				    __u16 vid);
208 void br_fdb_clear_offload(const struct net_device *dev, u16 vid);
209 bool br_port_flag_is_set(const struct net_device *dev, unsigned long flag);
210 u8 br_port_get_stp_state(const struct net_device *dev);
211 clock_t br_get_ageing_time(const struct net_device *br_dev);
212 #else
213 static inline struct net_device *
214 br_fdb_find_port(const struct net_device *br_dev,
215 		 const unsigned char *addr,
216 		 __u16 vid)
217 {
218 	return NULL;
219 }
220 
221 static inline void br_fdb_clear_offload(const struct net_device *dev, u16 vid)
222 {
223 }
224 
225 static inline bool
226 br_port_flag_is_set(const struct net_device *dev, unsigned long flag)
227 {
228 	return false;
229 }
230 
231 static inline u8 br_port_get_stp_state(const struct net_device *dev)
232 {
233 	return BR_STATE_DISABLED;
234 }
235 
236 static inline clock_t br_get_ageing_time(const struct net_device *br_dev)
237 {
238 	return 0;
239 }
240 #endif
241 
242 #endif
243