-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bridge: export multicast database via netlink
V5: fix two bugs pointed out by Thomas remove seq check for now, mark it as TODO V4: remove some useless #include some coding style fix V3: drop debugging printk's update selinux perm table as well V2: drop patch 1/2, export ifindex directly Redesign netlink attributes Improve netlink seq check Handle IPv6 addr as well This patch exports bridge multicast database via netlink message type RTM_GETMDB. Similar to fdb, but currently bridge-specific. We may need to support modify multicast database too (RTM_{ADD,DEL}MDB). (Thanks to Thomas for patient reviews) Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Stephen Hemminger <shemminger@vyatta.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Thomas Graf <tgraf@suug.ch> Cc: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: Cong Wang <amwang@redhat.com> Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Cong Wang
authored and
David S. Miller
committed
Dec 7, 2012
1 parent
5d248c4
commit ee07c6e
Showing
7 changed files
with
225 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#include <linux/err.h> | ||
#include <linux/igmp.h> | ||
#include <linux/kernel.h> | ||
#include <linux/netdevice.h> | ||
#include <linux/rculist.h> | ||
#include <linux/skbuff.h> | ||
#include <net/ip.h> | ||
#include <net/netlink.h> | ||
#if IS_ENABLED(CONFIG_IPV6) | ||
#include <net/ipv6.h> | ||
#endif | ||
|
||
#include "br_private.h" | ||
|
||
static int br_rports_fill_info(struct sk_buff *skb, struct netlink_callback *cb, | ||
struct net_device *dev) | ||
{ | ||
struct net_bridge *br = netdev_priv(dev); | ||
struct net_bridge_port *p; | ||
struct hlist_node *n; | ||
struct nlattr *nest; | ||
|
||
if (!br->multicast_router || hlist_empty(&br->router_list)) | ||
return 0; | ||
|
||
nest = nla_nest_start(skb, MDBA_ROUTER); | ||
if (nest == NULL) | ||
return -EMSGSIZE; | ||
|
||
hlist_for_each_entry_rcu(p, n, &br->router_list, rlist) { | ||
if (p && nla_put_u32(skb, MDBA_ROUTER_PORT, p->dev->ifindex)) | ||
goto fail; | ||
} | ||
|
||
nla_nest_end(skb, nest); | ||
return 0; | ||
fail: | ||
nla_nest_cancel(skb, nest); | ||
return -EMSGSIZE; | ||
} | ||
|
||
static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb, | ||
struct net_device *dev) | ||
{ | ||
struct net_bridge *br = netdev_priv(dev); | ||
struct net_bridge_mdb_htable *mdb; | ||
struct nlattr *nest, *nest2; | ||
int i, err = 0; | ||
int idx = 0, s_idx = cb->args[1]; | ||
|
||
if (br->multicast_disabled) | ||
return 0; | ||
|
||
mdb = rcu_dereference(br->mdb); | ||
if (!mdb) | ||
return 0; | ||
|
||
nest = nla_nest_start(skb, MDBA_MDB); | ||
if (nest == NULL) | ||
return -EMSGSIZE; | ||
|
||
for (i = 0; i < mdb->max; i++) { | ||
struct hlist_node *h; | ||
struct net_bridge_mdb_entry *mp; | ||
struct net_bridge_port_group *p, **pp; | ||
struct net_bridge_port *port; | ||
|
||
hlist_for_each_entry_rcu(mp, h, &mdb->mhash[i], hlist[mdb->ver]) { | ||
if (idx < s_idx) | ||
goto skip; | ||
|
||
nest2 = nla_nest_start(skb, MDBA_MDB_ENTRY); | ||
if (nest2 == NULL) { | ||
err = -EMSGSIZE; | ||
goto out; | ||
} | ||
|
||
for (pp = &mp->ports; | ||
(p = rcu_dereference(*pp)) != NULL; | ||
pp = &p->next) { | ||
port = p->port; | ||
if (port) { | ||
struct br_mdb_entry e; | ||
e.ifindex = port->dev->ifindex; | ||
e.addr.u.ip4 = p->addr.u.ip4; | ||
#if IS_ENABLED(CONFIG_IPV6) | ||
e.addr.u.ip6 = p->addr.u.ip6; | ||
#endif | ||
e.addr.proto = p->addr.proto; | ||
if (nla_put(skb, MDBA_MDB_ENTRY_INFO, sizeof(e), &e)) { | ||
nla_nest_cancel(skb, nest2); | ||
err = -EMSGSIZE; | ||
goto out; | ||
} | ||
} | ||
} | ||
nla_nest_end(skb, nest2); | ||
skip: | ||
idx++; | ||
} | ||
} | ||
|
||
out: | ||
cb->args[1] = idx; | ||
nla_nest_end(skb, nest); | ||
return err; | ||
} | ||
|
||
static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb) | ||
{ | ||
struct net_device *dev; | ||
struct net *net = sock_net(skb->sk); | ||
struct nlmsghdr *nlh = NULL; | ||
int idx = 0, s_idx; | ||
|
||
s_idx = cb->args[0]; | ||
|
||
rcu_read_lock(); | ||
|
||
/* TODO: in case of rehashing, we need to check | ||
* consistency for dumping. | ||
*/ | ||
cb->seq = net->dev_base_seq; | ||
|
||
for_each_netdev_rcu(net, dev) { | ||
if (dev->priv_flags & IFF_EBRIDGE) { | ||
struct br_port_msg *bpm; | ||
|
||
if (idx < s_idx) | ||
goto skip; | ||
|
||
nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, | ||
cb->nlh->nlmsg_seq, RTM_GETMDB, | ||
sizeof(*bpm), NLM_F_MULTI); | ||
if (nlh == NULL) | ||
break; | ||
|
||
bpm = nlmsg_data(nlh); | ||
bpm->ifindex = dev->ifindex; | ||
if (br_mdb_fill_info(skb, cb, dev) < 0) | ||
goto out; | ||
if (br_rports_fill_info(skb, cb, dev) < 0) | ||
goto out; | ||
|
||
cb->args[1] = 0; | ||
nlmsg_end(skb, nlh); | ||
skip: | ||
idx++; | ||
} | ||
} | ||
|
||
out: | ||
if (nlh) | ||
nlmsg_end(skb, nlh); | ||
rcu_read_unlock(); | ||
cb->args[0] = idx; | ||
return skb->len; | ||
} | ||
|
||
void br_mdb_init(void) | ||
{ | ||
rtnl_register(PF_BRIDGE, RTM_GETMDB, NULL, br_mdb_dump, NULL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters