Swconfig versus etc/config/network

Hi, tried

config switch_port
        option device 'eth0'
        option port '1'
        option enable_mirror_rx '1'

and

config switch_port
        option device 'switch0'
        option port '1'
        option enable_mirror_rx '1'

no luck.

Quite interesting my etc/config/network switch part (the one I put in openwrt/etc/config/network before building)

doesnt change my boot up swconfig dev eth0 show

in

mirror_monitor_port: 5   that shows  mirror_monitor_port: 15

while works for

 enable_vlan: 1

that part being:

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'
        option mirror_monitor_port '5'

if I do etc/init.d/network reload

mirror_monitor_port: 5    is fine

as per the switch_port problem

config switch_port
        option device 'eth0'
        option port '1'
        option enable_mirror_rx '1'

doesn't work even with if etc/init.d/network reload

uci network show does give

network.loopback=interface
network.loopback.ifname='lo'
network.loopback.proto='static'
network.loopback.ipaddr='127.0.0.1'
network.loopback.netmask='255.0.0.0'
network.globals=globals
network.globals.ula_prefix='auto'
network.lan=interface
network.lan.type='bridge'
network.lan.ifname='eth0.1'
network.lan.proto='static'
network.lan.ipaddr='192.168.1.1'
network.lan.netmask='255.255.255.0'
network.lan.ip6assign='60'
network.mir=interface
network.mir.ifname='eth0.2'
network.mir.proto='none'
network.@switch[0]=switch
network.@switch[0].name='switch0'
network.@switch[0].reset='1'
network.@switch[0].enable_vlan='1'
network.@switch[0].mirror_monitor_port='5'
network.@switch[0].enable_mirror_rx='1'
network.@switch[0].enable_mirror_tx='1'
network.@switch[0].mirror_source_port='1'
network.@switch_vlan[0]=switch_vlan
network.@switch_vlan[0].device='switch0'
network.@switch_vlan[0].vlan='1'
network.@switch_vlan[0].ports='0t 1'
network.@switch_vlan[0].vid='1'
network.@switch_vlan[1]=switch_vlan
network.@switch_vlan[1].device='switch0'
network.@switch_vlan[1].vlan='2'
network.@switch_vlan[1].ports='0t 5'
network.@switch_vlan[1].vid='2'
network.@switch_port[0]=switch_port
network.@switch_port[0].device='eth0'
network.@switch_port[0].port='1'
network.@switch_port[0].enable_mirror_rx='1'

but nothing gets to swconfig

Any Idea. I'll try to understand how Luci <---> uci <---> swconfig works but I don't think I would be able to grasp even the basics of it

I noticed you have the monitor port MIR in your picture set as ""untagged." Have you tried setting this port to "off" except for CPU?

You can cut out LuCI of the equation, I don't think it is related at all here. The swconfig utility is actually processing the /etc/config/network file directly by itself (using the swconfig dev switch0 load network command). So I think that swconfig's C code reading the config is applying the settings in a wrong order.

Note that it must be "option device switch0", not "eth0".

used both of them , no luck

tried today

port off works the same as port on

means need to manually add

swconfig dev eth0 set mirror_monitor_port '5' && swconfig dev eth0 port '1' set enable_mirror_rx '1' && swconfig dev eth0 port '1' set enable_mirror_tx '1'

but the monitoring port works as well as the other one that I use for Luci connection

