Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 2 | #include <linux/err.h> |
| 3 | #include <linux/igmp.h> |
| 4 | #include <linux/kernel.h> |
| 5 | #include <linux/netdevice.h> |
| 6 | #include <linux/rculist.h> |
| 7 | #include <linux/skbuff.h> |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 8 | #include <linux/if_ether.h> |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 9 | #include <net/ip.h> |
| 10 | #include <net/netlink.h> |
Elad Raz | f1fecb1 | 2016-01-10 21:06:23 +0100 | [diff] [blame] | 11 | #include <net/switchdev.h> |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 12 | #if IS_ENABLED(CONFIG_IPV6) |
| 13 | #include <net/ipv6.h> |
Linus Lüssing | 3c3769e | 2013-09-04 02:13:39 +0200 | [diff] [blame] | 14 | #include <net/addrconf.h> |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 15 | #endif |
| 16 | |
| 17 | #include "br_private.h" |
| 18 | |
| 19 | static int br_rports_fill_info(struct sk_buff *skb, struct netlink_callback *cb, |
| 20 | struct net_device *dev) |
| 21 | { |
| 22 | struct net_bridge *br = netdev_priv(dev); |
| 23 | struct net_bridge_port *p; |
Nikolay Aleksandrov | 59f78f9 | 2016-02-26 21:20:04 +0100 | [diff] [blame] | 24 | struct nlattr *nest, *port_nest; |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 25 | |
| 26 | if (!br->multicast_router || hlist_empty(&br->router_list)) |
| 27 | return 0; |
| 28 | |
| 29 | nest = nla_nest_start(skb, MDBA_ROUTER); |
| 30 | if (nest == NULL) |
| 31 | return -EMSGSIZE; |
| 32 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 33 | hlist_for_each_entry_rcu(p, &br->router_list, rlist) { |
Nikolay Aleksandrov | 59f78f9 | 2016-02-26 21:20:04 +0100 | [diff] [blame] | 34 | if (!p) |
| 35 | continue; |
| 36 | port_nest = nla_nest_start(skb, MDBA_ROUTER_PORT); |
| 37 | if (!port_nest) |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 38 | goto fail; |
Nikolay Aleksandrov | 59f78f9 | 2016-02-26 21:20:04 +0100 | [diff] [blame] | 39 | if (nla_put_nohdr(skb, sizeof(u32), &p->dev->ifindex) || |
| 40 | nla_put_u32(skb, MDBA_ROUTER_PATTR_TIMER, |
| 41 | br_timer_value(&p->multicast_router_timer)) || |
| 42 | nla_put_u8(skb, MDBA_ROUTER_PATTR_TYPE, |
| 43 | p->multicast_router)) { |
| 44 | nla_nest_cancel(skb, port_nest); |
| 45 | goto fail; |
| 46 | } |
| 47 | nla_nest_end(skb, port_nest); |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | nla_nest_end(skb, nest); |
| 51 | return 0; |
| 52 | fail: |
| 53 | nla_nest_cancel(skb, nest); |
| 54 | return -EMSGSIZE; |
| 55 | } |
| 56 | |
Elad Raz | 9d06b6d | 2016-02-03 09:57:05 +0100 | [diff] [blame] | 57 | static void __mdb_entry_fill_flags(struct br_mdb_entry *e, unsigned char flags) |
| 58 | { |
| 59 | e->state = flags & MDB_PG_FLAGS_PERMANENT; |
| 60 | e->flags = 0; |
| 61 | if (flags & MDB_PG_FLAGS_OFFLOAD) |
| 62 | e->flags |= MDB_FLAGS_OFFLOAD; |
| 63 | } |
| 64 | |
Elad Raz | 6dd684c | 2016-04-21 12:52:44 +0200 | [diff] [blame] | 65 | static void __mdb_entry_to_br_ip(struct br_mdb_entry *entry, struct br_ip *ip) |
| 66 | { |
| 67 | memset(ip, 0, sizeof(struct br_ip)); |
| 68 | ip->vid = entry->vid; |
| 69 | ip->proto = entry->addr.proto; |
| 70 | if (ip->proto == htons(ETH_P_IP)) |
| 71 | ip->u.ip4 = entry->addr.u.ip4; |
| 72 | #if IS_ENABLED(CONFIG_IPV6) |
| 73 | else |
| 74 | ip->u.ip6 = entry->addr.u.ip6; |
| 75 | #endif |
| 76 | } |
| 77 | |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 78 | static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb, |
| 79 | struct net_device *dev) |
| 80 | { |
| 81 | struct net_bridge *br = netdev_priv(dev); |
| 82 | struct net_bridge_mdb_htable *mdb; |
| 83 | struct nlattr *nest, *nest2; |
| 84 | int i, err = 0; |
| 85 | int idx = 0, s_idx = cb->args[1]; |
| 86 | |
| 87 | if (br->multicast_disabled) |
| 88 | return 0; |
| 89 | |
| 90 | mdb = rcu_dereference(br->mdb); |
| 91 | if (!mdb) |
| 92 | return 0; |
| 93 | |
| 94 | nest = nla_nest_start(skb, MDBA_MDB); |
| 95 | if (nest == NULL) |
| 96 | return -EMSGSIZE; |
| 97 | |
| 98 | for (i = 0; i < mdb->max; i++) { |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 99 | struct net_bridge_mdb_entry *mp; |
stephen hemminger | 762a3d8 | 2013-08-04 17:19:38 -0700 | [diff] [blame] | 100 | struct net_bridge_port_group *p; |
| 101 | struct net_bridge_port_group __rcu **pp; |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 102 | struct net_bridge_port *port; |
| 103 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 104 | hlist_for_each_entry_rcu(mp, &mdb->mhash[i], hlist[mdb->ver]) { |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 105 | if (idx < s_idx) |
| 106 | goto skip; |
| 107 | |
| 108 | nest2 = nla_nest_start(skb, MDBA_MDB_ENTRY); |
| 109 | if (nest2 == NULL) { |
| 110 | err = -EMSGSIZE; |
| 111 | goto out; |
| 112 | } |
| 113 | |
| 114 | for (pp = &mp->ports; |
| 115 | (p = rcu_dereference(*pp)) != NULL; |
| 116 | pp = &p->next) { |
Nikolay Aleksandrov | 2125715 | 2016-02-16 12:46:54 +0100 | [diff] [blame] | 117 | struct nlattr *nest_ent; |
Nikolay Aleksandrov | 76cc173 | 2016-02-16 12:46:53 +0100 | [diff] [blame] | 118 | struct br_mdb_entry e; |
| 119 | |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 120 | port = p->port; |
Nikolay Aleksandrov | 76cc173 | 2016-02-16 12:46:53 +0100 | [diff] [blame] | 121 | if (!port) |
| 122 | continue; |
Nikolay Aleksandrov | 2125715 | 2016-02-16 12:46:54 +0100 | [diff] [blame] | 123 | |
Nikolay Aleksandrov | 76cc173 | 2016-02-16 12:46:53 +0100 | [diff] [blame] | 124 | memset(&e, 0, sizeof(e)); |
| 125 | e.ifindex = port->dev->ifindex; |
| 126 | e.vid = p->addr.vid; |
| 127 | __mdb_entry_fill_flags(&e, p->flags); |
| 128 | if (p->addr.proto == htons(ETH_P_IP)) |
| 129 | e.addr.u.ip4 = p->addr.u.ip4; |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 130 | #if IS_ENABLED(CONFIG_IPV6) |
Nikolay Aleksandrov | 76cc173 | 2016-02-16 12:46:53 +0100 | [diff] [blame] | 131 | if (p->addr.proto == htons(ETH_P_IPV6)) |
| 132 | e.addr.u.ip6 = p->addr.u.ip6; |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 133 | #endif |
Nikolay Aleksandrov | 76cc173 | 2016-02-16 12:46:53 +0100 | [diff] [blame] | 134 | e.addr.proto = p->addr.proto; |
Nikolay Aleksandrov | 2125715 | 2016-02-16 12:46:54 +0100 | [diff] [blame] | 135 | nest_ent = nla_nest_start(skb, |
| 136 | MDBA_MDB_ENTRY_INFO); |
| 137 | if (!nest_ent) { |
Nikolay Aleksandrov | 76cc173 | 2016-02-16 12:46:53 +0100 | [diff] [blame] | 138 | nla_nest_cancel(skb, nest2); |
| 139 | err = -EMSGSIZE; |
| 140 | goto out; |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 141 | } |
Nikolay Aleksandrov | 2125715 | 2016-02-16 12:46:54 +0100 | [diff] [blame] | 142 | if (nla_put_nohdr(skb, sizeof(e), &e) || |
| 143 | nla_put_u32(skb, |
| 144 | MDBA_MDB_EATTR_TIMER, |
| 145 | br_timer_value(&p->timer))) { |
| 146 | nla_nest_cancel(skb, nest_ent); |
| 147 | nla_nest_cancel(skb, nest2); |
| 148 | err = -EMSGSIZE; |
| 149 | goto out; |
| 150 | } |
| 151 | nla_nest_end(skb, nest_ent); |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 152 | } |
| 153 | nla_nest_end(skb, nest2); |
| 154 | skip: |
| 155 | idx++; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | out: |
| 160 | cb->args[1] = idx; |
| 161 | nla_nest_end(skb, nest); |
| 162 | return err; |
| 163 | } |
| 164 | |
| 165 | static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb) |
| 166 | { |
| 167 | struct net_device *dev; |
| 168 | struct net *net = sock_net(skb->sk); |
| 169 | struct nlmsghdr *nlh = NULL; |
| 170 | int idx = 0, s_idx; |
| 171 | |
| 172 | s_idx = cb->args[0]; |
| 173 | |
| 174 | rcu_read_lock(); |
| 175 | |
Cong Wang | 2ce297f | 2012-12-10 02:15:35 +0000 | [diff] [blame] | 176 | /* In theory this could be wrapped to 0... */ |
| 177 | cb->seq = net->dev_base_seq + br_mdb_rehash_seq; |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 178 | |
| 179 | for_each_netdev_rcu(net, dev) { |
| 180 | if (dev->priv_flags & IFF_EBRIDGE) { |
| 181 | struct br_port_msg *bpm; |
| 182 | |
| 183 | if (idx < s_idx) |
| 184 | goto skip; |
| 185 | |
| 186 | nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, |
| 187 | cb->nlh->nlmsg_seq, RTM_GETMDB, |
| 188 | sizeof(*bpm), NLM_F_MULTI); |
| 189 | if (nlh == NULL) |
| 190 | break; |
| 191 | |
| 192 | bpm = nlmsg_data(nlh); |
Mathias Krause | c085c49 | 2013-03-09 05:52:19 +0000 | [diff] [blame] | 193 | memset(bpm, 0, sizeof(*bpm)); |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 194 | bpm->ifindex = dev->ifindex; |
| 195 | if (br_mdb_fill_info(skb, cb, dev) < 0) |
| 196 | goto out; |
| 197 | if (br_rports_fill_info(skb, cb, dev) < 0) |
| 198 | goto out; |
| 199 | |
| 200 | cb->args[1] = 0; |
| 201 | nlmsg_end(skb, nlh); |
| 202 | skip: |
| 203 | idx++; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | out: |
| 208 | if (nlh) |
| 209 | nlmsg_end(skb, nlh); |
| 210 | rcu_read_unlock(); |
| 211 | cb->args[0] = idx; |
| 212 | return skb->len; |
| 213 | } |
| 214 | |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 215 | static int nlmsg_populate_mdb_fill(struct sk_buff *skb, |
| 216 | struct net_device *dev, |
| 217 | struct br_mdb_entry *entry, u32 pid, |
| 218 | u32 seq, int type, unsigned int flags) |
| 219 | { |
| 220 | struct nlmsghdr *nlh; |
| 221 | struct br_port_msg *bpm; |
| 222 | struct nlattr *nest, *nest2; |
| 223 | |
Nicolas Dichtel | 8219967 | 2015-04-28 18:33:48 +0200 | [diff] [blame] | 224 | nlh = nlmsg_put(skb, pid, seq, type, sizeof(*bpm), 0); |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 225 | if (!nlh) |
| 226 | return -EMSGSIZE; |
| 227 | |
| 228 | bpm = nlmsg_data(nlh); |
Mathias Krause | c085c49 | 2013-03-09 05:52:19 +0000 | [diff] [blame] | 229 | memset(bpm, 0, sizeof(*bpm)); |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 230 | bpm->family = AF_BRIDGE; |
| 231 | bpm->ifindex = dev->ifindex; |
| 232 | nest = nla_nest_start(skb, MDBA_MDB); |
| 233 | if (nest == NULL) |
| 234 | goto cancel; |
| 235 | nest2 = nla_nest_start(skb, MDBA_MDB_ENTRY); |
| 236 | if (nest2 == NULL) |
| 237 | goto end; |
| 238 | |
| 239 | if (nla_put(skb, MDBA_MDB_ENTRY_INFO, sizeof(*entry), entry)) |
| 240 | goto end; |
| 241 | |
| 242 | nla_nest_end(skb, nest2); |
| 243 | nla_nest_end(skb, nest); |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 244 | nlmsg_end(skb, nlh); |
| 245 | return 0; |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 246 | |
| 247 | end: |
| 248 | nla_nest_end(skb, nest); |
| 249 | cancel: |
| 250 | nlmsg_cancel(skb, nlh); |
| 251 | return -EMSGSIZE; |
| 252 | } |
| 253 | |
| 254 | static inline size_t rtnl_mdb_nlmsg_size(void) |
| 255 | { |
| 256 | return NLMSG_ALIGN(sizeof(struct br_port_msg)) |
| 257 | + nla_total_size(sizeof(struct br_mdb_entry)); |
| 258 | } |
| 259 | |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 260 | struct br_mdb_complete_info { |
| 261 | struct net_bridge_port *port; |
| 262 | struct br_ip ip; |
| 263 | }; |
| 264 | |
| 265 | static void br_mdb_complete(struct net_device *dev, int err, void *priv) |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 266 | { |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 267 | struct br_mdb_complete_info *data = priv; |
| 268 | struct net_bridge_port_group __rcu **pp; |
| 269 | struct net_bridge_port_group *p; |
| 270 | struct net_bridge_mdb_htable *mdb; |
| 271 | struct net_bridge_mdb_entry *mp; |
| 272 | struct net_bridge_port *port = data->port; |
| 273 | struct net_bridge *br = port->br; |
| 274 | |
| 275 | if (err) |
| 276 | goto err; |
| 277 | |
| 278 | spin_lock_bh(&br->multicast_lock); |
| 279 | mdb = mlock_dereference(br->mdb, br); |
| 280 | mp = br_mdb_ip_get(mdb, &data->ip); |
| 281 | if (!mp) |
| 282 | goto out; |
| 283 | for (pp = &mp->ports; (p = mlock_dereference(*pp, br)) != NULL; |
| 284 | pp = &p->next) { |
| 285 | if (p->port != port) |
| 286 | continue; |
| 287 | p->flags |= MDB_PG_FLAGS_OFFLOAD; |
| 288 | } |
| 289 | out: |
| 290 | spin_unlock_bh(&br->multicast_lock); |
| 291 | err: |
| 292 | kfree(priv); |
| 293 | } |
| 294 | |
Andrew Lunn | 47d5b6d | 2017-11-09 23:10:59 +0100 | [diff] [blame] | 295 | static void br_mdb_switchdev_host_port(struct net_device *dev, |
| 296 | struct net_device *lower_dev, |
| 297 | struct br_mdb_entry *entry, int type) |
| 298 | { |
| 299 | struct switchdev_obj_port_mdb mdb = { |
| 300 | .obj = { |
| 301 | .id = SWITCHDEV_OBJ_ID_HOST_MDB, |
| 302 | .flags = SWITCHDEV_F_DEFER, |
| 303 | }, |
| 304 | .vid = entry->vid, |
| 305 | }; |
| 306 | |
| 307 | if (entry->addr.proto == htons(ETH_P_IP)) |
| 308 | ip_eth_mc_map(entry->addr.u.ip4, mdb.addr); |
| 309 | #if IS_ENABLED(CONFIG_IPV6) |
| 310 | else |
| 311 | ipv6_eth_mc_map(&entry->addr.u.ip6, mdb.addr); |
| 312 | #endif |
| 313 | |
| 314 | mdb.obj.orig_dev = dev; |
| 315 | switch (type) { |
| 316 | case RTM_NEWMDB: |
| 317 | switchdev_port_obj_add(lower_dev, &mdb.obj); |
| 318 | break; |
| 319 | case RTM_DELMDB: |
| 320 | switchdev_port_obj_del(lower_dev, &mdb.obj); |
| 321 | break; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | static void br_mdb_switchdev_host(struct net_device *dev, |
| 326 | struct br_mdb_entry *entry, int type) |
| 327 | { |
| 328 | struct net_device *lower_dev; |
| 329 | struct list_head *iter; |
| 330 | |
| 331 | netdev_for_each_lower_dev(dev, lower_dev, iter) |
| 332 | br_mdb_switchdev_host_port(dev, lower_dev, entry, type); |
| 333 | } |
| 334 | |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 335 | static void __br_mdb_notify(struct net_device *dev, struct net_bridge_port *p, |
| 336 | struct br_mdb_entry *entry, int type) |
| 337 | { |
| 338 | struct br_mdb_complete_info *complete_info; |
Elad Raz | f1fecb1 | 2016-01-10 21:06:23 +0100 | [diff] [blame] | 339 | struct switchdev_obj_port_mdb mdb = { |
| 340 | .obj = { |
| 341 | .id = SWITCHDEV_OBJ_ID_PORT_MDB, |
| 342 | .flags = SWITCHDEV_F_DEFER, |
| 343 | }, |
| 344 | .vid = entry->vid, |
| 345 | }; |
| 346 | struct net_device *port_dev; |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 347 | struct net *net = dev_net(dev); |
| 348 | struct sk_buff *skb; |
| 349 | int err = -ENOBUFS; |
| 350 | |
Elad Raz | f1fecb1 | 2016-01-10 21:06:23 +0100 | [diff] [blame] | 351 | port_dev = __dev_get_by_index(net, entry->ifindex); |
| 352 | if (entry->addr.proto == htons(ETH_P_IP)) |
| 353 | ip_eth_mc_map(entry->addr.u.ip4, mdb.addr); |
| 354 | #if IS_ENABLED(CONFIG_IPV6) |
| 355 | else |
| 356 | ipv6_eth_mc_map(&entry->addr.u.ip6, mdb.addr); |
| 357 | #endif |
| 358 | |
| 359 | mdb.obj.orig_dev = port_dev; |
Andrew Lunn | 2a26028 | 2017-11-09 23:10:58 +0100 | [diff] [blame] | 360 | if (p && port_dev && type == RTM_NEWMDB) { |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 361 | complete_info = kmalloc(sizeof(*complete_info), GFP_ATOMIC); |
| 362 | if (complete_info) { |
| 363 | complete_info->port = p; |
| 364 | __mdb_entry_to_br_ip(entry, &complete_info->ip); |
| 365 | mdb.obj.complete_priv = complete_info; |
| 366 | mdb.obj.complete = br_mdb_complete; |
Eduardo Valentin | 1bfb159 | 2017-07-11 14:55:12 -0700 | [diff] [blame] | 367 | if (switchdev_port_obj_add(port_dev, &mdb.obj)) |
| 368 | kfree(complete_info); |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 369 | } |
Andrew Lunn | 2a26028 | 2017-11-09 23:10:58 +0100 | [diff] [blame] | 370 | } else if (p && port_dev && type == RTM_DELMDB) { |
Elad Raz | f1fecb1 | 2016-01-10 21:06:23 +0100 | [diff] [blame] | 371 | switchdev_port_obj_del(port_dev, &mdb.obj); |
Elad Raz | 9e8430f | 2016-02-03 09:57:06 +0100 | [diff] [blame] | 372 | } |
Elad Raz | f1fecb1 | 2016-01-10 21:06:23 +0100 | [diff] [blame] | 373 | |
Andrew Lunn | 47d5b6d | 2017-11-09 23:10:59 +0100 | [diff] [blame] | 374 | if (!p) |
| 375 | br_mdb_switchdev_host(dev, entry, type); |
| 376 | |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 377 | skb = nlmsg_new(rtnl_mdb_nlmsg_size(), GFP_ATOMIC); |
| 378 | if (!skb) |
| 379 | goto errout; |
| 380 | |
| 381 | err = nlmsg_populate_mdb_fill(skb, dev, entry, 0, 0, type, NTF_SELF); |
| 382 | if (err < 0) { |
| 383 | kfree_skb(skb); |
| 384 | goto errout; |
| 385 | } |
| 386 | |
| 387 | rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_ATOMIC); |
| 388 | return; |
| 389 | errout: |
| 390 | rtnl_set_sk_err(net, RTNLGRP_MDB, err); |
| 391 | } |
| 392 | |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 393 | void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port, |
| 394 | struct br_ip *group, int type, u8 flags) |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 395 | { |
| 396 | struct br_mdb_entry entry; |
| 397 | |
Mathias Krause | c085c49 | 2013-03-09 05:52:19 +0000 | [diff] [blame] | 398 | memset(&entry, 0, sizeof(entry)); |
Andrew Lunn | 2a26028 | 2017-11-09 23:10:58 +0100 | [diff] [blame] | 399 | if (port) |
| 400 | entry.ifindex = port->dev->ifindex; |
| 401 | else |
| 402 | entry.ifindex = dev->ifindex; |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 403 | entry.addr.proto = group->proto; |
| 404 | entry.addr.u.ip4 = group->u.ip4; |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 405 | #if IS_ENABLED(CONFIG_IPV6) |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 406 | entry.addr.u.ip6 = group->u.ip6; |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 407 | #endif |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 408 | entry.vid = group->vid; |
| 409 | __mdb_entry_fill_flags(&entry, flags); |
| 410 | __br_mdb_notify(dev, port, &entry, type); |
Cong Wang | 37a393b | 2012-12-11 22:23:07 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Satish Ashok | 949f1e3 | 2015-07-23 05:00:53 -0700 | [diff] [blame] | 413 | static int nlmsg_populate_rtr_fill(struct sk_buff *skb, |
| 414 | struct net_device *dev, |
| 415 | int ifindex, u32 pid, |
| 416 | u32 seq, int type, unsigned int flags) |
| 417 | { |
| 418 | struct br_port_msg *bpm; |
| 419 | struct nlmsghdr *nlh; |
| 420 | struct nlattr *nest; |
| 421 | |
Nicolas Dichtel | f57fd58 | 2019-09-06 11:47:02 +0200 | [diff] [blame] | 422 | nlh = nlmsg_put(skb, pid, seq, type, sizeof(*bpm), 0); |
Satish Ashok | 949f1e3 | 2015-07-23 05:00:53 -0700 | [diff] [blame] | 423 | if (!nlh) |
| 424 | return -EMSGSIZE; |
| 425 | |
| 426 | bpm = nlmsg_data(nlh); |
| 427 | memset(bpm, 0, sizeof(*bpm)); |
| 428 | bpm->family = AF_BRIDGE; |
| 429 | bpm->ifindex = dev->ifindex; |
| 430 | nest = nla_nest_start(skb, MDBA_ROUTER); |
| 431 | if (!nest) |
| 432 | goto cancel; |
| 433 | |
| 434 | if (nla_put_u32(skb, MDBA_ROUTER_PORT, ifindex)) |
| 435 | goto end; |
| 436 | |
| 437 | nla_nest_end(skb, nest); |
| 438 | nlmsg_end(skb, nlh); |
| 439 | return 0; |
| 440 | |
| 441 | end: |
| 442 | nla_nest_end(skb, nest); |
| 443 | cancel: |
| 444 | nlmsg_cancel(skb, nlh); |
| 445 | return -EMSGSIZE; |
| 446 | } |
| 447 | |
| 448 | static inline size_t rtnl_rtr_nlmsg_size(void) |
| 449 | { |
| 450 | return NLMSG_ALIGN(sizeof(struct br_port_msg)) |
| 451 | + nla_total_size(sizeof(__u32)); |
| 452 | } |
| 453 | |
| 454 | void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port, |
| 455 | int type) |
| 456 | { |
| 457 | struct net *net = dev_net(dev); |
| 458 | struct sk_buff *skb; |
| 459 | int err = -ENOBUFS; |
| 460 | int ifindex; |
| 461 | |
| 462 | ifindex = port ? port->dev->ifindex : 0; |
| 463 | skb = nlmsg_new(rtnl_rtr_nlmsg_size(), GFP_ATOMIC); |
| 464 | if (!skb) |
| 465 | goto errout; |
| 466 | |
| 467 | err = nlmsg_populate_rtr_fill(skb, dev, ifindex, 0, 0, type, NTF_SELF); |
| 468 | if (err < 0) { |
| 469 | kfree_skb(skb); |
| 470 | goto errout; |
| 471 | } |
| 472 | |
| 473 | rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_ATOMIC); |
| 474 | return; |
| 475 | |
| 476 | errout: |
| 477 | rtnl_set_sk_err(net, RTNLGRP_MDB, err); |
| 478 | } |
| 479 | |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 480 | static bool is_valid_mdb_entry(struct br_mdb_entry *entry) |
| 481 | { |
| 482 | if (entry->ifindex == 0) |
| 483 | return false; |
| 484 | |
| 485 | if (entry->addr.proto == htons(ETH_P_IP)) { |
| 486 | if (!ipv4_is_multicast(entry->addr.u.ip4)) |
| 487 | return false; |
| 488 | if (ipv4_is_local_multicast(entry->addr.u.ip4)) |
| 489 | return false; |
| 490 | #if IS_ENABLED(CONFIG_IPV6) |
| 491 | } else if (entry->addr.proto == htons(ETH_P_IPV6)) { |
Linus Lüssing | 3c3769e | 2013-09-04 02:13:39 +0200 | [diff] [blame] | 492 | if (ipv6_addr_is_ll_all_nodes(&entry->addr.u.ip6)) |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 493 | return false; |
| 494 | #endif |
| 495 | } else |
| 496 | return false; |
Amerigo Wang | ccb1c31 | 2012-12-14 22:09:51 +0000 | [diff] [blame] | 497 | if (entry->state != MDB_PERMANENT && entry->state != MDB_TEMPORARY) |
| 498 | return false; |
Nikolay Aleksandrov | 74fe61f | 2015-07-10 08:02:08 -0700 | [diff] [blame] | 499 | if (entry->vid >= VLAN_VID_MASK) |
| 500 | return false; |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 501 | |
| 502 | return true; |
| 503 | } |
| 504 | |
| 505 | static int br_mdb_parse(struct sk_buff *skb, struct nlmsghdr *nlh, |
| 506 | struct net_device **pdev, struct br_mdb_entry **pentry) |
| 507 | { |
| 508 | struct net *net = sock_net(skb->sk); |
| 509 | struct br_mdb_entry *entry; |
| 510 | struct br_port_msg *bpm; |
| 511 | struct nlattr *tb[MDBA_SET_ENTRY_MAX+1]; |
| 512 | struct net_device *dev; |
| 513 | int err; |
| 514 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 515 | err = nlmsg_parse(nlh, sizeof(*bpm), tb, MDBA_SET_ENTRY_MAX, NULL, |
| 516 | NULL); |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 517 | if (err < 0) |
| 518 | return err; |
| 519 | |
| 520 | bpm = nlmsg_data(nlh); |
| 521 | if (bpm->ifindex == 0) { |
| 522 | pr_info("PF_BRIDGE: br_mdb_parse() with invalid ifindex\n"); |
| 523 | return -EINVAL; |
| 524 | } |
| 525 | |
| 526 | dev = __dev_get_by_index(net, bpm->ifindex); |
| 527 | if (dev == NULL) { |
| 528 | pr_info("PF_BRIDGE: br_mdb_parse() with unknown ifindex\n"); |
| 529 | return -ENODEV; |
| 530 | } |
| 531 | |
| 532 | if (!(dev->priv_flags & IFF_EBRIDGE)) { |
| 533 | pr_info("PF_BRIDGE: br_mdb_parse() with non-bridge\n"); |
| 534 | return -EOPNOTSUPP; |
| 535 | } |
| 536 | |
| 537 | *pdev = dev; |
| 538 | |
| 539 | if (!tb[MDBA_SET_ENTRY] || |
| 540 | nla_len(tb[MDBA_SET_ENTRY]) != sizeof(struct br_mdb_entry)) { |
| 541 | pr_info("PF_BRIDGE: br_mdb_parse() with invalid attr\n"); |
| 542 | return -EINVAL; |
| 543 | } |
| 544 | |
| 545 | entry = nla_data(tb[MDBA_SET_ENTRY]); |
| 546 | if (!is_valid_mdb_entry(entry)) { |
| 547 | pr_info("PF_BRIDGE: br_mdb_parse() with invalid entry\n"); |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | |
| 551 | *pentry = entry; |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port, |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 556 | struct br_ip *group, unsigned char state) |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 557 | { |
| 558 | struct net_bridge_mdb_entry *mp; |
| 559 | struct net_bridge_port_group *p; |
| 560 | struct net_bridge_port_group __rcu **pp; |
| 561 | struct net_bridge_mdb_htable *mdb; |
Satish Ashok | f7e2965 | 2015-07-06 05:53:35 -0700 | [diff] [blame] | 562 | unsigned long now = jiffies; |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 563 | int err; |
| 564 | |
| 565 | mdb = mlock_dereference(br->mdb, br); |
| 566 | mp = br_mdb_ip_get(mdb, group); |
| 567 | if (!mp) { |
| 568 | mp = br_multicast_new_group(br, port, group); |
Arnd Bergmann | 56bb7fd | 2016-02-10 16:09:02 +0100 | [diff] [blame] | 569 | err = PTR_ERR_OR_ZERO(mp); |
| 570 | if (err) |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 571 | return err; |
| 572 | } |
| 573 | |
| 574 | for (pp = &mp->ports; |
| 575 | (p = mlock_dereference(*pp, br)) != NULL; |
| 576 | pp = &p->next) { |
| 577 | if (p->port == port) |
| 578 | return -EEXIST; |
| 579 | if ((unsigned long)p->port < (unsigned long)port) |
| 580 | break; |
| 581 | } |
| 582 | |
Felix Fietkau | 6db6f0e | 2017-01-21 21:01:32 +0100 | [diff] [blame] | 583 | p = br_multicast_new_port_group(port, group, *pp, state, NULL); |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 584 | if (unlikely(!p)) |
| 585 | return -ENOMEM; |
| 586 | rcu_assign_pointer(*pp, p); |
Satish Ashok | f7e2965 | 2015-07-06 05:53:35 -0700 | [diff] [blame] | 587 | if (state == MDB_TEMPORARY) |
| 588 | mod_timer(&p->timer, now + br->multicast_membership_interval); |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 589 | |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static int __br_mdb_add(struct net *net, struct net_bridge *br, |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 594 | struct br_mdb_entry *entry) |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 595 | { |
| 596 | struct br_ip ip; |
| 597 | struct net_device *dev; |
| 598 | struct net_bridge_port *p; |
| 599 | int ret; |
| 600 | |
| 601 | if (!netif_running(br->dev) || br->multicast_disabled) |
| 602 | return -EINVAL; |
| 603 | |
| 604 | dev = __dev_get_by_index(net, entry->ifindex); |
| 605 | if (!dev) |
| 606 | return -ENODEV; |
| 607 | |
| 608 | p = br_port_get_rtnl(dev); |
| 609 | if (!p || p->br != br || p->state == BR_STATE_DISABLED) |
| 610 | return -EINVAL; |
| 611 | |
Elad Raz | 6dd684c | 2016-04-21 12:52:44 +0200 | [diff] [blame] | 612 | __mdb_entry_to_br_ip(entry, &ip); |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 613 | |
| 614 | spin_lock_bh(&br->multicast_lock); |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 615 | ret = br_mdb_add_group(br, p, &ip, entry->state); |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 616 | spin_unlock_bh(&br->multicast_lock); |
| 617 | return ret; |
| 618 | } |
| 619 | |
David Ahern | c21ef3e | 2017-04-16 09:48:24 -0700 | [diff] [blame] | 620 | static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, |
| 621 | struct netlink_ext_ack *extack) |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 622 | { |
| 623 | struct net *net = sock_net(skb->sk); |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 624 | struct net_bridge_vlan_group *vg; |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 625 | struct net_device *dev, *pdev; |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 626 | struct br_mdb_entry *entry; |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 627 | struct net_bridge_port *p; |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 628 | struct net_bridge_vlan *v; |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 629 | struct net_bridge *br; |
| 630 | int err; |
| 631 | |
| 632 | err = br_mdb_parse(skb, nlh, &dev, &entry); |
| 633 | if (err < 0) |
| 634 | return err; |
| 635 | |
| 636 | br = netdev_priv(dev); |
| 637 | |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 638 | /* If vlan filtering is enabled and VLAN is not specified |
| 639 | * install mdb entry on all vlans configured on the port. |
| 640 | */ |
| 641 | pdev = __dev_get_by_index(net, entry->ifindex); |
| 642 | if (!pdev) |
| 643 | return -ENODEV; |
| 644 | |
| 645 | p = br_port_get_rtnl(pdev); |
| 646 | if (!p || p->br != br || p->state == BR_STATE_DISABLED) |
| 647 | return -EINVAL; |
| 648 | |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 649 | vg = nbp_vlan_group(p); |
Ido Schimmel | 1f51445 | 2017-05-26 08:37:23 +0200 | [diff] [blame] | 650 | if (br_vlan_enabled(br->dev) && vg && entry->vid == 0) { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 651 | list_for_each_entry(v, &vg->vlan_list, vlist) { |
| 652 | entry->vid = v->vid; |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 653 | err = __br_mdb_add(net, br, entry); |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 654 | if (err) |
| 655 | break; |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 656 | __br_mdb_notify(dev, p, entry, RTM_NEWMDB); |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 657 | } |
| 658 | } else { |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 659 | err = __br_mdb_add(net, br, entry); |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 660 | if (!err) |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 661 | __br_mdb_notify(dev, p, entry, RTM_NEWMDB); |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 662 | } |
| 663 | |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 664 | return err; |
| 665 | } |
| 666 | |
| 667 | static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry) |
| 668 | { |
| 669 | struct net_bridge_mdb_htable *mdb; |
| 670 | struct net_bridge_mdb_entry *mp; |
| 671 | struct net_bridge_port_group *p; |
| 672 | struct net_bridge_port_group __rcu **pp; |
| 673 | struct br_ip ip; |
| 674 | int err = -EINVAL; |
| 675 | |
| 676 | if (!netif_running(br->dev) || br->multicast_disabled) |
| 677 | return -EINVAL; |
| 678 | |
Elad Raz | 6dd684c | 2016-04-21 12:52:44 +0200 | [diff] [blame] | 679 | __mdb_entry_to_br_ip(entry, &ip); |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 680 | |
| 681 | spin_lock_bh(&br->multicast_lock); |
| 682 | mdb = mlock_dereference(br->mdb, br); |
| 683 | |
| 684 | mp = br_mdb_ip_get(mdb, &ip); |
| 685 | if (!mp) |
| 686 | goto unlock; |
| 687 | |
| 688 | for (pp = &mp->ports; |
| 689 | (p = mlock_dereference(*pp, br)) != NULL; |
| 690 | pp = &p->next) { |
| 691 | if (!p->port || p->port->dev->ifindex != entry->ifindex) |
| 692 | continue; |
| 693 | |
| 694 | if (p->port->state == BR_STATE_DISABLED) |
| 695 | goto unlock; |
| 696 | |
Elad Raz | 9d06b6d | 2016-02-03 09:57:05 +0100 | [diff] [blame] | 697 | __mdb_entry_fill_flags(entry, p->flags); |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 698 | rcu_assign_pointer(*pp, p->next); |
| 699 | hlist_del_init(&p->mglist); |
| 700 | del_timer(&p->timer); |
| 701 | call_rcu_bh(&p->rcu, br_multicast_free_pg); |
| 702 | err = 0; |
| 703 | |
Andrew Lunn | ff0fd34 | 2017-11-09 23:10:57 +0100 | [diff] [blame] | 704 | if (!mp->ports && !mp->host_joined && |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 705 | netif_running(br->dev)) |
| 706 | mod_timer(&mp->timer, jiffies); |
| 707 | break; |
| 708 | } |
| 709 | |
| 710 | unlock: |
| 711 | spin_unlock_bh(&br->multicast_lock); |
| 712 | return err; |
| 713 | } |
| 714 | |
David Ahern | c21ef3e | 2017-04-16 09:48:24 -0700 | [diff] [blame] | 715 | static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, |
| 716 | struct netlink_ext_ack *extack) |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 717 | { |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 718 | struct net *net = sock_net(skb->sk); |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 719 | struct net_bridge_vlan_group *vg; |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 720 | struct net_device *dev, *pdev; |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 721 | struct br_mdb_entry *entry; |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 722 | struct net_bridge_port *p; |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 723 | struct net_bridge_vlan *v; |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 724 | struct net_bridge *br; |
| 725 | int err; |
| 726 | |
| 727 | err = br_mdb_parse(skb, nlh, &dev, &entry); |
| 728 | if (err < 0) |
| 729 | return err; |
| 730 | |
| 731 | br = netdev_priv(dev); |
| 732 | |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 733 | /* If vlan filtering is enabled and VLAN is not specified |
| 734 | * delete mdb entry on all vlans configured on the port. |
| 735 | */ |
| 736 | pdev = __dev_get_by_index(net, entry->ifindex); |
| 737 | if (!pdev) |
| 738 | return -ENODEV; |
| 739 | |
| 740 | p = br_port_get_rtnl(pdev); |
| 741 | if (!p || p->br != br || p->state == BR_STATE_DISABLED) |
| 742 | return -EINVAL; |
| 743 | |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 744 | vg = nbp_vlan_group(p); |
Ido Schimmel | 1f51445 | 2017-05-26 08:37:23 +0200 | [diff] [blame] | 745 | if (br_vlan_enabled(br->dev) && vg && entry->vid == 0) { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 746 | list_for_each_entry(v, &vg->vlan_list, vlist) { |
| 747 | entry->vid = v->vid; |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 748 | err = __br_mdb_del(br, entry); |
| 749 | if (!err) |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 750 | __br_mdb_notify(dev, p, entry, RTM_DELMDB); |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 751 | } |
| 752 | } else { |
| 753 | err = __br_mdb_del(br, entry); |
| 754 | if (!err) |
Elad Raz | 45ebcce | 2016-04-21 12:52:45 +0200 | [diff] [blame] | 755 | __br_mdb_notify(dev, p, entry, RTM_DELMDB); |
Satish Ashok | e44deb2 | 2015-08-03 13:29:16 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Cong Wang | cfd5675 | 2012-12-11 22:23:08 +0000 | [diff] [blame] | 758 | return err; |
| 759 | } |
| 760 | |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 761 | void br_mdb_init(void) |
| 762 | { |
Florian Westphal | c1c502b | 2017-12-02 21:44:07 +0100 | [diff] [blame] | 763 | rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_GETMDB, NULL, br_mdb_dump, 0); |
| 764 | rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_NEWMDB, br_mdb_add, NULL, 0); |
| 765 | rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_DELMDB, br_mdb_del, NULL, 0); |
Cong Wang | ee07c6e | 2012-12-07 00:04:48 +0000 | [diff] [blame] | 766 | } |
Vlad Yasevich | 6323315 | 2012-12-19 09:13:48 +0000 | [diff] [blame] | 767 | |
| 768 | void br_mdb_uninit(void) |
| 769 | { |
| 770 | rtnl_unregister(PF_BRIDGE, RTM_GETMDB); |
| 771 | rtnl_unregister(PF_BRIDGE, RTM_NEWMDB); |
| 772 | rtnl_unregister(PF_BRIDGE, RTM_DELMDB); |
| 773 | } |