[SOLVED] Vpn-policy-routing setup via uci set commands - having a hard time

Hello everyone,

I've searched and could not find how to set vpn policy routing policies by using uci set commands.

I'm trying to set individual policies for different hosts that need to go via the WireGuard interface, as I've set the default to be the wan interface.

I start by issuing an 'uci set vpn-policy-routing.@policy[0]=policy' command, which returns NO error.

But, I keep getting and "uci: Invalid argument" after each of the following commands:

uci set vpn-policy-routing.@policy[0].interface='wg0'
uci set vpn-policy-routing.@policy[0].name='MACMINI'
uci set vpn-policy-routing.@policy[0].src_addr='XX:XX:XX:XX:XX:XX'

I know I'm probably making a syntax mistake, but so far I have failed to discover where.
Is anybody here able to point me in the right direction?
TIA

PS: vpn-policy-routing is working if I change it to be the default, or if I set individual policies via the GUI. I'm only having problems setting the individual hosts policies via the uci set commands. Also, if I use the 'uci show -policy-routing' command after manually adding a host from the GUI, the working config is shown, ending with the following:

vpn-policy-routing.@policy[0]=policy
vpn-policy-routing.@policy[0].name='MACMINI'
vpn-policy-routing.@policy[0].src_addr='XX:XX:XX:XX:XX:XX'
vpn-policy-routing.@policy[0].interface='wg0'

PS2: Sorry, I forgot to post initially that this is on a x86/64 mini computer running 21.02-rc3.

Answering my own question, I just found out that the correct syntax is WITHOUT ' ' surrounding the interface name, host name and mac address, as follows:

uci set vpn-policy-routing.@policy[0]=policy
uci set vpn-policy-routing.@policy[0].interface=wg0
uci set vpn-policy-routing.@policy[0].name=MYROKU
uci set vpn-policy-routing.@policy[0].src_addr=XX:XX:XX:XX:XX:XX
uci commit vpn-policy-routing

In addition to the above mentioned, if you intend to add more than one policy programmatically, you may need to go like this:

#!/bin/sh
echo '==> Adding two VPN routing policies'
echo '==>'
echo '==> Adding first.'
uci add vpn-policy-routing policy
uci set vpn-policy-routing.@policy[-1].interface=wg0
uci set vpn-policy-routing.@policy[-1].name=MYROKU
uci set vpn-policy-routing.@policy[-1].src_addr=11:11:11:11:11:11
uci commit vpn-policy-routing
#
echo '==>'
echo '==> Adding one more.'
uci add vpn-policy-routing policy
uci set vpn-policy-routing.@policy[-1].interface=wg0
uci set vpn-policy-routing.@policy[-1].name=MacProEn0
uci set vpn-policy-routing.@policy[-1].src_addr=99:99:99:99:99:99
uci commit vpn-policy-routing
echo '==> vpn-policy-routing host policies added to configuration.'
2 Likes

Wow, thanks for bringing that out!
I don't quite know how I could not find it before, because I've searched and searched, but never got to find above mentioned wiki...

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