Commit 1bc844ee authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by David S. Miller

net: bridge: mdb: allow add/delete for host-joined groups

Currently this is needed only for user-space compatibility, so similar
object adds/deletes as the dumped ones would succeed. Later it can be
used for L2 mcast MAC add/delete.

v3: fix compiler warning (DaveM)
v2: don't send a notification when used from user-space, arm the group
    timer if no ports are left after host entry del
Signed-off-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e77b0c84
...@@ -616,6 +616,19 @@ static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port, ...@@ -616,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) {
...@@ -640,12 +653,13 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br, ...@@ -640,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;
...@@ -653,6 +667,7 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br, ...@@ -653,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);
...@@ -667,9 +682,9 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -667,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;
...@@ -680,6 +695,7 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -680,6 +695,7 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
br = netdev_priv(dev); br = netdev_priv(dev);
if (entry->ifindex != br->dev->ifindex) {
pdev = __dev_get_by_index(net, entry->ifindex); pdev = __dev_get_by_index(net, entry->ifindex);
if (!pdev) if (!pdev)
return -ENODEV; return -ENODEV;
...@@ -687,8 +703,11 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -687,8 +703,11 @@ 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 /* If vlan filtering is enabled and VLAN is not specified
* install mdb entry on all vlans configured on the port. * install mdb entry on all vlans configured on the port.
*/ */
...@@ -727,6 +746,15 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry) ...@@ -727,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) {
...@@ -759,9 +787,9 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -759,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;
...@@ -772,6 +800,7 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -772,6 +800,7 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
br = netdev_priv(dev); br = netdev_priv(dev);
if (entry->ifindex != br->dev->ifindex) {
pdev = __dev_get_by_index(net, entry->ifindex); pdev = __dev_get_by_index(net, entry->ifindex);
if (!pdev) if (!pdev)
return -ENODEV; return -ENODEV;
...@@ -779,8 +808,11 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -779,8 +808,11 @@ 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 /* If vlan filtering is enabled and VLAN is not specified
* delete mdb entry on all vlans configured on the port. * delete mdb entry on all vlans configured on the port.
*/ */
......
...@@ -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