Skip to content

Commit 9eb8eff

Browse files
vladimirolteankuba-moo
authored andcommitted
net: bridge: allow enslaving some DSA master network devices
Commit 8db0a2e ("net: bridge: reject DSA-enabled master netdevices as bridge members") added a special check in br_if.c in order to check for a DSA master network device with a tagging protocol configured. This was done because back then, such devices, once enslaved in a bridge would become inoperative and would not pass DSA tagged traffic anymore due to br_handle_frame returning RX_HANDLER_CONSUMED. But right now we have valid use cases which do require bridging of DSA masters. One such example is when the DSA master ports are DSA switch ports themselves (in a disjoint tree setup). This should be completely equivalent, functionally speaking, from having multiple DSA switches hanging off of the ports of a switchdev driver. So we should allow the enslaving of DSA tagged master network devices. Instead of the regular br_handle_frame(), install a new function br_handle_frame_dummy() on these DSA masters, which returns RX_HANDLER_PASS in order to call into the DSA specific tagging protocol handlers, and lift the restriction from br_add_if. Suggested-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com> Suggested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Acked-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Tested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 90d9834 commit 9eb8eff

4 files changed

Lines changed: 49 additions & 14 deletions

File tree

‎include/net/dsa.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ struct dsa_switch_driver {
651651
struct net_device *dsa_dev_to_net_device(struct device *dev);
652652

653653
/* Keep inline for faster access in hot path */
654-
static inline bool netdev_uses_dsa(struct net_device *dev)
654+
static inline bool netdev_uses_dsa(const struct net_device *dev)
655655
{
656656
#if IS_ENABLED(CONFIG_NET_DSA)
657657
return dev->dsa_ptr && dev->dsa_ptr->rcv;

‎net/bridge/br_if.c‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,18 +563,32 @@ int br_add_if(struct net_bridge *br, struct net_device *dev,
563563
unsigned br_hr, dev_hr;
564564
bool changed_addr;
565565

566-
/* Don't allow bridging non-ethernet like devices, or DSA-enabled
567-
* master network devices since the bridge layer rx_handler prevents
568-
* the DSA fake ethertype handler to be invoked, so we do not strip off
569-
* the DSA switch tag protocol header and the bridge layer just return
570-
* RX_HANDLER_CONSUMED, stopping RX processing for these frames.
571-
*/
566+
/* Don't allow bridging non-ethernet like devices. */
572567
if ((dev->flags & IFF_LOOPBACK) ||
573568
dev->type != ARPHRD_ETHER || dev->addr_len != ETH_ALEN ||
574-
!is_valid_ether_addr(dev->dev_addr) ||
575-
netdev_uses_dsa(dev))
569+
!is_valid_ether_addr(dev->dev_addr))
576570
return -EINVAL;
577571

572+
/* Also don't allow bridging of net devices that are DSA masters, since
573+
* the bridge layer rx_handler prevents the DSA fake ethertype handler
574+
* to be invoked, so we don't get the chance to strip off and parse the
575+
* DSA switch tag protocol header (the bridge layer just returns
576+
* RX_HANDLER_CONSUMED, stopping RX processing for these frames).
577+
* The only case where that would not be an issue is when bridging can
578+
* already be offloaded, such as when the DSA master is itself a DSA
579+
* or plain switchdev port, and is bridged only with other ports from
580+
* the same hardware device.
581+
*/
582+
if (netdev_uses_dsa(dev)) {
583+
list_for_each_entry(p, &br->port_list, list) {
584+
if (!netdev_port_same_parent_id(dev, p->dev)) {
585+
NL_SET_ERR_MSG(extack,
586+
"Cannot do software bridging with a DSA master");
587+
return -EINVAL;
588+
}
589+
}
590+
}
591+
578592
/* No bridging of bridges */
579593
if (dev->netdev_ops->ndo_start_xmit == br_dev_xmit) {
580594
NL_SET_ERR_MSG(extack,
@@ -618,7 +632,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev,
618632
if (err)
619633
goto err3;
620634

621-
err = netdev_rx_handler_register(dev, br_handle_frame, p);
635+
err = netdev_rx_handler_register(dev, br_get_rx_handler(dev), p);
622636
if (err)
623637
goto err4;
624638

‎net/bridge/br_input.c‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#endif
1818
#include <linux/neighbour.h>
1919
#include <net/arp.h>
20+
#include <net/dsa.h>
2021
#include <linux/export.h>
2122
#include <linux/rculist.h>
2223
#include "br_private.h"
@@ -257,7 +258,7 @@ static int nf_hook_bridge_pre(struct sk_buff *skb, struct sk_buff **pskb)
257258
* Return NULL if skb is handled
258259
* note: already called with rcu_read_lock
259260
*/
260-
rx_handler_result_t br_handle_frame(struct sk_buff **pskb)
261+
static rx_handler_result_t br_handle_frame(struct sk_buff **pskb)
261262
{
262263
struct net_bridge_port *p;
263264
struct sk_buff *skb = *pskb;
@@ -359,3 +360,23 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb)
359360
}
360361
return RX_HANDLER_CONSUMED;
361362
}
363+
364+
/* This function has no purpose other than to appease the br_port_get_rcu/rtnl
365+
* helpers which identify bridged ports according to the rx_handler installed
366+
* on them (so there _needs_ to be a bridge rx_handler even if we don't need it
367+
* to do anything useful). This bridge won't support traffic to/from the stack,
368+
* but only hardware bridging. So return RX_HANDLER_PASS so we don't steal
369+
* frames from the ETH_P_XDSA packet_type handler.
370+
*/
371+
static rx_handler_result_t br_handle_frame_dummy(struct sk_buff **pskb)
372+
{
373+
return RX_HANDLER_PASS;
374+
}
375+
376+
rx_handler_func_t *br_get_rx_handler(const struct net_device *dev)
377+
{
378+
if (netdev_uses_dsa(dev))
379+
return br_handle_frame_dummy;
380+
381+
return br_handle_frame;
382+
}

‎net/bridge/br_private.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,16 +702,16 @@ int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev);
702702

703703
/* br_input.c */
704704
int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
705-
rx_handler_result_t br_handle_frame(struct sk_buff **pskb);
705+
rx_handler_func_t *br_get_rx_handler(const struct net_device *dev);
706706

707707
static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
708708
{
709-
return rcu_dereference(dev->rx_handler) == br_handle_frame;
709+
return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev);
710710
}
711711

712712
static inline bool br_rx_handler_check_rtnl(const struct net_device *dev)
713713
{
714-
return rcu_dereference_rtnl(dev->rx_handler) == br_handle_frame;
714+
return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev);
715715
}
716716

717717
static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)

0 commit comments

Comments
 (0)