Skip to content

Commit 7f0aec7

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
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: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ec1606c commit 7f0aec7

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

include/uapi/linux/if_bridge.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ enum {
177177
};
178178
#define MDBA_MDB_EATTR_MAX (__MDBA_MDB_EATTR_MAX - 1)
179179

180+
/* multicast router types */
181+
enum {
182+
MDB_RTR_TYPE_DISABLED,
183+
MDB_RTR_TYPE_TEMP_QUERY,
184+
MDB_RTR_TYPE_PERM,
185+
};
186+
180187
enum {
181188
MDBA_ROUTER_UNSPEC,
182189
MDBA_ROUTER_PORT,

net/bridge/br_multicast.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ static void br_multicast_router_expired(unsigned long data)
759759
struct net_bridge *br = port->br;
760760

761761
spin_lock(&br->multicast_lock);
762-
if (port->multicast_router != 1 ||
762+
if (port->multicast_router != MDB_RTR_TYPE_TEMP_QUERY ||
763763
timer_pending(&port->multicast_router_timer) ||
764764
hlist_unhashed(&port->rlist))
765765
goto out;
@@ -912,7 +912,7 @@ static void br_ip6_multicast_port_query_expired(unsigned long data)
912912

913913
void br_multicast_add_port(struct net_bridge_port *port)
914914
{
915-
port->multicast_router = 1;
915+
port->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
916916

917917
setup_timer(&port->multicast_router_timer, br_multicast_router_expired,
918918
(unsigned long)port);
@@ -959,7 +959,8 @@ void br_multicast_enable_port(struct net_bridge_port *port)
959959
#if IS_ENABLED(CONFIG_IPV6)
960960
br_multicast_enable(&port->ip6_own_query);
961961
#endif
962-
if (port->multicast_router == 2 && hlist_unhashed(&port->rlist))
962+
if (port->multicast_router == MDB_RTR_TYPE_PERM &&
963+
hlist_unhashed(&port->rlist))
963964
br_multicast_add_router(br, port);
964965

965966
out:
@@ -1227,13 +1228,13 @@ static void br_multicast_mark_router(struct net_bridge *br,
12271228
unsigned long now = jiffies;
12281229

12291230
if (!port) {
1230-
if (br->multicast_router == 1)
1231+
if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY)
12311232
mod_timer(&br->multicast_router_timer,
12321233
now + br->multicast_querier_interval);
12331234
return;
12341235
}
12351236

1236-
if (port->multicast_router != 1)
1237+
if (port->multicast_router != MDB_RTR_TYPE_TEMP_QUERY)
12371238
return;
12381239

12391240
br_multicast_add_router(br, port);
@@ -1713,7 +1714,7 @@ void br_multicast_init(struct net_bridge *br)
17131714
br->hash_elasticity = 4;
17141715
br->hash_max = 512;
17151716

1716-
br->multicast_router = 1;
1717+
br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
17171718
br->multicast_querier = 0;
17181719
br->multicast_query_use_ifaddr = 0;
17191720
br->multicast_last_member_count = 2;
@@ -1823,11 +1824,11 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
18231824
spin_lock_bh(&br->multicast_lock);
18241825

18251826
switch (val) {
1826-
case 0:
1827-
case 2:
1827+
case MDB_RTR_TYPE_DISABLED:
1828+
case MDB_RTR_TYPE_PERM:
18281829
del_timer(&br->multicast_router_timer);
18291830
/* fall through */
1830-
case 1:
1831+
case MDB_RTR_TYPE_TEMP_QUERY:
18311832
br->multicast_router = val;
18321833
err = 0;
18331834
break;
@@ -1838,6 +1839,14 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
18381839
return err;
18391840
}
18401841

1842+
static void __del_port_router(struct net_bridge_port *p)
1843+
{
1844+
if (hlist_unhashed(&p->rlist))
1845+
return;
1846+
hlist_del_init_rcu(&p->rlist);
1847+
br_rtr_notify(p->br->dev, p, RTM_DELMDB);
1848+
}
1849+
18411850
int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val)
18421851
{
18431852
struct net_bridge *br = p->br;
@@ -1846,29 +1855,25 @@ int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val)
18461855
spin_lock(&br->multicast_lock);
18471856

18481857
switch (val) {
1849-
case 0:
1850-
case 1:
1851-
case 2:
1852-
p->multicast_router = val;
1853-
err = 0;
1854-
1855-
if (val < 2 && !hlist_unhashed(&p->rlist)) {
1856-
hlist_del_init_rcu(&p->rlist);
1857-
br_rtr_notify(br->dev, p, RTM_DELMDB);
1858-
}
1859-
1860-
if (val == 1)
1861-
break;
1862-
1858+
case MDB_RTR_TYPE_DISABLED:
1859+
p->multicast_router = MDB_RTR_TYPE_DISABLED;
1860+
__del_port_router(p);
1861+
del_timer(&p->multicast_router_timer);
1862+
break;
1863+
case MDB_RTR_TYPE_TEMP_QUERY:
1864+
p->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
1865+
__del_port_router(p);
1866+
break;
1867+
case MDB_RTR_TYPE_PERM:
1868+
p->multicast_router = MDB_RTR_TYPE_PERM;
18631869
del_timer(&p->multicast_router_timer);
1864-
1865-
if (val == 0)
1866-
break;
1867-
18681870
br_multicast_add_router(br, p);
18691871
break;
1872+
default:
1873+
goto unlock;
18701874
}
1871-
1875+
err = 0;
1876+
unlock:
18721877
spin_unlock(&br->multicast_lock);
18731878

18741879
return err;

0 commit comments

Comments
 (0)