Drop Water, use Wireguard tun library, drop TAP support

This commit is contained in:
Neil Alexander 2019-11-22 16:43:50 +00:00
parent 07ce8cde7a
commit f5517acc81
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
20 changed files with 146 additions and 616 deletions

View file

@ -6,31 +6,21 @@ package tuntap
import (
"github.com/vishvananda/netlink"
water "github.com/yggdrasil-network/water"
wgtun "golang.zx2c4.com/wireguard/tun"
)
// Configures the TAP adapter with the correct IPv6 address and MTU.
func (tun *TunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int) error {
var config water.Config
if iftapmode {
config = water.Config{DeviceType: water.TAP}
} else {
config = water.Config{DeviceType: water.TUN}
}
if ifname != "" && ifname != "auto" {
config.Name = ifname
}
iface, err := water.New(config)
// Configures the TUN adapter with the correct IPv6 address and MTU.
func (tun *TunAdapter) setup(ifname string, addr string, mtu int) error {
iface, err := wgtun.CreateTUN(ifname, mtu)
if err != nil {
panic(err)
}
tun.iface = iface
tun.mtu = getSupportedMTU(mtu, iftapmode)
// Friendly output
tun.log.Infof("Interface name: %s", tun.iface.Name())
tun.log.Infof("Interface IPv6: %s", addr)
tun.log.Infof("Interface MTU: %d", tun.mtu)
if mtu, err := iface.MTU(); err == nil {
tun.mtu = getSupportedMTU(mtu)
} else {
tun.mtu = 0
}
return tun.setupAddress(addr)
}
@ -56,5 +46,9 @@ func (tun *TunAdapter) setupAddress(addr string) error {
if err := netlink.LinkSetUp(nlintf); err != nil {
return err
}
// Friendly output
tun.log.Infof("Interface name: %s", tun.iface.Name())
tun.log.Infof("Interface IPv6: %s", addr)
tun.log.Infof("Interface MTU: %d", tun.mtu)
return nil
}