2 * Bridge netlink control interface
5 * Stephen Hemminger <shemminger@osdl.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/etherdevice.h>
16 #include <net/rtnetlink.h>
17 #include <net/net_namespace.h>
19 #include <uapi/linux/if_bridge.h>
21 #include "br_private.h"
22 #include "br_private_stp.h"
23 #include "br_private_tunnel.h"
25 static int __get_num_vlan_infos(struct net_bridge_vlan_group
*vg
,
28 struct net_bridge_vlan
*v
;
29 u16 vid_range_start
= 0, vid_range_end
= 0, vid_range_flags
= 0;
33 if (!(filter_mask
& RTEXT_FILTER_BRVLAN_COMPRESSED
))
36 pvid
= br_get_pvid(vg
);
37 /* Count number of vlan infos */
38 list_for_each_entry_rcu(v
, &vg
->vlan_list
, vlist
) {
40 /* only a context, bridge vlan not activated */
41 if (!br_vlan_should_use(v
))
44 flags
|= BRIDGE_VLAN_INFO_PVID
;
46 if (v
->flags
& BRIDGE_VLAN_INFO_UNTAGGED
)
47 flags
|= BRIDGE_VLAN_INFO_UNTAGGED
;
49 if (vid_range_start
== 0) {
51 } else if ((v
->vid
- vid_range_end
) == 1 &&
52 flags
== vid_range_flags
) {
53 vid_range_end
= v
->vid
;
56 if ((vid_range_end
- vid_range_start
) > 0)
62 vid_range_start
= v
->vid
;
63 vid_range_end
= v
->vid
;
64 vid_range_flags
= flags
;
67 if (vid_range_start
!= 0) {
68 if ((vid_range_end
- vid_range_start
) > 0)
77 static int br_get_num_vlan_infos(struct net_bridge_vlan_group
*vg
,
85 if (filter_mask
& RTEXT_FILTER_BRVLAN
)
89 num_vlans
= __get_num_vlan_infos(vg
, filter_mask
);
95 static size_t br_get_link_af_size_filtered(const struct net_device
*dev
,
98 struct net_bridge_vlan_group
*vg
= NULL
;
99 struct net_bridge_port
*p
= NULL
;
100 struct net_bridge
*br
;
105 if (br_port_exists(dev
)) {
106 p
= br_port_get_rcu(dev
);
107 vg
= nbp_vlan_group_rcu(p
);
108 } else if (dev
->priv_flags
& IFF_EBRIDGE
) {
109 br
= netdev_priv(dev
);
110 vg
= br_vlan_group_rcu(br
);
112 num_vlan_infos
= br_get_num_vlan_infos(vg
, filter_mask
);
115 if (p
&& (p
->flags
& BR_VLAN_TUNNEL
))
116 vinfo_sz
+= br_get_vlan_tunnel_info_size(vg
);
118 /* Each VLAN is returned in bridge_vlan_info along with flags */
119 vinfo_sz
+= num_vlan_infos
* nla_total_size(sizeof(struct bridge_vlan_info
));
124 static inline size_t br_port_info_size(void)
126 return nla_total_size(1) /* IFLA_BRPORT_STATE */
127 + nla_total_size(2) /* IFLA_BRPORT_PRIORITY */
128 + nla_total_size(4) /* IFLA_BRPORT_COST */
129 + nla_total_size(1) /* IFLA_BRPORT_MODE */
130 + nla_total_size(1) /* IFLA_BRPORT_GUARD */
131 + nla_total_size(1) /* IFLA_BRPORT_PROTECT */
132 + nla_total_size(1) /* IFLA_BRPORT_FAST_LEAVE */
133 + nla_total_size(1) /* IFLA_BRPORT_MCAST_TO_UCAST */
134 + nla_total_size(1) /* IFLA_BRPORT_LEARNING */
135 + nla_total_size(1) /* IFLA_BRPORT_UNICAST_FLOOD */
136 + nla_total_size(1) /* IFLA_BRPORT_PROXYARP */
137 + nla_total_size(1) /* IFLA_BRPORT_PROXYARP_WIFI */
138 + nla_total_size(1) /* IFLA_BRPORT_VLAN_TUNNEL */
139 + nla_total_size(sizeof(struct ifla_bridge_id
)) /* IFLA_BRPORT_ROOT_ID */
140 + nla_total_size(sizeof(struct ifla_bridge_id
)) /* IFLA_BRPORT_BRIDGE_ID */
141 + nla_total_size(sizeof(u16
)) /* IFLA_BRPORT_DESIGNATED_PORT */
142 + nla_total_size(sizeof(u16
)) /* IFLA_BRPORT_DESIGNATED_COST */
143 + nla_total_size(sizeof(u16
)) /* IFLA_BRPORT_ID */
144 + nla_total_size(sizeof(u16
)) /* IFLA_BRPORT_NO */
145 + nla_total_size(sizeof(u8
)) /* IFLA_BRPORT_TOPOLOGY_CHANGE_ACK */
146 + nla_total_size(sizeof(u8
)) /* IFLA_BRPORT_CONFIG_PENDING */
147 + nla_total_size_64bit(sizeof(u64
)) /* IFLA_BRPORT_MESSAGE_AGE_TIMER */
148 + nla_total_size_64bit(sizeof(u64
)) /* IFLA_BRPORT_FORWARD_DELAY_TIMER */
149 + nla_total_size_64bit(sizeof(u64
)) /* IFLA_BRPORT_HOLD_TIMER */
150 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
151 + nla_total_size(sizeof(u8
)) /* IFLA_BRPORT_MULTICAST_ROUTER */
156 static inline size_t br_nlmsg_size(struct net_device
*dev
, u32 filter_mask
)
158 return NLMSG_ALIGN(sizeof(struct ifinfomsg
))
159 + nla_total_size(IFNAMSIZ
) /* IFLA_IFNAME */
160 + nla_total_size(MAX_ADDR_LEN
) /* IFLA_ADDRESS */
161 + nla_total_size(4) /* IFLA_MASTER */
162 + nla_total_size(4) /* IFLA_MTU */
163 + nla_total_size(4) /* IFLA_LINK */
164 + nla_total_size(1) /* IFLA_OPERSTATE */
165 + nla_total_size(br_port_info_size()) /* IFLA_PROTINFO */
166 + nla_total_size(br_get_link_af_size_filtered(dev
,
167 filter_mask
)); /* IFLA_AF_SPEC */
170 static int br_port_fill_attrs(struct sk_buff
*skb
,
171 const struct net_bridge_port
*p
)
173 u8 mode
= !!(p
->flags
& BR_HAIRPIN_MODE
);
176 if (nla_put_u8(skb
, IFLA_BRPORT_STATE
, p
->state
) ||
177 nla_put_u16(skb
, IFLA_BRPORT_PRIORITY
, p
->priority
) ||
178 nla_put_u32(skb
, IFLA_BRPORT_COST
, p
->path_cost
) ||
179 nla_put_u8(skb
, IFLA_BRPORT_MODE
, mode
) ||
180 nla_put_u8(skb
, IFLA_BRPORT_GUARD
, !!(p
->flags
& BR_BPDU_GUARD
)) ||
181 nla_put_u8(skb
, IFLA_BRPORT_PROTECT
,
182 !!(p
->flags
& BR_ROOT_BLOCK
)) ||
183 nla_put_u8(skb
, IFLA_BRPORT_FAST_LEAVE
,
184 !!(p
->flags
& BR_MULTICAST_FAST_LEAVE
)) ||
185 nla_put_u8(skb
, IFLA_BRPORT_MCAST_TO_UCAST
,
186 !!(p
->flags
& BR_MULTICAST_TO_UNICAST
)) ||
187 nla_put_u8(skb
, IFLA_BRPORT_LEARNING
, !!(p
->flags
& BR_LEARNING
)) ||
188 nla_put_u8(skb
, IFLA_BRPORT_UNICAST_FLOOD
,
189 !!(p
->flags
& BR_FLOOD
)) ||
190 nla_put_u8(skb
, IFLA_BRPORT_MCAST_FLOOD
,
191 !!(p
->flags
& BR_MCAST_FLOOD
)) ||
192 nla_put_u8(skb
, IFLA_BRPORT_PROXYARP
, !!(p
->flags
& BR_PROXYARP
)) ||
193 nla_put_u8(skb
, IFLA_BRPORT_PROXYARP_WIFI
,
194 !!(p
->flags
& BR_PROXYARP_WIFI
)) ||
195 nla_put(skb
, IFLA_BRPORT_ROOT_ID
, sizeof(struct ifla_bridge_id
),
196 &p
->designated_root
) ||
197 nla_put(skb
, IFLA_BRPORT_BRIDGE_ID
, sizeof(struct ifla_bridge_id
),
198 &p
->designated_bridge
) ||
199 nla_put_u16(skb
, IFLA_BRPORT_DESIGNATED_PORT
, p
->designated_port
) ||
200 nla_put_u16(skb
, IFLA_BRPORT_DESIGNATED_COST
, p
->designated_cost
) ||
201 nla_put_u16(skb
, IFLA_BRPORT_ID
, p
->port_id
) ||
202 nla_put_u16(skb
, IFLA_BRPORT_NO
, p
->port_no
) ||
203 nla_put_u8(skb
, IFLA_BRPORT_TOPOLOGY_CHANGE_ACK
,
204 p
->topology_change_ack
) ||
205 nla_put_u8(skb
, IFLA_BRPORT_CONFIG_PENDING
, p
->config_pending
) ||
206 nla_put_u8(skb
, IFLA_BRPORT_VLAN_TUNNEL
, !!(p
->flags
&
210 timerval
= br_timer_value(&p
->message_age_timer
);
211 if (nla_put_u64_64bit(skb
, IFLA_BRPORT_MESSAGE_AGE_TIMER
, timerval
,
214 timerval
= br_timer_value(&p
->forward_delay_timer
);
215 if (nla_put_u64_64bit(skb
, IFLA_BRPORT_FORWARD_DELAY_TIMER
, timerval
,
218 timerval
= br_timer_value(&p
->hold_timer
);
219 if (nla_put_u64_64bit(skb
, IFLA_BRPORT_HOLD_TIMER
, timerval
,
223 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
224 if (nla_put_u8(skb
, IFLA_BRPORT_MULTICAST_ROUTER
,
225 p
->multicast_router
))
232 static int br_fill_ifvlaninfo_range(struct sk_buff
*skb
, u16 vid_start
,
233 u16 vid_end
, u16 flags
)
235 struct bridge_vlan_info vinfo
;
237 if ((vid_end
- vid_start
) > 0) {
238 /* add range to skb */
239 vinfo
.vid
= vid_start
;
240 vinfo
.flags
= flags
| BRIDGE_VLAN_INFO_RANGE_BEGIN
;
241 if (nla_put(skb
, IFLA_BRIDGE_VLAN_INFO
,
242 sizeof(vinfo
), &vinfo
))
243 goto nla_put_failure
;
246 vinfo
.flags
= flags
| BRIDGE_VLAN_INFO_RANGE_END
;
247 if (nla_put(skb
, IFLA_BRIDGE_VLAN_INFO
,
248 sizeof(vinfo
), &vinfo
))
249 goto nla_put_failure
;
251 vinfo
.vid
= vid_start
;
253 if (nla_put(skb
, IFLA_BRIDGE_VLAN_INFO
,
254 sizeof(vinfo
), &vinfo
))
255 goto nla_put_failure
;
264 static int br_fill_ifvlaninfo_compressed(struct sk_buff
*skb
,
265 struct net_bridge_vlan_group
*vg
)
267 struct net_bridge_vlan
*v
;
268 u16 vid_range_start
= 0, vid_range_end
= 0, vid_range_flags
= 0;
272 /* Pack IFLA_BRIDGE_VLAN_INFO's for every vlan
273 * and mark vlan info with begin and end flags
274 * if vlaninfo represents a range
276 pvid
= br_get_pvid(vg
);
277 list_for_each_entry_rcu(v
, &vg
->vlan_list
, vlist
) {
279 if (!br_vlan_should_use(v
))
282 flags
|= BRIDGE_VLAN_INFO_PVID
;
284 if (v
->flags
& BRIDGE_VLAN_INFO_UNTAGGED
)
285 flags
|= BRIDGE_VLAN_INFO_UNTAGGED
;
287 if (vid_range_start
== 0) {
289 } else if ((v
->vid
- vid_range_end
) == 1 &&
290 flags
== vid_range_flags
) {
291 vid_range_end
= v
->vid
;
294 err
= br_fill_ifvlaninfo_range(skb
, vid_range_start
,
302 vid_range_start
= v
->vid
;
303 vid_range_end
= v
->vid
;
304 vid_range_flags
= flags
;
307 if (vid_range_start
!= 0) {
308 /* Call it once more to send any left over vlans */
309 err
= br_fill_ifvlaninfo_range(skb
, vid_range_start
,
319 static int br_fill_ifvlaninfo(struct sk_buff
*skb
,
320 struct net_bridge_vlan_group
*vg
)
322 struct bridge_vlan_info vinfo
;
323 struct net_bridge_vlan
*v
;
326 pvid
= br_get_pvid(vg
);
327 list_for_each_entry_rcu(v
, &vg
->vlan_list
, vlist
) {
328 if (!br_vlan_should_use(v
))
334 vinfo
.flags
|= BRIDGE_VLAN_INFO_PVID
;
336 if (v
->flags
& BRIDGE_VLAN_INFO_UNTAGGED
)
337 vinfo
.flags
|= BRIDGE_VLAN_INFO_UNTAGGED
;
339 if (nla_put(skb
, IFLA_BRIDGE_VLAN_INFO
,
340 sizeof(vinfo
), &vinfo
))
341 goto nla_put_failure
;
351 * Create one netlink message for one interface
352 * Contains port and master info as well as carrier and bridge state.
354 static int br_fill_ifinfo(struct sk_buff
*skb
,
355 struct net_bridge_port
*port
,
356 u32 pid
, u32 seq
, int event
, unsigned int flags
,
357 u32 filter_mask
, const struct net_device
*dev
)
359 struct net_bridge
*br
;
360 struct ifinfomsg
*hdr
;
361 struct nlmsghdr
*nlh
;
362 u8 operstate
= netif_running(dev
) ? dev
->operstate
: IF_OPER_DOWN
;
367 br
= netdev_priv(dev
);
369 br_debug(br
, "br_fill_info event %d port %s master %s\n",
370 event
, dev
->name
, br
->dev
->name
);
372 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(*hdr
), flags
);
376 hdr
= nlmsg_data(nlh
);
377 hdr
->ifi_family
= AF_BRIDGE
;
379 hdr
->ifi_type
= dev
->type
;
380 hdr
->ifi_index
= dev
->ifindex
;
381 hdr
->ifi_flags
= dev_get_flags(dev
);
384 if (nla_put_string(skb
, IFLA_IFNAME
, dev
->name
) ||
385 nla_put_u32(skb
, IFLA_MASTER
, br
->dev
->ifindex
) ||
386 nla_put_u32(skb
, IFLA_MTU
, dev
->mtu
) ||
387 nla_put_u8(skb
, IFLA_OPERSTATE
, operstate
) ||
389 nla_put(skb
, IFLA_ADDRESS
, dev
->addr_len
, dev
->dev_addr
)) ||
390 (dev
->ifindex
!= dev_get_iflink(dev
) &&
391 nla_put_u32(skb
, IFLA_LINK
, dev_get_iflink(dev
))))
392 goto nla_put_failure
;
394 if (event
== RTM_NEWLINK
&& port
) {
396 = nla_nest_start(skb
, IFLA_PROTINFO
| NLA_F_NESTED
);
398 if (nest
== NULL
|| br_port_fill_attrs(skb
, port
) < 0)
399 goto nla_put_failure
;
400 nla_nest_end(skb
, nest
);
403 /* Check if the VID information is requested */
404 if ((filter_mask
& RTEXT_FILTER_BRVLAN
) ||
405 (filter_mask
& RTEXT_FILTER_BRVLAN_COMPRESSED
)) {
406 struct net_bridge_vlan_group
*vg
;
410 /* RCU needed because of the VLAN locking rules (rcu || rtnl) */
413 vg
= nbp_vlan_group_rcu(port
);
415 vg
= br_vlan_group_rcu(br
);
417 if (!vg
|| !vg
->num_vlans
) {
421 af
= nla_nest_start(skb
, IFLA_AF_SPEC
);
424 goto nla_put_failure
;
426 if (filter_mask
& RTEXT_FILTER_BRVLAN_COMPRESSED
)
427 err
= br_fill_ifvlaninfo_compressed(skb
, vg
);
429 err
= br_fill_ifvlaninfo(skb
, vg
);
431 if (port
&& (port
->flags
& BR_VLAN_TUNNEL
))
432 err
= br_fill_vlan_tunnel_info(skb
, vg
);
435 goto nla_put_failure
;
436 nla_nest_end(skb
, af
);
444 nlmsg_cancel(skb
, nlh
);
449 * Notify listeners of a change in port information
451 void br_ifinfo_notify(int event
, struct net_bridge_port
*port
)
456 u32 filter
= RTEXT_FILTER_BRVLAN_COMPRESSED
;
461 net
= dev_net(port
->dev
);
462 br_debug(port
->br
, "port %u(%s) event %d\n",
463 (unsigned int)port
->port_no
, port
->dev
->name
, event
);
465 skb
= nlmsg_new(br_nlmsg_size(port
->dev
, filter
), GFP_ATOMIC
);
469 err
= br_fill_ifinfo(skb
, port
, 0, 0, event
, 0, filter
, port
->dev
);
471 /* -EMSGSIZE implies BUG in br_nlmsg_size() */
472 WARN_ON(err
== -EMSGSIZE
);
476 rtnl_notify(skb
, net
, 0, RTNLGRP_LINK
, NULL
, GFP_ATOMIC
);
479 rtnl_set_sk_err(net
, RTNLGRP_LINK
, err
);
484 * Dump information about all ports, in response to GETLINK
486 int br_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
487 struct net_device
*dev
, u32 filter_mask
, int nlflags
)
489 struct net_bridge_port
*port
= br_port_get_rtnl(dev
);
491 if (!port
&& !(filter_mask
& RTEXT_FILTER_BRVLAN
) &&
492 !(filter_mask
& RTEXT_FILTER_BRVLAN_COMPRESSED
))
495 return br_fill_ifinfo(skb
, port
, pid
, seq
, RTM_NEWLINK
, nlflags
,
499 static int br_vlan_info(struct net_bridge
*br
, struct net_bridge_port
*p
,
500 int cmd
, struct bridge_vlan_info
*vinfo
)
507 /* if the MASTER flag is set this will act on the global
508 * per-VLAN entry as well
510 err
= nbp_vlan_add(p
, vinfo
->vid
, vinfo
->flags
);
514 vinfo
->flags
|= BRIDGE_VLAN_INFO_BRENTRY
;
515 err
= br_vlan_add(br
, vinfo
->vid
, vinfo
->flags
);
521 nbp_vlan_delete(p
, vinfo
->vid
);
522 if (vinfo
->flags
& BRIDGE_VLAN_INFO_MASTER
)
523 br_vlan_delete(p
->br
, vinfo
->vid
);
525 br_vlan_delete(br
, vinfo
->vid
);
533 static int br_process_vlan_info(struct net_bridge
*br
,
534 struct net_bridge_port
*p
, int cmd
,
535 struct bridge_vlan_info
*vinfo_curr
,
536 struct bridge_vlan_info
**vinfo_last
)
538 if (!vinfo_curr
->vid
|| vinfo_curr
->vid
>= VLAN_VID_MASK
)
541 if (vinfo_curr
->flags
& BRIDGE_VLAN_INFO_RANGE_BEGIN
) {
542 /* check if we are already processing a range */
545 *vinfo_last
= vinfo_curr
;
546 /* don't allow range of pvids */
547 if ((*vinfo_last
)->flags
& BRIDGE_VLAN_INFO_PVID
)
553 struct bridge_vlan_info tmp_vinfo
;
556 if (!(vinfo_curr
->flags
& BRIDGE_VLAN_INFO_RANGE_END
))
559 if (vinfo_curr
->vid
<= (*vinfo_last
)->vid
)
562 memcpy(&tmp_vinfo
, *vinfo_last
,
563 sizeof(struct bridge_vlan_info
));
564 for (v
= (*vinfo_last
)->vid
; v
<= vinfo_curr
->vid
; v
++) {
566 err
= br_vlan_info(br
, p
, cmd
, &tmp_vinfo
);
575 return br_vlan_info(br
, p
, cmd
, vinfo_curr
);
578 static int br_afspec(struct net_bridge
*br
,
579 struct net_bridge_port
*p
,
580 struct nlattr
*af_spec
,
583 struct bridge_vlan_info
*vinfo_curr
= NULL
;
584 struct bridge_vlan_info
*vinfo_last
= NULL
;
586 struct vtunnel_info tinfo_last
= {};
587 struct vtunnel_info tinfo_curr
= {};
590 nla_for_each_nested(attr
, af_spec
, rem
) {
592 switch (nla_type(attr
)) {
593 case IFLA_BRIDGE_VLAN_TUNNEL_INFO
:
594 if (!(p
->flags
& BR_VLAN_TUNNEL
))
596 err
= br_parse_vlan_tunnel_info(attr
, &tinfo_curr
);
599 err
= br_process_vlan_tunnel_info(br
, p
, cmd
,
605 case IFLA_BRIDGE_VLAN_INFO
:
606 if (nla_len(attr
) != sizeof(struct bridge_vlan_info
))
608 vinfo_curr
= nla_data(attr
);
609 err
= br_process_vlan_info(br
, p
, cmd
, vinfo_curr
,
620 static const struct nla_policy br_port_policy
[IFLA_BRPORT_MAX
+ 1] = {
621 [IFLA_BRPORT_STATE
] = { .type
= NLA_U8
},
622 [IFLA_BRPORT_COST
] = { .type
= NLA_U32
},
623 [IFLA_BRPORT_PRIORITY
] = { .type
= NLA_U16
},
624 [IFLA_BRPORT_MODE
] = { .type
= NLA_U8
},
625 [IFLA_BRPORT_GUARD
] = { .type
= NLA_U8
},
626 [IFLA_BRPORT_PROTECT
] = { .type
= NLA_U8
},
627 [IFLA_BRPORT_FAST_LEAVE
]= { .type
= NLA_U8
},
628 [IFLA_BRPORT_LEARNING
] = { .type
= NLA_U8
},
629 [IFLA_BRPORT_UNICAST_FLOOD
] = { .type
= NLA_U8
},
630 [IFLA_BRPORT_PROXYARP
] = { .type
= NLA_U8
},
631 [IFLA_BRPORT_PROXYARP_WIFI
] = { .type
= NLA_U8
},
632 [IFLA_BRPORT_MULTICAST_ROUTER
] = { .type
= NLA_U8
},
633 [IFLA_BRPORT_MCAST_TO_UCAST
] = { .type
= NLA_U8
},
636 /* Change the state of the port and notify spanning tree */
637 static int br_set_port_state(struct net_bridge_port
*p
, u8 state
)
639 if (state
> BR_STATE_BLOCKING
)
642 /* if kernel STP is running, don't allow changes */
643 if (p
->br
->stp_enabled
== BR_KERNEL_STP
)
646 /* if device is not up, change is not allowed
647 * if link is not present, only allowable state is disabled
649 if (!netif_running(p
->dev
) ||
650 (!netif_oper_up(p
->dev
) && state
!= BR_STATE_DISABLED
))
653 br_set_state(p
, state
);
654 br_port_state_selection(p
->br
);
658 /* Set/clear or port flags based on attribute */
659 static void br_set_port_flag(struct net_bridge_port
*p
, struct nlattr
*tb
[],
660 int attrtype
, unsigned long mask
)
663 u8 flag
= nla_get_u8(tb
[attrtype
]);
671 /* Process bridge protocol info on port */
672 static int br_setport(struct net_bridge_port
*p
, struct nlattr
*tb
[])
674 unsigned long old_flags
= p
->flags
;
675 bool br_vlan_tunnel_old
= false;
678 br_set_port_flag(p
, tb
, IFLA_BRPORT_MODE
, BR_HAIRPIN_MODE
);
679 br_set_port_flag(p
, tb
, IFLA_BRPORT_GUARD
, BR_BPDU_GUARD
);
680 br_set_port_flag(p
, tb
, IFLA_BRPORT_FAST_LEAVE
, BR_MULTICAST_FAST_LEAVE
);
681 br_set_port_flag(p
, tb
, IFLA_BRPORT_PROTECT
, BR_ROOT_BLOCK
);
682 br_set_port_flag(p
, tb
, IFLA_BRPORT_LEARNING
, BR_LEARNING
);
683 br_set_port_flag(p
, tb
, IFLA_BRPORT_UNICAST_FLOOD
, BR_FLOOD
);
684 br_set_port_flag(p
, tb
, IFLA_BRPORT_MCAST_FLOOD
, BR_MCAST_FLOOD
);
685 br_set_port_flag(p
, tb
, IFLA_BRPORT_MCAST_TO_UCAST
, BR_MULTICAST_TO_UNICAST
);
686 br_set_port_flag(p
, tb
, IFLA_BRPORT_PROXYARP
, BR_PROXYARP
);
687 br_set_port_flag(p
, tb
, IFLA_BRPORT_PROXYARP_WIFI
, BR_PROXYARP_WIFI
);
689 br_vlan_tunnel_old
= (p
->flags
& BR_VLAN_TUNNEL
) ? true : false;
690 br_set_port_flag(p
, tb
, IFLA_BRPORT_VLAN_TUNNEL
, BR_VLAN_TUNNEL
);
691 if (br_vlan_tunnel_old
&& !(p
->flags
& BR_VLAN_TUNNEL
))
692 nbp_vlan_tunnel_info_flush(p
);
694 if (tb
[IFLA_BRPORT_COST
]) {
695 err
= br_stp_set_path_cost(p
, nla_get_u32(tb
[IFLA_BRPORT_COST
]));
700 if (tb
[IFLA_BRPORT_PRIORITY
]) {
701 err
= br_stp_set_port_priority(p
, nla_get_u16(tb
[IFLA_BRPORT_PRIORITY
]));
706 if (tb
[IFLA_BRPORT_STATE
]) {
707 err
= br_set_port_state(p
, nla_get_u8(tb
[IFLA_BRPORT_STATE
]));
712 if (tb
[IFLA_BRPORT_FLUSH
])
713 br_fdb_delete_by_port(p
->br
, p
, 0, 0);
715 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
716 if (tb
[IFLA_BRPORT_MULTICAST_ROUTER
]) {
717 u8 mcast_router
= nla_get_u8(tb
[IFLA_BRPORT_MULTICAST_ROUTER
]);
719 err
= br_multicast_set_port_router(p
, mcast_router
);
724 br_port_flags_change(p
, old_flags
^ p
->flags
);
728 /* Change state and parameters on port. */
729 int br_setlink(struct net_device
*dev
, struct nlmsghdr
*nlh
, u16 flags
)
731 struct nlattr
*protinfo
;
732 struct nlattr
*afspec
;
733 struct net_bridge_port
*p
;
734 struct nlattr
*tb
[IFLA_BRPORT_MAX
+ 1];
737 protinfo
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_PROTINFO
);
738 afspec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
739 if (!protinfo
&& !afspec
)
742 p
= br_port_get_rtnl(dev
);
743 /* We want to accept dev as bridge itself if the AF_SPEC
744 * is set to see if someone is setting vlan info on the bridge
750 if (protinfo
->nla_type
& NLA_F_NESTED
) {
751 err
= nla_parse_nested(tb
, IFLA_BRPORT_MAX
,
752 protinfo
, br_port_policy
);
756 spin_lock_bh(&p
->br
->lock
);
757 err
= br_setport(p
, tb
);
758 spin_unlock_bh(&p
->br
->lock
);
760 /* Binary compatibility with old RSTP */
761 if (nla_len(protinfo
) < sizeof(u8
))
764 spin_lock_bh(&p
->br
->lock
);
765 err
= br_set_port_state(p
, nla_get_u8(protinfo
));
766 spin_unlock_bh(&p
->br
->lock
);
773 err
= br_afspec((struct net_bridge
*)netdev_priv(dev
), p
,
774 afspec
, RTM_SETLINK
);
778 br_ifinfo_notify(RTM_NEWLINK
, p
);
783 /* Delete port information */
784 int br_dellink(struct net_device
*dev
, struct nlmsghdr
*nlh
, u16 flags
)
786 struct nlattr
*afspec
;
787 struct net_bridge_port
*p
;
790 afspec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
794 p
= br_port_get_rtnl(dev
);
795 /* We want to accept dev as bridge itself as well */
796 if (!p
&& !(dev
->priv_flags
& IFF_EBRIDGE
))
799 err
= br_afspec((struct net_bridge
*)netdev_priv(dev
), p
,
800 afspec
, RTM_DELLINK
);
802 /* Send RTM_NEWLINK because userspace
803 * expects RTM_NEWLINK for vlan dels
805 br_ifinfo_notify(RTM_NEWLINK
, p
);
809 static int br_validate(struct nlattr
*tb
[], struct nlattr
*data
[])
811 if (tb
[IFLA_ADDRESS
]) {
812 if (nla_len(tb
[IFLA_ADDRESS
]) != ETH_ALEN
)
814 if (!is_valid_ether_addr(nla_data(tb
[IFLA_ADDRESS
])))
815 return -EADDRNOTAVAIL
;
821 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
822 if (data
[IFLA_BR_VLAN_PROTOCOL
]) {
823 switch (nla_get_be16(data
[IFLA_BR_VLAN_PROTOCOL
])) {
824 case htons(ETH_P_8021Q
):
825 case htons(ETH_P_8021AD
):
828 return -EPROTONOSUPPORT
;
836 static int br_port_slave_changelink(struct net_device
*brdev
,
837 struct net_device
*dev
,
839 struct nlattr
*data
[])
841 struct net_bridge
*br
= netdev_priv(brdev
);
847 spin_lock_bh(&br
->lock
);
848 ret
= br_setport(br_port_get_rtnl(dev
), data
);
849 spin_unlock_bh(&br
->lock
);
854 static int br_port_fill_slave_info(struct sk_buff
*skb
,
855 const struct net_device
*brdev
,
856 const struct net_device
*dev
)
858 return br_port_fill_attrs(skb
, br_port_get_rtnl(dev
));
861 static size_t br_port_get_slave_size(const struct net_device
*brdev
,
862 const struct net_device
*dev
)
864 return br_port_info_size();
867 static const struct nla_policy br_policy
[IFLA_BR_MAX
+ 1] = {
868 [IFLA_BR_FORWARD_DELAY
] = { .type
= NLA_U32
},
869 [IFLA_BR_HELLO_TIME
] = { .type
= NLA_U32
},
870 [IFLA_BR_MAX_AGE
] = { .type
= NLA_U32
},
871 [IFLA_BR_AGEING_TIME
] = { .type
= NLA_U32
},
872 [IFLA_BR_STP_STATE
] = { .type
= NLA_U32
},
873 [IFLA_BR_PRIORITY
] = { .type
= NLA_U16
},
874 [IFLA_BR_VLAN_FILTERING
] = { .type
= NLA_U8
},
875 [IFLA_BR_VLAN_PROTOCOL
] = { .type
= NLA_U16
},
876 [IFLA_BR_GROUP_FWD_MASK
] = { .type
= NLA_U16
},
877 [IFLA_BR_GROUP_ADDR
] = { .type
= NLA_BINARY
,
879 [IFLA_BR_MCAST_ROUTER
] = { .type
= NLA_U8
},
880 [IFLA_BR_MCAST_SNOOPING
] = { .type
= NLA_U8
},
881 [IFLA_BR_MCAST_QUERY_USE_IFADDR
] = { .type
= NLA_U8
},
882 [IFLA_BR_MCAST_QUERIER
] = { .type
= NLA_U8
},
883 [IFLA_BR_MCAST_HASH_ELASTICITY
] = { .type
= NLA_U32
},
884 [IFLA_BR_MCAST_HASH_MAX
] = { .type
= NLA_U32
},
885 [IFLA_BR_MCAST_LAST_MEMBER_CNT
] = { .type
= NLA_U32
},
886 [IFLA_BR_MCAST_STARTUP_QUERY_CNT
] = { .type
= NLA_U32
},
887 [IFLA_BR_MCAST_LAST_MEMBER_INTVL
] = { .type
= NLA_U64
},
888 [IFLA_BR_MCAST_MEMBERSHIP_INTVL
] = { .type
= NLA_U64
},
889 [IFLA_BR_MCAST_QUERIER_INTVL
] = { .type
= NLA_U64
},
890 [IFLA_BR_MCAST_QUERY_INTVL
] = { .type
= NLA_U64
},
891 [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
] = { .type
= NLA_U64
},
892 [IFLA_BR_MCAST_STARTUP_QUERY_INTVL
] = { .type
= NLA_U64
},
893 [IFLA_BR_NF_CALL_IPTABLES
] = { .type
= NLA_U8
},
894 [IFLA_BR_NF_CALL_IP6TABLES
] = { .type
= NLA_U8
},
895 [IFLA_BR_NF_CALL_ARPTABLES
] = { .type
= NLA_U8
},
896 [IFLA_BR_VLAN_DEFAULT_PVID
] = { .type
= NLA_U16
},
897 [IFLA_BR_VLAN_STATS_ENABLED
] = { .type
= NLA_U8
},
898 [IFLA_BR_MCAST_STATS_ENABLED
] = { .type
= NLA_U8
},
899 [IFLA_BR_MCAST_IGMP_VERSION
] = { .type
= NLA_U8
},
900 [IFLA_BR_MCAST_MLD_VERSION
] = { .type
= NLA_U8
},
903 static int br_changelink(struct net_device
*brdev
, struct nlattr
*tb
[],
904 struct nlattr
*data
[])
906 struct net_bridge
*br
= netdev_priv(brdev
);
912 if (data
[IFLA_BR_FORWARD_DELAY
]) {
913 err
= br_set_forward_delay(br
, nla_get_u32(data
[IFLA_BR_FORWARD_DELAY
]));
918 if (data
[IFLA_BR_HELLO_TIME
]) {
919 err
= br_set_hello_time(br
, nla_get_u32(data
[IFLA_BR_HELLO_TIME
]));
924 if (data
[IFLA_BR_MAX_AGE
]) {
925 err
= br_set_max_age(br
, nla_get_u32(data
[IFLA_BR_MAX_AGE
]));
930 if (data
[IFLA_BR_AGEING_TIME
]) {
931 err
= br_set_ageing_time(br
, nla_get_u32(data
[IFLA_BR_AGEING_TIME
]));
936 if (data
[IFLA_BR_STP_STATE
]) {
937 u32 stp_enabled
= nla_get_u32(data
[IFLA_BR_STP_STATE
]);
939 br_stp_set_enabled(br
, stp_enabled
);
942 if (data
[IFLA_BR_PRIORITY
]) {
943 u32 priority
= nla_get_u16(data
[IFLA_BR_PRIORITY
]);
945 br_stp_set_bridge_priority(br
, priority
);
948 if (data
[IFLA_BR_VLAN_FILTERING
]) {
949 u8 vlan_filter
= nla_get_u8(data
[IFLA_BR_VLAN_FILTERING
]);
951 err
= __br_vlan_filter_toggle(br
, vlan_filter
);
956 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
957 if (data
[IFLA_BR_VLAN_PROTOCOL
]) {
958 __be16 vlan_proto
= nla_get_be16(data
[IFLA_BR_VLAN_PROTOCOL
]);
960 err
= __br_vlan_set_proto(br
, vlan_proto
);
965 if (data
[IFLA_BR_VLAN_DEFAULT_PVID
]) {
966 __u16 defpvid
= nla_get_u16(data
[IFLA_BR_VLAN_DEFAULT_PVID
]);
968 err
= __br_vlan_set_default_pvid(br
, defpvid
);
973 if (data
[IFLA_BR_VLAN_STATS_ENABLED
]) {
974 __u8 vlan_stats
= nla_get_u8(data
[IFLA_BR_VLAN_STATS_ENABLED
]);
976 err
= br_vlan_set_stats(br
, vlan_stats
);
982 if (data
[IFLA_BR_GROUP_FWD_MASK
]) {
983 u16 fwd_mask
= nla_get_u16(data
[IFLA_BR_GROUP_FWD_MASK
]);
985 if (fwd_mask
& BR_GROUPFWD_RESTRICTED
)
987 br
->group_fwd_mask
= fwd_mask
;
990 if (data
[IFLA_BR_GROUP_ADDR
]) {
991 u8 new_addr
[ETH_ALEN
];
993 if (nla_len(data
[IFLA_BR_GROUP_ADDR
]) != ETH_ALEN
)
995 memcpy(new_addr
, nla_data(data
[IFLA_BR_GROUP_ADDR
]), ETH_ALEN
);
996 if (!is_link_local_ether_addr(new_addr
))
998 if (new_addr
[5] == 1 || /* 802.3x Pause address */
999 new_addr
[5] == 2 || /* 802.3ad Slow protocols */
1000 new_addr
[5] == 3) /* 802.1X PAE address */
1002 spin_lock_bh(&br
->lock
);
1003 memcpy(br
->group_addr
, new_addr
, sizeof(br
->group_addr
));
1004 spin_unlock_bh(&br
->lock
);
1005 br
->group_addr_set
= true;
1006 br_recalculate_fwd_mask(br
);
1009 if (data
[IFLA_BR_FDB_FLUSH
])
1012 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1013 if (data
[IFLA_BR_MCAST_ROUTER
]) {
1014 u8 multicast_router
= nla_get_u8(data
[IFLA_BR_MCAST_ROUTER
]);
1016 err
= br_multicast_set_router(br
, multicast_router
);
1021 if (data
[IFLA_BR_MCAST_SNOOPING
]) {
1022 u8 mcast_snooping
= nla_get_u8(data
[IFLA_BR_MCAST_SNOOPING
]);
1024 err
= br_multicast_toggle(br
, mcast_snooping
);
1029 if (data
[IFLA_BR_MCAST_QUERY_USE_IFADDR
]) {
1032 val
= nla_get_u8(data
[IFLA_BR_MCAST_QUERY_USE_IFADDR
]);
1033 br
->multicast_query_use_ifaddr
= !!val
;
1036 if (data
[IFLA_BR_MCAST_QUERIER
]) {
1037 u8 mcast_querier
= nla_get_u8(data
[IFLA_BR_MCAST_QUERIER
]);
1039 err
= br_multicast_set_querier(br
, mcast_querier
);
1044 if (data
[IFLA_BR_MCAST_HASH_ELASTICITY
]) {
1045 u32 val
= nla_get_u32(data
[IFLA_BR_MCAST_HASH_ELASTICITY
]);
1047 br
->hash_elasticity
= val
;
1050 if (data
[IFLA_BR_MCAST_HASH_MAX
]) {
1051 u32 hash_max
= nla_get_u32(data
[IFLA_BR_MCAST_HASH_MAX
]);
1053 err
= br_multicast_set_hash_max(br
, hash_max
);
1058 if (data
[IFLA_BR_MCAST_LAST_MEMBER_CNT
]) {
1059 u32 val
= nla_get_u32(data
[IFLA_BR_MCAST_LAST_MEMBER_CNT
]);
1061 br
->multicast_last_member_count
= val
;
1064 if (data
[IFLA_BR_MCAST_STARTUP_QUERY_CNT
]) {
1065 u32 val
= nla_get_u32(data
[IFLA_BR_MCAST_STARTUP_QUERY_CNT
]);
1067 br
->multicast_startup_query_count
= val
;
1070 if (data
[IFLA_BR_MCAST_LAST_MEMBER_INTVL
]) {
1071 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_LAST_MEMBER_INTVL
]);
1073 br
->multicast_last_member_interval
= clock_t_to_jiffies(val
);
1076 if (data
[IFLA_BR_MCAST_MEMBERSHIP_INTVL
]) {
1077 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_MEMBERSHIP_INTVL
]);
1079 br
->multicast_membership_interval
= clock_t_to_jiffies(val
);
1082 if (data
[IFLA_BR_MCAST_QUERIER_INTVL
]) {
1083 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_QUERIER_INTVL
]);
1085 br
->multicast_querier_interval
= clock_t_to_jiffies(val
);
1088 if (data
[IFLA_BR_MCAST_QUERY_INTVL
]) {
1089 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_QUERY_INTVL
]);
1091 br
->multicast_query_interval
= clock_t_to_jiffies(val
);
1094 if (data
[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
]) {
1095 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
]);
1097 br
->multicast_query_response_interval
= clock_t_to_jiffies(val
);
1100 if (data
[IFLA_BR_MCAST_STARTUP_QUERY_INTVL
]) {
1101 u64 val
= nla_get_u64(data
[IFLA_BR_MCAST_STARTUP_QUERY_INTVL
]);
1103 br
->multicast_startup_query_interval
= clock_t_to_jiffies(val
);
1106 if (data
[IFLA_BR_MCAST_STATS_ENABLED
]) {
1109 mcast_stats
= nla_get_u8(data
[IFLA_BR_MCAST_STATS_ENABLED
]);
1110 br
->multicast_stats_enabled
= !!mcast_stats
;
1113 if (data
[IFLA_BR_MCAST_IGMP_VERSION
]) {
1116 igmp_version
= nla_get_u8(data
[IFLA_BR_MCAST_IGMP_VERSION
]);
1117 err
= br_multicast_set_igmp_version(br
, igmp_version
);
1122 #if IS_ENABLED(CONFIG_IPV6)
1123 if (data
[IFLA_BR_MCAST_MLD_VERSION
]) {
1126 mld_version
= nla_get_u8(data
[IFLA_BR_MCAST_MLD_VERSION
]);
1127 err
= br_multicast_set_mld_version(br
, mld_version
);
1133 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1134 if (data
[IFLA_BR_NF_CALL_IPTABLES
]) {
1135 u8 val
= nla_get_u8(data
[IFLA_BR_NF_CALL_IPTABLES
]);
1137 br
->nf_call_iptables
= val
? true : false;
1140 if (data
[IFLA_BR_NF_CALL_IP6TABLES
]) {
1141 u8 val
= nla_get_u8(data
[IFLA_BR_NF_CALL_IP6TABLES
]);
1143 br
->nf_call_ip6tables
= val
? true : false;
1146 if (data
[IFLA_BR_NF_CALL_ARPTABLES
]) {
1147 u8 val
= nla_get_u8(data
[IFLA_BR_NF_CALL_ARPTABLES
]);
1149 br
->nf_call_arptables
= val
? true : false;
1156 static int br_dev_newlink(struct net
*src_net
, struct net_device
*dev
,
1157 struct nlattr
*tb
[], struct nlattr
*data
[])
1159 struct net_bridge
*br
= netdev_priv(dev
);
1162 if (tb
[IFLA_ADDRESS
]) {
1163 spin_lock_bh(&br
->lock
);
1164 br_stp_change_bridge_id(br
, nla_data(tb
[IFLA_ADDRESS
]));
1165 spin_unlock_bh(&br
->lock
);
1168 err
= br_changelink(dev
, tb
, data
);
1172 return register_netdevice(dev
);
1175 static size_t br_get_size(const struct net_device
*brdev
)
1177 return nla_total_size(sizeof(u32
)) + /* IFLA_BR_FORWARD_DELAY */
1178 nla_total_size(sizeof(u32
)) + /* IFLA_BR_HELLO_TIME */
1179 nla_total_size(sizeof(u32
)) + /* IFLA_BR_MAX_AGE */
1180 nla_total_size(sizeof(u32
)) + /* IFLA_BR_AGEING_TIME */
1181 nla_total_size(sizeof(u32
)) + /* IFLA_BR_STP_STATE */
1182 nla_total_size(sizeof(u16
)) + /* IFLA_BR_PRIORITY */
1183 nla_total_size(sizeof(u8
)) + /* IFLA_BR_VLAN_FILTERING */
1184 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1185 nla_total_size(sizeof(__be16
)) + /* IFLA_BR_VLAN_PROTOCOL */
1186 nla_total_size(sizeof(u16
)) + /* IFLA_BR_VLAN_DEFAULT_PVID */
1187 nla_total_size(sizeof(u8
)) + /* IFLA_BR_VLAN_STATS_ENABLED */
1189 nla_total_size(sizeof(u16
)) + /* IFLA_BR_GROUP_FWD_MASK */
1190 nla_total_size(sizeof(struct ifla_bridge_id
)) + /* IFLA_BR_ROOT_ID */
1191 nla_total_size(sizeof(struct ifla_bridge_id
)) + /* IFLA_BR_BRIDGE_ID */
1192 nla_total_size(sizeof(u16
)) + /* IFLA_BR_ROOT_PORT */
1193 nla_total_size(sizeof(u32
)) + /* IFLA_BR_ROOT_PATH_COST */
1194 nla_total_size(sizeof(u8
)) + /* IFLA_BR_TOPOLOGY_CHANGE */
1195 nla_total_size(sizeof(u8
)) + /* IFLA_BR_TOPOLOGY_CHANGE_DETECTED */
1196 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_HELLO_TIMER */
1197 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_TCN_TIMER */
1198 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_TOPOLOGY_CHANGE_TIMER */
1199 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_GC_TIMER */
1200 nla_total_size(ETH_ALEN
) + /* IFLA_BR_GROUP_ADDR */
1201 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1202 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_ROUTER */
1203 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_SNOOPING */
1204 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_QUERY_USE_IFADDR */
1205 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_QUERIER */
1206 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_STATS_ENABLED */
1207 nla_total_size(sizeof(u32
)) + /* IFLA_BR_MCAST_HASH_ELASTICITY */
1208 nla_total_size(sizeof(u32
)) + /* IFLA_BR_MCAST_HASH_MAX */
1209 nla_total_size(sizeof(u32
)) + /* IFLA_BR_MCAST_LAST_MEMBER_CNT */
1210 nla_total_size(sizeof(u32
)) + /* IFLA_BR_MCAST_STARTUP_QUERY_CNT */
1211 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_LAST_MEMBER_INTVL */
1212 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_MEMBERSHIP_INTVL */
1213 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_QUERIER_INTVL */
1214 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_QUERY_INTVL */
1215 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_QUERY_RESPONSE_INTVL */
1216 nla_total_size_64bit(sizeof(u64
)) + /* IFLA_BR_MCAST_STARTUP_QUERY_INTVL */
1217 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_IGMP_VERSION */
1218 nla_total_size(sizeof(u8
)) + /* IFLA_BR_MCAST_MLD_VERSION */
1220 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1221 nla_total_size(sizeof(u8
)) + /* IFLA_BR_NF_CALL_IPTABLES */
1222 nla_total_size(sizeof(u8
)) + /* IFLA_BR_NF_CALL_IP6TABLES */
1223 nla_total_size(sizeof(u8
)) + /* IFLA_BR_NF_CALL_ARPTABLES */
1228 static int br_fill_info(struct sk_buff
*skb
, const struct net_device
*brdev
)
1230 struct net_bridge
*br
= netdev_priv(brdev
);
1231 u32 forward_delay
= jiffies_to_clock_t(br
->forward_delay
);
1232 u32 hello_time
= jiffies_to_clock_t(br
->hello_time
);
1233 u32 age_time
= jiffies_to_clock_t(br
->max_age
);
1234 u32 ageing_time
= jiffies_to_clock_t(br
->ageing_time
);
1235 u32 stp_enabled
= br
->stp_enabled
;
1236 u16 priority
= (br
->bridge_id
.prio
[0] << 8) | br
->bridge_id
.prio
[1];
1237 u8 vlan_enabled
= br_vlan_enabled(br
);
1240 clockval
= br_timer_value(&br
->hello_timer
);
1241 if (nla_put_u64_64bit(skb
, IFLA_BR_HELLO_TIMER
, clockval
, IFLA_BR_PAD
))
1243 clockval
= br_timer_value(&br
->tcn_timer
);
1244 if (nla_put_u64_64bit(skb
, IFLA_BR_TCN_TIMER
, clockval
, IFLA_BR_PAD
))
1246 clockval
= br_timer_value(&br
->topology_change_timer
);
1247 if (nla_put_u64_64bit(skb
, IFLA_BR_TOPOLOGY_CHANGE_TIMER
, clockval
,
1250 clockval
= br_timer_value(&br
->gc_work
.timer
);
1251 if (nla_put_u64_64bit(skb
, IFLA_BR_GC_TIMER
, clockval
, IFLA_BR_PAD
))
1254 if (nla_put_u32(skb
, IFLA_BR_FORWARD_DELAY
, forward_delay
) ||
1255 nla_put_u32(skb
, IFLA_BR_HELLO_TIME
, hello_time
) ||
1256 nla_put_u32(skb
, IFLA_BR_MAX_AGE
, age_time
) ||
1257 nla_put_u32(skb
, IFLA_BR_AGEING_TIME
, ageing_time
) ||
1258 nla_put_u32(skb
, IFLA_BR_STP_STATE
, stp_enabled
) ||
1259 nla_put_u16(skb
, IFLA_BR_PRIORITY
, priority
) ||
1260 nla_put_u8(skb
, IFLA_BR_VLAN_FILTERING
, vlan_enabled
) ||
1261 nla_put_u16(skb
, IFLA_BR_GROUP_FWD_MASK
, br
->group_fwd_mask
) ||
1262 nla_put(skb
, IFLA_BR_BRIDGE_ID
, sizeof(struct ifla_bridge_id
),
1264 nla_put(skb
, IFLA_BR_ROOT_ID
, sizeof(struct ifla_bridge_id
),
1265 &br
->designated_root
) ||
1266 nla_put_u16(skb
, IFLA_BR_ROOT_PORT
, br
->root_port
) ||
1267 nla_put_u32(skb
, IFLA_BR_ROOT_PATH_COST
, br
->root_path_cost
) ||
1268 nla_put_u8(skb
, IFLA_BR_TOPOLOGY_CHANGE
, br
->topology_change
) ||
1269 nla_put_u8(skb
, IFLA_BR_TOPOLOGY_CHANGE_DETECTED
,
1270 br
->topology_change_detected
) ||
1271 nla_put(skb
, IFLA_BR_GROUP_ADDR
, ETH_ALEN
, br
->group_addr
))
1274 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
1275 if (nla_put_be16(skb
, IFLA_BR_VLAN_PROTOCOL
, br
->vlan_proto
) ||
1276 nla_put_u16(skb
, IFLA_BR_VLAN_DEFAULT_PVID
, br
->default_pvid
) ||
1277 nla_put_u8(skb
, IFLA_BR_VLAN_STATS_ENABLED
, br
->vlan_stats_enabled
))
1280 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1281 if (nla_put_u8(skb
, IFLA_BR_MCAST_ROUTER
, br
->multicast_router
) ||
1282 nla_put_u8(skb
, IFLA_BR_MCAST_SNOOPING
, !br
->multicast_disabled
) ||
1283 nla_put_u8(skb
, IFLA_BR_MCAST_QUERY_USE_IFADDR
,
1284 br
->multicast_query_use_ifaddr
) ||
1285 nla_put_u8(skb
, IFLA_BR_MCAST_QUERIER
, br
->multicast_querier
) ||
1286 nla_put_u8(skb
, IFLA_BR_MCAST_STATS_ENABLED
,
1287 br
->multicast_stats_enabled
) ||
1288 nla_put_u32(skb
, IFLA_BR_MCAST_HASH_ELASTICITY
,
1289 br
->hash_elasticity
) ||
1290 nla_put_u32(skb
, IFLA_BR_MCAST_HASH_MAX
, br
->hash_max
) ||
1291 nla_put_u32(skb
, IFLA_BR_MCAST_LAST_MEMBER_CNT
,
1292 br
->multicast_last_member_count
) ||
1293 nla_put_u32(skb
, IFLA_BR_MCAST_STARTUP_QUERY_CNT
,
1294 br
->multicast_startup_query_count
) ||
1295 nla_put_u8(skb
, IFLA_BR_MCAST_IGMP_VERSION
,
1296 br
->multicast_igmp_version
))
1298 #if IS_ENABLED(CONFIG_IPV6)
1299 if (nla_put_u8(skb
, IFLA_BR_MCAST_MLD_VERSION
,
1300 br
->multicast_mld_version
))
1303 clockval
= jiffies_to_clock_t(br
->multicast_last_member_interval
);
1304 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_LAST_MEMBER_INTVL
, clockval
,
1307 clockval
= jiffies_to_clock_t(br
->multicast_membership_interval
);
1308 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_MEMBERSHIP_INTVL
, clockval
,
1311 clockval
= jiffies_to_clock_t(br
->multicast_querier_interval
);
1312 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_QUERIER_INTVL
, clockval
,
1315 clockval
= jiffies_to_clock_t(br
->multicast_query_interval
);
1316 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_QUERY_INTVL
, clockval
,
1319 clockval
= jiffies_to_clock_t(br
->multicast_query_response_interval
);
1320 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
, clockval
,
1323 clockval
= jiffies_to_clock_t(br
->multicast_startup_query_interval
);
1324 if (nla_put_u64_64bit(skb
, IFLA_BR_MCAST_STARTUP_QUERY_INTVL
, clockval
,
1328 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1329 if (nla_put_u8(skb
, IFLA_BR_NF_CALL_IPTABLES
,
1330 br
->nf_call_iptables
? 1 : 0) ||
1331 nla_put_u8(skb
, IFLA_BR_NF_CALL_IP6TABLES
,
1332 br
->nf_call_ip6tables
? 1 : 0) ||
1333 nla_put_u8(skb
, IFLA_BR_NF_CALL_ARPTABLES
,
1334 br
->nf_call_arptables
? 1 : 0))
1341 static size_t br_get_linkxstats_size(const struct net_device
*dev
, int attr
)
1343 struct net_bridge_port
*p
= NULL
;
1344 struct net_bridge_vlan_group
*vg
;
1345 struct net_bridge_vlan
*v
;
1346 struct net_bridge
*br
;
1350 case IFLA_STATS_LINK_XSTATS
:
1351 br
= netdev_priv(dev
);
1352 vg
= br_vlan_group(br
);
1354 case IFLA_STATS_LINK_XSTATS_SLAVE
:
1355 p
= br_port_get_rtnl(dev
);
1359 vg
= nbp_vlan_group(p
);
1366 /* we need to count all, even placeholder entries */
1367 list_for_each_entry(v
, &vg
->vlan_list
, vlist
)
1371 return numvls
* nla_total_size(sizeof(struct bridge_vlan_xstats
)) +
1372 nla_total_size(sizeof(struct br_mcast_stats
)) +
1376 static int br_fill_linkxstats(struct sk_buff
*skb
,
1377 const struct net_device
*dev
,
1378 int *prividx
, int attr
)
1380 struct nlattr
*nla __maybe_unused
;
1381 struct net_bridge_port
*p
= NULL
;
1382 struct net_bridge_vlan_group
*vg
;
1383 struct net_bridge_vlan
*v
;
1384 struct net_bridge
*br
;
1385 struct nlattr
*nest
;
1389 case IFLA_STATS_LINK_XSTATS
:
1390 br
= netdev_priv(dev
);
1391 vg
= br_vlan_group(br
);
1393 case IFLA_STATS_LINK_XSTATS_SLAVE
:
1394 p
= br_port_get_rtnl(dev
);
1398 vg
= nbp_vlan_group(p
);
1404 nest
= nla_nest_start(skb
, LINK_XSTATS_TYPE_BRIDGE
);
1411 pvid
= br_get_pvid(vg
);
1412 list_for_each_entry(v
, &vg
->vlan_list
, vlist
) {
1413 struct bridge_vlan_xstats vxi
;
1414 struct br_vlan_stats stats
;
1416 if (++vl_idx
< *prividx
)
1418 memset(&vxi
, 0, sizeof(vxi
));
1420 vxi
.flags
= v
->flags
;
1422 vxi
.flags
|= BRIDGE_VLAN_INFO_PVID
;
1423 br_vlan_get_stats(v
, &stats
);
1424 vxi
.rx_bytes
= stats
.rx_bytes
;
1425 vxi
.rx_packets
= stats
.rx_packets
;
1426 vxi
.tx_bytes
= stats
.tx_bytes
;
1427 vxi
.tx_packets
= stats
.tx_packets
;
1429 if (nla_put(skb
, BRIDGE_XSTATS_VLAN
, sizeof(vxi
), &vxi
))
1430 goto nla_put_failure
;
1434 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1435 if (++vl_idx
>= *prividx
) {
1436 nla
= nla_reserve_64bit(skb
, BRIDGE_XSTATS_MCAST
,
1437 sizeof(struct br_mcast_stats
),
1440 goto nla_put_failure
;
1441 br_multicast_get_stats(br
, p
, nla_data(nla
));
1444 nla_nest_end(skb
, nest
);
1450 nla_nest_end(skb
, nest
);
1456 static struct rtnl_af_ops br_af_ops __read_mostly
= {
1457 .family
= AF_BRIDGE
,
1458 .get_link_af_size
= br_get_link_af_size_filtered
,
1461 struct rtnl_link_ops br_link_ops __read_mostly
= {
1463 .priv_size
= sizeof(struct net_bridge
),
1464 .setup
= br_dev_setup
,
1465 .maxtype
= IFLA_BR_MAX
,
1466 .policy
= br_policy
,
1467 .validate
= br_validate
,
1468 .newlink
= br_dev_newlink
,
1469 .changelink
= br_changelink
,
1470 .dellink
= br_dev_delete
,
1471 .get_size
= br_get_size
,
1472 .fill_info
= br_fill_info
,
1473 .fill_linkxstats
= br_fill_linkxstats
,
1474 .get_linkxstats_size
= br_get_linkxstats_size
,
1476 .slave_maxtype
= IFLA_BRPORT_MAX
,
1477 .slave_policy
= br_port_policy
,
1478 .slave_changelink
= br_port_slave_changelink
,
1479 .get_slave_size
= br_port_get_slave_size
,
1480 .fill_slave_info
= br_port_fill_slave_info
,
1483 int __init
br_netlink_init(void)
1488 rtnl_af_register(&br_af_ops
);
1490 err
= rtnl_link_register(&br_link_ops
);
1497 rtnl_af_unregister(&br_af_ops
);
1502 void br_netlink_fini(void)
1505 rtnl_af_unregister(&br_af_ops
);
1506 rtnl_link_unregister(&br_link_ops
);