From b6642e1e49df304743fde631b30072538e1022a6 Mon Sep 17 00:00:00 2001 From: Nayana Bidari Date: Mon, 28 Jul 2025 14:46:35 -0700 Subject: [PATCH] Find the new NICID for the multicast address during restore. PiperOrigin-RevId: 788164674 --- .../transport/internal/network/endpoint_state.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/tcpip/transport/internal/network/endpoint_state.go b/pkg/tcpip/transport/internal/network/endpoint_state.go index d495029671..eca313df13 100644 --- a/pkg/tcpip/transport/internal/network/endpoint_state.go +++ b/pkg/tcpip/transport/internal/network/endpoint_state.go @@ -30,7 +30,17 @@ func (e *Endpoint) Resume(s *stack.Stack) { e.stack = s for m := range e.multicastMemberships { - if err := e.stack.JoinGroup(e.netProto, m.nicID, m.multicastAddr); err != nil { + // The NICID can change during restore, find the possible new NICID for the + // multicast address and then join the group. + var nicID tcpip.NICID + if r, err := e.stack.FindRoute(0, tcpip.Address{}, m.multicastAddr, e.netProto, false /* multicastLoop */); err == nil { + nicID = r.NICID() + r.Release() + } + if nicID == 0 { + panic(fmt.Sprintf("could not find a NIC for multicast address %s during restore", m.multicastAddr)) + } + if err := e.stack.JoinGroup(e.netProto, nicID, m.multicastAddr); err != nil { panic(fmt.Sprintf("e.stack.JoinGroup(%d, %d, %s): %s", e.netProto, m.nicID, m.multicastAddr, err)) } }