Add multiple fw rule with UCI

uci add firewall rule
uci set firewall.@rule[-1].src='xxxxc'
uci set firewall.@rule[-1].target='xxxxx'
uci set firewall.@rule[-1].proto='xxxxxx'
uci set firewall.@rule[-1].dest_port='xxxxx'

uci add firewall rule
uci set firewall.@rule[-2].src='xxxxx'
uci set firewall.@rule[-2].target='xxxxx'
uci set firewall.@rule[-2].proto='xxxxx'
uci set firewall.@rule[-2].dest_port='xxxx'

uci add firewall rule
uci set firewall.@rule[-3].src='xxxxx'
uci set firewall.@rule[-3].target='xxxxxx'
uci set firewall.@rule[-3].proto='xxxxx’
uci set firewall.@rule[-3].dest_port='xxxx'

uci commit firewall

This code is an example of the problem!
If I want in a script to add three firewall rules in one go should I then have index -1, -2 and -3 as above or should I have index -1 on all?

The actual result with his code was that the rule with index -3 was the only one written in the firewall config file and two more rule headlines without any included rules was also written in the config file!?

Or do need to run “commit” between each -1 rule?

1 Like
id=$(uci add firewall rule)
uci set firewall.$id.src='...'
...
1 Like

That's correct.

2 Likes

Thanks, now it works as expected :smiley:

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.