How to configure port mirroring?

I have an Ethernet switch Zyxel GS1900-8 with Realtek RTL8380M SoC. In the Linux DSA source code I saw that port mirroring is supported by the driver. After trying this feature (OpenWrt SNAPSHOT, r33995+2-a2dcbd79a4, Linux 6.18.21) via tc (see below) it seems that port mirroring is working - wow - I didn’t expect that honestly saying! Thanks to the developers!

My question is: Is there a more user-friendly option to configure it e.g. via uci?

When only using tc, lan8 in my example is still part of the bridge which means that I see all broadcast messages multiple times on lan8 because all broadcast messages are mirrored from lan2 to lan8 additionally. Of course, I could remove lan8 from the bridge, but that requires many additionally configuration steps that need to be reverted after disabling port mirroring.

How to enable port mirror

# Mirror all traffic on lan2 to lan8:
tc qdisc add dev lan2 clsact
tc filter add dev lan2 ingress matchall action mirred egress mirror dev lan8
tc filter add dev lan2 egress  matchall action mirred egress mirror dev lan8

How to disable port mirror

tc qdisc del dev lan2 clsact

I opened a pull request for an uci integration here https://github.com/openwrt/openwrt/pull/22988.

I raised up the port-mirror-scripts idea in the developer mailing list: https://lists.openwrt.org/pipermail/openwrt-devel/2026-April/044751.html.

Here is how Teltonika solved it (I’m using a TSW202 industrial switch based on the RTL8380M).

Some screenshots from the web interface:

In the background there is a Teltonika proprietary daemon tswconfig which handles the config file /etc/config/tswconfig. It seems that this daemon implements tons of switch specific options (see example below).

For port mirroring the important options are

[...]
list ingress_ports 'port7'
list egress_ports 'port7'
option mirror '0'
[...]

Example

root@TSW202:~# cat /etc/config/tswconfig

config switch_port 'port1'
option enable '1'
option advert '0x3F'
option autoneg '1'
option eee_enable '1'
option ingr_bw '0'
option ingr_rate '62500'
option egr_bw '0'
option egr_rate '62500'
option storm_mult '0'
option storm_mult_rate '62500'
option storm_broad '0'
option storm_broad_rate '62500'
option storm_uni '0'
option storm_uni_rate '62500'
option storm_uni_type 'unknown'
option storm_multi_type 'unknown'
option qos_pri_group '0'
option qos_pri_inner '0'
option qos_pri_outer '0'
list ingress_ports 'port7'
list egress_ports 'port7'
option mirror '0'

[...]
config switch_port 'port7'
	option enable '1'
	option advert '0x3F'
	option autoneg '1'
	option mirror '0'
	option eee_enable '1'
	option ingr_bw '0'
	option ingr_rate '62500'
	option egr_bw '0'
	option egr_rate '62500'
	option storm_mult '0'
	option storm_mult_rate '62500'
	option storm_broad '0'
	option storm_broad_rate '62500'
	option storm_uni '0'
	option storm_uni_rate '62500'
	option storm_uni_type 'unknown'
	option storm_multi_type 'unknown'
	option qos_pri_group '0'
	option qos_pri_inner '0'
	option qos_pri_outer '0'
[...]