/* look for port or vlan sections */
	uci_foreach_element(&p->sections, e) {
		struct uci_element *os;
		s = uci_to_section(e);

		if (!strcmp(s->type, "switch_port")) {
			char *devn = NULL, *port = NULL, *port_err = NULL;
			int port_n;

			uci_foreach_element(&s->options, os) {
				o = uci_to_option(os);
				if (o->type != UCI_TYPE_STRING)
					continue;

				if (!strcmp(os->name, "device")) {
					devn = o->v.string;
					if (!swlib_match_name(dev, devn))
						devn = NULL;
				} else if (!strcmp(os->name, "port")) {
					port = o->v.string;
				}
			}
			if (!devn || !port || !port[0])
				continue;

			port_n = strtoul(port, &port_err, 0);
			if (port_err && port_err[0])
				continue;

			swlib_map_settings(dev, SWLIB_ATTR_GROUP_PORT, port_n, s);
		} else if (!strcmp(s->type, "switch_vlan")) {
			char *devn = NULL, *vlan = NULL, *vlan_err = NULL;
			int vlan_n;

			uci_foreach_element(&s->options, os) {
				o = uci_to_option(os);
				if (o->type != UCI_TYPE_STRING)
					continue;

here ?

Given that I gave up after

#include <stdio.h>
int main()
{
   // printf() displays the string inside quotation
   printf("Hello, World!");
   return 0;
}


I think I'll pass on it and see if I can something like

swconfig dev eth0 set mirror_monitor_port '5' && swconfig dev eth0 port '1' set enable_mirror_rx '1' && swconfig dev eth0 port '1' set enable_mirror_tx '1'

everytime the network reinitialise ?

Any help with that ??

Hi jow,

just to be sure I got it right if swconfig reads in the wrong order the network config means that

root@OpenWrt:/# swconfig dev eth0 help
switch0: eth0(AR934X built-in switch), ports: 6 (cpu @ 0), vlans: 16
     --switch
        Attribute 1 (int): enable_vlan (Enable VLAN mode)
        Attribute 2 (int): mirror_monitor_port (Mirror monitor port)
        Attribute 3 (none): apply (Activate changes in the hardware)
        Attribute 4 (none): reset (Reset the switch)
     --vlan
        Attribute 1 (int): vid (VLAN ID)
        Attribute 2 (ports): ports (VLAN port mapping)
     --port
        Attribute 1 (int): enable_mirror_rx (Enable mirroring of RX packets)
        Attribute 2 (int): enable_mirror_tx (Enable mirroring of TX packets)
        Attribute 3 (int): pvid (Primary VLAN ID)
        Attribute 4 (unknown): link (Get port link information)
root@OpenWrt:/# 

are the valid attributes ?

when Luci tries to set them Luci writes the in wrong order too ?

Apparently the swconfig load operation always triggers 'apply' function which in this switch driver currently clears port mirroring flags effectively undoing port mirroring configuration.

I've submitted a patch for this, however there's one more issue that I'm trying to resolve:

  • /etc/init.d/network reload works fine
  • /etc/init.d/network restart initially works fine, the mirror flags are set, but after about 3 seconds they are reset
  • the same issue is present after reboot, can be worked around with network reload

I cannot determine where this is triggered from though.

According to my research, swconfig load sets up vlans and mirror flags via swconfig netlink API, but shortly afterwards netifd triggers switch reset via ioctl. This occurs when interface eth0 comes up, which happens on boot, during '/etc/init.d/network restart', basically when the first interface (e.g. 'lan') is attached to eth0.

When soft reset is triggered from the driver, the switch chip appears to clear mirror flags, while preserving the vlan config.

         ar7240sw_reg_write(mii, AR7240_REG_MASK_CTRL,
                           AR7240_MASK_CTRL_SOFT_RESET);

I don't know how to fix this - swconfig/netifd behaviour is probably expected and not to be touched, and the driver issuing soft reset during switch reset operation also looks good, and is probably necessary. I'm not sure whether preserving mirror flags in the driver during a switch reset operation should be done.

Any ideas?

Where did you find the

 ar7240sw_reg_write(mii, AR7240_REG_MASK_CTRL,
                           AR7240_MASK_CTRL_SOFT_RESET);

Just curios about how openwrt works ?

One way to find the usages and hopefully the source is

jeff@deb-devel:~/devel/openwrt$ fgrep -rI ar7240sw_reg_write  build_dir/target-mips_24kc_musl/linux-ath79_generic/
build_dir/target-mips_24kc_musl/linux-ath79_generic/linux-4.14.93/.tmp_System.map:ffffffff802bb1c0 t __ar7240sw_reg_write
build_dir/target-mips_24kc_musl/linux-ath79_generic/linux-4.14.93/.tmp_System.map:ffffffff802bb7e4 t ar7240sw_reg_write
build_dir/target-mips_24kc_musl/linux-ath79_generic/linux-4.14.93/drivers/net/ethernet/atheros/ag71xx/ag71xx_ar7240.c:static void __ar7240sw_reg_write(struct mii_bus *mii, u32 reg, u32 val)
[...]

From that I'd look in drivers/net/ethernet/atheros/ag71xx/ag71xx_ar7240.c

You can, for example, | fgrep .h to limit to header files, but in this case, nothing was returned.

hi @Pippo how you have resolved/removed the "unknown topology" for switch eth1 ?
I have open a thread about this issue about 5 days ago... apparently there's no solution also over google search.