Skip to content

Commit 47419da

Browse files
dilyevskyclaude
andcommitted
fix(lwtunnel): remove stale overlay addresses in SetAddr
SetAddr only added new addresses without removing previously assigned ones, causing multiple ULA addresses to accumulate on gnv0 when an endpoint gets re-allocated (e.g. after infra-apiserver restart). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6f6b895 commit 47419da

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

pkg/net/lwtunnel/geneve.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ func (r *Geneve) SetUp(_ context.Context, privAddr netip.Addr) error {
194194
return nil
195195
}
196196

197-
// SetAddr adds an IPv6 overlay address to the Geneve interface. This is
198-
// optional and only needed for originating end of the tunnel to assign
199-
// an inner source IP address.
197+
// SetAddr sets the IPv6 overlay address on the Geneve interface, removing any
198+
// previously assigned overlay addresses. This is optional and only needed for
199+
// the originating end of the tunnel to assign an inner source IP address.
200200
func (r *Geneve) SetAddr(_ context.Context, ula netip.Addr) error {
201201
h, err := r.getHandle()
202202
if err != nil {
@@ -235,11 +235,33 @@ func (r *Geneve) SetAddr(_ context.Context, ula netip.Addr) error {
235235
if err != nil {
236236
return fmt.Errorf("failed to list addresses: %w", err)
237237
}
238+
239+
// Check if the desired address is already configured, and remove any
240+
// stale non-link-local addresses (e.g. from a previous endpoint allocation).
241+
alreadyConfigured := false
238242
for _, existing := range addrs {
239243
if existing.Equal(*addr) {
240-
slog.Info("IPv6 address already configured", slog.Any("addr", existing))
241-
return nil
244+
alreadyConfigured = true
245+
continue
242246
}
247+
existingIP, ok := netip.AddrFromSlice(existing.IP)
248+
if !ok || existingIP.IsLinkLocalUnicast() {
249+
continue
250+
}
251+
slog.Info("Removing stale overlay address", slog.Any("addr", existing))
252+
if h != nil {
253+
err = h.AddrDel(link, &existing)
254+
} else {
255+
err = netlink.AddrDel(link, &existing)
256+
}
257+
if err != nil {
258+
return fmt.Errorf("failed to remove stale address %v: %w", existing, err)
259+
}
260+
}
261+
262+
if alreadyConfigured {
263+
slog.Info("IPv6 address already configured", slog.Any("addr", addr))
264+
return nil
243265
}
244266

245267
if h != nil {

0 commit comments

Comments
 (0)