Mirroring port on Banana Pi R3


On Banana Pi R3 Is there a way to configure a mirror port (wan for example) to receive a copy of traffic on other ports (Rx and TX of lan1, lan2, lan3 and lan4 ports) ? I would be very happy to know that such function exists, because this is a must to analyse network traffic with tcpdump, wireshark or other tools. I am using Ubuntu 22.04 (official image).

Mt7531 has mirror option in CFC (cpu forward control) register 0x4

Bit 19 MIRROR_EN Mirror Port Enable Enable the mirror port specified in MIRROR_PORT. 
  0: No mirror available   1: Enable mirror

Bits 18:16 MIRROR_PORT Mirror Port Number Set the mirror port number. 
3'h0: Port 0

Thank you very much, you give me hope. Could you tell me please how to write these values into MT7531 register ? Is there an existing tool or application ? a command line to excute ? or it is necessary to modify the driver, modify mt7530.c, rebuild driver and install new kernel ? I am using official image Ubuntu 22.04.

easiest way would be adding the code to the driver (if not already there).

there is also a way to directly write to registers see my answer here Sniff network with the Pi - #50 by frank-w

but you have to know on which adress the switch is, as it is detected on mdio you cannot read its adress from dts

I used to achieve this with tc qdisc on r2-pro, albeit there are an extra set of kernel configs need to be changed during compilation. Also, tc uses CPU and reduces the throughput from 940 Mbps to 630 Mbps (could be brought back to 940 Mbps after reassigning the irq-balance and queues, since r2-pro’s CPU is capable of 2.2Gbps+ forwarding), so not exactly desirable. Better to do it is through the MT7531, which is hardware based. R3 has a worse CPU than R2-Pro, so tc is again not the best solution.

Seems dsa driver already supports this

I guess it can be activated with ethtool,but not tested

Edit: found this:

Hello, I am interested in your solution using tc qdisc, for my project on banana-pi r3 I will need only 10 Mbps (all ports). Could you send please more details on how you have achieved this ?

Hello lalmi, I forget which kernel modules are required to get the tc to work correctly, so an archaeological dig is required either to get tc working, or get the port mirroring on the MT7531 working. Given getting the hw port mirroring is a better bet than tc for both performance and intention, then we should go explore the MT7531 way.

Oh no, tc seems still to be required. I will try to identify which kernel modules are required and maybe add to your default config later?

I got a non-related PCIe power issue need some investigation. AX210 card and iwlwifi iwlmvm got crashed after no wlan traffic for 2 hours…

Hello, So tc is still required even if modifications are done on MT7531 driver ? There are options in mt7530.c to activate mirroring, I don’t know this option was not activated by default, it is very important to analyse network traffic…

I don’t know this option was not activated by default, it is very important to analyse network traffic

To be clear, Linux is largely a community-driven project. There is no need to insinuate the importance or triviality of certain features, or imply someone’s job could be done better. We are largely volunteering our time here.