1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Bridge netlink control interface
6 * Stephen Hemminger <shemminger@osdl.org>
9 #include <linux/kernel.h>
10 #include <linux/slab.h>
11 #include <linux/etherdevice.h>
12 #include <net/rtnetlink.h>
13 #include <net/net_namespace.h>
15 #include <uapi/linux/if_bridge.h>
17 #include "br_private.h"
18 #include "br_private_stp.h"
19 #include "br_private_cfm.h"
20 #include "br_private_tunnel.h"
21 #include "br_private_mcast_eht.h"
23 static int __get_num_vlan_infos(struct net_bridge_vlan_group
*vg
,
26 struct net_bridge_vlan
*v
;
27 u16 vid_range_start
= 0, vid_range_end
= 0, vid_range_flags
= 0;
31 if (!(filter_mask
& RTEXT_FILTER_BRVLAN_COMPRESSED
))
34 pvid
= br_get_pvid(vg
);
35 /* Count number of vlan infos */
36 list_for_each_entry_rcu(v
, &vg
->vlan_list
, vlist
) {
38 /* only a context, bridge vlan not activated */
39 if (!br_vlan_should_use(v
))
42 flags
|= BRIDGE_VLAN_INFO_PVID
;
44 if (v
->flags
& BRIDGE_VLAN_INFO_UNTAGGED
)
45 flags
|= BRIDGE_VLAN_INFO_UNTAGGED
;
47 if (vid_range_start
== 0) {
49 } else if ((v
->vid
- vid_range_end
) == 1 &&
50 flags
== vid_range_flags
) {
51 vid_range_end
= v
->vid
;
54 if ((vid_range_end
- vid_range_start
) > 0)
60 vid_range_start
= v
->vid
;
61 vid_range_end
= v
->vid
;
62 vid_range_flags
= flags
;
65 if (vid_range_start
!= 0) {
66 if ((vid_range_end
- vid_range_start
) > 0)
75 static int br_get_num_vlan_infos(struct net_bridge_vlan_group
*vg
,
83 if (filter_mask
& RTEXT_FILTER_BRVLAN
)
87 num_vlans
= __get_num_vlan_infos(vg
, filter_mask
);
93 static size_t br_get_link_af_size_filtered(const struct net_device
*dev
,
96 struct net_bridge_vlan_group
*vg
= NULL
;
97 struct net_bridge_port
*p
= NULL
;
98 struct net_bridge
*br
= NULL
;
99 u32 num_cfm_peer_mep_infos
;
100 u32 num_cfm_mep_infos
;
105 if (netif_is_bridge_port(dev
)) {
106 p
= br_port_get_check_rcu(dev
);
108 vg
= nbp_vlan_group_rcu(p
);
109 } else if (netif_is_bridge_master(dev
)) {
110 br
= netdev_priv(dev
);
111 vg
= br_vlan_group_rcu(br
);
113 num_vlan_infos
= br_get_num_vlan_infos(vg
, filter_mask
);
116 if (p
&& (p
->flags
& BR_VLAN_TUNNEL
))
117 vinfo_sz
+= br_get_vlan_tunnel_info_size(vg
);
119 /* Each VLAN is returned in bridge_vlan_info along with flags */
120 vinfo_sz
+= num_vlan_infos
* nla_total_size(sizeof(struct bridge_vlan_info
));
122 if (p
&& vg
&& (filter_mask
& RTEXT_FILTER_MST
))
123 vinfo_sz
+= br_mst_info_size(vg
);
125 if (!(filter_mask
& RTEXT_FILTER_CFM_STATUS
))
131 /* CFM status info must be added */
132 br_cfm_mep_count(br
, &num_cfm_mep_infos
);
133 br_cfm_peer_mep_count(br
, &num_cfm_peer_mep_infos
);
135 vinfo_sz
+= nla_total_size(0); /* IFLA_BRIDGE_CFM */
136 /* For each status struct the MEP instance (u32) is added */
137 /* MEP instance (u32) + br_cfm_mep_status */
138 vinfo_sz
+= num_cfm_mep_infos
*
139 /*IFLA_BRIDGE_CFM_MEP_STATUS_INSTANCE */
140 (nla_total_size(sizeof(u32
))
141 /* IFLA_BRIDGE_CFM_MEP_STATUS_OPCODE_UNEXP_SEEN */
142 + nla_total_size(sizeof(u32
))
143 /* IFLA_BRIDGE_CFM_MEP_STATUS_VERSION_UNEXP_SEEN */
144 + nla_total_size(sizeof(u32
))
145 /* IFLA_BRIDGE_CFM_MEP_STATUS_RX_LEVEL_LOW_SEEN */
146 + nla_total_size(sizeof(u32
)));
147 /* MEP instance (u32) + br_cfm_cc_peer_status */
148 vinfo_sz
+= num_cfm_peer_mep_infos
*
149 /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_INSTANCE */
150 (nla_total_size(sizeof(u32
))
151 /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_PEER_MEPID */
152 + nla_total_size(sizeof(u32
))
153 /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_CCM_DEFECT */
154 + nla_total_size(sizeof(u32
))
155 /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_RDI */
156 + nla_total_size(sizeof(u32
))
157 /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_PORT_TLV_VALUE */
158 + nla_total_size(sizeof(u8
))
159 /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_IF_TLV_VALUE */
160 + nla_total_size(sizeof(u8
))
161 /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_SEEN */
162 + nla_total_size(sizeof(u32
))
163 /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_TLV_SEEN */
164 + nla_total_size(sizeof(u32
))
165 /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_SEQ_UNEXP_SEEN */
166 + nla_total_size(sizeof(u32
)));
171 static inline size_t br_port_info_size(void)
173 return nla_total_size(1) /* IFLA_BRPORT_STATE */
174 + nla_total_size(2) /* IFLA_BRPORT_PRIORITY */
175 + nla_total_size(4) /* IFLA_BRPORT_COST */
176 + nla_total_size(1) /* IFLA_BRPORT_MODE */
177 + nla_total_size(1) /* IFLA_BRPORT_GUARD */
178 + nla_total_size(1) /* IFLA_BRPORT_PROTECT */
179 + nla_total_size(1) /* IFLA_BRPORT_FAST_LEAVE */
180 + nla_total_size(1) /* IFLA_BRPORT_MCAST_TO_UCAST */
181 + nla_total_size(1) /* IFLA_BRPORT_LEARNING */
182 + nla_total_size(1) /* IFLA_BRPORT_UNICAST_FLOOD */
183 + nla_total_size(1) /* IFLA_BRPORT_MCAST_FLOOD */
184 + nla_total_size(1) /* IFLA_BRPORT_BCAST_FLOOD */
185 + nla_total_size(1) /* IFLA_BRPORT_PROXYARP */
186 + nla_total_size(1) /* IFLA_BRPORT_PROXYARP_WIFI */
187 + nla_total_size(1) /* IFLA_BRPORT_VLAN_TUNNEL */
188 + nla_total_size(1) /* IFLA_BRPORT_NEIGH_SUPPRESS */
189 + nla_total_size(1) /* IFLA_BRPORT_ISOLATED */
190 + nla_total_size(1) /* IFLA_BRPORT_LOCKED */
191 + nla_total_size(1) /* IFLA_BRPORT_MAB */
192 + nla_total_size(1) /* IFLA_BRPORT_NEIGH_VLAN_SUPPRESS */
193 + nla_total_size(sizeof(struct ifla_bridge_id
)) /* IFLA_BRPORT_ROOT_ID */
194 + nla_total_size(sizeof(struct ifla_bridge_id
)) /* IFLA_BRPORT_BRIDGE_ID */
195 + nla_total_size(sizeof(u16
)) /* IFLA_BRPORT_DESIGNATED_PORT */
196 + nla_total_size(sizeof(u16
)) /* IFLA_BRPORT_DESIGNATED_COST */
197 + nla_total_size(sizeof(u16
)) /* IFLA_BRPORT_ID */
198 + nla_total_size(sizeof(u16
)) /* IFLA_BRPORT_NO */
199 + nla_total_size(sizeof(u8
)) /* IFLA_BRPORT_TOPOLOGY_CHANGE_ACK */
200 + nla_total_size(sizeof(u8
)) /* IFLA_BRPORT_CONFIG_PENDING */
201 + nla_total_size_64bit(sizeof(u64
)) /* IFLA_BRPORT_MESSAGE_AGE_TIMER */
202 + nla_total_size_64bit(sizeof(u64
)) /* IFLA_BRPORT_FORWARD_DELAY_TIMER */
203 + nla_total_size_64bit(sizeof(u64
)) /* IFLA_BRPORT_HOLD_TIMER */
204 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
205 + nla_total_size(sizeof(u8
)) /* IFLA_BRPORT_MULTICAST_ROUTER */
206 + nla_total_size(sizeof(u32
)) /* IFLA_BRPORT_MCAST_N_GROUPS */
207 + nla_total_size(sizeof(u32
)) /* IFLA_BRPORT_MCAST_MAX_GROUPS */
209 + nla_total_size(sizeof(u16
)) /* IFLA_BRPORT_GROUP_FWD_MASK */
210 + nla_total_size(sizeof(u8
)) /* IFLA_BRPORT_MRP_RING_OPEN */
211 + nla_total_size(sizeof(u8
)) /* IFLA_BRPORT_MRP_IN_OPEN */
212 + nla_total_size(sizeof(u32
)) /* IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT */
213 + nla_total_size(sizeof(u32
)) /* IFLA_BRPORT_MCAST_EHT_HOSTS_CNT */
214 + nla_total_size(sizeof(u32
)) /* IFLA_BRPORT_BACKUP_NHID */
218 static inline size_t br_nlmsg_size(struct net_device
*dev
, u32 filter_mask
)
220 return NLMSG_ALIGN(sizeof(struct ifinfomsg
))
221 + nla_total_size(IFNAMSIZ
) /* IFLA_IFNAME */
222 + nla_total_size(MAX_ADDR_LEN
) /* IFLA_ADDRESS */
223 + nla_total_size(4) /* IFLA_MASTER */
224 + nla_total_size(4) /* IFLA_MTU */
225 + nla_total_size(4) /* IFLA_LINK */
226 + nla_total_size(1) /* IFLA_OPERSTATE */
227 + nla_total_size(br_port_info_size()) /* IFLA_PROTINFO */
228 + nla_total_size(br_get_link_af_size_filtered(dev
,
229 filter_mask
)) /* IFLA_AF_SPEC */
230 + nla_total_size(4); /* IFLA_BRPORT_BACKUP_PORT */
233 static int br_port_fill_attrs(struct sk_buff
*skb
,
234 const struct net_bridge_port
*p
)
236 u8 mode
= !!(p
->flags
& BR_HAIRPIN_MODE
);
237 struct net_bridge_port
*backup_p
;
240 if (nla_put_u8(skb
, IFLA_BRPORT_STATE
, p
->state
) ||
241 nla_put_u16(skb
, IFLA_BRPORT_PRIORITY
, p
->priority
) ||
242 nla_put_u32(skb
, IFLA_BRPORT_COST
, p
->path_cost
) ||
243 nla_put_u8(skb
, IFLA_BRPORT_MODE
, mode
) ||
244 nla_put_u8(skb
, IFLA_BRPORT_GUARD
, !!(p
->flags
& BR_BPDU_GUARD
)) ||
245 nla_put_u8(skb
, IFLA_BRPORT_PROTECT
,
246 !!(p
->flags
& BR_ROOT_BLOCK
)) ||
247 nla_put_u8(skb
, IFLA_BRPORT_FAST_LEAVE
,
248 !!(p
->flags
& BR_MULTICAST_FAST_LEAVE
)) ||
249 nla_put_u8(skb
, IFLA_BRPORT_MCAST_TO_UCAST
,
250 !!(p
->flags
& BR_MULTICAST_TO_UNICAST
)) ||
251 nla_put_u8(skb
, IFLA_BRPORT_LEARNING
, !!(p
->flags
& BR_LEARNING
)) ||
252 nla_put_u8(skb
, IFLA_BRPORT_UNICAST_FLOOD
,
253 !!(p
->flags
& BR_FLOOD
)) ||
254 nla_put_u8(skb
, IFLA_BRPORT_MCAST_FLOOD
,
255 !!(p
->flags
& BR_MCAST_FLOOD
)) ||
256 nla_put_u8(skb
, IFLA_BRPORT_BCAST_FLOOD
,
257 !!(p
->flags
& BR_BCAST_FLOOD
)) ||
258 nla_put_u8(skb
, IFLA_BRPORT_PROXYARP
, !!(p
->flags
& BR_PROXYARP
)) ||
259 nla_put_u8(skb
, IFLA_BRPORT_PROXYARP_WIFI
,
260 !!(p
->flags
& BR_PROXYARP_WIFI
)) ||
261 nla_put(skb
, IFLA_BRPORT_ROOT_ID
, sizeof(struct ifla_bridge_id
),
262 &p
->designated_root
) ||
263 nla_put(skb
, IFLA_BRPORT_BRIDGE_ID
, sizeof(struct ifla_bridge_id
),
264 &p
->designated_bridge
) ||
265 nla_put_u16(skb
, IFLA_BRPORT_DESIGNATED_PORT
, p
->designated_port
) ||
266 nla_put_u16(skb
, IFLA_BRPORT_DESIGNATED_COST
, p
->designated_cost
) ||
267 nla_put_u16(skb
, IFLA_BRPORT_ID
, p
->port_id
) ||
268 nla_put_u16(skb
, IFLA_BRPORT_NO
, p
->port_no
) ||
269 nla_put_u8(skb
, IFLA_BRPORT_TOPOLOGY_CHANGE_ACK
,
270 p
->topology_change_ack
) ||
271 nla_put_u8(skb
, IFLA_BRPORT_CONFIG_PENDING
, p
->config_pending
) ||
272 nla_put_u8(skb
, IFLA_BRPORT_VLAN_TUNNEL
, !!(p
->flags
&
274 nla_put_u16(skb
, IFLA_BRPORT_GROUP_FWD_MASK
, p
->group_fwd_mask
) ||
275 nla_put_u8(skb
, IFLA_BRPORT_NEIGH_SUPPRESS
,
276 !!(p
->flags
& BR_NEIGH_SUPPRESS
)) ||
277 nla_put_u8(skb
, IFLA_BRPORT_MRP_RING_OPEN
, !!(p
->flags
&
278 BR_MRP_LOST_CONT
)) ||
279 nla_put_u8(skb
, IFLA_BRPORT_MRP_IN_OPEN
,
280 !!(p
->flags
& BR_MRP_LOST_IN_CONT
)) ||
281 nla_put_u8(skb
, IFLA_BRPORT_ISOLATED
, !!(p
->flags
& BR_ISOLATED
)) ||
282 nla_put_u8(skb
, IFLA_BRPORT_LOCKED
, !!(p
->flags
& BR_PORT_LOCKED
)) ||
283 nla_put_u8(skb
, IFLA_BRPORT_MAB
, !!(p
->flags
& BR_PORT_MAB
)) ||
284 nla_put_u8(skb
, IFLA_BRPORT_NEIGH_VLAN_SUPPRESS
,
285 !!(p
->flags
& BR_NEIGH_VLAN_SUPPRESS
)))
288 timerval
= br_timer_value(&p
->message_age_timer
);
289 if (nla_put_u64_64bit(skb
, IFLA_BRPORT_MESSAGE_AGE_TIMER
, timerval
,
292 timerval
= br_timer_value(&p
->forward_delay_timer
);
293 if (nla_put_u64_64bit(skb
, IFLA_BRPORT_FORWARD_DELAY_TIMER
, timerval
,
296 timerval
= br_timer_value(&p
->hold_timer
);
297 if (nla_put_u64_64bit(skb
, IFLA_BRPORT_HOLD_TIMER
, timerval
,
301 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
302 if (nla_put_u8(skb
, IFLA_BRPORT_MULTICAST_ROUTER
,
303 p
->multicast_ctx
.multicast_router
) ||
304 nla_put_u32(skb
, IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT
,
305 p
->multicast_eht_hosts_limit
) ||
306 nla_put_u32(skb
, IFLA_BRPORT_MCAST_EHT_HOSTS_CNT
,
307 p
->multicast_eht_hosts_cnt
) ||
308 nla_put_u32(skb
, IFLA_BRPORT_MCAST_N_GROUPS
,
309 br_multicast_ngroups_get(&p
->multicast_ctx
)) ||
310 nla_put_u32(skb
, IFLA_BRPORT_MCAST_MAX_GROUPS
,
311 br_multicast_ngroups_get_max(&p
->multicast_ctx
)))
315 /* we might be called only with br->lock */
317 backup_p
= rcu_dereference(p
->backup_port
);
319 nla_put_u32(skb
, IFLA_BRPORT_BACKUP_PORT
,
320 backup_p
->dev
->ifindex
);
323 if (p
->backup_nhid
&&
324 nla_put_u32(skb
, IFLA_BRPORT_BACKUP_NHID
, p
->backup_nhid
))
330 static int br_fill_ifvlaninfo_range(struct sk_buff
*skb
, u16 vid_start
,
331 u16 vid_end
, u16 flags
)
333 struct bridge_vlan_info vinfo
;
335 if ((vid_end
- vid_start
) > 0) {
336 /* add range to skb */
337 vinfo
.vid
= vid_start
;
338 vinfo
.flags
= flags
| BRIDGE_VLAN_INFO_RANGE_BEGIN
;
339 if (nla_put(skb
, IFLA_BRIDGE_VLAN_INFO
,
340 sizeof(vinfo
), &vinfo
))
341 goto nla_put_failure
;
344 vinfo
.flags
= flags
| BRIDGE_VLAN_INFO_RANGE_END
;
345 if (nla_put(skb
, IFLA_BRIDGE_VLAN_INFO
,
346 sizeof(vinfo
), &vinfo
))
347 goto nla_put_failure
;
349 vinfo
.vid
= vid_start
;
351 if (nla_put(skb
, IFLA_BRIDGE_VLAN_INFO
,
352 sizeof(vinfo
), &vinfo
))
353 goto nla_put_failure
;
362 static int br_fill_ifvlaninfo_compressed(struct sk_buff
*skb
,
363 struct net_bridge_vlan_group
*vg
)
365 struct net_bridge_vlan
*v
;
366 u16 vid_range_start
= 0, vid_range_end
= 0, vid_range_flags
= 0;
370 /* Pack IFLA_BRIDGE_VLAN_INFO's for every vlan
371 * and mark vlan info with begin and end flags
372 * if vlaninfo represents a range
374 pvid
= br_get_pvid(vg
);
375 list_for_each_entry_rcu(v
, &vg
->vlan_list
, vlist
) {
377 if (!br_vlan_should_use(v
))
380 flags
|= BRIDGE_VLAN_INFO_PVID
;
382 if (v
->flags
& BRIDGE_VLAN_INFO_UNTAGGED
)
383 flags
|= BRIDGE_VLAN_INFO_UNTAGGED
;
385 if (vid_range_start
== 0) {
387 } else if ((v
->vid
- vid_range_end
) == 1 &&
388 flags
== vid_range_flags
) {
389 vid_range_end
= v
->vid
;
392 err
= br_fill_ifvlaninfo_range(skb
, vid_range_start
,
400 vid_range_start
= v
->vid
;
401 vid_range_end
= v
->vid
;
402 vid_range_flags
= flags
;
405 if (vid_range_start
!= 0) {
406 /* Call it once more to send any left over vlans */
407 err
= br_fill_ifvlaninfo_range(skb
, vid_range_start
,
417 static int br_fill_ifvlaninfo(struct sk_buff
*skb
,
418 struct net_bridge_vlan_group
*vg
)
420 struct bridge_vlan_info vinfo
;
421 struct net_bridge_vlan
*v
;
424 pvid
= br_get_pvid(vg
);
425 list_for_each_entry_rcu(v
, &vg
->vlan_list
, vlist
) {
426 if (!br_vlan_should_use(v
))
432 vinfo
.flags
|= BRIDGE_VLAN_INFO_PVID
;
434 if (v
->flags
& BRIDGE_VLAN_INFO_UNTAGGED
)
435 vinfo
.flags
|= BRIDGE_VLAN_INFO_UNTAGGED
;
437 if (nla_put(skb
, IFLA_BRIDGE_VLAN_INFO
,
438 sizeof(vinfo
), &vinfo
))
439 goto nla_put_failure
;
449 * Create one netlink message for one interface
450 * Contains port and master info as well as carrier and bridge state.
452 static int br_fill_ifinfo(struct sk_buff
*skb
,
453 const struct net_bridge_port
*port
,
454 u32 pid
, u32 seq
, int event
, unsigned int flags
,
455 u32 filter_mask
, const struct net_device
*dev
,
458 u8 operstate
= netif_running(dev
) ? READ_ONCE(dev
->operstate
) :
460 struct nlattr
*af
= NULL
;
461 struct net_bridge
*br
;
462 struct ifinfomsg
*hdr
;
463 struct nlmsghdr
*nlh
;
468 br
= netdev_priv(dev
);
470 br_debug(br
, "br_fill_info event %d port %s master %s\n",
471 event
, dev
->name
, br
->dev
->name
);
473 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(*hdr
), flags
);
477 hdr
= nlmsg_data(nlh
);
478 hdr
->ifi_family
= AF_BRIDGE
;
480 hdr
->ifi_type
= dev
->type
;
481 hdr
->ifi_index
= dev
->ifindex
;
482 hdr
->ifi_flags
= dev_get_flags(dev
);
485 if (nla_put_string(skb
, IFLA_IFNAME
, dev
->name
) ||
486 nla_put_u32(skb
, IFLA_MASTER
, br
->dev
->ifindex
) ||
487 nla_put_u32(skb
, IFLA_MTU
, dev
->mtu
) ||
488 nla_put_u8(skb
, IFLA_OPERSTATE
, operstate
) ||
490 nla_put(skb
, IFLA_ADDRESS
, dev
->addr_len
, dev
->dev_addr
)) ||
491 (dev
->ifindex
!= dev_get_iflink(dev
) &&
492 nla_put_u32(skb
, IFLA_LINK
, dev_get_iflink(dev
))))
493 goto nla_put_failure
;
495 if (event
== RTM_NEWLINK
&& port
) {
498 nest
= nla_nest_start(skb
, IFLA_PROTINFO
);
499 if (nest
== NULL
|| br_port_fill_attrs(skb
, port
) < 0)
500 goto nla_put_failure
;
501 nla_nest_end(skb
, nest
);
504 if (filter_mask
& (RTEXT_FILTER_BRVLAN
|
505 RTEXT_FILTER_BRVLAN_COMPRESSED
|
507 RTEXT_FILTER_CFM_CONFIG
|
508 RTEXT_FILTER_CFM_STATUS
|
510 af
= nla_nest_start_noflag(skb
, IFLA_AF_SPEC
);
512 goto nla_put_failure
;
515 /* Check if the VID information is requested */
516 if ((filter_mask
& RTEXT_FILTER_BRVLAN
) ||
517 (filter_mask
& RTEXT_FILTER_BRVLAN_COMPRESSED
)) {
518 struct net_bridge_vlan_group
*vg
;
521 /* RCU needed because of the VLAN locking rules (rcu || rtnl) */
524 vg
= nbp_vlan_group_rcu(port
);
526 vg
= br_vlan_group_rcu(br
);
528 if (!vg
|| !vg
->num_vlans
) {
532 if (filter_mask
& RTEXT_FILTER_BRVLAN_COMPRESSED
)
533 err
= br_fill_ifvlaninfo_compressed(skb
, vg
);
535 err
= br_fill_ifvlaninfo(skb
, vg
);
537 if (port
&& (port
->flags
& BR_VLAN_TUNNEL
))
538 err
= br_fill_vlan_tunnel_info(skb
, vg
);
541 goto nla_put_failure
;
544 if (filter_mask
& RTEXT_FILTER_MRP
) {
547 if (!br_mrp_enabled(br
) || port
)
551 err
= br_mrp_fill_info(skb
, br
);
555 goto nla_put_failure
;
558 if (filter_mask
& (RTEXT_FILTER_CFM_CONFIG
| RTEXT_FILTER_CFM_STATUS
)) {
559 struct nlattr
*cfm_nest
= NULL
;
562 if (!br_cfm_created(br
) || port
)
565 cfm_nest
= nla_nest_start(skb
, IFLA_BRIDGE_CFM
);
567 goto nla_put_failure
;
569 if (filter_mask
& RTEXT_FILTER_CFM_CONFIG
) {
571 err
= br_cfm_config_fill_info(skb
, br
);
574 goto nla_put_failure
;
577 if (filter_mask
& RTEXT_FILTER_CFM_STATUS
) {
579 err
= br_cfm_status_fill_info(skb
, br
, getlink
);
582 goto nla_put_failure
;
585 nla_nest_end(skb
, cfm_nest
);
588 if ((filter_mask
& RTEXT_FILTER_MST
) &&
589 br_opt_get(br
, BROPT_MST_ENABLED
) && port
) {
590 const struct net_bridge_vlan_group
*vg
= nbp_vlan_group(port
);
591 struct nlattr
*mst_nest
;
594 if (!vg
|| !vg
->num_vlans
)
597 mst_nest
= nla_nest_start(skb
, IFLA_BRIDGE_MST
);
599 goto nla_put_failure
;
601 err
= br_mst_fill_info(skb
, vg
);
603 goto nla_put_failure
;
605 nla_nest_end(skb
, mst_nest
);
610 if (nlmsg_get_pos(skb
) - (void *)af
> nla_attr_size(0))
611 nla_nest_end(skb
, af
);
613 nla_nest_cancel(skb
, af
);
620 nlmsg_cancel(skb
, nlh
);
624 void br_info_notify(int event
, const struct net_bridge
*br
,
625 const struct net_bridge_port
*port
, u32 filter
)
627 struct net_device
*dev
;
633 if (WARN_ON(!port
&& !br
))
639 port_no
= port
->port_no
;
645 br_debug(br
, "port %u(%s) event %d\n", port_no
, dev
->name
, event
);
647 skb
= nlmsg_new(br_nlmsg_size(dev
, filter
), GFP_ATOMIC
);
651 err
= br_fill_ifinfo(skb
, port
, 0, 0, event
, 0, filter
, dev
, false);
653 /* -EMSGSIZE implies BUG in br_nlmsg_size() */
654 WARN_ON(err
== -EMSGSIZE
);
658 rtnl_notify(skb
, net
, 0, RTNLGRP_LINK
, NULL
, GFP_ATOMIC
);
661 rtnl_set_sk_err(net
, RTNLGRP_LINK
, err
);
664 /* Notify listeners of a change in bridge or port information */
665 void br_ifinfo_notify(int event
, const struct net_bridge
*br
,
666 const struct net_bridge_port
*port
)
668 u32 filter
= RTEXT_FILTER_BRVLAN_COMPRESSED
;
670 br_info_notify(event
, br
, port
, filter
);
674 * Dump information about all ports, in response to GETLINK
676 int br_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
677 struct net_device
*dev
, u32 filter_mask
, int nlflags
)
679 struct net_bridge_port
*port
= br_port_get_rtnl(dev
);
681 if (!port
&& !(filter_mask
& RTEXT_FILTER_BRVLAN
) &&
682 !(filter_mask
& RTEXT_FILTER_BRVLAN_COMPRESSED
) &&
683 !(filter_mask
& RTEXT_FILTER_MRP
) &&
684 !(filter_mask
& RTEXT_FILTER_CFM_CONFIG
) &&
685 !(filter_mask
& RTEXT_FILTER_CFM_STATUS
))
688 return br_fill_ifinfo(skb
, port
, pid
, seq
, RTM_NEWLINK
, nlflags
,
689 filter_mask
, dev
, true);
692 static int br_vlan_info(struct net_bridge
*br
, struct net_bridge_port
*p
,
693 int cmd
, struct bridge_vlan_info
*vinfo
, bool *changed
,
694 struct netlink_ext_ack
*extack
)
702 /* if the MASTER flag is set this will act on the global
703 * per-VLAN entry as well
705 err
= nbp_vlan_add(p
, vinfo
->vid
, vinfo
->flags
,
706 &curr_change
, extack
);
708 vinfo
->flags
|= BRIDGE_VLAN_INFO_BRENTRY
;
709 err
= br_vlan_add(br
, vinfo
->vid
, vinfo
->flags
,
710 &curr_change
, extack
);
718 if (!nbp_vlan_delete(p
, vinfo
->vid
))
721 if ((vinfo
->flags
& BRIDGE_VLAN_INFO_MASTER
) &&
722 !br_vlan_delete(p
->br
, vinfo
->vid
))
724 } else if (!br_vlan_delete(br
, vinfo
->vid
)) {
733 int br_process_vlan_info(struct net_bridge
*br
,
734 struct net_bridge_port
*p
, int cmd
,
735 struct bridge_vlan_info
*vinfo_curr
,
736 struct bridge_vlan_info
**vinfo_last
,
738 struct netlink_ext_ack
*extack
)
742 if (!br_vlan_valid_id(vinfo_curr
->vid
, extack
))
745 /* needed for vlan-only NEWVLAN/DELVLAN notifications */
746 rtm_cmd
= br_afspec_cmd_to_rtm(cmd
);
748 if (vinfo_curr
->flags
& BRIDGE_VLAN_INFO_RANGE_BEGIN
) {
749 if (!br_vlan_valid_range(vinfo_curr
, *vinfo_last
, extack
))
751 *vinfo_last
= vinfo_curr
;
756 struct bridge_vlan_info tmp_vinfo
;
757 int v
, v_change_start
= 0;
759 if (!br_vlan_valid_range(vinfo_curr
, *vinfo_last
, extack
))
762 memcpy(&tmp_vinfo
, *vinfo_last
,
763 sizeof(struct bridge_vlan_info
));
764 for (v
= (*vinfo_last
)->vid
; v
<= vinfo_curr
->vid
; v
++) {
765 bool curr_change
= false;
768 err
= br_vlan_info(br
, p
, cmd
, &tmp_vinfo
, &curr_change
,
773 *changed
= curr_change
;
777 /* nothing to notify yet */
780 br_vlan_notify(br
, p
, v_change_start
,
786 /* v_change_start is set only if the last/whole range changed */
788 br_vlan_notify(br
, p
, v_change_start
,
796 err
= br_vlan_info(br
, p
, cmd
, vinfo_curr
, changed
, extack
);
798 br_vlan_notify(br
, p
, vinfo_curr
->vid
, 0, rtm_cmd
);
803 static int br_afspec(struct net_bridge
*br
,
804 struct net_bridge_port
*p
,
805 struct nlattr
*af_spec
,
806 int cmd
, bool *changed
,
807 struct netlink_ext_ack
*extack
)
809 struct bridge_vlan_info
*vinfo_curr
= NULL
;
810 struct bridge_vlan_info
*vinfo_last
= NULL
;
812 struct vtunnel_info tinfo_last
= {};
813 struct vtunnel_info tinfo_curr
= {};
816 nla_for_each_nested(attr
, af_spec
, rem
) {
818 switch (nla_type(attr
)) {
819 case IFLA_BRIDGE_VLAN_TUNNEL_INFO
:
820 if (!p
|| !(p
->flags
& BR_VLAN_TUNNEL
))
822 err
= br_parse_vlan_tunnel_info(attr
, &tinfo_curr
);
825 err
= br_process_vlan_tunnel_info(br
, p
, cmd
,
832 case IFLA_BRIDGE_VLAN_INFO
:
833 if (nla_len(attr
) != sizeof(struct bridge_vlan_info
))
835 vinfo_curr
= nla_data(attr
);
836 err
= br_process_vlan_info(br
, p
, cmd
, vinfo_curr
,
837 &vinfo_last
, changed
,
842 case IFLA_BRIDGE_MRP
:
843 err
= br_mrp_parse(br
, p
, attr
, cmd
, extack
);
847 case IFLA_BRIDGE_CFM
:
848 err
= br_cfm_parse(br
, p
, attr
, cmd
, extack
);
852 case IFLA_BRIDGE_MST
:
854 NL_SET_ERR_MSG(extack
,
855 "MST states can only be set on bridge ports");
859 if (cmd
!= RTM_SETLINK
) {
860 NL_SET_ERR_MSG(extack
,
861 "MST states can only be set through RTM_SETLINK");
865 err
= br_mst_process(p
, attr
, extack
);
875 static const struct nla_policy br_port_policy
[IFLA_BRPORT_MAX
+ 1] = {
876 [IFLA_BRPORT_UNSPEC
] = { .strict_start_type
=
877 IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT
+ 1 },
878 [IFLA_BRPORT_STATE
] = { .type
= NLA_U8
},
879 [IFLA_BRPORT_COST
] = { .type
= NLA_U32
},
880 [IFLA_BRPORT_PRIORITY
] = { .type
= NLA_U16
},
881 [IFLA_BRPORT_MODE
] = { .type
= NLA_U8
},
882 [IFLA_BRPORT_GUARD
] = { .type
= NLA_U8
},
883 [IFLA_BRPORT_PROTECT
] = { .type
= NLA_U8
},
884 [IFLA_BRPORT_FAST_LEAVE
]= { .type
= NLA_U8
},
885 [IFLA_BRPORT_LEARNING
] = { .type
= NLA_U8
},
886 [IFLA_BRPORT_UNICAST_FLOOD
] = { .type
= NLA_U8
},
887 [IFLA_BRPORT_PROXYARP
] = { .type
= NLA_U8
},
888 [IFLA_BRPORT_PROXYARP_WIFI
] = { .type
= NLA_U8
},
889 [IFLA_BRPORT_MULTICAST_ROUTER
] = { .type
= NLA_U8
},
890 [IFLA_BRPORT_MCAST_TO_UCAST
] = { .type
= NLA_U8
},
891 [IFLA_BRPORT_MCAST_FLOOD
] = { .type
= NLA_U8
},
892 [IFLA_BRPORT_BCAST_FLOOD
] = { .type
= NLA_U8
},
893 [IFLA_BRPORT_VLAN_TUNNEL
] = { .type
= NLA_U8
},
894 [IFLA_BRPORT_GROUP_FWD_MASK
] = { .type
= NLA_U16
},
895 [IFLA_BRPORT_NEIGH_SUPPRESS
] = { .type
= NLA_U8
},
896 [IFLA_BRPORT_ISOLATED
] = { .type
= NLA_U8
},
897 [IFLA_BRPORT_LOCKED
] = { .type
= NLA_U8
},
898 [IFLA_BRPORT_MAB
] = { .type
= NLA_U8
},
899 [IFLA_BRPORT_BACKUP_PORT
] = { .type
= NLA_U32
},
900 [IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT
] = { .type
= NLA_U32
},
901 [IFLA_BRPORT_MCAST_N_GROUPS
] = { .type
= NLA_REJECT
},
902 [IFLA_BRPORT_MCAST_MAX_GROUPS
] = { .type
= NLA_U32
},
903 [IFLA_BRPORT_NEIGH_VLAN_SUPPRESS
] = NLA_POLICY_MAX(NLA_U8
, 1),
904 [IFLA_BRPORT_BACKUP_NHID
] = { .type
= NLA_U32
},
907 /* Change the state of the port and notify spanning tree */
908 static int br_set_port_state(struct net_bridge_port
*p
, u8 state
)
910 if (state
> BR_STATE_BLOCKING
)
913 /* if kernel STP is running, don't allow changes */
914 if (p
->br
->stp_enabled
== BR_KERNEL_STP
)
917 /* if device is not up, change is not allowed
918 * if link is not present, only allowable state is disabled
920 if (!netif_running(p
->dev
) ||
921 (!netif_oper_up(p
->dev
) && state
!= BR_STATE_DISABLED
))
924 br_set_state(p
, state
);
925 br_port_state_selection(p
->br
);
929 /* Set/clear or port flags based on attribute */
930 static void br_set_port_flag(struct net_bridge_port
*p
, struct nlattr
*tb
[],
931 int attrtype
, unsigned long mask
)
936 if (nla_get_u8(tb
[attrtype
]))
942 /* Process bridge protocol info on port */
943 static int br_setport(struct net_bridge_port
*p
, struct nlattr
*tb
[],
944 struct netlink_ext_ack
*extack
)
946 unsigned long old_flags
, changed_mask
;
947 bool br_vlan_tunnel_old
;
950 old_flags
= p
->flags
;
951 br_vlan_tunnel_old
= (old_flags
& BR_VLAN_TUNNEL
) ? true : false;
953 br_set_port_flag(p
, tb
, IFLA_BRPORT_MODE
, BR_HAIRPIN_MODE
);
954 br_set_port_flag(p
, tb
, IFLA_BRPORT_GUARD
, BR_BPDU_GUARD
);
955 br_set_port_flag(p
, tb
, IFLA_BRPORT_FAST_LEAVE
,
956 BR_MULTICAST_FAST_LEAVE
);
957 br_set_port_flag(p
, tb
, IFLA_BRPORT_PROTECT
, BR_ROOT_BLOCK
);
958 br_set_port_flag(p
, tb
, IFLA_BRPORT_LEARNING
, BR_LEARNING
);
959 br_set_port_flag(p
, tb
, IFLA_BRPORT_UNICAST_FLOOD
, BR_FLOOD
);
960 br_set_port_flag(p
, tb
, IFLA_BRPORT_MCAST_FLOOD
, BR_MCAST_FLOOD
);
961 br_set_port_flag(p
, tb
, IFLA_BRPORT_MCAST_TO_UCAST
,
962 BR_MULTICAST_TO_UNICAST
);
963 br_set_port_flag(p
, tb
, IFLA_BRPORT_BCAST_FLOOD
, BR_BCAST_FLOOD
);
964 br_set_port_flag(p
, tb
, IFLA_BRPORT_PROXYARP
, BR_PROXYARP
);
965 br_set_port_flag(p
, tb
, IFLA_BRPORT_PROXYARP_WIFI
, BR_PROXYARP_WIFI
);
966 br_set_port_flag(p
, tb
, IFLA_BRPORT_VLAN_TUNNEL
, BR_VLAN_TUNNEL
);
967 br_set_port_flag(p
, tb
, IFLA_BRPORT_NEIGH_SUPPRESS
, BR_NEIGH_SUPPRESS
);
968 br_set_port_flag(p
, tb
, IFLA_BRPORT_ISOLATED
, BR_ISOLATED
);
969 br_set_port_flag(p
, tb
, IFLA_BRPORT_LOCKED
, BR_PORT_LOCKED
);
970 br_set_port_flag(p
, tb
, IFLA_BRPORT_MAB
, BR_PORT_MAB
);
971 br_set_port_flag(p
, tb
, IFLA_BRPORT_NEIGH_VLAN_SUPPRESS
,
972 BR_NEIGH_VLAN_SUPPRESS
);
974 if ((p
->flags
& BR_PORT_MAB
) &&
975 (!(p
->flags
& BR_PORT_LOCKED
) || !(p
->flags
& BR_LEARNING
))) {
976 NL_SET_ERR_MSG(extack
, "Bridge port must be locked and have learning enabled when MAB is enabled");
977 p
->flags
= old_flags
;
979 } else if (!(p
->flags
& BR_PORT_MAB
) && (old_flags
& BR_PORT_MAB
)) {
980 struct net_bridge_fdb_flush_desc desc
= {
981 .flags
= BIT(BR_FDB_LOCKED
),
982 .flags_mask
= BIT(BR_FDB_LOCKED
),
983 .port_ifindex
= p
->dev
->ifindex
,
986 br_fdb_flush(p
->br
, &desc
);
989 changed_mask
= old_flags
^ p
->flags
;
991 err
= br_switchdev_set_port_flag(p
, p
->flags
, changed_mask
, extack
);
993 p
->flags
= old_flags
;
997 if (br_vlan_tunnel_old
&& !(p
->flags
& BR_VLAN_TUNNEL
))
998 nbp_vlan_tunnel_info_flush(p
);
1000 br_port_flags_change(p
, changed_mask
);
1002 if (tb
[IFLA_BRPORT_COST
]) {
1003 err
= br_stp_set_path_cost(p
, nla_get_u32(tb
[IFLA_BRPORT_COST
]));
1008 if (tb
[IFLA_BRPORT_PRIORITY
]) {
1009 err
= br_stp_set_port_priority(p
, nla_get_u16(tb
[IFLA_BRPORT_PRIORITY
]));
1014 if (tb
[IFLA_BRPORT_STATE
]) {
1015 err
= br_set_port_state(p
, nla_get_u8(tb
[IFLA_BRPORT_STATE
]));
1020 if (tb
[IFLA_BRPORT_FLUSH
])
1021 br_fdb_delete_by_port(p
->br
, p
, 0, 0);
1023 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1024 if (tb
[IFLA_BRPORT_MULTICAST_ROUTER
]) {
1025 u8 mcast_router
= nla_get_u8(tb
[IFLA_BRPORT_MULTICAST_ROUTER
]);
1027 err
= br_multicast_set_port_router(&p
->multicast_ctx
,
1033 if (tb
[IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT
]) {
1036 hlimit
= nla_get_u32(tb
[IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT
]);
1037 err
= br_multicast_eht_set_hosts_limit(p
, hlimit
);
1042 if (tb
[IFLA_BRPORT_MCAST_MAX_GROUPS
]) {
1045 max_groups
= nla_get_u32(tb
[IFLA_BRPORT_MCAST_MAX_GROUPS
]);
1046 br_multicast_ngroups_set_max(&p
->multicast_ctx
, max_groups
);
1050 if (tb
[IFLA_BRPORT_GROUP_FWD_MASK
]) {
1051 u16 fwd_mask
= nla_get_u16(tb
[IFLA_BRPORT_GROUP_FWD_MASK
]);
1053 if (fwd_mask
& BR_GROUPFWD_MACPAUSE
)
1055 p
->group_fwd_mask
= fwd_mask
;
1058 if (tb
[IFLA_BRPORT_BACKUP_PORT
]) {
1059 struct net_device
*backup_dev
= NULL
;
1062 backup_ifindex
= nla_get_u32(tb
[IFLA_BRPORT_BACKUP_PORT
]);
1063 if (backup_ifindex
) {
1064 backup_dev
= __dev_get_by_index(dev_net(p
->dev
),
1070 err
= nbp_backup_change(p
, backup_dev
);
1075 if (tb
[IFLA_BRPORT_BACKUP_NHID
]) {
1076 u32 backup_nhid
= nla_get_u32(tb
[IFLA_BRPORT_BACKUP_NHID
]);
1078 WRITE_ONCE(p
->backup_nhid
, backup_nhid
);
1084 /* Change state and parameters on port. */
1085 int br_setlink(struct net_device
*dev
, struct nlmsghdr
*nlh
, u16 flags
,
1086 struct netlink_ext_ack
*extack
)
1088 struct net_bridge
*br
= (struct net_bridge
*)netdev_priv(dev
);
1089 struct nlattr
*tb
[IFLA_BRPORT_MAX
+ 1];
1090 struct net_bridge_port
*p
;
1091 struct nlattr
*protinfo
;
1092 struct nlattr
*afspec
;
1093 bool changed
= false;
1096 protinfo
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_PROTINFO
);
1097 afspec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
1098 if (!protinfo
&& !afspec
)
1101 p
= br_port_get_rtnl(dev
);
1102 /* We want to accept dev as bridge itself if the AF_SPEC
1103 * is set to see if someone is setting vlan info on the bridge
1108 if (p
&& protinfo
) {
1109 if (protinfo
->nla_type
& NLA_F_NESTED
) {
1110 err
= nla_parse_nested_deprecated(tb
, IFLA_BRPORT_MAX
,
1117 spin_lock_bh(&p
->br
->lock
);
1118 err
= br_setport(p
, tb
, extack
);
1119 spin_unlock_bh(&p
->br
->lock
);
1121 /* Binary compatibility with old RSTP */
1122 if (nla_len(protinfo
) < sizeof(u8
))
1125 spin_lock_bh(&p
->br
->lock
);
1126 err
= br_set_port_state(p
, nla_get_u8(protinfo
));
1127 spin_unlock_bh(&p
->br
->lock
);
1135 err
= br_afspec(br
, p
, afspec
, RTM_SETLINK
, &changed
, extack
);
1138 br_ifinfo_notify(RTM_NEWLINK
, br
, p
);
1143 /* Delete port information */
1144 int br_dellink(struct net_device
*dev
, struct nlmsghdr
*nlh
, u16 flags
)
1146 struct net_bridge
*br
= (struct net_bridge
*)netdev_priv(dev
);
1147 struct net_bridge_port
*p
;
1148 struct nlattr
*afspec
;
1149 bool changed
= false;
1152 afspec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
1156 p
= br_port_get_rtnl(dev
);
1157 /* We want to accept dev as bridge itself as well */
1158 if (!p
&& !netif_is_bridge_master(dev
))
1161 err
= br_afspec(br
, p
, afspec
, RTM_DELLINK
, &changed
, NULL
);
1163 /* Send RTM_NEWLINK because userspace
1164 * expects RTM_NEWLINK for vlan dels
1166 br_ifinfo_notify(RTM_NEWLINK
, br
, p
);
1171 static int br_validate(struct nlattr
*tb
[], struct nlattr
*data
[],
1172 struct netlink_ext_ack
*extack
)
1174 if (tb
[IFLA_ADDRESS
]) {
1175 if (nla_len(tb
[IFLA_ADDRESS
]) != ETH_ALEN
)
1177 if (!is_valid_ether_addr(nla_data(tb
[IFLA_ADDRESS
])))
1178 return -EADDRNOTAVAIL
;
1184 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1185 if (data
[IFLA_BR_VLAN_PROTOCOL
] &&
1186 !eth_type_vlan(nla_get_be16(data
[IFLA_BR_VLAN_PROTOCOL
])))
1187 return -EPROTONOSUPPORT
;
1189 if (data
[IFLA_BR_VLAN_DEFAULT_PVID
]) {
1190 __u16 defpvid
= nla_get_u16(data
[IFLA_BR_VLAN_DEFAULT_PVID
]);
1192 if (defpvid
>= VLAN_VID_MASK
)
1200 static int br_port_slave_changelink(struct net_device
*brdev
,
1201 struct net_device
*dev
,
1202 struct nlattr
*tb
[],
1203 struct nlattr
*data
[],
1204 struct netlink_ext_ack
*extack
)
1206 struct net_bridge
*br
= netdev_priv(brdev
);
1212 spin_lock_bh(&br
->lock
);
1213 ret
= br_setport(br_port_get_rtnl(dev
), data
, extack
);
1214 spin_unlock_bh(&br
->lock
);
1219 static int br_port_fill_slave_info(struct sk_buff
*skb
,
1220 const struct net_device
*brdev
,
1221 const struct net_device
*dev
)
1223 return br_port_fill_attrs(skb
, br_port_get_rtnl(dev
));
1226 static size_t br_port_get_slave_size(const struct net_device
*brdev
,
1227 const struct net_device
*dev
)
1229 return br_port_info_size();
1232 static const struct nla_policy br_policy
[IFLA_BR_MAX
+ 1] = {
1233 [IFLA_BR_UNSPEC
] = { .strict_start_type
=
1234 IFLA_BR_FDB_N_LEARNED
},
1235 [IFLA_BR_FORWARD_DELAY
] = { .type
= NLA_U32
},
1236 [IFLA_BR_HELLO_TIME
] = { .type
= NLA_U32
},
1237 [IFLA_BR_MAX_AGE
] = { .type
= NLA_U32
},
1238 [IFLA_BR_AGEING_TIME
] = { .type
= NLA_U32
},
1239 [IFLA_BR_STP_STATE
] = { .type
= NLA_U32
},
1240 [IFLA_BR_PRIORITY
] = { .type
= NLA_U16
},
1241 [IFLA_BR_VLAN_FILTERING
] = { .type
= NLA_U8
},
1242 [IFLA_BR_VLAN_PROTOCOL
] = { .type
= NLA_U16
},
1243 [IFLA_BR_GROUP_FWD_MASK
] = { .type
= NLA_U16
},
1244 [IFLA_BR_GROUP_ADDR
] = { .type
= NLA_BINARY
,
1246 [IFLA_BR_MCAST_ROUTER
] = { .type
= NLA_U8
},
1247 [IFLA_BR_MCAST_SNOOPING
] = { .type
= NLA_U8
},
1248 [IFLA_BR_MCAST_QUERY_USE_IFADDR
] = { .type
= NLA_U8
},
1249 [IFLA_BR_MCAST_QUERIER
] = { .type
= NLA_U8
},
1250 [IFLA_BR_MCAST_HASH_ELASTICITY
] = { .type
= NLA_U32
},
1251 [IFLA_BR_MCAST_HASH_MAX
] = { .type
= NLA_U32
},
1252 [IFLA_BR_MCAST_LAST_MEMBER_CNT
] = { .type
= NLA_U32
},
1253 [IFLA_BR_MCAST_STARTUP_QUERY_CNT
] = { .type
= NLA_U32
},
1254 [IFLA_BR_MCAST_LAST_MEMBER_INTVL
] = { .type
= NLA_U64
},
1255 [IFLA_BR_MCAST_MEMBERSHIP_INTVL
] = { .type
= NLA_U64
},
1256 [IFLA_BR_MCAST_QUERIER_INTVL
] = { .type
= NLA_U64
},
1257 [IFLA_BR_MCAST_QUERY_INTVL
] = { .type
= NLA_U64
},
1258 [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
] = { .type
= NLA_U64
},
1259 [IFLA_BR_MCAST_STARTUP_QUERY_INTVL
] = { .type
= NLA_U64
},
1260 [IFLA_BR_NF_CALL_IPTABLES
] = { .type
= NLA_U8
},
1261 [IFLA_BR_NF_CALL_IP6TABLES
] = { .type
= NLA_U8
},
1262 [IFLA_BR_NF_CALL_ARPTABLES
] = { .type
= NLA_U8
},
1263 [IFLA_BR_VLAN_DEFAULT_PVID
] = { .type
= NLA_U16
},
1264 [IFLA_BR_VLAN_STATS_ENABLED
] = { .type
= NLA_U8
},
1265 [IFLA_BR_MCAST_STATS_ENABLED
] = { .type
= NLA_U8
},
1266 [IFLA_BR_MCAST_IGMP_VERSION
] = { .type
= NLA_U8
},
1267 [IFLA_BR_MCAST_MLD_VERSION
] = { .type
= NLA_U8
},
1268 [IFLA_BR_VLAN_STATS_PER_PORT
] = { .type
= NLA_U8
},
1269 [IFLA_BR_MULTI_BOOLOPT
] =
1270 NLA_POLICY_EXACT_LEN(sizeof(struct br_boolopt_multi
)),
1271 [IFLA_BR_FDB_N_LEARNED
] = { .type
= NLA_REJECT
},
1272 [IFLA_BR_FDB_MAX_LEARNED
] = { .type
= NLA_U32
},
1275 static int br_changelink(struct net_device
*brdev
, struct nlattr
*tb
[],
1276 struct nlattr
*data
[],
1277 struct netlink_ext_ack
*extack
)
1279 struct net_bridge
*br
= netdev_priv(brdev
);
1285 if (data
[IFLA_BR_FORWARD_DELAY
]) {
1286 err
= br_set_forward_delay(br
, nla_get_u32(data
[IFLA_BR_FORWARD_DELAY
]));
1291 if (data
[IFLA_BR_HELLO_TIME
]) {
1292 err
= br_set_hello_time(br
, nla_get_u32(data
[IFLA_BR_HELLO_TIME
]));
1297 if (data
[IFLA_BR_MAX_AGE
]) {
1298 err
= br_set_max_age(br
, nla_get_u32(data
[IFLA_BR_MAX_AGE
]));
1303 if (data
[IFLA_BR_AGEING_TIME
]) {
1304 err
= br_set_ageing_time(br
, nla_get_u32(data
[IFLA_BR_AGEING_TIME
]));
1309 if (data
[IFLA_BR_STP_STATE
]) {
1310 u32 stp_enabled
= nla_get_u32(data
[IFLA_BR_STP_STATE
]);
1312 err
= br_stp_set_enabled(br
, stp_enabled
, extack
);
1317 if (data
[IFLA_BR_PRIORITY
]) {
1318 u32 priority
= nla_get_u16(data
[IFLA_BR_PRIORITY
]);
1320 br_stp_set_bridge_priority(br
, priority
);
1323 if (data
[IFLA_BR_VLAN_FILTERING
]) {
1324 u8 vlan_filter
= nla_get_u8(data
[IFLA_BR_VLAN_FILTERING
]);
1326 err
= br_vlan_filter_toggle(br
, vlan_filter
, extack
);
1331 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1332 if (data
[IFLA_BR_VLAN_PROTOCOL
]) {
1333 __be16 vlan_proto
= nla_get_be16(data
[IFLA_BR_VLAN_PROTOCOL
]);
1335 err
= __br_vlan_set_proto(br
, vlan_proto
, extack
);
1340 if (data
[IFLA_BR_VLAN_DEFAULT_PVID
]) {
1341 __u16 defpvid
= nla_get_u16(data
[IFLA_BR_VLAN_DEFAULT_PVID
]);
1343 err
= __br_vlan_set_default_pvid(br
, defpvid
, extack
);
1348 if (data
[IFLA_BR_VLAN_STATS_ENABLED
]) {
1349 __u8 vlan_stats
= nla_get_u8(data
[IFLA_BR_VLAN_STATS_ENABLED
]);
1351 err
= br_vlan_set_stats(br
, vlan_stats
);
1356 if (data
[IFLA_BR_VLAN_STATS_PER_PORT
]) {
1357 __u8 per_port
= nla_get_u8(data
[IFLA_BR_VLAN_STATS_PER_PORT
]);
1359 err
= br_vlan_set_stats_per_port(br
, per_port
);
1365 if (data
[IFLA_BR_GROUP_FWD_MASK
]) {
1366 u16 fwd_mask
= nla_get_u16(data
[IFLA_BR_GROUP_FWD_MASK
]);
1368 if (fwd_mask
& BR_GROUPFWD_RESTRICTED
)
1370 br
->group_fwd_mask
= fwd_mask
;
1373 if (data
[IFLA_BR_GROUP_ADDR
]) {
1374 u8 new_addr
[ETH_ALEN
];
1376 if (nla_len(data
[IFLA_BR_GROUP_ADDR
]) != ETH_ALEN
)
1378 memcpy(new_addr
, nla_data(data
[IFLA_BR_GROUP_ADDR
]), ETH_ALEN
);
1379 if (!is_link_local_ether_addr(new_addr
))
1381 if (new_addr
[5] == 1 || /* 802.3x Pause address */
1382 new_addr
[5] == 2 || /* 802.3ad Slow protocols */
1383 new_addr
[5] == 3) /* 802.1X PAE address */
1385 spin_lock_bh(&br
->lock
);
1386 memcpy(br
->group_addr
, new_addr
, sizeof(br
->group_addr
));
1387 spin_unlock_bh(&br
->lock
);
1388 br_opt_toggle(br
, BROPT_GROUP_ADDR_SET
, true);
1389 br_recalculate_fwd_mask(br
);
1392 if (data
[IFLA_BR_FDB_FLUSH
]) {
1393 struct net_bridge_fdb_flush_desc desc
= {
1394 .flags_mask
= BIT(BR_FDB_STATIC
)
1397 br_fdb_flush(br
, &desc
);
1400 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1401 if (data
[IFLA_BR_MCAST_ROUTER
]) {
1402 u8 multicast_router
= nla_get_u8(data
[IFLA_BR_MCAST_ROUTER
]);
1404 err
= br_multicast_set_router(&br
->multicast_ctx
,
1410 if (data
[IFLA_BR_MCAST_SNOOPING
]) {
1411 u8 mcast_snooping
= nla_get_u8(data
[IFLA_BR_MCAST_SNOOPING
]);
1413 err
= br_multicast_toggle(br
, mcast_snooping
, extack
);
1418 if (data
[IFLA_BR_MCAST_QUERY_USE_IFADDR
]) {
1421 val
= nla_get_u8(data
[IFLA_BR_MCAST_QUERY_USE_IFADDR
]);
1422 br_opt_toggle(br
, BROPT_MULTICAST_QUERY_USE_IFADDR
, !!val
);
1425 if (data
[IFLA_BR_MCAST_QUERIER
]) {
1426 u8 mcast_querier
= nla_get_u8(data
[IFLA_BR_MCAST_QUERIER
]);
1428 err
= br_multicast_set_querier(&br
->multicast_ctx
,
1434 if (data
[IFLA_BR_MCAST_HASH_ELASTICITY
])
1435 br_warn(br
, "the hash_elasticity option has been deprecated and is always %u\n",
1438 if (data
[IFLA_BR_MCAST_HASH_MAX
])
1439 br
->hash_max
= nla_get_u32(data
[IFLA_BR_MCAST_HASH_MAX
]);
1441 if (data
[IFLA_BR_MCAST_LAST_MEMBER_CNT
]) {
1442 u32 val
= nla_get_u32(data
[IFLA_BR_MCAST_LAST_MEMBER_CNT
]);
1444 br
->multicast_ctx
.multicast_last_member_count
= val
;
1447 if (data
[IFLA_BR_MCAST_STARTUP_QUERY_CNT
]) {
1448 u32 val
= nla_get_u32(data
[IFLA_BR_MCAST_STARTUP_QUERY_CNT
]);
1450 br
->multicast_ctx
.multicast_startup_query_count
= val
;
1453 if (data
[IFLA_BR_MCAST_LAST_MEMBER_INTVL
]) {
1454 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_LAST_MEMBER_INTVL
]);
1456 br
->multicast_ctx
.multicast_last_member_interval
= clock_t_to_jiffies(val
);
1459 if (data
[IFLA_BR_MCAST_MEMBERSHIP_INTVL
]) {
1460 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_MEMBERSHIP_INTVL
]);
1462 br
->multicast_ctx
.multicast_membership_interval
= clock_t_to_jiffies(val
);
1465 if (data
[IFLA_BR_MCAST_QUERIER_INTVL
]) {
1466 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_QUERIER_INTVL
]);
1468 br
->multicast_ctx
.multicast_querier_interval
= clock_t_to_jiffies(val
);
1471 if (data
[IFLA_BR_MCAST_QUERY_INTVL
]) {
1472 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_QUERY_INTVL
]);
1474 br_multicast_set_query_intvl(&br
->multicast_ctx
, val
);
1477 if (data
[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
]) {
1478 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
]);
1480 br
->multicast_ctx
.multicast_query_response_interval
= clock_t_to_jiffies(val
);
1483 if (data
[IFLA_BR_MCAST_STARTUP_QUERY_INTVL
]) {
1484 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_STARTUP_QUERY_INTVL
]);
1486 br_multicast_set_startup_query_intvl(&br
->multicast_ctx
, val
);
1489 if (data
[IFLA_BR_MCAST_STATS_ENABLED
]) {
1492 mcast_stats
= nla_get_u8(data
[IFLA_BR_MCAST_STATS_ENABLED
]);
1493 br_opt_toggle(br
, BROPT_MULTICAST_STATS_ENABLED
, !!mcast_stats
);
1496 if (data
[IFLA_BR_MCAST_IGMP_VERSION
]) {
1499 igmp_version
= nla_get_u8(data
[IFLA_BR_MCAST_IGMP_VERSION
]);
1500 err
= br_multicast_set_igmp_version(&br
->multicast_ctx
,
1506 #if IS_ENABLED(CONFIG_IPV6)
1507 if (data
[IFLA_BR_MCAST_MLD_VERSION
]) {
1510 mld_version
= nla_get_u8(data
[IFLA_BR_MCAST_MLD_VERSION
]);
1511 err
= br_multicast_set_mld_version(&br
->multicast_ctx
,
1518 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1519 if (data
[IFLA_BR_NF_CALL_IPTABLES
]) {
1520 u8 val
= nla_get_u8(data
[IFLA_BR_NF_CALL_IPTABLES
]);
1522 br_opt_toggle(br
, BROPT_NF_CALL_IPTABLES
, !!val
);
1525 if (data
[IFLA_BR_NF_CALL_IP6TABLES
]) {
1526 u8 val
= nla_get_u8(data
[IFLA_BR_NF_CALL_IP6TABLES
]);
1528 br_opt_toggle(br
, BROPT_NF_CALL_IP6TABLES
, !!val
);
1531 if (data
[IFLA_BR_NF_CALL_ARPTABLES
]) {
1532 u8 val
= nla_get_u8(data
[IFLA_BR_NF_CALL_ARPTABLES
]);
1534 br_opt_toggle(br
, BROPT_NF_CALL_ARPTABLES
, !!val
);
1538 if (data
[IFLA_BR_MULTI_BOOLOPT
]) {
1539 struct br_boolopt_multi
*bm
;
1541 bm
= nla_data(data
[IFLA_BR_MULTI_BOOLOPT
]);
1542 err
= br_boolopt_multi_toggle(br
, bm
, extack
);
1547 if (data
[IFLA_BR_FDB_MAX_LEARNED
]) {
1548 u32 val
= nla_get_u32(data
[IFLA_BR_FDB_MAX_LEARNED
]);
1550 WRITE_ONCE(br
->fdb_max_learned
, val
);
1556 static int br_dev_newlink(struct net
*src_net
, struct net_device
*dev
,
1557 struct nlattr
*tb
[], struct nlattr
*data
[],
1558 struct netlink_ext_ack
*extack
)
1560 struct net_bridge
*br
= netdev_priv(dev
);
1563 err
= register_netdevice(dev
);
1567 if (tb
[IFLA_ADDRESS
]) {
1568 spin_lock_bh(&br
->lock
);
1569 br_stp_change_bridge_id(br
, nla_data(tb
[IFLA_ADDRESS
]));
1570 spin_unlock_bh(&br
->lock
);
1573 err
= br_changelink(dev
, tb
, data
, extack
);
1575 br_dev_delete(dev
, NULL
);
1580 static size_t br_get_size(const struct net_device
*brdev
)
1582 return nla_total_size(sizeof(u32
)) + /* IFLA_BR_FORWARD_DELAY */
1583 nla_total_size(sizeof(u32
)) + /* IFLA_BR_HELLO_TIME */
1584 nla_total_size(sizeof(u32
)) + /* IFLA_BR_MAX_AGE */
1585 nla_total_size(sizeof(u32
)) + /* IFLA_BR_AGEING_TIME */
1586 nla_total_size(sizeof(u32
)) + /* IFLA_BR_STP_STATE */
1587 nla_total_size(sizeof(u16
)) + /* IFLA_BR_PRIORITY */
1588 nla_total_size(sizeof(u8
)) + /* IFLA_BR_VLAN_FILTERING */
1589 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1590 nla_total_size(sizeof(__be16
)) + /* IFLA_BR_VLAN_PROTOCOL */
1591 nla_total_size(sizeof(u16
)) + /* IFLA_BR_VLAN_DEFAULT_PVID */
1592 nla_total_size(sizeof(u8
)) + /* IFLA_BR_VLAN_STATS_ENABLED */
1593 nla_total_size(sizeof(u8
)) + /* IFLA_BR_VLAN_STATS_PER_PORT */
1595 nla_total_size(sizeof(u16
)) + /* IFLA_BR_GROUP_FWD_MASK */
1596 nla_total_size(sizeof(struct ifla_bridge_id
)) + /* IFLA_BR_ROOT_ID */
1597 nla_total_size(sizeof(struct ifla_bridge_id
)) + /* IFLA_BR_BRIDGE_ID */
1598 nla_total_size(sizeof(u16
)) + /* IFLA_BR_ROOT_PORT */
1599 nla_total_size(sizeof(u32
)) + /* IFLA_BR_ROOT_PATH_COST */
1600 nla_total_size(sizeof(u8
)) + /* IFLA_BR_TOPOLOGY_CHANGE */
1601 nla_total_size(sizeof(u8
)) + /* IFLA_BR_TOPOLOGY_CHANGE_DETECTED */
1602 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_HELLO_TIMER */
1603 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_TCN_TIMER */
1604 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_TOPOLOGY_CHANGE_TIMER */
1605 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_GC_TIMER */
1606 nla_total_size(ETH_ALEN
) + /* IFLA_BR_GROUP_ADDR */
1607 nla_total_size(sizeof(u32
)) + /* IFLA_BR_FDB_N_LEARNED */
1608 nla_total_size(sizeof(u32
)) + /* IFLA_BR_FDB_MAX_LEARNED */
1609 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1610 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_ROUTER */
1611 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_SNOOPING */
1612 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_QUERY_USE_IFADDR */
1613 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_QUERIER */
1614 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_STATS_ENABLED */
1615 nla_total_size(sizeof(u32
)) + /* IFLA_BR_MCAST_HASH_ELASTICITY */
1616 nla_total_size(sizeof(u32
)) + /* IFLA_BR_MCAST_HASH_MAX */
1617 nla_total_size(sizeof(u32
)) + /* IFLA_BR_MCAST_LAST_MEMBER_CNT */
1618 nla_total_size(sizeof(u32
)) + /* IFLA_BR_MCAST_STARTUP_QUERY_CNT */
1619 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_LAST_MEMBER_INTVL */
1620 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_MEMBERSHIP_INTVL */
1621 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_QUERIER_INTVL */
1622 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_QUERY_INTVL */
1623 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_QUERY_RESPONSE_INTVL */
1624 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_STARTUP_QUERY_INTVL */
1625 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_IGMP_VERSION */
1626 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_MLD_VERSION */
1627 br_multicast_querier_state_size() + /* IFLA_BR_MCAST_QUERIER_STATE */
1629 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1630 nla_total_size(sizeof(u8
)) + /* IFLA_BR_NF_CALL_IPTABLES */
1631 nla_total_size(sizeof(u8
)) + /* IFLA_BR_NF_CALL_IP6TABLES */
1632 nla_total_size(sizeof(u8
)) + /* IFLA_BR_NF_CALL_ARPTABLES */
1634 nla_total_size(sizeof(struct br_boolopt_multi
)) + /* IFLA_BR_MULTI_BOOLOPT */
1638 static int br_fill_info(struct sk_buff
*skb
, const struct net_device
*brdev
)
1640 struct net_bridge
*br
= netdev_priv(brdev
);
1641 u32 forward_delay
= jiffies_to_clock_t(br
->forward_delay
);
1642 u32 hello_time
= jiffies_to_clock_t(br
->hello_time
);
1643 u32 age_time
= jiffies_to_clock_t(br
->max_age
);
1644 u32 ageing_time
= jiffies_to_clock_t(br
->ageing_time
);
1645 u32 stp_enabled
= br
->stp_enabled
;
1646 u16 priority
= (br
->bridge_id
.prio
[0] << 8) | br
->bridge_id
.prio
[1];
1647 u8 vlan_enabled
= br_vlan_enabled(br
->dev
);
1648 struct br_boolopt_multi bm
;
1651 clockval
= br_timer_value(&br
->hello_timer
);
1652 if (nla_put_u64_64bit(skb
, IFLA_BR_HELLO_TIMER
, clockval
, IFLA_BR_PAD
))
1654 clockval
= br_timer_value(&br
->tcn_timer
);
1655 if (nla_put_u64_64bit(skb
, IFLA_BR_TCN_TIMER
, clockval
, IFLA_BR_PAD
))
1657 clockval
= br_timer_value(&br
->topology_change_timer
);
1658 if (nla_put_u64_64bit(skb
, IFLA_BR_TOPOLOGY_CHANGE_TIMER
, clockval
,
1661 clockval
= br_timer_value(&br
->gc_work
.timer
);
1662 if (nla_put_u64_64bit(skb
, IFLA_BR_GC_TIMER
, clockval
, IFLA_BR_PAD
))
1665 br_boolopt_multi_get(br
, &bm
);
1666 if (nla_put_u32(skb
, IFLA_BR_FORWARD_DELAY
, forward_delay
) ||
1667 nla_put_u32(skb
, IFLA_BR_HELLO_TIME
, hello_time
) ||
1668 nla_put_u32(skb
, IFLA_BR_MAX_AGE
, age_time
) ||
1669 nla_put_u32(skb
, IFLA_BR_AGEING_TIME
, ageing_time
) ||
1670 nla_put_u32(skb
, IFLA_BR_STP_STATE
, stp_enabled
) ||
1671 nla_put_u16(skb
, IFLA_BR_PRIORITY
, priority
) ||
1672 nla_put_u8(skb
, IFLA_BR_VLAN_FILTERING
, vlan_enabled
) ||
1673 nla_put_u16(skb
, IFLA_BR_GROUP_FWD_MASK
, br
->group_fwd_mask
) ||
1674 nla_put(skb
, IFLA_BR_BRIDGE_ID
, sizeof(struct ifla_bridge_id
),
1676 nla_put(skb
, IFLA_BR_ROOT_ID
, sizeof(struct ifla_bridge_id
),
1677 &br
->designated_root
) ||
1678 nla_put_u16(skb
, IFLA_BR_ROOT_PORT
, br
->root_port
) ||
1679 nla_put_u32(skb
, IFLA_BR_ROOT_PATH_COST
, br
->root_path_cost
) ||
1680 nla_put_u8(skb
, IFLA_BR_TOPOLOGY_CHANGE
, br
->topology_change
) ||
1681 nla_put_u8(skb
, IFLA_BR_TOPOLOGY_CHANGE_DETECTED
,
1682 br
->topology_change_detected
) ||
1683 nla_put(skb
, IFLA_BR_GROUP_ADDR
, ETH_ALEN
, br
->group_addr
) ||
1684 nla_put(skb
, IFLA_BR_MULTI_BOOLOPT
, sizeof(bm
), &bm
) ||
1685 nla_put_u32(skb
, IFLA_BR_FDB_N_LEARNED
,
1686 atomic_read(&br
->fdb_n_learned
)) ||
1687 nla_put_u32(skb
, IFLA_BR_FDB_MAX_LEARNED
, br
->fdb_max_learned
))
1690 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1691 if (nla_put_be16(skb
, IFLA_BR_VLAN_PROTOCOL
, br
->vlan_proto
) ||
1692 nla_put_u16(skb
, IFLA_BR_VLAN_DEFAULT_PVID
, br
->default_pvid
) ||
1693 nla_put_u8(skb
, IFLA_BR_VLAN_STATS_ENABLED
,
1694 br_opt_get(br
, BROPT_VLAN_STATS_ENABLED
)) ||
1695 nla_put_u8(skb
, IFLA_BR_VLAN_STATS_PER_PORT
,
1696 br_opt_get(br
, BROPT_VLAN_STATS_PER_PORT
)))
1699 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1700 if (nla_put_u8(skb
, IFLA_BR_MCAST_ROUTER
,
1701 br
->multicast_ctx
.multicast_router
) ||
1702 nla_put_u8(skb
, IFLA_BR_MCAST_SNOOPING
,
1703 br_opt_get(br
, BROPT_MULTICAST_ENABLED
)) ||
1704 nla_put_u8(skb
, IFLA_BR_MCAST_QUERY_USE_IFADDR
,
1705 br_opt_get(br
, BROPT_MULTICAST_QUERY_USE_IFADDR
)) ||
1706 nla_put_u8(skb
, IFLA_BR_MCAST_QUERIER
,
1707 br
->multicast_ctx
.multicast_querier
) ||
1708 nla_put_u8(skb
, IFLA_BR_MCAST_STATS_ENABLED
,
1709 br_opt_get(br
, BROPT_MULTICAST_STATS_ENABLED
)) ||
1710 nla_put_u32(skb
, IFLA_BR_MCAST_HASH_ELASTICITY
, RHT_ELASTICITY
) ||
1711 nla_put_u32(skb
, IFLA_BR_MCAST_HASH_MAX
, br
->hash_max
) ||
1712 nla_put_u32(skb
, IFLA_BR_MCAST_LAST_MEMBER_CNT
,
1713 br
->multicast_ctx
.multicast_last_member_count
) ||
1714 nla_put_u32(skb
, IFLA_BR_MCAST_STARTUP_QUERY_CNT
,
1715 br
->multicast_ctx
.multicast_startup_query_count
) ||
1716 nla_put_u8(skb
, IFLA_BR_MCAST_IGMP_VERSION
,
1717 br
->multicast_ctx
.multicast_igmp_version
) ||
1718 br_multicast_dump_querier_state(skb
, &br
->multicast_ctx
,
1719 IFLA_BR_MCAST_QUERIER_STATE
))
1721 #if IS_ENABLED(CONFIG_IPV6)
1722 if (nla_put_u8(skb
, IFLA_BR_MCAST_MLD_VERSION
,
1723 br
->multicast_ctx
.multicast_mld_version
))
1726 clockval
= jiffies_to_clock_t(br
->multicast_ctx
.multicast_last_member_interval
);
1727 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_LAST_MEMBER_INTVL
, clockval
,
1730 clockval
= jiffies_to_clock_t(br
->multicast_ctx
.multicast_membership_interval
);
1731 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_MEMBERSHIP_INTVL
, clockval
,
1734 clockval
= jiffies_to_clock_t(br
->multicast_ctx
.multicast_querier_interval
);
1735 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_QUERIER_INTVL
, clockval
,
1738 clockval
= jiffies_to_clock_t(br
->multicast_ctx
.multicast_query_interval
);
1739 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_QUERY_INTVL
, clockval
,
1742 clockval
= jiffies_to_clock_t(br
->multicast_ctx
.multicast_query_response_interval
);
1743 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
, clockval
,
1746 clockval
= jiffies_to_clock_t(br
->multicast_ctx
.multicast_startup_query_interval
);
1747 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_STARTUP_QUERY_INTVL
, clockval
,
1751 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1752 if (nla_put_u8(skb
, IFLA_BR_NF_CALL_IPTABLES
,
1753 br_opt_get(br
, BROPT_NF_CALL_IPTABLES
) ? 1 : 0) ||
1754 nla_put_u8(skb
, IFLA_BR_NF_CALL_IP6TABLES
,
1755 br_opt_get(br
, BROPT_NF_CALL_IP6TABLES
) ? 1 : 0) ||
1756 nla_put_u8(skb
, IFLA_BR_NF_CALL_ARPTABLES
,
1757 br_opt_get(br
, BROPT_NF_CALL_ARPTABLES
) ? 1 : 0))
1764 static size_t br_get_linkxstats_size(const struct net_device
*dev
, int attr
)
1766 struct net_bridge_port
*p
= NULL
;
1767 struct net_bridge_vlan_group
*vg
;
1768 struct net_bridge_vlan
*v
;
1769 struct net_bridge
*br
;
1773 case IFLA_STATS_LINK_XSTATS
:
1774 br
= netdev_priv(dev
);
1775 vg
= br_vlan_group(br
);
1777 case IFLA_STATS_LINK_XSTATS_SLAVE
:
1778 p
= br_port_get_rtnl(dev
);
1781 vg
= nbp_vlan_group(p
);
1788 /* we need to count all, even placeholder entries */
1789 list_for_each_entry(v
, &vg
->vlan_list
, vlist
)
1793 return numvls
* nla_total_size(sizeof(struct bridge_vlan_xstats
)) +
1794 nla_total_size_64bit(sizeof(struct br_mcast_stats
)) +
1795 (p
? nla_total_size_64bit(sizeof(p
->stp_xstats
)) : 0) +
1799 static int br_fill_linkxstats(struct sk_buff
*skb
,
1800 const struct net_device
*dev
,
1801 int *prividx
, int attr
)
1803 struct nlattr
*nla __maybe_unused
;
1804 struct net_bridge_port
*p
= NULL
;
1805 struct net_bridge_vlan_group
*vg
;
1806 struct net_bridge_vlan
*v
;
1807 struct net_bridge
*br
;
1808 struct nlattr
*nest
;
1812 case IFLA_STATS_LINK_XSTATS
:
1813 br
= netdev_priv(dev
);
1814 vg
= br_vlan_group(br
);
1816 case IFLA_STATS_LINK_XSTATS_SLAVE
:
1817 p
= br_port_get_rtnl(dev
);
1821 vg
= nbp_vlan_group(p
);
1827 nest
= nla_nest_start_noflag(skb
, LINK_XSTATS_TYPE_BRIDGE
);
1834 pvid
= br_get_pvid(vg
);
1835 list_for_each_entry(v
, &vg
->vlan_list
, vlist
) {
1836 struct bridge_vlan_xstats vxi
;
1837 struct pcpu_sw_netstats stats
;
1839 if (++vl_idx
< *prividx
)
1841 memset(&vxi
, 0, sizeof(vxi
));
1843 vxi
.flags
= v
->flags
;
1845 vxi
.flags
|= BRIDGE_VLAN_INFO_PVID
;
1846 br_vlan_get_stats(v
, &stats
);
1847 vxi
.rx_bytes
= u64_stats_read(&stats
.rx_bytes
);
1848 vxi
.rx_packets
= u64_stats_read(&stats
.rx_packets
);
1849 vxi
.tx_bytes
= u64_stats_read(&stats
.tx_bytes
);
1850 vxi
.tx_packets
= u64_stats_read(&stats
.tx_packets
);
1852 if (nla_put(skb
, BRIDGE_XSTATS_VLAN
, sizeof(vxi
), &vxi
))
1853 goto nla_put_failure
;
1857 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1858 if (++vl_idx
>= *prividx
) {
1859 nla
= nla_reserve_64bit(skb
, BRIDGE_XSTATS_MCAST
,
1860 sizeof(struct br_mcast_stats
),
1863 goto nla_put_failure
;
1864 br_multicast_get_stats(br
, p
, nla_data(nla
));
1869 nla
= nla_reserve_64bit(skb
, BRIDGE_XSTATS_STP
,
1870 sizeof(p
->stp_xstats
),
1873 goto nla_put_failure
;
1875 spin_lock_bh(&br
->lock
);
1876 memcpy(nla_data(nla
), &p
->stp_xstats
, sizeof(p
->stp_xstats
));
1877 spin_unlock_bh(&br
->lock
);
1880 nla_nest_end(skb
, nest
);
1886 nla_nest_end(skb
, nest
);
1892 static struct rtnl_af_ops br_af_ops __read_mostly
= {
1893 .family
= AF_BRIDGE
,
1894 .get_link_af_size
= br_get_link_af_size_filtered
,
1897 struct rtnl_link_ops br_link_ops __read_mostly
= {
1899 .priv_size
= sizeof(struct net_bridge
),
1900 .setup
= br_dev_setup
,
1901 .maxtype
= IFLA_BR_MAX
,
1902 .policy
= br_policy
,
1903 .validate
= br_validate
,
1904 .newlink
= br_dev_newlink
,
1905 .changelink
= br_changelink
,
1906 .dellink
= br_dev_delete
,
1907 .get_size
= br_get_size
,
1908 .fill_info
= br_fill_info
,
1909 .fill_linkxstats
= br_fill_linkxstats
,
1910 .get_linkxstats_size
= br_get_linkxstats_size
,
1912 .slave_maxtype
= IFLA_BRPORT_MAX
,
1913 .slave_policy
= br_port_policy
,
1914 .slave_changelink
= br_port_slave_changelink
,
1915 .get_slave_size
= br_port_get_slave_size
,
1916 .fill_slave_info
= br_port_fill_slave_info
,
1919 int __init
br_netlink_init(void)
1923 err
= br_vlan_rtnl_init();
1927 err
= rtnl_af_register(&br_af_ops
);
1931 err
= rtnl_link_register(&br_link_ops
);
1938 rtnl_af_unregister(&br_af_ops
);
1940 br_vlan_rtnl_uninit();
1945 void br_netlink_fini(void)
1947 br_vlan_rtnl_uninit();
1948 rtnl_af_unregister(&br_af_ops
);
1949 rtnl_link_unregister(&br_link_ops
);