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

Merge branch 'bridge-split-ipv4-ipv6-mc-router-state'

Linus Lüssing says:

====================
net: bridge: split IPv4/v6 mc router state and export for batman-adv

The following patches are splitting the so far combined multicast router
state in the Linux bridge into two ones, one for IPv4 and one for IPv6,
for a more fine-grained detection of multicast routers. This avoids
sending IPv4 multicast packets to an IPv6-only multicast router and
avoids sending IPv6 multicast packets to an IPv4-only multicast router.
This also allows batman-adv to make use of the now split information in
the final patch.

The first eight patches prepare the bridge code to avoid duplicate
code or IPv6-#ifdef clutter for the multicast router state split. And
contain no functional changes yet.

The ninth patch then implements the IPv4+IPv6 multicast router state
split.

Patch number ten adds IPv4+IPv6 specific timers to the mdb netlink
router port dump, so that the timers validity can be checked individually
from userspace.

The final, eleventh patch exports this now per protocol family multicast
router state so that batman-adv can then later make full use of the
Multicast Router Discovery (MRD) support in the Linux bridge. The
batman-adv protocol format currently expects separate multicast router
states for IPv4 and IPv6, therefore it depends on the first patch.
batman-adv will then make use of this newly exported functions like
this[0].

Regards, Linus

[0]: https://git.open-mesh.org/batman-adv.git/shortlog/refs/heads/linus/multicast-routeable-mrd
     -> https://git.open-mesh.org/batman-adv.git/commit/d4bed3a92427445708baeb1f2d1841c5fb816fd4

Changelog v3:

* Patch 01/11:
  * fixed/added missing rename of br->router_list to
    br->ip4_mc_router_list in br_multicast_flood()
* Patch 02/11:
  * moved inline functions from br_forward.c to br_private.h
* Patch 03/11:
  * removed inline attribute from functions added to br_mdb.c
* Patch 04/11:
  * unchanged
* Patch 05/11:
  * converted if()'s into switch-case in br_multicast_is_router()
* Patch 06/11:
  * removed inline attribute from function added to br_multicast.c
* Patch 07/11:
  * added missing static attribute to function
    br_ip4_multicast_get_rport_slot() added to br_multicast.c
* Patch 08/11:
  * removed inline attribute from function added to br_multicast.c
* Patch 09/11:
  * added missing static attribute to function
    br_ip6_multicast_get_rport_slot() added to br_multicast.c
  * removed inline attribute from function added to br_multicast.c
* Patch 10/11:
  * unchanged
* Patch 11/11:
  * simplified bridge check in br_multicast_has_router_adjacent()
    by using br_port_get_check_rcu()
  * added missing declaration for br_multicast_has_router_adjacent()
    in include/linux/if_bridge.h

Changelog v2:

* split into multiple patches as suggested by Nikolay
* added helper functions to br_multicast_flood(), avoiding
  IPv6 #ifdef clutter
* fixed reverse xmas tree ordering in br_rports_fill_info() and
  added helper functions to avoid IPv6 #ifdef clutter
* Added a common br_multicast_add_router() and a helper function
  to retrieve the correct slot to avoid duplicate code for an
  ip4 and ip6 variant
* replaced the "1" and "2" constants in br_multicast_is_router()
  with the appropriate enums
* added br_{ip4,ip6}_multicast_rport_del() wrappers to reduce
  IPv6 #ifdef clutter
* added return values to br_*multicast_rport_del() to only notify
  if the port was actually removed and did not race with a readdition
  somewhere else
