If I create multiple tun interfaces and specify .ifname='tun' (without tunnel number) in /etc/config/network for all of them, they get automatically numbered depending on wherever the tunnel is up/down.
Is there a ubus call or something to retrieve the mapping between the interface name and specific tunX interface name in that case? uci command returns just tun from the config file, I'm interested in getting the tunX with the tunnel number.
Thanks for the suggestion, I just tried that and it didn't work:
WRT3200 in ~ # source /lib/functions/network.sh
WRT3200 in ~ # network_flush_cache
WRT3200 in ~ # iface=pia
WRT3200 in ~ # uci show network.${iface}
network.pia=interface
network.pia.proto='none'
network.pia.ifname='tun'
WRT3200 in ~ # network_get_device dev $iface
WRT3200 in ~ # echo "Device of $iface is $dev"
Device of pia is
Seems this is not tracked by netifd then, some external program appears to manage these interfaces. I am also not aware of any tunnel name auto-allocation in netifd, especially not for proto none.
What is actually creating those tun0 etc. interfaces?
So first of all, whatever is in /etc/config/network is totally unrelated to the tun interfaces spawned by OpenVPN. What you can do is assigning fixed interface names in your OpenVPN configuration.
Instead of
dev tun
use
dev-type tun
dev foobar0
You can replace foobar0 with any valid interface name you like. This way the same OpenVPN instances will always create the same named interfaces.
From my limited testing on 17.01.4, I've discovered that if the tunnel name is set with dev_type=tun and dev=ovpnc0 then:
network_get_device dev pia sets dev to an empty string.
neither fw3 nor my own PROCD service get reloaded on the pia interface reload.
Everything works fine if I use tunX instead of ovpnc0 as the device/tunnel name tho.
Is that expected? Should I file a bug on that? Against what?
UPDATE: I've looked at the system logs a bit more and turns out that if the device name is set to tunX then I do get the following in the log: daemon.notice netifd: Network device 'tun1' link is up. If the device name is set to ovpnc0 I do not get the Network device 'ovpnc0' link is up notice in the log and neither fw3 nor my PROCD service get reloaded. Oh, and network_get_device doesn't work as intended.
We're missing a piece of the picture here. Do you have any custom up scripts for OpenVPN or any hotplug scripts performing additional actions? Can you share your redacted full OpenVPN configuration as well as your network config?
The network config is different to what you have posted previously
It is important that you provide the exact configuration. Previously you said you use option ifname 'tun' on pia which wouldn't make any sense. Now it seems it actually uses tun1.
What is reported by ifstatus vpnserver and ifstatus pia after the VPNs are established?
Yeah, with just tun as the ifnames for both vpnserver and pia things didn't work at all.
Discovered the problem -- I forgot to change the ifname in the network config to reflect the new dev settings in openvpn config. Once I changed it to ovpns0 and ovpnc0 in both openvpn and network config files everything works.