I've made a change to the UCI article that would like to have some review

Diff: https://openwrt.org/docs/guide-user/base-system/uci?do=diff&rev2[0]=1678034462&rev2[1]=1678343805&difftype=sidebyside

Before:

When there are multiple rules next to each other, UCI supports array-like references for them.

After:

When there are multiple sections of the same type in a config, UCI supports array-like references for them.

I believe the change makes the concept more clearer as the original one seems to make sense only in the firewall configuration context, nonetheless I would like someone to take a look.

Thanks in advance.

Looks good to me.

1 Like

You have to be careful what you mean by "section".
From the same document:

  • sections: config is divided into sections. A section can either be named or unnamed.

I think your change should read:

When there are multiple unnamed sections of the same type in a config, UCI supports array-like references for them.

2 Likes

Not sure what do you specifically mean, however at my system named config section of the same config type can also be referenced using the array-like syntax:

root@brlin-openwrt-test:~# uci show firewall.@rule[0]
firewall.allow_ssh_from_wan=rule
firewall.allow_ssh_from_wan.name='Allow SSH access from the WAN interface'
firewall.allow_ssh_from_wan.proto='tcp'
firewall.allow_ssh_from_wan.src='wan'
firewall.allow_ssh_from_wan.dest_port='22'
firewall.allow_ssh_from_wan.target='ACCEPT'
root@brlin-openwrt-test:~# uci show firewall.@rule[1]
firewall.allow_luci_from_wan=rule
firewall.allow_luci_from_wan.name='Allow LuCI access from the WAN interface'
firewall.allow_luci_from_wan.proto='tcp'
firewall.allow_luci_from_wan.src='wan'
firewall.allow_luci_from_wan.dest_port='80 443'
firewall.allow_luci_from_wan.target='ACCEPT'
root@brlin-openwrt-test:~# uci show firewall.@rule[3]
firewall.cfg0892bd=rule
firewall.cfg0892bd.name='Allow-Ping'
firewall.cfg0892bd.src='wan'
firewall.cfg0892bd.proto='icmp'
firewall.cfg0892bd.icmp_type='echo-request'
firewall.cfg0892bd.family='ipv4'
firewall.cfg0892bd.target='ACCEPT'

Yes it does work with named sections BUT if things are added/deleted/modified the index can change.
Using the "array-like" syntax is just a way of working around unnamed sections and should not really be used otherwise as the results can be a bit random with unexpected results.
The more complex a config becomes the more likely it is that things will go wrong with the indexing.
Referring to a section by name is guaranteed to give the same results.

2 Likes