blob: 4b5c236998ff1010831711a17b773e16c7d8ba58 [file] [log] [blame]
Stephen Hemminger11dc1f32006-05-25 16:00:12 -07001/*
2 * Bridge netlink control interface
3 *
4 * Authors:
5 * Stephen Hemminger <shemminger@osdl.org>
6 *
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.
11 */
12
13#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
stephen hemmingerbb900b22011-04-04 14:03:32 +000015#include <linux/etherdevice.h>
Thomas Graf32fe21c2007-03-22 11:59:03 -070016#include <net/rtnetlink.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070017#include <net/net_namespace.h>
Denis V. Lunevb8542722007-12-01 00:21:31 +110018#include <net/sock.h>
Roopa Prabhu68e331c2015-01-29 22:40:14 -080019#include <net/switchdev.h>
Vlad Yasevich407af322013-02-13 12:00:12 +000020#include <uapi/linux/if_bridge.h>
stephen hemmingerbb900b22011-04-04 14:03:32 +000021
Stephen Hemminger11dc1f32006-05-25 16:00:12 -070022#include "br_private.h"
Vitalii Demianetsb03b6dd2011-11-25 00:16:37 +000023#include "br_private_stp.h"
Stephen Hemminger11dc1f32006-05-25 16:00:12 -070024
Roopa Prabhufed0a152015-02-25 23:55:40 -080025static int br_get_num_vlan_infos(const struct net_port_vlans *pv,
26 u32 filter_mask)
27{
28 u16 vid_range_start = 0, vid_range_end = 0;
29 u16 vid_range_flags = 0;
30 u16 pvid, vid, flags;
31 int num_vlans = 0;
32
33 if (filter_mask & RTEXT_FILTER_BRVLAN)
34 return pv->num_vlans;
35
36 if (!(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED))
37 return 0;
38
39 /* Count number of vlan info's
40 */
41 pvid = br_get_pvid(pv);
42 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID) {
43 flags = 0;
44 if (vid == pvid)
45 flags |= BRIDGE_VLAN_INFO_PVID;
46
47 if (test_bit(vid, pv->untagged_bitmap))
48 flags |= BRIDGE_VLAN_INFO_UNTAGGED;
49
50 if (vid_range_start == 0) {
51 goto initvars;
52 } else if ((vid - vid_range_end) == 1 &&
53 flags == vid_range_flags) {
54 vid_range_end = vid;
55 continue;
56 } else {
57 if ((vid_range_end - vid_range_start) > 0)
58 num_vlans += 2;
59 else
60 num_vlans += 1;
61 }
62initvars:
63 vid_range_start = vid;
64 vid_range_end = vid;
65 vid_range_flags = flags;
66 }
67
68 if (vid_range_start != 0) {
69 if ((vid_range_end - vid_range_start) > 0)
70 num_vlans += 2;
71 else
72 num_vlans += 1;
73 }
74
75 return num_vlans;
76}
77
78static size_t br_get_link_af_size_filtered(const struct net_device *dev,
79 u32 filter_mask)
Roopa Prabhub7853d72015-02-21 20:21:51 -080080{
81 struct net_port_vlans *pv;
Roopa Prabhufed0a152015-02-25 23:55:40 -080082 int num_vlan_infos;
Roopa Prabhub7853d72015-02-21 20:21:51 -080083
Johannes Berg2f56f6b2015-03-03 16:02:16 +010084 rcu_read_lock();
Roopa Prabhub7853d72015-02-21 20:21:51 -080085 if (br_port_exists(dev))
Johannes Berg2f56f6b2015-03-03 16:02:16 +010086 pv = nbp_get_vlan_info(br_port_get_rcu(dev));
Roopa Prabhub7853d72015-02-21 20:21:51 -080087 else if (dev->priv_flags & IFF_EBRIDGE)
88 pv = br_get_vlan_info((struct net_bridge *)netdev_priv(dev));
89 else
Johannes Berg2f56f6b2015-03-03 16:02:16 +010090 pv = NULL;
91 if (pv)
92 num_vlan_infos = br_get_num_vlan_infos(pv, filter_mask);
93 else
94 num_vlan_infos = 0;
95 rcu_read_unlock();
Roopa Prabhub7853d72015-02-21 20:21:51 -080096
Roopa Prabhufed0a152015-02-25 23:55:40 -080097 if (!num_vlan_infos)
98 return 0;
99
Roopa Prabhub7853d72015-02-21 20:21:51 -0800100 /* Each VLAN is returned in bridge_vlan_info along with flags */
Roopa Prabhufed0a152015-02-25 23:55:40 -0800101 return num_vlan_infos * nla_total_size(sizeof(struct bridge_vlan_info));
Roopa Prabhub7853d72015-02-21 20:21:51 -0800102}
103
stephen hemminger25c71c72012-11-13 07:53:05 +0000104static inline size_t br_port_info_size(void)
105{
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 */
stephen hemmingera2e01a62012-11-13 07:53:07 +0000110 + nla_total_size(1) /* IFLA_BRPORT_GUARD */
stephen hemminger1007dd12012-11-13 07:53:08 +0000111 + nla_total_size(1) /* IFLA_BRPORT_PROTECT */
stephen hemminger3da889b2013-03-11 13:52:17 +0000112 + nla_total_size(1) /* IFLA_BRPORT_FAST_LEAVE */
Vlad Yasevich9ba18892013-06-05 10:08:00 -0400113 + nla_total_size(1) /* IFLA_BRPORT_LEARNING */
Vlad Yasevich867a5942013-06-05 10:08:01 -0400114 + nla_total_size(1) /* IFLA_BRPORT_UNICAST_FLOOD */
stephen hemminger25c71c72012-11-13 07:53:05 +0000115 + 0;
116}
117
Roopa Prabhufed0a152015-02-25 23:55:40 -0800118static inline size_t br_nlmsg_size(struct net_device *dev, u32 filter_mask)
Thomas Graf339bf982006-11-10 14:10:15 -0800119{
120 return NLMSG_ALIGN(sizeof(struct ifinfomsg))
stephen hemminger25c71c72012-11-13 07:53:05 +0000121 + 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 */
Roopa Prabhub7853d72015-02-21 20:21:51 -0800127 + nla_total_size(br_port_info_size()) /* IFLA_PROTINFO */
Roopa Prabhufed0a152015-02-25 23:55:40 -0800128 + nla_total_size(br_get_link_af_size_filtered(dev,
129 filter_mask)); /* IFLA_AF_SPEC */
stephen hemminger25c71c72012-11-13 07:53:05 +0000130}
131
132static int br_port_fill_attrs(struct sk_buff *skb,
133 const struct net_bridge_port *p)
134{
135 u8 mode = !!(p->flags & BR_HAIRPIN_MODE);
136
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) ||
stephen hemmingera2e01a62012-11-13 07:53:07 +0000140 nla_put_u8(skb, IFLA_BRPORT_MODE, mode) ||
stephen hemminger1007dd12012-11-13 07:53:08 +0000141 nla_put_u8(skb, IFLA_BRPORT_GUARD, !!(p->flags & BR_BPDU_GUARD)) ||
David S. Millerc2d3bab2012-12-05 16:24:45 -0500142 nla_put_u8(skb, IFLA_BRPORT_PROTECT, !!(p->flags & BR_ROOT_BLOCK)) ||
Vlad Yasevich9ba18892013-06-05 10:08:00 -0400143 nla_put_u8(skb, IFLA_BRPORT_FAST_LEAVE, !!(p->flags & BR_MULTICAST_FAST_LEAVE)) ||
Vlad Yasevich867a5942013-06-05 10:08:01 -0400144 nla_put_u8(skb, IFLA_BRPORT_LEARNING, !!(p->flags & BR_LEARNING)) ||
Kyeyoon Park95850112014-10-23 14:49:17 -0700145 nla_put_u8(skb, IFLA_BRPORT_UNICAST_FLOOD, !!(p->flags & BR_FLOOD)) ||
Jouni Malinen842a9ae2015-03-04 12:54:21 +0200146 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)))
stephen hemminger25c71c72012-11-13 07:53:05 +0000149 return -EMSGSIZE;
150
151 return 0;
Thomas Graf339bf982006-11-10 14:10:15 -0800152}
153
Roopa Prabhu36cd0ff2015-01-10 07:31:14 -0800154static int br_fill_ifvlaninfo_range(struct sk_buff *skb, u16 vid_start,
155 u16 vid_end, u16 flags)
156{
157 struct bridge_vlan_info vinfo;
158
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;
166
167 vinfo.flags &= ~BRIDGE_VLAN_INFO_RANGE_BEGIN;
168
169 vinfo.vid = vid_end;
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;
174 } else {
175 vinfo.vid = vid_start;
176 vinfo.flags = flags;
177 if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
178 sizeof(vinfo), &vinfo))
179 goto nla_put_failure;
180 }
181
182 return 0;
183
184nla_put_failure:
185 return -EMSGSIZE;
186}
187
188static int br_fill_ifvlaninfo_compressed(struct sk_buff *skb,
189 const struct net_port_vlans *pv)
190{
191 u16 vid_range_start = 0, vid_range_end = 0;
Roopa Prabhu0fe6de42015-01-12 16:25:28 -0800192 u16 vid_range_flags = 0;
Roopa Prabhu36cd0ff2015-01-10 07:31:14 -0800193 u16 pvid, vid, flags;
194 int err = 0;
195
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
199 */
200 pvid = br_get_pvid(pv);
201 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID) {
202 flags = 0;
203 if (vid == pvid)
204 flags |= BRIDGE_VLAN_INFO_PVID;
205
206 if (test_bit(vid, pv->untagged_bitmap))
207 flags |= BRIDGE_VLAN_INFO_UNTAGGED;
208
209 if (vid_range_start == 0) {
210 goto initvars;
211 } else if ((vid - vid_range_end) == 1 &&
212 flags == vid_range_flags) {
213 vid_range_end = vid;
214 continue;
215 } else {
216 err = br_fill_ifvlaninfo_range(skb, vid_range_start,
217 vid_range_end,
218 vid_range_flags);
219 if (err)
220 return err;
221 }
222
223initvars:
224 vid_range_start = vid;
225 vid_range_end = vid;
226 vid_range_flags = flags;
227 }
228
Roopa Prabhu0fe6de42015-01-12 16:25:28 -0800229 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,
232 vid_range_end,
233 vid_range_flags);
234 if (err)
235 return err;
236 }
Roopa Prabhu36cd0ff2015-01-10 07:31:14 -0800237
238 return 0;
239}
240
241static int br_fill_ifvlaninfo(struct sk_buff *skb,
242 const struct net_port_vlans *pv)
243{
244 struct bridge_vlan_info vinfo;
245 u16 pvid, vid;
246
247 pvid = br_get_pvid(pv);
248 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID) {
249 vinfo.vid = vid;
250 vinfo.flags = 0;
251 if (vid == pvid)
252 vinfo.flags |= BRIDGE_VLAN_INFO_PVID;
253
254 if (test_bit(vid, pv->untagged_bitmap))
255 vinfo.flags |= BRIDGE_VLAN_INFO_UNTAGGED;
256
257 if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
258 sizeof(vinfo), &vinfo))
259 goto nla_put_failure;
260 }
261
262 return 0;
263
264nla_put_failure:
265 return -EMSGSIZE;
266}
267
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700268/*
269 * Create one netlink message for one interface
270 * Contains port and master info as well as carrier and bridge state.
271 */
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000272static 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)
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700276{
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000277 const struct net_bridge *br;
Thomas Graf74685962006-11-20 16:20:22 -0800278 struct ifinfomsg *hdr;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700279 struct nlmsghdr *nlh;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700280 u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700281
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000282 if (port)
283 br = port->br;
284 else
285 br = netdev_priv(dev);
286
stephen hemminger28a16c92010-05-10 09:31:09 +0000287 br_debug(br, "br_fill_info event %d port %s master %s\n",
288 event, dev->name, br->dev->name);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700289
Thomas Graf74685962006-11-20 16:20:22 -0800290 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*hdr), flags);
291 if (nlh == NULL)
Patrick McHardy26932562007-01-31 23:16:40 -0800292 return -EMSGSIZE;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700293
Thomas Graf74685962006-11-20 16:20:22 -0800294 hdr = nlmsg_data(nlh);
295 hdr->ifi_family = AF_BRIDGE;
296 hdr->__ifi_pad = 0;
297 hdr->ifi_type = dev->type;
298 hdr->ifi_index = dev->ifindex;
299 hdr->ifi_flags = dev_get_flags(dev);
300 hdr->ifi_change = 0;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700301
David S. Miller2eb812e2012-04-01 20:49:54 -0400302 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) ||
306 (dev->addr_len &&
307 nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) ||
Nicolas Dichtela54acb32015-04-02 17:07:00 +0200308 (dev->ifindex != dev_get_iflink(dev) &&
309 nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))))
David S. Miller2eb812e2012-04-01 20:49:54 -0400310 goto nla_put_failure;
stephen hemminger25c71c72012-11-13 07:53:05 +0000311
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000312 if (event == RTM_NEWLINK && port) {
stephen hemminger25c71c72012-11-13 07:53:05 +0000313 struct nlattr *nest
314 = nla_nest_start(skb, IFLA_PROTINFO | NLA_F_NESTED);
315
316 if (nest == NULL || br_port_fill_attrs(skb, port) < 0)
317 goto nla_put_failure;
318 nla_nest_end(skb, nest);
319 }
320
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000321 /* Check if the VID information is requested */
Roopa Prabhu36cd0ff2015-01-10 07:31:14 -0800322 if ((filter_mask & RTEXT_FILTER_BRVLAN) ||
323 (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) {
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000324 const struct net_port_vlans *pv;
Roopa Prabhu36cd0ff2015-01-10 07:31:14 -0800325 struct nlattr *af;
326 int err;
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000327
328 if (port)
329 pv = nbp_get_vlan_info(port);
330 else
331 pv = br_get_vlan_info(br);
332
Toshiaki Makitaef40b7e2013-08-20 17:10:18 +0900333 if (!pv || bitmap_empty(pv->vlan_bitmap, VLAN_N_VID))
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000334 goto done;
335
336 af = nla_nest_start(skb, IFLA_AF_SPEC);
337 if (!af)
338 goto nla_put_failure;
339
Roopa Prabhu36cd0ff2015-01-10 07:31:14 -0800340 if (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)
341 err = br_fill_ifvlaninfo_compressed(skb, pv);
342 else
343 err = br_fill_ifvlaninfo(skb, pv);
344 if (err)
345 goto nla_put_failure;
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000346 nla_nest_end(skb, af);
347 }
348
349done:
Johannes Berg053c0952015-01-16 22:09:00 +0100350 nlmsg_end(skb, nlh);
351 return 0;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700352
Thomas Graf74685962006-11-20 16:20:22 -0800353nla_put_failure:
Patrick McHardy26932562007-01-31 23:16:40 -0800354 nlmsg_cancel(skb, nlh);
355 return -EMSGSIZE;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700356}
357
358/*
359 * Notify listeners of a change in port information
360 */
361void br_ifinfo_notify(int event, struct net_bridge_port *port)
362{
Vlad Yasevich407af322013-02-13 12:00:12 +0000363 struct net *net;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700364 struct sk_buff *skb;
Thomas Graf280a3062006-08-15 00:36:28 -0700365 int err = -ENOBUFS;
Roopa Prabhufed0a152015-02-25 23:55:40 -0800366 u32 filter = RTEXT_FILTER_BRVLAN_COMPRESSED;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700367
Vlad Yasevich407af322013-02-13 12:00:12 +0000368 if (!port)
369 return;
370
371 net = dev_net(port->dev);
stephen hemminger28a16c92010-05-10 09:31:09 +0000372 br_debug(port->br, "port %u(%s) event %d\n",
Eric Dumazet95c96172012-04-15 05:58:06 +0000373 (unsigned int)port->port_no, port->dev->name, event);
stephen hemminger28a16c92010-05-10 09:31:09 +0000374
Roopa Prabhufed0a152015-02-25 23:55:40 -0800375 skb = nlmsg_new(br_nlmsg_size(port->dev, filter), GFP_ATOMIC);
Thomas Graf280a3062006-08-15 00:36:28 -0700376 if (skb == NULL)
377 goto errout;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700378
Roopa Prabhufed0a152015-02-25 23:55:40 -0800379 err = br_fill_ifinfo(skb, port, 0, 0, event, 0, filter, port->dev);
Patrick McHardy26932562007-01-31 23:16:40 -0800380 if (err < 0) {
381 /* -EMSGSIZE implies BUG in br_nlmsg_size() */
382 WARN_ON(err == -EMSGSIZE);
383 kfree_skb(skb);
384 goto errout;
385 }
Pablo Neira Ayuso1ce85fe2009-02-24 23:18:28 -0800386 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
387 return;
Thomas Graf280a3062006-08-15 00:36:28 -0700388errout:
tanxiaojun87e823b2013-12-19 13:28:10 +0800389 rtnl_set_sk_err(net, RTNLGRP_LINK, err);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700390}
391
Vlad Yasevich407af322013-02-13 12:00:12 +0000392
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700393/*
394 * Dump information about all ports, in response to GETLINK
395 */
John Fastabende5a55a82012-10-24 08:12:57 +0000396int br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +0200397 struct net_device *dev, u32 filter_mask, int nlflags)
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700398{
Hong Zhiguo1fb17542013-09-14 22:42:27 +0800399 struct net_bridge_port *port = br_port_get_rtnl(dev);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700400
Roopa Prabhu36cd0ff2015-01-10 07:31:14 -0800401 if (!port && !(filter_mask & RTEXT_FILTER_BRVLAN) &&
402 !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED))
Dan Carpenter1b846f92015-01-21 12:22:35 +0300403 return 0;
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000404
Nicolas Dichtel46c264d2015-04-28 18:33:49 +0200405 return br_fill_ifinfo(skb, port, pid, seq, RTM_NEWLINK, nlflags,
Dan Carpenter1b846f92015-01-21 12:22:35 +0300406 filter_mask, dev);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700407}
408
Roopa Prabhubdced7e2015-01-10 07:31:12 -0800409static int br_vlan_info(struct net_bridge *br, struct net_bridge_port *p,
410 int cmd, struct bridge_vlan_info *vinfo)
411{
412 int err = 0;
413
414 switch (cmd) {
415 case RTM_SETLINK:
416 if (p) {
417 err = nbp_vlan_add(p, vinfo->vid, vinfo->flags);
418 if (err)
419 break;
420
421 if (vinfo->flags & BRIDGE_VLAN_INFO_MASTER)
422 err = br_vlan_add(p->br, vinfo->vid,
423 vinfo->flags);
424 } else {
425 err = br_vlan_add(br, vinfo->vid, vinfo->flags);
426 }
427 break;
428
429 case RTM_DELLINK:
430 if (p) {
431 nbp_vlan_delete(p, vinfo->vid);
432 if (vinfo->flags & BRIDGE_VLAN_INFO_MASTER)
433 br_vlan_delete(p->br, vinfo->vid);
434 } else {
435 br_vlan_delete(br, vinfo->vid);
436 }
437 break;
438 }
439
440 return err;
441}
Vlad Yasevich407af322013-02-13 12:00:12 +0000442
443static int br_afspec(struct net_bridge *br,
444 struct net_bridge_port *p,
445 struct nlattr *af_spec,
446 int cmd)
447{
Roopa Prabhubdced7e2015-01-10 07:31:12 -0800448 struct bridge_vlan_info *vinfo_start = NULL;
449 struct bridge_vlan_info *vinfo = NULL;
450 struct nlattr *attr;
Vlad Yasevich407af322013-02-13 12:00:12 +0000451 int err = 0;
Roopa Prabhubdced7e2015-01-10 07:31:12 -0800452 int rem;
Vlad Yasevich407af322013-02-13 12:00:12 +0000453
Roopa Prabhubdced7e2015-01-10 07:31:12 -0800454 nla_for_each_nested(attr, af_spec, rem) {
455 if (nla_type(attr) != IFLA_BRIDGE_VLAN_INFO)
456 continue;
457 if (nla_len(attr) != sizeof(struct bridge_vlan_info))
Vlad Yasevich407af322013-02-13 12:00:12 +0000458 return -EINVAL;
Roopa Prabhubdced7e2015-01-10 07:31:12 -0800459 vinfo = nla_data(attr);
460 if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
461 if (vinfo_start)
462 return -EINVAL;
463 vinfo_start = vinfo;
464 continue;
465 }
Vlad Yasevich407af322013-02-13 12:00:12 +0000466
Roopa Prabhubdced7e2015-01-10 07:31:12 -0800467 if (vinfo_start) {
468 struct bridge_vlan_info tmp_vinfo;
469 int v;
470
471 if (!(vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END))
472 return -EINVAL;
473
474 if (vinfo->vid <= vinfo_start->vid)
475 return -EINVAL;
476
477 memcpy(&tmp_vinfo, vinfo_start,
478 sizeof(struct bridge_vlan_info));
479
480 for (v = vinfo_start->vid; v <= vinfo->vid; v++) {
481 tmp_vinfo.vid = v;
482 err = br_vlan_info(br, p, cmd, &tmp_vinfo);
Vlad Yasevich407af322013-02-13 12:00:12 +0000483 if (err)
484 break;
Roopa Prabhubdced7e2015-01-10 07:31:12 -0800485 }
486 vinfo_start = NULL;
487 } else {
488 err = br_vlan_info(br, p, cmd, vinfo);
Vlad Yasevich407af322013-02-13 12:00:12 +0000489 }
Roopa Prabhubdced7e2015-01-10 07:31:12 -0800490 if (err)
491 break;
Vlad Yasevich407af322013-02-13 12:00:12 +0000492 }
493
494 return err;
495}
496
Jiri Pirko3ac636b2014-09-05 15:51:30 +0200497static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX + 1] = {
stephen hemminger25c71c72012-11-13 07:53:05 +0000498 [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 },
stephen hemmingera2e01a62012-11-13 07:53:07 +0000502 [IFLA_BRPORT_GUARD] = { .type = NLA_U8 },
stephen hemminger1007dd12012-11-13 07:53:08 +0000503 [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 },
Thomas Graf6f705d82014-11-26 13:42:19 +0100504 [IFLA_BRPORT_FAST_LEAVE]= { .type = NLA_U8 },
Vlad Yasevich9ba18892013-06-05 10:08:00 -0400505 [IFLA_BRPORT_LEARNING] = { .type = NLA_U8 },
Vlad Yasevich867a5942013-06-05 10:08:01 -0400506 [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NLA_U8 },
stephen hemminger25c71c72012-11-13 07:53:05 +0000507};
508
509/* Change the state of the port and notify spanning tree */
510static int br_set_port_state(struct net_bridge_port *p, u8 state)
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700511{
stephen hemminger25c71c72012-11-13 07:53:05 +0000512 if (state > BR_STATE_BLOCKING)
stephen hemmingerb5ed54e2010-11-15 06:38:13 +0000513 return -EINVAL;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700514
515 /* if kernel STP is running, don't allow changes */
Stephen Hemminger9cde0702007-03-21 14:22:44 -0700516 if (p->br->stp_enabled == BR_KERNEL_STP)
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700517 return -EBUSY;
518
stephen hemminger576eb622012-12-28 18:15:22 +0000519 /* if device is not up, change is not allowed
520 * if link is not present, only allowable state is disabled
521 */
stephen hemminger25c71c72012-11-13 07:53:05 +0000522 if (!netif_running(p->dev) ||
stephen hemminger576eb622012-12-28 18:15:22 +0000523 (!netif_oper_up(p->dev) && state != BR_STATE_DISABLED))
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700524 return -ENETDOWN;
525
Florian Fainelli775dd692014-09-30 16:13:19 -0700526 br_set_state(p, state);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700527 br_log_state(p);
Vitalii Demianetsb03b6dd2011-11-25 00:16:37 +0000528 br_port_state_selection(p->br);
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700529 return 0;
530}
531
stephen hemminger25c71c72012-11-13 07:53:05 +0000532/* Set/clear or port flags based on attribute */
533static void br_set_port_flag(struct net_bridge_port *p, struct nlattr *tb[],
534 int attrtype, unsigned long mask)
535{
536 if (tb[attrtype]) {
537 u8 flag = nla_get_u8(tb[attrtype]);
538 if (flag)
539 p->flags |= mask;
540 else
541 p->flags &= ~mask;
542 }
543}
544
545/* Process bridge protocol info on port */
546static int br_setport(struct net_bridge_port *p, struct nlattr *tb[])
547{
548 int err;
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400549 unsigned long old_flags = p->flags;
stephen hemminger25c71c72012-11-13 07:53:05 +0000550
551 br_set_port_flag(p, tb, IFLA_BRPORT_MODE, BR_HAIRPIN_MODE);
stephen hemmingera2e01a62012-11-13 07:53:07 +0000552 br_set_port_flag(p, tb, IFLA_BRPORT_GUARD, BR_BPDU_GUARD);
David S. Millerc2d3bab2012-12-05 16:24:45 -0500553 br_set_port_flag(p, tb, IFLA_BRPORT_FAST_LEAVE, BR_MULTICAST_FAST_LEAVE);
Vlad Yasevich3d84fa92013-03-15 06:39:12 +0000554 br_set_port_flag(p, tb, IFLA_BRPORT_PROTECT, BR_ROOT_BLOCK);
Vlad Yasevich9ba18892013-06-05 10:08:00 -0400555 br_set_port_flag(p, tb, IFLA_BRPORT_LEARNING, BR_LEARNING);
Vlad Yasevich867a5942013-06-05 10:08:01 -0400556 br_set_port_flag(p, tb, IFLA_BRPORT_UNICAST_FLOOD, BR_FLOOD);
Kyeyoon Park95850112014-10-23 14:49:17 -0700557 br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP, BR_PROXYARP);
Jouni Malinen842a9ae2015-03-04 12:54:21 +0200558 br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP_WIFI, BR_PROXYARP_WIFI);
stephen hemminger25c71c72012-11-13 07:53:05 +0000559
560 if (tb[IFLA_BRPORT_COST]) {
561 err = br_stp_set_path_cost(p, nla_get_u32(tb[IFLA_BRPORT_COST]));
562 if (err)
563 return err;
564 }
565
566 if (tb[IFLA_BRPORT_PRIORITY]) {
567 err = br_stp_set_port_priority(p, nla_get_u16(tb[IFLA_BRPORT_PRIORITY]));
568 if (err)
569 return err;
570 }
571
572 if (tb[IFLA_BRPORT_STATE]) {
573 err = br_set_port_state(p, nla_get_u8(tb[IFLA_BRPORT_STATE]));
574 if (err)
575 return err;
576 }
Vlad Yaseviche028e4b2014-05-16 09:59:16 -0400577
578 br_port_flags_change(p, old_flags ^ p->flags);
stephen hemminger25c71c72012-11-13 07:53:05 +0000579 return 0;
580}
581
582/* Change state and parameters on port. */
Roopa Prabhuadd511b2015-01-29 22:40:12 -0800583int br_setlink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags)
stephen hemminger25c71c72012-11-13 07:53:05 +0000584{
stephen hemminger25c71c72012-11-13 07:53:05 +0000585 struct nlattr *protinfo;
Vlad Yasevich407af322013-02-13 12:00:12 +0000586 struct nlattr *afspec;
stephen hemminger25c71c72012-11-13 07:53:05 +0000587 struct net_bridge_port *p;
Dan Carpenter2062cc22012-12-07 01:10:46 +0000588 struct nlattr *tb[IFLA_BRPORT_MAX + 1];
Roopa Prabhu68e331c2015-01-29 22:40:14 -0800589 int err = 0, ret_offload = 0;
stephen hemminger25c71c72012-11-13 07:53:05 +0000590
Hong zhi guoc60ee672013-03-28 06:21:22 +0000591 protinfo = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_PROTINFO);
592 afspec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Vlad Yasevich407af322013-02-13 12:00:12 +0000593 if (!protinfo && !afspec)
stephen hemminger25c71c72012-11-13 07:53:05 +0000594 return 0;
595
596 p = br_port_get_rtnl(dev);
Vlad Yasevich407af322013-02-13 12:00:12 +0000597 /* We want to accept dev as bridge itself if the AF_SPEC
stephen hemminger8e3bff92013-12-08 12:15:44 -0800598 * is set to see if someone is setting vlan info on the bridge
Vlad Yasevich407af322013-02-13 12:00:12 +0000599 */
Hong zhi guo7b99a992013-03-24 03:26:47 +0000600 if (!p && !afspec)
stephen hemminger25c71c72012-11-13 07:53:05 +0000601 return -EINVAL;
602
Vlad Yasevich407af322013-02-13 12:00:12 +0000603 if (p && protinfo) {
604 if (protinfo->nla_type & NLA_F_NESTED) {
605 err = nla_parse_nested(tb, IFLA_BRPORT_MAX,
Jiri Pirko3ac636b2014-09-05 15:51:30 +0200606 protinfo, br_port_policy);
Vlad Yasevich407af322013-02-13 12:00:12 +0000607 if (err)
608 return err;
609
610 spin_lock_bh(&p->br->lock);
611 err = br_setport(p, tb);
612 spin_unlock_bh(&p->br->lock);
613 } else {
stephen hemminger8e3bff92013-12-08 12:15:44 -0800614 /* Binary compatibility with old RSTP */
Vlad Yasevich407af322013-02-13 12:00:12 +0000615 if (nla_len(protinfo) < sizeof(u8))
616 return -EINVAL;
617
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);
621 }
stephen hemminger25c71c72012-11-13 07:53:05 +0000622 if (err)
Vlad Yasevich407af322013-02-13 12:00:12 +0000623 goto out;
624 }
stephen hemminger25c71c72012-11-13 07:53:05 +0000625
Vlad Yasevich407af322013-02-13 12:00:12 +0000626 if (afspec) {
627 err = br_afspec((struct net_bridge *)netdev_priv(dev), p,
628 afspec, RTM_SETLINK);
stephen hemminger25c71c72012-11-13 07:53:05 +0000629 }
630
Roopa Prabhu1fd0bdd2015-02-05 22:24:45 -0800631 if (p && !(flags & BRIDGE_FLAGS_SELF)) {
Roopa Prabhu68e331c2015-01-29 22:40:14 -0800632 /* set bridge attributes in hardware if supported
633 */
634 ret_offload = netdev_switch_port_bridge_setlink(dev, nlh,
635 flags);
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);
639 }
640
stephen hemminger25c71c72012-11-13 07:53:05 +0000641 if (err == 0)
642 br_ifinfo_notify(RTM_NEWLINK, p);
Vlad Yasevich407af322013-02-13 12:00:12 +0000643out:
stephen hemminger25c71c72012-11-13 07:53:05 +0000644 return err;
645}
646
Vlad Yasevich407af322013-02-13 12:00:12 +0000647/* Delete port information */
Roopa Prabhuadd511b2015-01-29 22:40:12 -0800648int br_dellink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags)
Vlad Yasevich407af322013-02-13 12:00:12 +0000649{
Vlad Yasevich407af322013-02-13 12:00:12 +0000650 struct nlattr *afspec;
651 struct net_bridge_port *p;
Roopa Prabhu68e331c2015-01-29 22:40:14 -0800652 int err = 0, ret_offload = 0;
Vlad Yasevich407af322013-02-13 12:00:12 +0000653
Hong zhi guoc60ee672013-03-28 06:21:22 +0000654 afspec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Vlad Yasevich407af322013-02-13 12:00:12 +0000655 if (!afspec)
656 return 0;
657
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))
661 return -EINVAL;
662
663 err = br_afspec((struct net_bridge *)netdev_priv(dev), p,
664 afspec, RTM_DELLINK);
Roopa Prabhu02dba432015-01-14 20:02:25 -0800665 if (err == 0)
666 /* Send RTM_NEWLINK because userspace
667 * expects RTM_NEWLINK for vlan dels
668 */
669 br_ifinfo_notify(RTM_NEWLINK, p);
Vlad Yasevich407af322013-02-13 12:00:12 +0000670
Roopa Prabhu1fd0bdd2015-02-05 22:24:45 -0800671 if (p && !(flags & BRIDGE_FLAGS_SELF)) {
Roopa Prabhu68e331c2015-01-29 22:40:14 -0800672 /* del bridge attributes in hardware
673 */
674 ret_offload = netdev_switch_port_bridge_dellink(dev, nlh,
675 flags);
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);
679 }
680
Vlad Yasevich407af322013-02-13 12:00:12 +0000681 return err;
682}
stephen hemmingerbb900b22011-04-04 14:03:32 +0000683static int br_validate(struct nlattr *tb[], struct nlattr *data[])
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700684{
stephen hemmingerbb900b22011-04-04 14:03:32 +0000685 if (tb[IFLA_ADDRESS]) {
686 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
687 return -EINVAL;
688 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
689 return -EADDRNOTAVAIL;
690 }
Thomas Graf32fe21c2007-03-22 11:59:03 -0700691
692 return 0;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700693}
694
Toshiaki Makita30313a32014-04-25 17:01:18 +0900695static int br_dev_newlink(struct net *src_net, struct net_device *dev,
696 struct nlattr *tb[], struct nlattr *data[])
697{
698 struct net_bridge *br = netdev_priv(dev);
699
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);
704 }
705
706 return register_netdevice(dev);
707}
708
Jiri Pirko3ac636b2014-09-05 15:51:30 +0200709static int br_port_slave_changelink(struct net_device *brdev,
710 struct net_device *dev,
711 struct nlattr *tb[],
712 struct nlattr *data[])
713{
714 if (!data)
715 return 0;
716 return br_setport(br_port_get_rtnl(dev), data);
717}
718
Jiri Pirkoced82832014-09-05 15:51:29 +0200719static int br_port_fill_slave_info(struct sk_buff *skb,
720 const struct net_device *brdev,
721 const struct net_device *dev)
722{
723 return br_port_fill_attrs(skb, br_port_get_rtnl(dev));
724}
725
726static size_t br_port_get_slave_size(const struct net_device *brdev,
727 const struct net_device *dev)
728{
729 return br_port_info_size();
730}
731
Jiri Pirko13323512014-09-05 15:51:32 +0200732static 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 },
Jörg Thalheimaf615762015-03-18 10:06:58 +0100736 [IFLA_BR_AGEING_TIME] = { .type = NLA_U32 },
737 [IFLA_BR_STP_STATE] = { .type = NLA_U32 },
738 [IFLA_BR_PRIORITY] = { .type = NLA_U16 },
Jiri Pirko13323512014-09-05 15:51:32 +0200739};
740
741static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
742 struct nlattr *data[])
743{
744 struct net_bridge *br = netdev_priv(brdev);
745 int err;
746
747 if (!data)
748 return 0;
749
750 if (data[IFLA_BR_FORWARD_DELAY]) {
751 err = br_set_forward_delay(br, nla_get_u32(data[IFLA_BR_FORWARD_DELAY]));
752 if (err)
753 return err;
754 }
755
756 if (data[IFLA_BR_HELLO_TIME]) {
757 err = br_set_hello_time(br, nla_get_u32(data[IFLA_BR_HELLO_TIME]));
758 if (err)
759 return err;
760 }
761
762 if (data[IFLA_BR_MAX_AGE]) {
763 err = br_set_max_age(br, nla_get_u32(data[IFLA_BR_MAX_AGE]));
764 if (err)
765 return err;
766 }
767
Jörg Thalheimaf615762015-03-18 10:06:58 +0100768 if (data[IFLA_BR_AGEING_TIME]) {
769 u32 ageing_time = nla_get_u32(data[IFLA_BR_AGEING_TIME]);
770
771 br->ageing_time = clock_t_to_jiffies(ageing_time);
772 }
773
774 if (data[IFLA_BR_STP_STATE]) {
775 u32 stp_enabled = nla_get_u32(data[IFLA_BR_STP_STATE]);
776
777 br_stp_set_enabled(br, stp_enabled);
778 }
779
780 if (data[IFLA_BR_PRIORITY]) {
781 u32 priority = nla_get_u16(data[IFLA_BR_PRIORITY]);
782
783 br_stp_set_bridge_priority(br, priority);
784 }
785
Jiri Pirko13323512014-09-05 15:51:32 +0200786 return 0;
787}
788
Jiri Pirkoe5c3ea52014-09-05 15:51:31 +0200789static size_t br_get_size(const struct net_device *brdev)
790{
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 */
Jörg Thalheimaf615762015-03-18 10:06:58 +0100794 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 */
Jiri Pirkoe5c3ea52014-09-05 15:51:31 +0200797 0;
798}
799
800static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
801{
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);
Jörg Thalheimaf615762015-03-18 10:06:58 +0100806 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];
Jiri Pirkoe5c3ea52014-09-05 15:51:31 +0200809
810 if (nla_put_u32(skb, IFLA_BR_FORWARD_DELAY, forward_delay) ||
811 nla_put_u32(skb, IFLA_BR_HELLO_TIME, hello_time) ||
Jörg Thalheimaf615762015-03-18 10:06:58 +0100812 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))
Jiri Pirkoe5c3ea52014-09-05 15:51:31 +0200816 return -EMSGSIZE;
817
818 return 0;
819}
820
Roopa Prabhufed0a152015-02-25 23:55:40 -0800821static size_t br_get_link_af_size(const struct net_device *dev)
822{
823 struct net_port_vlans *pv;
824
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));
829 else
830 return 0;
831
832 if (!pv)
833 return 0;
834
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));
837}
838
Daniel Borkmann207895f2015-01-29 12:15:03 +0100839static struct rtnl_af_ops br_af_ops __read_mostly = {
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000840 .family = AF_BRIDGE,
841 .get_link_af_size = br_get_link_af_size,
842};
843
stephen hemminger149ddd82012-06-26 05:48:45 +0000844struct rtnl_link_ops br_link_ops __read_mostly = {
Jiri Pirkoced82832014-09-05 15:51:29 +0200845 .kind = "bridge",
846 .priv_size = sizeof(struct net_bridge),
847 .setup = br_dev_setup,
Jiri Pirko13323512014-09-05 15:51:32 +0200848 .maxtype = IFLA_BRPORT_MAX,
849 .policy = br_policy,
Jiri Pirkoced82832014-09-05 15:51:29 +0200850 .validate = br_validate,
851 .newlink = br_dev_newlink,
Jiri Pirko13323512014-09-05 15:51:32 +0200852 .changelink = br_changelink,
Jiri Pirkoced82832014-09-05 15:51:29 +0200853 .dellink = br_dev_delete,
Jiri Pirkoe5c3ea52014-09-05 15:51:31 +0200854 .get_size = br_get_size,
855 .fill_info = br_fill_info,
Jiri Pirko3ac636b2014-09-05 15:51:30 +0200856
857 .slave_maxtype = IFLA_BRPORT_MAX,
858 .slave_policy = br_port_policy,
859 .slave_changelink = br_port_slave_changelink,
Jiri Pirkoced82832014-09-05 15:51:29 +0200860 .get_slave_size = br_port_get_slave_size,
861 .fill_slave_info = br_port_fill_slave_info,
stephen hemmingerbb900b22011-04-04 14:03:32 +0000862};
863
864int __init br_netlink_init(void)
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700865{
Vlad Yasevich3ec8e9f2013-01-02 09:41:25 +0000866 int err;
867
868 br_mdb_init();
stephen hemminger3678a9d2013-12-30 10:41:32 -0800869 rtnl_af_register(&br_af_ops);
Vlad Yasevich3ec8e9f2013-01-02 09:41:25 +0000870
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000871 err = rtnl_link_register(&br_link_ops);
872 if (err)
873 goto out_af;
874
Vlad Yasevich3ec8e9f2013-01-02 09:41:25 +0000875 return 0;
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000876
877out_af:
878 rtnl_af_unregister(&br_af_ops);
Vlad Yasevich3ec8e9f2013-01-02 09:41:25 +0000879 br_mdb_uninit();
880 return err;
Stephen Hemminger11dc1f32006-05-25 16:00:12 -0700881}
882
Pablo Neira Ayuso34666d42014-09-18 11:29:03 +0200883void br_netlink_fini(void)
stephen hemmingerbb900b22011-04-04 14:03:32 +0000884{
Vlad Yasevich3ec8e9f2013-01-02 09:41:25 +0000885 br_mdb_uninit();
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000886 rtnl_af_unregister(&br_af_ops);
stephen hemmingerbb900b22011-04-04 14:03:32 +0000887 rtnl_link_unregister(&br_link_ops);
stephen hemmingerbb900b22011-04-04 14:03:32 +0000888}