[OpenWrt-Devel] netifd: adding default route + route via previous default route

Yousong Zhou yszhou4tech at gmail.com
Sun May 15 08:50:06 EDT 2016

On 15 May 2016 at 19:14, Nikos Mavrogiannopoulos
<n.mavrogiannopoulos at gmail.com> wrote:
> On Sat, 2016-05-14 at 18:29 +0800, Yousong Zhou wrote:
>> On 14 May 2016 at 16:18, Nikos Mavrogiannopoulos
>> <n.mavrogiannopoulos at gmail.com> wrote:
>> >
>> > Hi,
>> >  A user of openconnect VPN is trying to use openconnect as a
>> > default
>> > route on his router [0]. Currently this works by setting
>> > defaultroute=1
>> > on his /etc/config/network, however, once the default route is
>> > setup
>> > the VPN connection drops because there is no direct route to the
>> > VPN
>> > gateway.
>> >
>> > Obviously I need to setup a /32 (or /128 for IPv6) route for the
>> > VPN
>> > gateway using the previous defaultroute interface. However it is
>> > not
>> > apparent to me how to do that via the netifd-proto.sh or the
>> > functions/network.sh. Any hints? Should I use the user's suggestion
>> > of
>> > directly setting the route via busybox' route command?
>> >
>> I remember `proto_add_host_dependency` can be used to instruct netifd
>> to setup such a route.  But it looks like the relevant code for
>> openconnect.sh is now commented out.
> It was causing an infinite loop, and I could not understand through
> code what the add_host_dependency was supposed to do. Do you have any
> information about this function?

`proto_add_host_dependency` takes 3 arguments.

 - The 1st is the logical interface name we are adding dependency for
 - The 2nd is the host the above interface will depend on
 - The 3rd is also a logical interface name.  It's optional and is for
explicitly specifying which logical interface the 1st argument depends

If the 3rd argument is not given, netifd will try to find the logical
interface which provides route to to the specified host (2nd argument)
and a host route will be available.  The 1st logical interface will
also be added to the list of "users" of that logical interface and
will be notified of it's up/down/update

I guess the problem with openconnect.sh may be that the 3rd argument
was using the incorrect type.  Is that `vpn-$config` meant to be a
linux system interface name?  We can try just not passing the 3rd
argument and see how it works.

I often misunderstood the code because of the naming convention about
linux system interface name and logical interface name.  I tend to
believe ifname is for the former but it's not always so in the code...

2 relevant links for your information

- https://github.com/openwrt/packages/blob/master/net/pppossh/files/pppossh.sh#L38
- https://github.com/openwrt/openwrt/commit/dd8ae0460259ae764e6becfdb4dad91a0d478392


> regards,
> Nikos
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list