Add windows support and update wireguard-go deps

This commit is contained in:
mlsmaycon
2021-06-06 00:40:44 +02:00
parent 3520b6471b
commit 59360519d6
7 changed files with 152 additions and 63 deletions

View File

@@ -3,6 +3,8 @@ package iface
import (
log "github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"golang.zx2c4.com/wireguard/tun"
"os"
)
@@ -11,19 +13,20 @@ import (
//)
// assignAddr Adds IP address to the tunnel interface
func assignAddr(iface string, address string) error {
func assignAddr(address string, tunDevice tun.Device) error {
var err error
attrs := netlink.NewLinkAttrs()
attrs.Name = iface
attrs.Name, err = tunDevice.Name()
link := wgLink{
attrs: &attrs,
}
log.Debugf("adding address %s to interface: %s", address, iface)
log.Debugf("adding address %s to interface: %s", address, attrs.Name)
addr, _ := netlink.ParseAddr(address)
err := netlink.AddrAdd(&link, addr)
err = netlink.AddrAdd(&link, addr)
if os.IsExist(err) {
log.Infof("interface %s already has the address: %s", iface, address)
log.Infof("interface %s already has the address: %s", attrs.Name, address)
} else if err != nil {
return err
}
@@ -31,3 +34,17 @@ func assignAddr(iface string, address string) error {
err = netlink.LinkSetUp(&link)
return err
}
type wgLink struct {
attrs *netlink.LinkAttrs
}
// Attrs returns the Wireguard's default attributes
func (w *wgLink) Attrs() *netlink.LinkAttrs {
return w.attrs
}
// Type returns the interface type
func (w *wgLink) Type() string {
return "wireguard"
}