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
This commit is contained in:
Martin Eskdale Moen 2020-12-27 18:07:06 +00:00
parent e3ba27bd6c
commit c47ff356c1

8
up.go
View File

@ -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,