Firewall Config Forwarding - uci name unnamed type


not sure this question should placed in "For Developers".

I'm using OpenWRT for around 3 weeks and struggle with uci set. I want to change
the firewall forwarding between two zones with uci.
As the type / section is unnamed the struggle for me is to change an option in unnamed configs.
At the moment I have only one forwarding setting, but it could be that some more will come. To access this forwarding setting better I gave the type a name.

In /etc/config/firewall I changed:

config forwarding
	option src 'lan'
	option dest 'wan'


config forwarding 'nameit'
	option src 'lan'
	option dest 'wan'
	option enabled '1'

Now I can do uci set firewall.nameit.enabled=1 && uci commit && /etc/firewall restart to enable
and uci set firewall.nameit.enabled=0 && uci commit && /etc/firewall restart which is very

I tested it and it works so far, but as I have no longer experience if that could have side
effects. Any suggestions are welcome.


When there are multiple rules next to each other, UCI supports array-like references for them. If there are 8 NTP servers defined in /etc/config/system , UCI will let you reference their sections as system.@timeserver[0] for the first or system.@timeserver[7] for the last one. You can also use negative indexes, such as system.@timeserver[-1] . “-1” means the last one, “-2” means the second-to-last one, and so on. This comes in very handy when appending new rules to the end of a list. See the examples below.

In a clean installtion forwarding[0] will be lan->wan

That was the documentation I found. I understand that unnamed sections could
be accessed with the array-like syntax.
I struggle with finding the right index to access the specific configuration which I want
to change. Thats why I want to know if it have side effects if I name it.

It is right, that in the clean installation the index would be 0, but what if for some reason
the index change, ex. a new forwarding rule or such.

You certainly can rename them.

uci rename firewall.@zone[0]="lan"
uci rename firewall.@zone[1]="wan"
uci rename firewall.@forwarding[0]="lan_wan"

Then it would be best for your convenience to rename them from the start and avoid any confusion.

1 Like