[PATCH net-next 27/30] net: dsa: mt7530: introduce BPDU trapping for MT7530 switch

arinc9.unal@gmail.com posted 30 patches 1 year, 4 months ago
[PATCH net-next 27/30] net: dsa: mt7530: introduce BPDU trapping for MT7530 switch
Posted by arinc9.unal@gmail.com 1 year, 4 months ago
From: Arınç ÜNAL <arinc.unal@arinc9.com>

The MT753X switches are capable of trapping certain frames. Introduce
trapping BPDUs to the CPU port for the MT7530 switch.

BPDUs will be trapped to the numerically smallest CPU port which is affine
to the DSA conduit interface that is set up. The BPDUs won't necessarily be
trapped to the CPU port the user port, which these BPDUs are received from,
is affine to.

Tested-by: Arınç ÜNAL <arinc.unal@arinc9.com>
Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
---
 drivers/net/dsa/mt7530.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index cd16911fcb01..2fb4b0bc6335 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2223,6 +2223,10 @@ mt7530_setup(struct dsa_switch *ds)
 	val |= MHWTRAP_MANUAL;
 	mt7530_write(priv, MT7530_MHWTRAP, val);
 
+	/* Trap BPDUs to the CPU port */
+	mt7530_rmw(priv, MT753X_BPC, MT753X_BPDU_PORT_FW_MASK,
+		   MT753X_BPDU_CPU_ONLY);
+
 	/* Enable and reset MIB counters */
 	mt7530_mib_reset(ds);
 
-- 
2.39.2

Re: [PATCH net-next 27/30] net: dsa: mt7530: introduce BPDU trapping for MT7530 switch
Posted by Vladimir Oltean 1 year, 3 months ago
On Mon, May 22, 2023 at 03:15:29PM +0300, arinc9.unal@gmail.com wrote:
> From: Arınç ÜNAL <arinc.unal@arinc9.com>
> 
> The MT753X switches are capable of trapping certain frames. Introduce
> trapping BPDUs to the CPU port for the MT7530 switch.
> 
> BPDUs will be trapped to the numerically smallest CPU port which is affine
> to the DSA conduit interface that is set up. The BPDUs won't necessarily be
> trapped to the CPU port the user port, which these BPDUs are received from,
> is affine to.
> 
> Tested-by: Arınç ÜNAL <arinc.unal@arinc9.com>
> Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
> ---
>  drivers/net/dsa/mt7530.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index cd16911fcb01..2fb4b0bc6335 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -2223,6 +2223,10 @@ mt7530_setup(struct dsa_switch *ds)
>  	val |= MHWTRAP_MANUAL;
>  	mt7530_write(priv, MT7530_MHWTRAP, val);
>  
> +	/* Trap BPDUs to the CPU port */
> +	mt7530_rmw(priv, MT753X_BPC, MT753X_BPDU_PORT_FW_MASK,
> +		   MT753X_BPDU_CPU_ONLY);
> +

If the switch doesn't currently trap BPDUs, isn't STP broken?

ip link add br0 type bridge stp_state 1
(with or without a userspace helper installed at /sbin/bridge-stp
for more modern protocols than the original 802.1D STP)

>  	/* Enable and reset MIB counters */
>  	mt7530_mib_reset(ds);
>  
> -- 
> 2.39.2
> 
Re: [PATCH net-next 27/30] net: dsa: mt7530: introduce BPDU trapping for MT7530 switch
Posted by Arınç ÜNAL 1 year, 3 months ago
On 26.05.2023 20:02, Vladimir Oltean wrote:
> On Mon, May 22, 2023 at 03:15:29PM +0300, arinc9.unal@gmail.com wrote:
>> From: Arınç ÜNAL <arinc.unal@arinc9.com>
>>
>> The MT753X switches are capable of trapping certain frames. Introduce
>> trapping BPDUs to the CPU port for the MT7530 switch.
>>
>> BPDUs will be trapped to the numerically smallest CPU port which is affine
>> to the DSA conduit interface that is set up. The BPDUs won't necessarily be
>> trapped to the CPU port the user port, which these BPDUs are received from,
>> is affine to.
>>
>> Tested-by: Arınç ÜNAL <arinc.unal@arinc9.com>
>> Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
>> ---
>>   drivers/net/dsa/mt7530.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
>> index cd16911fcb01..2fb4b0bc6335 100644
>> --- a/drivers/net/dsa/mt7530.c
>> +++ b/drivers/net/dsa/mt7530.c
>> @@ -2223,6 +2223,10 @@ mt7530_setup(struct dsa_switch *ds)
>>   	val |= MHWTRAP_MANUAL;
>>   	mt7530_write(priv, MT7530_MHWTRAP, val);
>>   
>> +	/* Trap BPDUs to the CPU port */
>> +	mt7530_rmw(priv, MT753X_BPC, MT753X_BPDU_PORT_FW_MASK,
>> +		   MT753X_BPDU_CPU_ONLY);
>> +
> 
> If the switch doesn't currently trap BPDUs, isn't STP broken?

No, the BPDU_PORT_FW bits are 0 after reset. The MT7620 programming 
guide states that frames with 01:80:C2:00:00:00 MAC DA (which is how the 
BPDU distinction is being made) will follow the system default which 
means the BPDUs will be treated as normal multicast frames.

Only if all 3 bits are set will the BPDUs be dropped.

> 
> ip link add br0 type bridge stp_state 1
> (with or without a userspace helper installed at /sbin/bridge-stp
> for more modern protocols than the original 802.1D STP)

For reference, the mstpd package on Buildroot includes this.

