Delete pkg/tcpip/stack.UniqueID.

There are 2 interfaces in gVisor which are exactly the same:
- pkg/tcpip/stack.UniqueID
- pkg/sentry/uniqueid.Provider

Before this change, both were using the Kernel as the unique number generator.
However, we want to decouple the netstack from the kernel. This coupling is
causing bugs in restore because netstack needs to be created before the Kernel
is restored. So right now, netstack ends up using a "temporary" Kernel which is
later destroyed in the restore sequence, but netstack keeps referencing it.

Before this change, the unique ID generator in pkg/tcpip/stack.Stack was used
for 2 things:
1. Provide NIC IDs which are unique across all network namespaces.
2. Implement stack.TransportEndpoint.UniqueID.

(2) is not used anywhere, so deleted it. (1) is overly unique. NIC IDs do not
need to be unique across network namespace. So instead of holding a pointer to
the kernel, added a NIC ID generator in stack.Stack itself and added
NextNICID() function with proper typing.

PiperOrigin-RevId: 646997006
This commit is contained in:
Ayush Ranjan
2024-06-26 10:34:48 -07:00
committed by gVisor bot
parent b4ca91450f
commit 344f19745f
11 changed files with 33 additions and 72 deletions
+3 -3
View File
@@ -247,8 +247,8 @@ func (s *Stack) newVeth(ctx context.Context, linkAttrs map[uint16]nlmsg.BytesVie
}
}
ep, peerEP := veth.NewPair(defaultMTU)
id := tcpip.NICID(s.Stack.UniqueID())
peerID := tcpip.NICID(peerStack.Stack.UniqueID())
id := s.Stack.NextNICID()
peerID := peerStack.Stack.NextNICID()
if ifname == "" {
ifname = fmt.Sprintf("veth%d", id)
}
@@ -293,7 +293,7 @@ func (s *Stack) newBridge(ctx context.Context, linkAttrs map[uint16]nlmsg.BytesV
ifname = v.String()
}
ep := stack.NewBridgeEndpoint(defaultMTU)
id := tcpip.NICID(s.Stack.UniqueID())
id := s.Stack.NextNICID()
err := s.Stack.CreateNICWithOptions(id, ep, stack.NICOptions{
Name: ifname,
})