Commit f7750830 authored by David S. Miller's avatar David S. Miller

Merge branch 'bridge-mdb'

Nikolay Aleksandrov says:

====================
net: bridge: mdb: allow dump/add/del of host-joined entries

This set makes the bridge dump host-joined mdb entries, they should be
treated as normal entries since they take a slot and are aging out.
We already have notifications for them but we couldn't dump them until
now so they remained hidden. We dump them similar to how they're
notified, in order to keep user-space compatibility with the dumped
objects (e.g. iproute2 dumps mdbs in a format which can be fed into
add/del commands) we allow host-joined groups also to be added/deleted via
mdb commands. That can later be used for L2 mcast MAC manipulation as
was recently discussed. Note that iproute2 changes are not necessary,
this set will work with the current user-space mdb code.

Patch 01 - a trivial comment move
Patch 02 - factors out the mdb filling code so it can be
           re-used for the host-joined entries
Patch 03 - dumps host-joined entries
Patch 04 - allows manipulation of host-joined entries via standard mdb
           calls

v3: fix compiler warning in patch 04 (DaveM)
v2: change patch 04 to avoid double notification and improve host group
    manual removal if no ports are present in the group
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 59d0f749 1bc844ee
...@@ -77,6 +77,53 @@ static void __mdb_entry_to_br_ip(struct br_mdb_entry *entry, struct br_ip *ip) ...@@ -77,6 +77,53 @@ static void __mdb_entry_to_br_ip(struct br_mdb_entry *entry, struct br_ip *ip)
#endif #endif
} }
static int __mdb_fill_info(struct sk_buff *skb,
struct net_bridge_mdb_entry *mp,
struct net_bridge_port_group *p)
{
struct timer_list *mtimer;
struct nlattr *nest_ent;
struct br_mdb_entry e;
u8 flags = 0;
int ifindex;
memset(&e, 0, sizeof(e));
if (p) {
ifindex = p->port->dev->ifindex;
mtimer = &p->timer;
flags = p->flags;
} else {
ifindex = mp->br->dev->ifindex;
mtimer = &mp->timer;
}
__mdb_entry_fill_flags(&e, flags);
e.ifindex = ifindex;
e.vid = mp->addr.vid;
if (mp->addr.proto == htons(ETH_P_IP))
e.addr.u.ip4 = mp->addr.u.ip4;
#if IS_ENABLED(CONFIG_IPV6)
if (mp->addr.proto == htons(ETH_P_IPV6))
e.addr.u.ip6 = mp->addr.u.ip6;
#endif
e.addr.proto = mp->addr.proto;
nest_ent = nla_nest_start_noflag(skb,
MDBA_MDB_ENTRY_INFO);
if (!nest_ent)
return -EMSGSIZE;
if (nla_put_nohdr(skb, sizeof(e), &e) ||
nla_put_u32(skb,
MDBA_MDB_EATTR_TIMER,
br_timer_value(mtimer))) {
nla_nest_cancel(skb, nest_ent);
return -EMSGSIZE;
}
nla_nest_end(skb, nest_ent);
return 0;
}
static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb, static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
struct net_device *dev) struct net_device *dev)
{ {
...@@ -95,7 +142,6 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb, ...@@ -95,7 +142,6 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
hlist_for_each_entry_rcu(mp, &br->mdb_list, mdb_node) { hlist_for_each_entry_rcu(mp, &br->mdb_list, mdb_node) {
struct net_bridge_port_group *p; struct net_bridge_port_group *p;
struct net_bridge_port_group __rcu **pp; struct net_bridge_port_group __rcu **pp;
struct net_bridge_port *port;
if (idx < s_idx) if (idx < s_idx)
goto skip; goto skip;
...@@ -106,43 +152,24 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb, ...@@ -106,43 +152,24 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
break; break;
} }
if (mp->host_joined) {
err = __mdb_fill_info(skb, mp, NULL);
if (err) {
nla_nest_cancel(skb, nest2);
break;
}
}
for (pp = &mp->ports; (p = rcu_dereference(*pp)) != NULL; for (pp = &mp->ports; (p = rcu_dereference(*pp)) != NULL;
pp = &p->next) { pp = &p->next) {
struct nlattr *nest_ent; if (!p->port)
struct br_mdb_entry e;
port = p->port;
if (!port)
continue; continue;
memset(&e, 0, sizeof(e)); err = __mdb_fill_info(skb, mp, p);
e.ifindex = port->dev->ifindex; if (err) {
e.vid = p->addr.vid;
__mdb_entry_fill_flags(&e, p->flags);
if (p->addr.proto == htons(ETH_P_IP))
e.addr.u.ip4 = p->addr.u.ip4;
#if IS_ENABLED(CONFIG_IPV6)
if (p->addr.proto == htons(ETH_P_IPV6))
e.addr.u.ip6 = p->addr.u.ip6;
#endif
e.addr.proto = p->addr.proto;
nest_ent = nla_nest_start_noflag(skb,
MDBA_MDB_ENTRY_INFO);
if (!nest_ent) {
nla_nest_cancel(skb, nest2);
err = -EMSGSIZE;
goto out;
}
if (nla_put_nohdr(skb, sizeof(e), &e) ||
nla_put_u32(skb,
MDBA_MDB_EATTR_TIMER,
br_timer_value(&p->timer))) {
nla_nest_cancel(skb, nest_ent);
nla_nest_cancel(skb, nest2); nla_nest_cancel(skb, nest2);
err = -EMSGSIZE;
goto out; goto out;
} }
nla_nest_end(skb, nest_ent);
} }
nla_nest_end(skb, nest2); nla_nest_end(skb, nest2);
skip: skip:
...@@ -589,6 +616,19 @@ static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port, ...@@ -589,6 +616,19 @@ static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port,
return err; return err;
} }
/* host join */
if (!port) {
/* don't allow any flags for host-joined groups */
if (state)
return -EINVAL;
if (mp->host_joined)
return -EEXIST;
br_multicast_host_join(mp, false);
return 0;
}
for (pp = &mp->ports; for (pp = &mp->ports;
(p = mlock_dereference(*pp, br)) != NULL; (p = mlock_dereference(*pp, br)) != NULL;
pp = &p->next) { pp = &p->next) {
...@@ -613,12 +653,13 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br, ...@@ -613,12 +653,13 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br,
{ {
struct br_ip ip; struct br_ip ip;
struct net_device *dev; struct net_device *dev;
struct net_bridge_port *p; struct net_bridge_port *p = NULL;
int ret; int ret;
if (!netif_running(br->dev) || !br_opt_get(br, BROPT_MULTICAST_ENABLED)) if (!netif_running(br->dev) || !br_opt_get(br, BROPT_MULTICAST_ENABLED))
return -EINVAL; return -EINVAL;
if (entry->ifindex != br->dev->ifindex) {
dev = __dev_get_by_index(net, entry->ifindex); dev = __dev_get_by_index(net, entry->ifindex);
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
...@@ -626,6 +667,7 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br, ...@@ -626,6 +667,7 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br,
p = br_port_get_rtnl(dev); p = br_port_get_rtnl(dev);
if (!p || p->br != br || p->state == BR_STATE_DISABLED) if (!p || p->br != br || p->state == BR_STATE_DISABLED)
return -EINVAL; return -EINVAL;
}
__mdb_entry_to_br_ip(entry, &ip); __mdb_entry_to_br_ip(entry, &ip);
...@@ -640,9 +682,9 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -640,9 +682,9 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
{ {
struct net *net = sock_net(skb->sk); struct net *net = sock_net(skb->sk);
struct net_bridge_vlan_group *vg; struct net_bridge_vlan_group *vg;
struct net_bridge_port *p = NULL;
struct net_device *dev, *pdev; struct net_device *dev, *pdev;
struct br_mdb_entry *entry; struct br_mdb_entry *entry;
struct net_bridge_port *p;
struct net_bridge_vlan *v; struct net_bridge_vlan *v;
struct net_bridge *br; struct net_bridge *br;
int err; int err;
...@@ -653,9 +695,7 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -653,9 +695,7 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
br = netdev_priv(dev); br = netdev_priv(dev);
/* If vlan filtering is enabled and VLAN is not specified if (entry->ifindex != br->dev->ifindex) {
* install mdb entry on all vlans configured on the port.
*/
pdev = __dev_get_by_index(net, entry->ifindex); pdev = __dev_get_by_index(net, entry->ifindex);
if (!pdev) if (!pdev)
return -ENODEV; return -ENODEV;
...@@ -663,8 +703,14 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -663,8 +703,14 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
p = br_port_get_rtnl(pdev); p = br_port_get_rtnl(pdev);
if (!p || p->br != br || p->state == BR_STATE_DISABLED) if (!p || p->br != br || p->state == BR_STATE_DISABLED)
return -EINVAL; return -EINVAL;
vg = nbp_vlan_group(p); vg = nbp_vlan_group(p);
} else {
vg = br_vlan_group(br);
}
/* If vlan filtering is enabled and VLAN is not specified
* install mdb entry on all vlans configured on the port.
*/
if (br_vlan_enabled(br->dev) && vg && entry->vid == 0) { if (br_vlan_enabled(br->dev) && vg && entry->vid == 0) {
list_for_each_entry(v, &vg->vlan_list, vlist) { list_for_each_entry(v, &vg->vlan_list, vlist) {
entry->vid = v->vid; entry->vid = v->vid;
...@@ -700,6 +746,15 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry) ...@@ -700,6 +746,15 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry)
if (!mp) if (!mp)
goto unlock; goto unlock;
/* host leave */
if (entry->ifindex == mp->br->dev->ifindex && mp->host_joined) {
br_multicast_host_leave(mp, false);
err = 0;
if (!mp->ports && netif_running(br->dev))
mod_timer(&mp->timer, jiffies);
goto unlock;
}
for (pp = &mp->ports; for (pp = &mp->ports;
(p = mlock_dereference(*pp, br)) != NULL; (p = mlock_dereference(*pp, br)) != NULL;
pp = &p->next) { pp = &p->next) {
...@@ -732,9 +787,9 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -732,9 +787,9 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
{ {
struct net *net = sock_net(skb->sk); struct net *net = sock_net(skb->sk);
struct net_bridge_vlan_group *vg; struct net_bridge_vlan_group *vg;
struct net_bridge_port *p = NULL;
struct net_device *dev, *pdev; struct net_device *dev, *pdev;
struct br_mdb_entry *entry; struct br_mdb_entry *entry;
struct net_bridge_port *p;
struct net_bridge_vlan *v; struct net_bridge_vlan *v;
struct net_bridge *br; struct net_bridge *br;
int err; int err;
...@@ -745,9 +800,7 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -745,9 +800,7 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
br = netdev_priv(dev); br = netdev_priv(dev);
/* If vlan filtering is enabled and VLAN is not specified if (entry->ifindex != br->dev->ifindex) {
* delete mdb entry on all vlans configured on the port.
*/
pdev = __dev_get_by_index(net, entry->ifindex); pdev = __dev_get_by_index(net, entry->ifindex);
if (!pdev) if (!pdev)
return -ENODEV; return -ENODEV;
...@@ -755,8 +808,14 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -755,8 +808,14 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
p = br_port_get_rtnl(pdev); p = br_port_get_rtnl(pdev);
if (!p || p->br != br || p->state == BR_STATE_DISABLED) if (!p || p->br != br || p->state == BR_STATE_DISABLED)
return -EINVAL; return -EINVAL;
vg = nbp_vlan_group(p); vg = nbp_vlan_group(p);
} else {
vg = br_vlan_group(br);
}
/* If vlan filtering is enabled and VLAN is not specified
* delete mdb entry on all vlans configured on the port.
*/
if (br_vlan_enabled(br->dev) && vg && entry->vid == 0) { if (br_vlan_enabled(br->dev) && vg && entry->vid == 0) {
list_for_each_entry(v, &vg->vlan_list, vlist) { list_for_each_entry(v, &vg->vlan_list, vlist) {
entry->vid = v->vid; entry->vid = v->vid;
......
...@@ -148,8 +148,7 @@ static void br_multicast_group_expired(struct timer_list *t) ...@@ -148,8 +148,7 @@ static void br_multicast_group_expired(struct timer_list *t)
if (!netif_running(br->dev) || timer_pending(&mp->timer)) if (!netif_running(br->dev) || timer_pending(&mp->timer))
goto out; goto out;
mp->host_joined = false; br_multicast_host_leave(mp, true);
br_mdb_notify(br->dev, NULL, &mp->addr, RTM_DELMDB, 0);
if (mp->ports) if (mp->ports)
goto out; goto out;
...@@ -512,6 +511,27 @@ static bool br_port_group_equal(struct net_bridge_port_group *p, ...@@ -512,6 +511,27 @@ static bool br_port_group_equal(struct net_bridge_port_group *p,
return ether_addr_equal(src, p->eth_addr); return ether_addr_equal(src, p->eth_addr);
} }
void br_multicast_host_join(struct net_bridge_mdb_entry *mp, bool notify)
{
if (!mp->host_joined) {
mp->host_joined = true;
if (notify)
br_mdb_notify(mp->br->dev, NULL, &mp->addr,
RTM_NEWMDB, 0);
}
mod_timer(&mp->timer, jiffies + mp->br->multicast_membership_interval);
}
void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify)
{
if (!mp->host_joined)
return;
mp->host_joined = false;
if (notify)
br_mdb_notify(mp->br->dev, NULL, &mp->addr, RTM_DELMDB, 0);
}
static int br_multicast_add_group(struct net_bridge *br, static int br_multicast_add_group(struct net_bridge *br,
struct net_bridge_port *port, struct net_bridge_port *port,
struct br_ip *group, struct br_ip *group,
...@@ -534,11 +554,7 @@ static int br_multicast_add_group(struct net_bridge *br, ...@@ -534,11 +554,7 @@ static int br_multicast_add_group(struct net_bridge *br,
goto err; goto err;
if (!port) { if (!port) {
if (!mp->host_joined) { br_multicast_host_join(mp, true);
mp->host_joined = true;
br_mdb_notify(br->dev, NULL, &mp->addr, RTM_NEWMDB, 0);
}
mod_timer(&mp->timer, now + br->multicast_membership_interval);
goto out; goto out;
} }
......
...@@ -702,6 +702,8 @@ void br_multicast_get_stats(const struct net_bridge *br, ...@@ -702,6 +702,8 @@ void br_multicast_get_stats(const struct net_bridge *br,
struct br_mcast_stats *dest); struct br_mcast_stats *dest);
void br_mdb_init(void); void br_mdb_init(void);
void br_mdb_uninit(void); void br_mdb_uninit(void);
void br_multicast_host_join(struct net_bridge_mdb_entry *mp, bool notify);
void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify);
#define mlock_dereference(X, br) \ #define mlock_dereference(X, br) \
rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock)) rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment