Re: Tunnel interfaces and vnet boundary crossing

From: Milan Obuch <freebsd-net_at_dino.sk>
Date: Wed, 17 Aug 2022 21:16:17 UTC
On Wed, 17 Aug 2022 22:22:45 +0200
Michael Gmelin <grembo@freebsd.org> wrote:

> > On 15. Aug 2022, at 08:52, Milan Obuch <freebsd-net@dino.sk> wrote:
> > 
> > Hi,
> > 
> > some time ago I managed to design and implement multi-tenant OpenVPN
> > server using vnet jails. This way I am able to use more OpenVPN
> > instances on single public IP.
> > 
> > This is made possible using tun/tap interface property allowing to
> > cross vnet boundary - here is part of my initialisation command
> > sequence for one instance:
> > 
> > jail -c name=ov1 vnet persist
> > jexec ov1 hostname -s ov1
> > jexec ov1 ifconfig lo0 127.0.0.1/8
> > jexec ov1 sysctl net.inet.ip.forwarding=1
> > ifconfig tun1 create vnet ov1
> > /usr/local/sbin/openvpn --cd /usr/local/etc/openvpn --daemon ov1
> > --config ov1.cfg --writepid /var/run/ov1.pid
> > 
> > In ov1.cfg, relevant bits are
> > 
> > port 1001
> > management localhost 2001
> > dev tun1
> > 
> > (Actual numbers are different, but important thing is how they
> > relate together.)
> > 
> > This way, OpenVPN process runs in base vnet, using one side of
> > pre-created tun/tap interface, while networking uses the other side
> > of this interface in child vnet, isolated from base vnet (and other
> > OpenVPN instances as well).
> > 
> > Presently, I am using vlan interfaces on one ethernet interface to
> > connect individual instances to their respective local network. I'd
> > like to replace this with some tunnel interface (gif, gre, ideally
> > ipsec secured). The best way to illustrate is using Cisco config
> > snippet:
> > 
> > interface Tunnel1
> > vrf forwarding vrf1
> > ip address 192.168.0.1 255.255.255.252
> > tunnel source Loopback0
> > tunnel destination 172.16.0.1
> > 
> > This means outer layer uses base route table for tunnel creation,
> > while inner layer, packets/datagrams transferred over tunnel, use
> > other vrf.
> > 
> > I tried to mimic this in FreeBSD with following commands:
> > 
> > ifconfig gre1 create tunnel 172.16.1.1 172.16.0.1 vnet ov1
> > jexec ov1 ifconfig gre1 10.1.0.2/30 10.1.0.1
> > 
> > This does not work. I found some older post which made me believing
> > this is caused by clearing whole tunnel configuration after moving
> > interface into different vnet. My (failed) tests indicate this is
> > most probably the cause.
> > 
> > So, my question is, does anybody use tunnel interface similar way?
> > Is it possible to achieve what I am trying with netgraph? I am able
> > to create some inter-vnet link using epair interface, but this is
> > something different. Or ideally, is somebody using IPSEC with VNET
> > jails, processing encapsulating packets in base and raw content in
> > some child vnet?
> >   
> 
> Not sure if that helps you at all, but what I’ve done in the past is
> create a tunnel interface on the jailhost and add a devfs rule to
> allow access to it from within the vnet jail. I then run OpenVPN
> within that jail (so OpenVPN and tunnel interface are in the same
> jail).
>

How would that devfs rule look like? Did you try that with multiple
OpenVPN processes? Where are routing rules for network to be accessed
via tunnels created?

> It’s super stable, only issue is that you need to be careful when to
> release/destroy the interface on jail restart, otherwise it will
> become unavailable on the jailhost and in a (new) jail.

I have no problem with stability, I just like to add ability to use
gif/gre/ipsec tunnel to my solution (I can connect to some remote LAN
via dedicated VLAN configured on ethernet, but this is of no use when
some network not under my control is to be crossed).

Regards,
Milan