Commit 7f0aec7a authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by David S. Miller

bridge: mcast: use names for the different multicast_router types

Using raw values makes it difficult to extend and also understand the
code, give them names and do explicit per-option manipulation in
br_multicast_set_port_router.
Signed-off-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ec1606c0
...@@ -177,6 +177,13 @@ enum { ...@@ -177,6 +177,13 @@ enum {
}; };
#define MDBA_MDB_EATTR_MAX (__MDBA_MDB_EATTR_MAX - 1) #define MDBA_MDB_EATTR_MAX (__MDBA_MDB_EATTR_MAX - 1)
/* multicast router types */
enum {
MDB_RTR_TYPE_DISABLED,
MDB_RTR_TYPE_TEMP_QUERY,
MDB_RTR_TYPE_PERM,
};
enum { enum {
MDBA_ROUTER_UNSPEC, MDBA_ROUTER_UNSPEC,
MDBA_ROUTER_PORT, MDBA_ROUTER_PORT,
......
...@@ -759,7 +759,7 @@ static void br_multicast_router_expired(unsigned long data) ...@@ -759,7 +759,7 @@ static void br_multicast_router_expired(unsigned long data)
struct net_bridge *br = port->br; struct net_bridge *br = port->br;
spin_lock(&br->multicast_lock); spin_lock(&br->multicast_lock);
if (port->multicast_router != 1 || if (port->multicast_router != MDB_RTR_TYPE_TEMP_QUERY ||
timer_pending(&port->multicast_router_timer) || timer_pending(&port->multicast_router_timer) ||
hlist_unhashed(&port->rlist)) hlist_unhashed(&port->rlist))
goto out; goto out;
...@@ -912,7 +912,7 @@ static void br_ip6_multicast_port_query_expired(unsigned long data) ...@@ -912,7 +912,7 @@ static void br_ip6_multicast_port_query_expired(unsigned long data)
void br_multicast_add_port(struct net_bridge_port *port) void br_multicast_add_port(struct net_bridge_port *port)
{ {
port->multicast_router = 1; port->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
setup_timer(&port->multicast_router_timer, br_multicast_router_expired, setup_timer(&port->multicast_router_timer, br_multicast_router_expired,
(unsigned long)port); (unsigned long)port);
...@@ -959,7 +959,8 @@ void br_multicast_enable_port(struct net_bridge_port *port) ...@@ -959,7 +959,8 @@ void br_multicast_enable_port(struct net_bridge_port *port)
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
br_multicast_enable(&port->ip6_own_query); br_multicast_enable(&port->ip6_own_query);
#endif #endif
if (port->multicast_router == 2 && hlist_unhashed(&port->rlist)) if (port->multicast_router == MDB_RTR_TYPE_PERM &&
hlist_unhashed(&port->rlist))
br_multicast_add_router(br, port); br_multicast_add_router(br, port);
out: out:
...@@ -1227,13 +1228,13 @@ static void br_multicast_mark_router(struct net_bridge *br, ...@@ -1227,13 +1228,13 @@ static void br_multicast_mark_router(struct net_bridge *br,
unsigned long now = jiffies; unsigned long now = jiffies;
if (!port) { if (!port) {
if (br->multicast_router == 1) if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY)
mod_timer(&br->multicast_router_timer, mod_timer(&br->multicast_router_timer,
now + br->multicast_querier_interval); now + br->multicast_querier_interval);
return; return;
} }
if (port->multicast_router != 1) if (port->multicast_router != MDB_RTR_TYPE_TEMP_QUERY)
return; return;
br_multicast_add_router(br, port); br_multicast_add_router(br, port);
...@@ -1713,7 +1714,7 @@ void br_multicast_init(struct net_bridge *br) ...@@ -1713,7 +1714,7 @@ void br_multicast_init(struct net_bridge *br)
br->hash_elasticity = 4; br->hash_elasticity = 4;
br->hash_max = 512; br->hash_max = 512;
br->multicast_router = 1; br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
br->multicast_querier = 0; br->multicast_querier = 0;
br->multicast_query_use_ifaddr = 0; br->multicast_query_use_ifaddr = 0;
br->multicast_last_member_count = 2; br->multicast_last_member_count = 2;
...@@ -1823,11 +1824,11 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val) ...@@ -1823,11 +1824,11 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
spin_lock_bh(&br->multicast_lock); spin_lock_bh(&br->multicast_lock);
switch (val) { switch (val) {
case 0: case MDB_RTR_TYPE_DISABLED:
case 2: case MDB_RTR_TYPE_PERM:
del_timer(&br->multicast_router_timer); del_timer(&br->multicast_router_timer);
/* fall through */ /* fall through */
case 1: case MDB_RTR_TYPE_TEMP_QUERY:
br->multicast_router = val; br->multicast_router = val;
err = 0; err = 0;
break; break;
...@@ -1838,6 +1839,14 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val) ...@@ -1838,6 +1839,14 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
return err; return err;
} }
static void __del_port_router(struct net_bridge_port *p)
{
if (hlist_unhashed(&p->rlist))
return;
hlist_del_init_rcu(&p->rlist);
br_rtr_notify(p->br->dev, p, RTM_DELMDB);
}
int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val) int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val)
{ {
struct net_bridge *br = p->br; struct net_bridge *br = p->br;
...@@ -1846,29 +1855,25 @@ int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val) ...@@ -1846,29 +1855,25 @@ int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val)
spin_lock(&br->multicast_lock); spin_lock(&br->multicast_lock);
switch (val) { switch (val) {
case 0: case MDB_RTR_TYPE_DISABLED:
case 1: p->multicast_router = MDB_RTR_TYPE_DISABLED;
case 2: __del_port_router(p);
p->multicast_router = val;
err = 0;
if (val < 2 && !hlist_unhashed(&p->rlist)) {
hlist_del_init_rcu(&p->rlist);
br_rtr_notify(br->dev, p, RTM_DELMDB);
}
if (val == 1)
break;
del_timer(&p->multicast_router_timer); del_timer(&p->multicast_router_timer);
if (val == 0)
break; break;
case MDB_RTR_TYPE_TEMP_QUERY:
p->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
__del_port_router(p);
break;
case MDB_RTR_TYPE_PERM:
p->multicast_router = MDB_RTR_TYPE_PERM;
del_timer(&p->multicast_router_timer);
br_multicast_add_router(br, p); br_multicast_add_router(br, p);
break; break;
default:
goto unlock;
} }
err = 0;
unlock:
spin_unlock(&br->multicast_lock); spin_unlock(&br->multicast_lock);
return err; return err;
......
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