diff options
author | Ian Lewis <ianlewis@google.com> | 2020-10-27 00:16:14 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-10-27 00:18:10 -0700 |
commit | 59e2c9f16a9a4cce2ecf8b6449a47316fdf76ca2 (patch) | |
tree | 6d542609a517c573bf3400e7d690ca58b69357f9 /pkg/sentry/inet/test_stack.go | |
parent | ef9378711ba4a5d27f9e819ff4811d4b0c210cc5 (diff) |
Add basic address deletion to netlink
Updates #3921
PiperOrigin-RevId: 339195417
Diffstat (limited to 'pkg/sentry/inet/test_stack.go')
-rw-r--r-- | pkg/sentry/inet/test_stack.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/pkg/sentry/inet/test_stack.go b/pkg/sentry/inet/test_stack.go index 1779cc6f3..9ebeba8a3 100644 --- a/pkg/sentry/inet/test_stack.go +++ b/pkg/sentry/inet/test_stack.go @@ -15,6 +15,9 @@ package inet import ( + "bytes" + "fmt" + "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/stack" ) @@ -58,6 +61,24 @@ func (s *TestStack) AddInterfaceAddr(idx int32, addr InterfaceAddr) error { return nil } +// RemoveInterfaceAddr implements Stack.RemoveInterfaceAddr. +func (s *TestStack) RemoveInterfaceAddr(idx int32, addr InterfaceAddr) error { + interfaceAddrs, ok := s.InterfaceAddrsMap[idx] + if !ok { + return fmt.Errorf("unknown idx: %d", idx) + } + + var filteredAddrs []InterfaceAddr + for _, interfaceAddr := range interfaceAddrs { + if !bytes.Equal(interfaceAddr.Addr, addr.Addr) { + filteredAddrs = append(filteredAddrs, addr) + } + } + s.InterfaceAddrsMap[idx] = filteredAddrs + + return nil +} + // SupportsIPv6 implements Stack.SupportsIPv6. func (s *TestStack) SupportsIPv6() bool { return s.SupportsIPv6Flag |