robur-coop / miragevpn

An opinionated implementation of the OpenVPN protocol
BSD 2-Clause "Simplified" License
79 stars 9 forks source link

Compute routes with net_gateway or remote_host #268

Closed reynir closed 5 months ago

reynir commented 5 months ago

And attempt autolocal.

Instead of the `Established _ action returning a list of routes it returns an opaque object of type route_info which under the hood is Config.t. Then the client of the engine can call Miragevpn.routes passing the route_info as well as some required information on the remote host ip and routing table. This way we can resolve magic keywords net_gateway and remote_host in --route directives, and we attempt to figure out autolocal. We also respect the local flag in --redirect-gateway if present.

I learnt that OpenVPN discards routes which it can't resolve, for example a --route with net_gateway on an IPv6-only host. Thus I decided to warn and skip such routes. The net_gateway and remote_host are Ipaddr.V4.t options in case of IPv6.

Certainly the route detection in miragevpn-client-lwt could be made more robust.

reynir commented 5 months ago

While testing this (before I had removed remote_host_route) I discovered on Linux at least if you try to add the exact same route twice ip route exits with code 2 and a message RTNETLINK answer: file exists. I found there is as well ip route replace which may be worth looking into.

hannesm commented 5 months ago

great!