fix(vip): apply per-call DAD skip instead of leaking it into persistent state

Signed-off-by: Maximilian Rink <maximilian.rink@telekom.de>
This commit is contained in:
Maximilian Rink
2026-08-23 23:00:11 +02:00
parent 5131b92810
commit d6e5753464
2 changed files with 44 additions and 3 deletions

View File

@@ -469,9 +469,13 @@ func (configurator *network) AddIP(precheck bool, skipDAD bool, minLifetime ...i
// an address that we know should be ours (e.g., after DADFAILED recovery).
// We also allow to globally configure NODAD in case user knows they are running in an
// environment where multiple nodes may advertise the same VIP (e.g., ECMP routing).
if configurator.shouldSkipDAD(skipDAD) && utils.IsIPv6(configurator.address.IP.String()) {
configurator.address.Flags |= unix.IFA_F_NODAD
log.Debug("Setting IFA_F_NODAD flag for IPv6 address to skip DAD", "ip", configurator.address.IP.String())
if utils.IsIPv6(configurator.address.IP.String()) {
if configurator.shouldSkipDAD(skipDAD) {
configurator.address.Flags |= unix.IFA_F_NODAD
log.Debug("Setting IFA_F_NODAD flag for IPv6 address to skip DAD", "ip", configurator.address.IP.String())
} else {
configurator.address.Flags &^= unix.IFA_F_NODAD
}
}
log.Debug("replacing IP", "address", configurator.address)

View File

@@ -0,0 +1,37 @@
//go:build linux
package vip
import (
"testing"
"github.com/kube-vip/kube-vip/pkg/networkinterface"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
)
func TestAddIPPerCallDADSkipDoesNotPersist(t *testing.T) {
address, err := netlink.ParseAddr("2001:db8::10/128")
if err != nil {
t.Fatal(err)
}
configurator := &network{
address: address,
link: &networkinterface.Link{
Intf: &netlink.Dummy{LinkAttrs: netlink.LinkAttrs{Name: "kube-vip-dad-test"}},
},
}
// The netlink operation may fail without CAP_NET_ADMIN, but the address
// flags are set before that operation and are what this test exercises.
_, _ = configurator.AddIP(false, true)
if configurator.address.Flags&unix.IFA_F_NODAD == 0 {
t.Fatal("skipDAD=true did not set IFA_F_NODAD")
}
_, _ = configurator.AddIP(false, false)
if configurator.address.Flags&unix.IFA_F_NODAD != 0 {
t.Fatal("IFA_F_NODAD persisted into a normal AddIP call")
}
}