From c47ff356c1b6c3260e0be134ca2205350fa76b4c Mon Sep 17 00:00:00 2001 From: Martin Eskdale Moen Date: Sun, 27 Dec 2020 18:07:06 +0000 Subject: [PATCH 1/2] Ensure we always have at least 1 address in config This should avoid weird behaviours of having an interface up without an address, also less confusing moments for users --- up.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/up.go b/up.go index 91bbcfd..9156375 100644 --- a/up.go +++ b/up.go @@ -33,7 +33,11 @@ func CreateLink(conf *DsnetConfig) { ExitFail("Could not add interface '%s' (%v)", conf.InterfaceName, err) } - if conf.IP != nil { + if len(conf.IP) == 0 && len(conf.IP6) == 0 { + ExitFail("No IPv4 or IPv6 network defined in config") + } + + if len(conf.IP) != 0 { addr := &netlink.Addr{ IPNet: &net.IPNet{ IP: conf.IP, @@ -47,7 +51,7 @@ func CreateLink(conf *DsnetConfig) { } } - if conf.IP6 != nil { + if len(conf.IP6) != 0 { addr6 := &netlink.Addr{ IPNet: &net.IPNet{ IP: conf.IP6, From 0e3eb80602264c762f30d6028499db453cfc8741 Mon Sep 17 00:00:00 2001 From: Martin Eskdale Moen Date: Sun, 27 Dec 2020 18:12:42 +0000 Subject: [PATCH 2/2] Make sure we check for ipv4 and ipv6 early Otherwise we still get an interface added but without any config --- up.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/up.go b/up.go index 9156375..5eaa9a6 100644 --- a/up.go +++ b/up.go @@ -20,6 +20,10 @@ func RunPostUp(conf *DsnetConfig) { // CreateLink sets up the WG interface and link with the correct // address func CreateLink(conf *DsnetConfig) { + if len(conf.IP) == 0 && len(conf.IP6) == 0 { + ExitFail("No IPv4 or IPv6 network defined in config") + } + linkAttrs := netlink.NewLinkAttrs() linkAttrs.Name = conf.InterfaceName @@ -33,10 +37,6 @@ func CreateLink(conf *DsnetConfig) { ExitFail("Could not add interface '%s' (%v)", conf.InterfaceName, err) } - if len(conf.IP) == 0 && len(conf.IP6) == 0 { - ExitFail("No IPv4 or IPv6 network defined in config") - } - if len(conf.IP) != 0 { addr := &netlink.Addr{ IPNet: &net.IPNet{