* added empty, void br_ip6_multicast_mark_router() if compiled
  without IPv6, to reduce IPv6 #ifdef clutter
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 8380c81d 3b85f9ba
...@@ -67,6 +67,7 @@ int br_multicast_list_adjacent(struct net_device *dev, ...@@ -67,6 +67,7 @@ int br_multicast_list_adjacent(struct net_device *dev,
struct list_head *br_ip_list); struct list_head *br_ip_list);
bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto); 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_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_enabled(const struct net_device *dev);
bool br_multicast_router(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, int br_mdb_replay(struct net_device *br_dev, struct net_device *dev,
...@@ -87,6 +88,13 @@ static inline bool br_multicast_has_querier_adjacent(struct net_device *dev, ...@@ -87,6 +88,13 @@ static inline bool br_multicast_has_querier_adjacent(struct net_device *dev,
{ {
return false; 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) static inline bool br_multicast_enabled(const struct net_device *dev)
{ {
return false; return false;
......
...@@ -627,6 +627,8 @@ enum { ...@@ -627,6 +627,8 @@ enum {
MDBA_ROUTER_PATTR_UNSPEC, MDBA_ROUTER_PATTR_UNSPEC,
MDBA_ROUTER_PATTR_TIMER, MDBA_ROUTER_PATTR_TIMER,
MDBA_ROUTER_PATTR_TYPE, MDBA_ROUTER_PATTR_TYPE,
MDBA_ROUTER_PATTR_INET_TIMER,
MDBA_ROUTER_PATTR_INET6_TIMER,
__MDBA_ROUTER_PATTR_MAX __MDBA_ROUTER_PATTR_MAX
}; };
#define MDBA_ROUTER_PATTR_MAX (__MDBA_ROUTER_PATTR_MAX - 1) #define MDBA_ROUTER_PATTR_MAX (__MDBA_ROUTER_PATTR_MAX - 1)
......
...@@ -276,7 +276,8 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, ...@@ -276,7 +276,8 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
bool allow_mode_include = true; bool allow_mode_include = true;
struct hlist_node *rp; struct hlist_node *rp;
rp = rcu_dereference(hlist_first_rcu(&br->router_list)); rp = br_multicast_get_first_rport_node(br, skb);
if (mdst) { if (mdst) {
p = rcu_dereference(mdst->ports); p = rcu_dereference(mdst->ports);
if (br_multicast_should_handle_mode(br, mdst->addr.proto) && if (br_multicast_should_handle_mode(br, mdst->addr.proto) &&
...@@ -290,7 +291,7 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, ...@@ -290,7 +291,7 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
struct net_bridge_port *port, *lport, *rport; struct net_bridge_port *port, *lport, *rport;
lport = p ? p->key.port : NULL; lport = p ? p->key.port : NULL;
rport = hlist_entry_safe(rp, struct net_bridge_port, rlist); rport = br_multicast_rport_from_node_skb(rp, skb);
if ((unsigned long)lport > (unsigned long)rport) { if ((unsigned long)lport > (unsigned long)rport) {
port = lport; port = lport;
......
...@@ -132,7 +132,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb ...@@ -132,7 +132,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb
if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) && if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) &&
br_multicast_querier_exists(br, eth_hdr(skb), mdst)) { br_multicast_querier_exists(br, eth_hdr(skb), mdst)) {
if ((mdst && mdst->host_joined) || if ((mdst && mdst->host_joined) ||
br_multicast_is_router(br)) { br_multicast_is_router(br, skb)) {
local_rcv = true; local_rcv = true;
br->dev->stats.multicast++; br->dev->stats.multicast++;
} }
......
...@@ -16,31 +16,76 @@ ...@@ -16,31 +16,76 @@
#include "br_private.h" #include "br_private.h"
static bool br_rports_have_mc_router(struct net_bridge *br)
{
#if IS_ENABLED(CONFIG_IPV6)
return !hlist_empty(&br->ip4_mc_router_list) ||
!hlist_empty(&br->ip6_mc_router_list);
#else
return !hlist_empty(&br->ip4_mc_router_list);
#endif
}
static bool
br_ip4_rports_get_timer(struct net_bridge_port *port, unsigned long *timer)
{
*timer = br_timer_value(&port->ip4_mc_router_timer);
return !hlist_unhashed(&port->ip4_rlist);
}
static bool
br_ip6_rports_get_timer(struct net_bridge_port *port, unsigned long *timer)
{
#if IS_ENABLED(CONFIG_IPV6)
*timer = br_timer_value(&port->ip6_mc_router_timer);
return !hlist_unhashed(&port->ip6_rlist);
#else
*timer = 0;
return false;
#endif
}
static int br_rports_fill_info(struct sk_buff *skb, struct netlink_callback *cb, static int br_rports_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
struct net_device *dev) struct net_device *dev)
{ {
struct net_bridge *br = netdev_priv(dev); struct net_bridge *br = netdev_priv(dev);
struct net_bridge_port *p; bool have_ip4_mc_rtr, have_ip6_mc_rtr;
unsigned long ip4_timer, ip6_timer;
struct nlattr *nest, *port_nest; struct nlattr *nest, *port_nest;
struct net_bridge_port *p;
if (!br->multicast_router || hlist_empty(&br->router_list)) if (!br->multicast_router)
return 0;
if (!br_rports_have_mc_router(br))
return 0; return 0;
nest = nla_nest_start_noflag(skb, MDBA_ROUTER); nest = nla_nest_start_noflag(skb, MDBA_ROUTER);
if (nest == NULL) if (nest == NULL)
return -EMSGSIZE; return -EMSGSIZE;
hlist_for_each_entry_rcu(p, &br->router_list, rlist) { list_for_each_entry_rcu(p, &br->port_list, list) {
if (!p) have_ip4_mc_rtr = br_ip4_rports_get_timer(p, &ip4_timer);
have_ip6_mc_rtr = br_ip6_rports_get_timer(p, &ip6_timer);
if (!have_ip4_mc_rtr && !have_ip6_mc_rtr)
continue; continue;
port_nest = nla_nest_start_noflag(skb, MDBA_ROUTER_PORT); port_nest = nla_nest_start_noflag(skb, MDBA_ROUTER_PORT);
if (!port_nest) if (!port_nest)
goto fail; goto fail;
if (nla_put_nohdr(skb, sizeof(u32), &p->dev->ifindex) || if (nla_put_nohdr(skb, sizeof(u32), &p->dev->ifindex) ||
nla_put_u32(skb, MDBA_ROUTER_PATTR_TIMER, nla_put_u32(skb, MDBA_ROUTER_PATTR_TIMER,
br_timer_value(&p->multicast_router_timer)) || max(ip4_timer, ip6_timer)) ||
nla_put_u8(skb, MDBA_ROUTER_PATTR_TYPE, nla_put_u8(skb, MDBA_ROUTER_PATTR_TYPE,
p->multicast_router)) { p->multicast_router) ||
(have_ip4_mc_rtr &&
nla_put_u32(skb, MDBA_ROUTER_PATTR_INET_TIMER,
ip4_timer)) ||
(have_ip6_mc_rtr &&
nla_put_u32(skb, MDBA_ROUTER_PATTR_INET6_TIMER,
ip6_timer))) {
nla_nest_cancel(skb, port_nest); nla_nest_cancel(skb, port_nest);
goto fail; goto fail;
} }
......
This diff is collapsed.
...@@ -307,16 +307,18 @@ struct net_bridge_port { ...@@ -307,16 +307,18 @@ struct net_bridge_port {
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
struct bridge_mcast_own_query ip4_own_query; struct bridge_mcast_own_query ip4_own_query;
struct timer_list ip4_mc_router_timer;
struct hlist_node ip4_rlist;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
struct bridge_mcast_own_query ip6_own_query; struct bridge_mcast_own_query ip6_own_query;
struct timer_list ip6_mc_router_timer;
struct hlist_node ip6_rlist;
#endif /* IS_ENABLED(CONFIG_IPV6) */ #endif /* IS_ENABLED(CONFIG_IPV6) */
u32 multicast_eht_hosts_limit; u32 multicast_eht_hosts_limit;
u32 multicast_eht_hosts_cnt; u32 multicast_eht_hosts_cnt;
unsigned char multicast_router; unsigned char multicast_router;
struct bridge_mcast_stats __percpu *mcast_stats; struct bridge_mcast_stats __percpu *mcast_stats;
struct timer_list multicast_router_timer;
struct hlist_head mglist; struct hlist_head mglist;
struct hlist_node rlist;
#endif #endif
#ifdef CONFIG_SYSFS #ifdef CONFIG_SYSFS
...@@ -449,14 +451,16 @@ struct net_bridge { ...@@ -449,14 +451,16 @@ struct net_bridge {
struct hlist_head mcast_gc_list; struct hlist_head mcast_gc_list;
struct hlist_head mdb_list; struct hlist_head mdb_list;
struct hlist_head router_list;
struct timer_list multicast_router_timer; struct hlist_head ip4_mc_router_list;
struct timer_list ip4_mc_router_timer;
struct bridge_mcast_other_query ip4_other_query; struct bridge_mcast_other_query ip4_other_query;
struct bridge_mcast_own_query ip4_own_query; struct bridge_mcast_own_query ip4_own_query;
struct bridge_mcast_querier ip4_querier; struct bridge_mcast_querier ip4_querier;
struct bridge_mcast_stats __percpu *mcast_stats; struct bridge_mcast_stats __percpu *mcast_stats;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
struct hlist_head ip6_mc_router_list;
struct timer_list ip6_mc_router_timer;
struct bridge_mcast_other_query ip6_other_query; struct bridge_mcast_other_query ip6_other_query;
struct bridge_mcast_own_query ip6_own_query; struct bridge_mcast_own_query ip6_own_query;
struct bridge_mcast_querier ip6_querier; struct bridge_mcast_querier ip6_querier;
...@@ -864,11 +868,58 @@ static inline bool br_group_is_l2(const struct br_ip *group) ...@@ -864,11 +868,58 @@ static inline bool br_group_is_l2(const struct br_ip *group)
#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))
static inline bool br_multicast_is_router(struct net_bridge *br) static inline struct hlist_node *
br_multicast_get_first_rport_node(struct net_bridge *b, struct sk_buff *skb) {
#if IS_ENABLED(CONFIG_IPV6)
if (skb->protocol == htons(ETH_P_IPV6))
return rcu_dereference(hlist_first_rcu(&b->ip6_mc_router_list));
#endif
return rcu_dereference(hlist_first_rcu(&b->ip4_mc_router_list));
}
static inline struct net_bridge_port *
br_multicast_rport_from_node_skb(struct hlist_node *rp, struct sk_buff *skb) {
#if IS_ENABLED(CONFIG_IPV6)
if (skb->protocol == htons(ETH_P_IPV6))
return hlist_entry_safe(rp, struct net_bridge_port, ip6_rlist);
#endif
return hlist_entry_safe(rp, struct net_bridge_port, ip4_rlist);
}
static inline bool br_ip4_multicast_is_router(struct net_bridge *br)
{
return timer_pending(&br->ip4_mc_router_timer);
}
static inline bool br_ip6_multicast_is_router(struct net_bridge *br)
{ {
return br->multicast_router == 2 || #if IS_ENABLED(CONFIG_IPV6)
(br->multicast_router == 1 && return timer_pending(&br->ip6_mc_router_timer);
timer_pending(&br->multicast_router_timer)); #else
return false;
#endif
}
static inline bool
br_multicast_is_router(struct net_bridge *br, struct sk_buff *skb)
{
switch (br->multicast_router) {
case MDB_RTR_TYPE_PERM:
return true;
case MDB_RTR_TYPE_TEMP_QUERY:
if (skb) {
if (skb->protocol == htons(ETH_P_IP))
return br_ip4_multicast_is_router(br);
else if (skb->protocol == htons(ETH_P_IPV6))
return br_ip6_multicast_is_router(br);
} else {
return br_ip4_multicast_is_router(br) ||
br_ip6_multicast_is_router(br);
}
fallthrough;
default:
return false;
}
} }
static inline bool static inline bool
......
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