Arınç
Re: [PATCH net-next 27/30] net: dsa: mt7530: introduce BPDU trapping for MT7530 switch
Posted by Vladimir Oltean 1 year, 3 months ago
On Sun, Jun 04, 2023 at 11:51:33AM +0300, Arınç ÜNAL wrote:
> > If the switch doesn't currently trap BPDUs, isn't STP broken?
> 
> No, the BPDU_PORT_FW bits are 0 after reset. The MT7620 programming guide
> states that frames with 01:80:C2:00:00:00 MAC DA (which is how the BPDU
> distinction is being made) will follow the system default which means the
> BPDUs will be treated as normal multicast frames.
> 
> Only if all 3 bits are set will the BPDUs be dropped.

Right, if you don't trap BPDUs just to the CPU but flood them, I believe
the STP protocol won't behave properly with switching loops. Worth testing.
Re: [PATCH net-next 27/30] net: dsa: mt7530: introduce BPDU trapping for MT7530 switch
Posted by Arınç ÜNAL 1 year, 3 months ago
On 4.06.2023 12:23, Vladimir Oltean wrote:
> On Sun, Jun 04, 2023 at 11:51:33AM +0300, Arınç ÜNAL wrote:
>>> If the switch doesn't currently trap BPDUs, isn't STP broken?
>>
>> No, the BPDU_PORT_FW bits are 0 after reset. The MT7620 programming guide
>> states that frames with 01:80:C2:00:00:00 MAC DA (which is how the BPDU
>> distinction is being made) will follow the system default which means the
>> BPDUs will be treated as normal multicast frames.
>>
>> Only if all 3 bits are set will the BPDUs be dropped.
> 
> Right, if you don't trap BPDUs just to the CPU but flood them, I believe
> the STP protocol won't behave properly with switching loops. Worth testing.

I've got no interest spending time playing around with STP at the moment 
so I'm going to pass.

Arınç
Re: [PATCH net-next 27/30] net: dsa: mt7530: introduce BPDU trapping for MT7530 switch
Posted by Vladimir Oltean 1 year, 3 months ago
On Sun, Jun 04, 2023 at 12:39:33PM +0300, Arınç ÜNAL wrote:
> On 4.06.2023 12:23, Vladimir Oltean wrote:
> > On Sun, Jun 04, 2023 at 11:51:33AM +0300, Arınç ÜNAL wrote:
> > > > If the switch doesn't currently trap BPDUs, isn't STP broken?
> > > 
> > > No, the BPDU_PORT_FW bits are 0 after reset. The MT7620 programming guide
> > > states that frames with 01:80:C2:00:00:00 MAC DA (which is how the BPDU
> > > distinction is being made) will follow the system default which means the
> > > BPDUs will be treated as normal multicast frames.
> > > 
> > > Only if all 3 bits are set will the BPDUs be dropped.
> > 
> > Right, if you don't trap BPDUs just to the CPU but flood them, I believe
> > the STP protocol won't behave properly with switching loops. Worth testing.
> 
> I've got no interest spending time playing around with STP at the moment so
> I'm going to pass.

You can at the very least move it towards the beginning of the net-next patch
set, so that we can be sure it doesn't depend on the other refactoring work,
in case someone in the future makes a request for the patch to be backported
to stable.
Re: [PATCH net-next 27/30] net: dsa: mt7530: introduce BPDU trapping for MT7530 switch
Posted by Arınç ÜNAL 1 year, 3 months ago
On 4.06.2023 15:47, Vladimir Oltean wrote:
> On Sun, Jun 04, 2023 at 12:39:33PM +0300, Arınç ÜNAL wrote:
>> On 4.06.2023 12:23, Vladimir Oltean wrote:
>>> On Sun, Jun 04, 2023 at 11:51:33AM +0300, Arınç ÜNAL wrote:
>>>>> If the switch doesn't currently trap BPDUs, isn't STP broken?
>>>>
>>>> No, the BPDU_PORT_FW bits are 0 after reset. The MT7620 programming guide
>>>> states that frames with 01:80:C2:00:00:00 MAC DA (which is how the BPDU
>>>> distinction is being made) will follow the system default which means the
>>>> BPDUs will be treated as normal multicast frames.
>>>>
>>>> Only if all 3 bits are set will the BPDUs be dropped.
>>>
>>> Right, if you don't trap BPDUs just to the CPU but flood them, I believe
>>> the STP protocol won't behave properly with switching loops. Worth testing.
>>
>> I've got no interest spending time playing around with STP at the moment so
>> I'm going to pass.
> 
> You can at the very least move it towards the beginning of the net-next patch
> set, so that we can be sure it doesn't depend on the other refactoring work,
> in case someone in the future makes a request for the patch to be backported
> to stable.

Maybe I should submit this and LLDP trapping to net? Currently, the 
MT7530 subdriver on the stable kernels treat LLDP frames and BPDUs as 
regular multicast frames, therefore flooding them to user ports, which 
is wrong. These patches could count as bug fixes.

Arınç
Re: [PATCH net-next 27/30] net: dsa: mt7530: introduce BPDU trapping for MT7530 switch
Posted by Vladimir Oltean 1 year, 3 months ago
On Sat, Jun 10, 2023 at 11:32:45AM +0300, Arınç ÜNAL wrote:
> Maybe I should submit this and LLDP trapping to net? Currently, the MT7530
> subdriver on the stable kernels treat LLDP frames and BPDUs as regular
> multicast frames, therefore flooding them to user ports, which is wrong.
> These patches could count as bug fixes.

Yes, I believe that trapping link-local frames only to the host
constitutes "net.git" material.