Skip to content

Commit

Permalink
net: bridge: mcast: export multicast router presence adjacent to a port
Browse files Browse the repository at this point in the history
To properly support routable multicast addresses in batman-adv in a
group-aware way, a batman-adv node needs to know if it serves multicast
routers.

This adds a function to the bridge to export this so that batman-adv
can then make full use of the Multicast Router Discovery capability of
the bridge.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Linus Lüssing authored and David S. Miller committed May 13, 2021
1 parent b7fb091 commit 3b85f9b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/linux/if_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int br_multicast_list_adjacent(struct net_device *dev,
struct list_head *br_ip_list);
bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto);
bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto);
bool br_multicast_has_router_adjacent(struct net_device *dev, int proto);
bool br_multicast_enabled(const struct net_device *dev);
bool br_multicast_router(const struct net_device *dev);
int br_mdb_replay(struct net_device *br_dev, struct net_device *dev,
Expand All @@ -87,6 +88,13 @@ static inline bool br_multicast_has_querier_adjacent(struct net_device *dev,
{
return false;
}

static inline bool br_multicast_has_router_adjacent(struct net_device *dev,
int proto)
{
return true;
}

static inline bool br_multicast_enabled(const struct net_device *dev)
{
return false;
Expand Down
55 changes: 55 additions & 0 deletions net/bridge/br_multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -4054,6 +4054,61 @@ bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto)
}
EXPORT_SYMBOL_GPL(br_multicast_has_querier_adjacent);

/**
* br_multicast_has_router_adjacent - Checks for a router behind a bridge port
* @dev: The bridge port adjacent to which to check for a multicast router
* @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6
*
* Checks whether the given interface has a bridge on top and if so returns
* true if a multicast router is behind one of the other ports of this
* bridge. Otherwise returns false.
*/
bool br_multicast_has_router_adjacent(struct net_device *dev, int proto)
{
struct net_bridge_port *port, *p;
bool ret = false;

rcu_read_lock();
port = br_port_get_check_rcu(dev);
if (!port)
goto unlock;

switch (proto) {
case ETH_P_IP:
hlist_for_each_entry_rcu(p, &port->br->ip4_mc_router_list,
ip4_rlist) {
if (p == port)
continue;

ret = true;
goto unlock;
}
break;
#if IS_ENABLED(CONFIG_IPV6)
case ETH_P_IPV6:
hlist_for_each_entry_rcu(p, &port->br->ip6_mc_router_list,
ip6_rlist) {
if (p == port)
continue;

ret = true;
goto unlock;
}
break;
#endif
default:
/* when compiled without IPv6 support, be conservative and
* always assume presence of an IPv6 multicast router
*/
ret = true;
}

unlock:
rcu_read_unlock();
return ret;
}
EXPORT_SYMBOL_GPL(br_multicast_has_router_adjacent);

static void br_mcast_stats_add(struct bridge_mcast_stats __percpu *stats,
const struct sk_buff *skb, u8 type, u8 dir)
{
Expand Down

0 comments on commit 3b85f9b

Please sign in to comment.