mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Don't prevent removing loopback in core netstack
Implement this check in netstack integration (in sentry) so that the core netstack does not prevent an integrator from removing loopback. PiperOrigin-RevId: 493992707
This commit is contained in:
committed by
gVisor bot
parent
2ff7a2750a
commit
d947422655
@@ -80,6 +80,17 @@ func (s *Stack) Interfaces() map[int32]inet.Interface {
|
||||
// RemoveInterface implements inet.Stack.RemoveInterface.
|
||||
func (s *Stack) RemoveInterface(idx int32) error {
|
||||
nic := tcpip.NICID(idx)
|
||||
|
||||
nicInfo, ok := s.Stack.NICInfo()[nic]
|
||||
if !ok {
|
||||
return syserr.ErrUnknownNICID.ToError()
|
||||
}
|
||||
|
||||
// Don't allow removing the loopback interface.
|
||||
if nicInfo.Flags.Loopback {
|
||||
return syserr.ErrNotSupported.ToError()
|
||||
}
|
||||
|
||||
return syserr.TranslateNetstackError(s.Stack.RemoveNIC(nic)).ToError()
|
||||
}
|
||||
|
||||
|
||||
@@ -957,9 +957,6 @@ func (s *Stack) removeNICLocked(id tcpip.NICID) tcpip.Error {
|
||||
if !ok {
|
||||
return &tcpip.ErrUnknownNICID{}
|
||||
}
|
||||
if nic.IsLoopback() {
|
||||
return &tcpip.ErrNotSupported{}
|
||||
}
|
||||
delete(s.nics, id)
|
||||
|
||||
// Remove routes in-place. n tracks the number of routes written.
|
||||
|
||||
@@ -966,19 +966,16 @@ func TestRemoveUnknownNIC(t *testing.T) {
|
||||
|
||||
func TestRemoveNIC(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
linkep stack.LinkEndpoint
|
||||
expectErr tcpip.Error
|
||||
name string
|
||||
linkep stack.LinkEndpoint
|
||||
}{
|
||||
{
|
||||
name: "loopback",
|
||||
linkep: loopback.New(),
|
||||
expectErr: &tcpip.ErrNotSupported{},
|
||||
name: "loopback",
|
||||
linkep: loopback.New(),
|
||||
},
|
||||
{
|
||||
name: "channel",
|
||||
linkep: channel.New(0, defaultMTU, ""),
|
||||
expectErr: nil,
|
||||
name: "channel",
|
||||
linkep: channel.New(0, defaultMTU, ""),
|
||||
},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -1006,16 +1003,14 @@ func TestRemoveNIC(t *testing.T) {
|
||||
|
||||
// Removing a NIC should remove it from NICInfo and e should be detached from
|
||||
// the NetworkDispatcher.
|
||||
if got, want := s.RemoveNIC(nicID), tt.expectErr; got != want {
|
||||
t.Fatalf("got s.RemoveNIC(%d) = %s, want %s", nicID, got, want)
|
||||
if err := s.RemoveNIC(nicID); err != nil {
|
||||
t.Fatalf("s.RemoveNIC(%d): %s", nicID, err)
|
||||
}
|
||||
if tt.expectErr == nil {
|
||||
if nicInfo, ok := s.NICInfo()[nicID]; ok {
|
||||
t.Errorf("got unexpected NICInfo entry for deleted NIC %d = %+v", nicID, nicInfo)
|
||||
}
|
||||
if e.isAttached() {
|
||||
t.Error("link endpoint for removed NIC still attached to a network dispatcher")
|
||||
}
|
||||
if nicInfo, ok := s.NICInfo()[nicID]; ok {
|
||||
t.Errorf("got unexpected NICInfo entry for deleted NIC %d = %+v", nicID, nicInfo)
|
||||
}
|
||||
if e.isAttached() {
|
||||
t.Error("link endpoint for removed NIC still attached to a network dispatcher")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user