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 <net/switchdev.h>
20 #include <uapi/linux/if_bridge.h>
22 #include "br_private.h"
23 #include "br_private_stp.h"
25 static int br_get_num_vlan_infos(const struct net_port_vlans *pv,
28 u16 vid_range_start = 0, vid_range_end = 0;
29 u16 vid_range_flags = 0;
33 if (filter_mask & RTEXT_FILTER_BRVLAN)
36 if (!(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED))
39 /* Count number of vlan info's
41 pvid = br_get_pvid(pv);
42 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID) {
45 flags |= BRIDGE_VLAN_INFO_PVID;
47 if (test_bit(vid, pv->untagged_bitmap))
48 flags |= BRIDGE_VLAN_INFO_UNTAGGED;
50 if (vid_range_start == 0) {
52 } else if ((vid - vid_range_end) == 1 &&
53 flags == vid_range_flags) {
57 if ((vid_range_end - vid_range_start) > 0)
63 vid_range_start = vid;
65 vid_range_flags = flags;
68 if (vid_range_start != 0) {
69 if ((vid_range_end - vid_range_start) > 0)
78 static size_t br_get_link_af_size_filtered(const struct net_device *dev,
81 struct net_port_vlans *pv;
85 if (br_port_exists(dev))
86 pv = nbp_get_vlan_info(br_port_get_rcu(dev));
87 else if (dev->priv_flags & IFF_EBRIDGE)
88 pv = br_get_vlan_info((struct net_bridge *)netdev_priv(dev));
92 num_vlan_infos = br_get_num_vlan_infos(pv, filter_mask);
100 /* Each VLAN is returned in bridge_vlan_info along with flags */
101 return num_vlan_infos * nla_total_size(sizeof(struct bridge_vlan_info));
104 static inline size_t br_port_info_size(void)
106 return nla_total_size(1) /* IFLA_BRPORT_STATE */
107 + nla_total_size(2) /* IFLA_BRPORT_PRIORITY */
108 + nla_total_size(4) /* IFLA_BRPORT_COST */
109 + nla_total_size(1) /* IFLA_BRPORT_MODE */
110 + nla_total_size(1) /* IFLA_BRPORT_GUARD */
111 + nla_total_size(1) /* IFLA_BRPORT_PROTECT */
112 + nla_total_size(1) /* IFLA_BRPORT_FAST_LEAVE */
113 + nla_total_size(1) /* IFLA_BRPORT_LEARNING */
114 + nla_total_size(1) /* IFLA_BRPORT_UNICAST_FLOOD */
118 static inline size_t br_nlmsg_size(struct net_device *dev, u32 filter_mask)
120 return NLMSG_ALIGN(sizeof(struct ifinfomsg))
121 + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
122 + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
123 + nla_total_size(4) /* IFLA_MASTER */
124 + nla_total_size(4) /* IFLA_MTU */
125 + nla_total_size(4) /* IFLA_LINK */
126 + nla_total_size(1) /* IFLA_OPERSTATE */
127 + nla_total_size(br_port_info_size()) /* IFLA_PROTINFO */
128 + nla_total_size(br_get_link_af_size_filtered(dev,
129 filter_mask)); /* IFLA_AF_SPEC */
132 static int br_port_fill_attrs(struct sk_buff *skb,
133 const struct net_bridge_port *p)
135 u8 mode = !!(p->flags & BR_HAIRPIN_MODE);
137 if (nla_put_u8(skb, IFLA_BRPORT_STATE, p->state) ||
138 nla_put_u16(skb, IFLA_BRPORT_PRIORITY, p->priority) ||
139 nla_put_u32(skb, IFLA_BRPORT_COST, p->path_cost) ||
140 nla_put_u8(skb, IFLA_BRPORT_MODE, mode) ||
141 nla_put_u8(skb, IFLA_BRPORT_GUARD, !!(p->flags & BR_BPDU_GUARD)) ||
142 nla_put_u8(skb, IFLA_BRPORT_PROTECT, !!(p->flags & BR_ROOT_BLOCK)) ||
143 nla_put_u8(skb, IFLA_BRPORT_FAST_LEAVE, !!(p->flags & BR_MULTICAST_FAST_LEAVE)) ||
144 nla_put_u8(skb, IFLA_BRPORT_LEARNING, !!(p->flags & BR_LEARNING)) ||
145 nla_put_u8(skb, IFLA_BRPORT_UNICAST_FLOOD, !!(p->flags & BR_FLOOD)) ||
146 nla_put_u8(skb, IFLA_BRPORT_PROXYARP, !!(p->flags & BR_PROXYARP)) ||
147 nla_put_u8(skb, IFLA_BRPORT_PROXYARP_WIFI,
148 !!(p->flags & BR_PROXYARP_WIFI)))
154 static int br_fill_ifvlaninfo_range(struct sk_buff *skb, u16 vid_start,
155 u16 vid_end, u16 flags)
157 struct bridge_vlan_info vinfo;
159 if ((vid_end - vid_start) > 0) {
160 /* add range to skb */
161 vinfo.vid = vid_start;
162 vinfo.flags = flags | BRIDGE_VLAN_INFO_RANGE_BEGIN;
163 if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
164 sizeof(vinfo), &vinfo))
165 goto nla_put_failure;
167 vinfo.flags &= ~BRIDGE_VLAN_INFO_RANGE_BEGIN;
170 vinfo.flags = flags | BRIDGE_VLAN_INFO_RANGE_END;
171 if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
172 sizeof(vinfo), &vinfo))
173 goto nla_put_failure;
175 vinfo.vid = vid_start;
177 if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
178 sizeof(vinfo), &vinfo))
179 goto nla_put_failure;
188 static int br_fill_ifvlaninfo_compressed(struct sk_buff *skb,
189 const struct net_port_vlans *pv)
191 u16 vid_range_start = 0, vid_range_end = 0;
192 u16 vid_range_flags = 0;
193 u16 pvid, vid, flags;
196 /* Pack IFLA_BRIDGE_VLAN_INFO's for every vlan
197 * and mark vlan info with begin and end flags
198 * if vlaninfo represents a range
200 pvid = br_get_pvid(pv);
201 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID) {
204 flags |= BRIDGE_VLAN_INFO_PVID;
206 if (test_bit(vid, pv->untagged_bitmap))
207 flags |= BRIDGE_VLAN_INFO_UNTAGGED;
209 if (vid_range_start == 0) {
211 } else if ((vid - vid_range_end) == 1 &&
212 flags == vid_range_flags) {
216 err = br_fill_ifvlaninfo_range(skb, vid_range_start,
224 vid_range_start = vid;
226 vid_range_flags = flags;
229 if (vid_range_start != 0) {
230 /* Call it once more to send any left over vlans */
231 err = br_fill_ifvlaninfo_range(skb, vid_range_start,
241 static int br_fill_ifvlaninfo(struct sk_buff *skb,
242 const struct net_port_vlans *pv)
244 struct bridge_vlan_info vinfo;
247 pvid = br_get_pvid(pv);
248 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID) {
252 vinfo.flags |= BRIDGE_VLAN_INFO_PVID;
254 if (test_bit(vid, pv->untagged_bitmap))
255 vinfo.flags |= BRIDGE_VLAN_INFO_UNTAGGED;
257 if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
258 sizeof(vinfo), &vinfo))
259 goto nla_put_failure;
269 * Create one netlink message for one interface
270 * Contains port and master info as well as carrier and bridge state.
272 static int br_fill_ifinfo(struct sk_buff *skb,
273 const struct net_bridge_port *port,
274 u32 pid, u32 seq, int event, unsigned int flags,
275 u32 filter_mask, const struct net_device *dev)
277 const struct net_bridge *br;
278 struct ifinfomsg *hdr;
279 struct nlmsghdr *nlh;
280 u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN;
285 br = netdev_priv(dev);
287 br_debug(br, "br_fill_info event %d port %s master %s\n",
288 event, dev->name, br->dev->name);
290 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*hdr), flags);
294 hdr = nlmsg_data(nlh);
295 hdr->ifi_family = AF_BRIDGE;
297 hdr->ifi_type = dev->type;
298 hdr->ifi_index = dev->ifindex;
299 hdr->ifi_flags = dev_get_flags(dev);
302 if (nla_put_string(skb, IFLA_IFNAME, dev->name) ||
303 nla_put_u32(skb, IFLA_MASTER, br->dev->ifindex) ||
304 nla_put_u32(skb, IFLA_MTU, dev->mtu) ||
305 nla_put_u8(skb, IFLA_OPERSTATE, operstate) ||
307 nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) ||
308 (dev->ifindex != dev_get_iflink(dev) &&
309 nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))))
310 goto nla_put_failure;
312 if (event == RTM_NEWLINK && port) {
314 = nla_nest_start(skb, IFLA_PROTINFO | NLA_F_NESTED);
316 if (nest == NULL || br_port_fill_attrs(skb, port) < 0)
317 goto nla_put_failure;
318 nla_nest_end(skb, nest);
321 /* Check if the VID information is requested */
322 if ((filter_mask & RTEXT_FILTER_BRVLAN) ||
323 (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) {
324 const struct net_port_vlans *pv;
329 pv = nbp_get_vlan_info(port);
331 pv = br_get_vlan_info(br);
333 if (!pv || bitmap_empty(pv->vlan_bitmap, VLAN_N_VID))
336 af = nla_nest_start(skb, IFLA_AF_SPEC);
338 goto nla_put_failure;
340 if (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)
341 err = br_fill_ifvlaninfo_compressed(skb, pv);
343 err = br_fill_ifvlaninfo(skb, pv);
345 goto nla_put_failure;
346 nla_nest_end(skb, af);
354 nlmsg_cancel(skb, nlh);
359 * Notify listeners of a change in port information
361 void br_ifinfo_notify(int event, struct net_bridge_port *port)
366 u32 filter = RTEXT_FILTER_BRVLAN_COMPRESSED;
371 net = dev_net(port->dev);
372 br_debug(port->br, "port %u(%s) event %d\n",
373 (unsigned int)port->port_no, port->dev->name, event);
375 skb = nlmsg_new(br_nlmsg_size(port->dev, filter), GFP_ATOMIC);
379 err = br_fill_ifinfo(skb, port, 0, 0, event, 0, filter, port->dev);
381 /* -EMSGSIZE implies BUG in br_nlmsg_size() */
382 WARN_ON(err == -EMSGSIZE);
386 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
389 rtnl_set_sk_err(net, RTNLGRP_LINK, err);
394 * Dump information about all ports, in response to GETLINK
396 int br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
397 struct net_device *dev, u32 filter_mask, int nlflags)
399 struct net_bridge_port *port = br_port_get_rtnl(dev);
401 if (!port && !(filter_mask & RTEXT_FILTER_BRVLAN) &&
402 !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED))
405 return br_fill_ifinfo(skb, port, pid, seq, RTM_NEWLINK, nlflags,
409 static int br_vlan_info(struct net_bridge *br, struct net_bridge_port *p,
410 int cmd, struct bridge_vlan_info *vinfo)
417 err = nbp_vlan_add(p, vinfo->vid, vinfo->flags);
421 if (vinfo->flags & BRIDGE_VLAN_INFO_MASTER)
422 err = br_vlan_add(p->br, vinfo->vid,
425 err = br_vlan_add(br, vinfo->vid, vinfo->flags);
431 nbp_vlan_delete(p, vinfo->vid);
432 if (vinfo->flags & BRIDGE_VLAN_INFO_MASTER)
433 br_vlan_delete(p->br, vinfo->vid);
435 br_vlan_delete(br, vinfo->vid);
443 static int br_afspec(struct net_bridge *br,
444 struct net_bridge_port *p,
445 struct nlattr *af_spec,
448 struct bridge_vlan_info *vinfo_start = NULL;
449 struct bridge_vlan_info *vinfo = NULL;
454 nla_for_each_nested(attr, af_spec, rem) {
455 if (nla_type(attr) != IFLA_BRIDGE_VLAN_INFO)
457 if (nla_len(attr) != sizeof(struct bridge_vlan_info))
459 vinfo = nla_data(attr);
460 if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
468 struct bridge_vlan_info tmp_vinfo;
471 if (!(vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END))
474 if (vinfo->vid <= vinfo_start->vid)
477 memcpy(&tmp_vinfo, vinfo_start,
478 sizeof(struct bridge_vlan_info));
480 for (v = vinfo_start->vid; v <= vinfo->vid; v++) {
482 err = br_vlan_info(br, p, cmd, &tmp_vinfo);
488 err = br_vlan_info(br, p, cmd, vinfo);
497 static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX + 1] = {
498 [IFLA_BRPORT_STATE] = { .type = NLA_U8 },
499 [IFLA_BRPORT_COST] = { .type = NLA_U32 },
500 [IFLA_BRPORT_PRIORITY] = { .type = NLA_U16 },
501 [IFLA_BRPORT_MODE] = { .type = NLA_U8 },
502 [IFLA_BRPORT_GUARD] = { .type = NLA_U8 },
503 [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 },
504 [IFLA_BRPORT_FAST_LEAVE]= { .type = NLA_U8 },
505 [IFLA_BRPORT_LEARNING] = { .type = NLA_U8 },
506 [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NLA_U8 },
509 /* Change the state of the port and notify spanning tree */
510 static int br_set_port_state(struct net_bridge_port *p, u8 state)
512 if (state > BR_STATE_BLOCKING)
515 /* if kernel STP is running, don't allow changes */
516 if (p->br->stp_enabled == BR_KERNEL_STP)
519 /* if device is not up, change is not allowed
520 * if link is not present, only allowable state is disabled
522 if (!netif_running(p->dev) ||
523 (!netif_oper_up(p->dev) && state != BR_STATE_DISABLED))
526 br_set_state(p, state);
528 br_port_state_selection(p->br);
532 /* Set/clear or port flags based on attribute */
533 static void br_set_port_flag(struct net_bridge_port *p, struct nlattr *tb[],
534 int attrtype, unsigned long mask)
537 u8 flag = nla_get_u8(tb[attrtype]);
545 /* Process bridge protocol info on port */
546 static int br_setport(struct net_bridge_port *p, struct nlattr *tb[])
549 unsigned long old_flags = p->flags;
551 br_set_port_flag(p, tb, IFLA_BRPORT_MODE, BR_HAIRPIN_MODE);
552 br_set_port_flag(p, tb, IFLA_BRPORT_GUARD, BR_BPDU_GUARD);
553 br_set_port_flag(p, tb, IFLA_BRPORT_FAST_LEAVE, BR_MULTICAST_FAST_LEAVE);
554 br_set_port_flag(p, tb, IFLA_BRPORT_PROTECT, BR_ROOT_BLOCK);
555 br_set_port_flag(p, tb, IFLA_BRPORT_LEARNING, BR_LEARNING);
556 br_set_port_flag(p, tb, IFLA_BRPORT_UNICAST_FLOOD, BR_FLOOD);
557 br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP, BR_PROXYARP);
558 br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP_WIFI, BR_PROXYARP_WIFI);
560 if (tb[IFLA_BRPORT_COST]) {
561 err = br_stp_set_path_cost(p, nla_get_u32(tb[IFLA_BRPORT_COST]));
566 if (tb[IFLA_BRPORT_PRIORITY]) {
567 err = br_stp_set_port_priority(p, nla_get_u16(tb[IFLA_BRPORT_PRIORITY]));
572 if (tb[IFLA_BRPORT_STATE]) {
573 err = br_set_port_state(p, nla_get_u8(tb[IFLA_BRPORT_STATE]));
578 br_port_flags_change(p, old_flags ^ p->flags);
582 /* Change state and parameters on port. */
583 int br_setlink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags)
585 struct nlattr *protinfo;
586 struct nlattr *afspec;
587 struct net_bridge_port *p;
588 struct nlattr *tb[IFLA_BRPORT_MAX + 1];
589 int err = 0, ret_offload = 0;
591 protinfo = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_PROTINFO);
592 afspec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
593 if (!protinfo && !afspec)
596 p = br_port_get_rtnl(dev);
597 /* We want to accept dev as bridge itself if the AF_SPEC
598 * is set to see if someone is setting vlan info on the bridge
604 if (protinfo->nla_type & NLA_F_NESTED) {
605 err = nla_parse_nested(tb, IFLA_BRPORT_MAX,
606 protinfo, br_port_policy);
610 spin_lock_bh(&p->br->lock);
611 err = br_setport(p, tb);
612 spin_unlock_bh(&p->br->lock);
614 /* Binary compatibility with old RSTP */
615 if (nla_len(protinfo) < sizeof(u8))
618 spin_lock_bh(&p->br->lock);
619 err = br_set_port_state(p, nla_get_u8(protinfo));
620 spin_unlock_bh(&p->br->lock);
627 err = br_afspec((struct net_bridge *)netdev_priv(dev), p,
628 afspec, RTM_SETLINK);
631 if (p && !(flags & BRIDGE_FLAGS_SELF)) {
632 /* set bridge attributes in hardware if supported
634 ret_offload = netdev_switch_port_bridge_setlink(dev, nlh,
636 if (ret_offload && ret_offload != -EOPNOTSUPP)
637 br_warn(p->br, "error setting attrs on port %u(%s)\n",
638 (unsigned int)p->port_no, p->dev->name);
642 br_ifinfo_notify(RTM_NEWLINK, p);
647 /* Delete port information */
648 int br_dellink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags)
650 struct nlattr *afspec;
651 struct net_bridge_port *p;
652 int err = 0, ret_offload = 0;
654 afspec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
658 p = br_port_get_rtnl(dev);
659 /* We want to accept dev as bridge itself as well */
660 if (!p && !(dev->priv_flags & IFF_EBRIDGE))
663 err = br_afspec((struct net_bridge *)netdev_priv(dev), p,
664 afspec, RTM_DELLINK);
666 /* Send RTM_NEWLINK because userspace
667 * expects RTM_NEWLINK for vlan dels
669 br_ifinfo_notify(RTM_NEWLINK, p);
671 if (p && !(flags & BRIDGE_FLAGS_SELF)) {
672 /* del bridge attributes in hardware
674 ret_offload = netdev_switch_port_bridge_dellink(dev, nlh,
676 if (ret_offload && ret_offload != -EOPNOTSUPP)
677 br_warn(p->br, "error deleting attrs on port %u (%s)\n",
678 (unsigned int)p->port_no, p->dev->name);
683 static int br_validate(struct nlattr *tb[], struct nlattr *data[])
685 if (tb[IFLA_ADDRESS]) {
686 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
688 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
689 return -EADDRNOTAVAIL;
695 static int br_dev_newlink(struct net *src_net, struct net_device *dev,
696 struct nlattr *tb[], struct nlattr *data[])
698 struct net_bridge *br = netdev_priv(dev);
700 if (tb[IFLA_ADDRESS]) {
701 spin_lock_bh(&br->lock);
702 br_stp_change_bridge_id(br, nla_data(tb[IFLA_ADDRESS]));
703 spin_unlock_bh(&br->lock);
706 return register_netdevice(dev);
709 static int br_port_slave_changelink(struct net_device *brdev,
710 struct net_device *dev,
712 struct nlattr *data[])
716 return br_setport(br_port_get_rtnl(dev), data);
719 static int br_port_fill_slave_info(struct sk_buff *skb,
720 const struct net_device *brdev,
721 const struct net_device *dev)
723 return br_port_fill_attrs(skb, br_port_get_rtnl(dev));
726 static size_t br_port_get_slave_size(const struct net_device *brdev,
727 const struct net_device *dev)
729 return br_port_info_size();
732 static const struct nla_policy br_policy[IFLA_BR_MAX + 1] = {
733 [IFLA_BR_FORWARD_DELAY] = { .type = NLA_U32 },
734 [IFLA_BR_HELLO_TIME] = { .type = NLA_U32 },
735 [IFLA_BR_MAX_AGE] = { .type = NLA_U32 },
736 [IFLA_BR_AGEING_TIME] = { .type = NLA_U32 },
737 [IFLA_BR_STP_STATE] = { .type = NLA_U32 },
738 [IFLA_BR_PRIORITY] = { .type = NLA_U16 },
741 static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
742 struct nlattr *data[])
744 struct net_bridge *br = netdev_priv(brdev);
750 if (data[IFLA_BR_FORWARD_DELAY]) {
751 err = br_set_forward_delay(br, nla_get_u32(data[IFLA_BR_FORWARD_DELAY]));
756 if (data[IFLA_BR_HELLO_TIME]) {
757 err = br_set_hello_time(br, nla_get_u32(data[IFLA_BR_HELLO_TIME]));
762 if (data[IFLA_BR_MAX_AGE]) {
763 err = br_set_max_age(br, nla_get_u32(data[IFLA_BR_MAX_AGE]));
768 if (data[IFLA_BR_AGEING_TIME]) {
769 u32 ageing_time = nla_get_u32(data[IFLA_BR_AGEING_TIME]);
771 br->ageing_time = clock_t_to_jiffies(ageing_time);
774 if (data[IFLA_BR_STP_STATE]) {
775 u32 stp_enabled = nla_get_u32(data[IFLA_BR_STP_STATE]);
777 br_stp_set_enabled(br, stp_enabled);
780 if (data[IFLA_BR_PRIORITY]) {
781 u32 priority = nla_get_u16(data[IFLA_BR_PRIORITY]);
783 br_stp_set_bridge_priority(br, priority);
789 static size_t br_get_size(const struct net_device *brdev)
791 return nla_total_size(sizeof(u32)) + /* IFLA_BR_FORWARD_DELAY */
792 nla_total_size(sizeof(u32)) + /* IFLA_BR_HELLO_TIME */
793 nla_total_size(sizeof(u32)) + /* IFLA_BR_MAX_AGE */
794 nla_total_size(sizeof(u32)) + /* IFLA_BR_AGEING_TIME */
795 nla_total_size(sizeof(u32)) + /* IFLA_BR_STP_STATE */
796 nla_total_size(sizeof(u16)) + /* IFLA_BR_PRIORITY */
800 static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
802 struct net_bridge *br = netdev_priv(brdev);
803 u32 forward_delay = jiffies_to_clock_t(br->forward_delay);
804 u32 hello_time = jiffies_to_clock_t(br->hello_time);
805 u32 age_time = jiffies_to_clock_t(br->max_age);
806 u32 ageing_time = jiffies_to_clock_t(br->ageing_time);
807 u32 stp_enabled = br->stp_enabled;
808 u16 priority = (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1];
810 if (nla_put_u32(skb, IFLA_BR_FORWARD_DELAY, forward_delay) ||
811 nla_put_u32(skb, IFLA_BR_HELLO_TIME, hello_time) ||
812 nla_put_u32(skb, IFLA_BR_MAX_AGE, age_time) ||
813 nla_put_u32(skb, IFLA_BR_AGEING_TIME, ageing_time) ||
814 nla_put_u32(skb, IFLA_BR_STP_STATE, stp_enabled) ||
815 nla_put_u16(skb, IFLA_BR_PRIORITY, priority))
821 static size_t br_get_link_af_size(const struct net_device *dev)
823 struct net_port_vlans *pv;
825 if (br_port_exists(dev))
826 pv = nbp_get_vlan_info(br_port_get_rtnl(dev));
827 else if (dev->priv_flags & IFF_EBRIDGE)
828 pv = br_get_vlan_info((struct net_bridge *)netdev_priv(dev));
835 /* Each VLAN is returned in bridge_vlan_info along with flags */
836 return pv->num_vlans * nla_total_size(sizeof(struct bridge_vlan_info));
839 static struct rtnl_af_ops br_af_ops __read_mostly = {
841 .get_link_af_size = br_get_link_af_size,
844 struct rtnl_link_ops br_link_ops __read_mostly = {
846 .priv_size = sizeof(struct net_bridge),
847 .setup = br_dev_setup,
848 .maxtype = IFLA_BRPORT_MAX,
850 .validate = br_validate,
851 .newlink = br_dev_newlink,
852 .changelink = br_changelink,
853 .dellink = br_dev_delete,
854 .get_size = br_get_size,
855 .fill_info = br_fill_info,
857 .slave_maxtype = IFLA_BRPORT_MAX,
858 .slave_policy = br_port_policy,
859 .slave_changelink = br_port_slave_changelink,
860 .get_slave_size = br_port_get_slave_size,
861 .fill_slave_info = br_port_fill_slave_info,
864 int __init br_netlink_init(void)
869 rtnl_af_register(&br_af_ops);
871 err = rtnl_link_register(&br_link_ops);
878 rtnl_af_unregister(&br_af_ops);
883 void br_netlink_fini(void)
886 rtnl_af_unregister(&br_af_ops);
887 rtnl_link_unregister(&br_link_ops);