noop.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Package overlaytest provides fakes of overlay.Device for tests that do
  2. // not want to touch a real tun device or route table.
  3. package overlaytest
  4. import (
  5. "errors"
  6. "net/netip"
  7. "github.com/slackhq/nebula/overlay/tio"
  8. "github.com/slackhq/nebula/routing"
  9. "github.com/slackhq/nebula/wire"
  10. )
  11. // NoopTun is an overlay.Device that silently discards every read and write.
  12. // Useful in tests that need to construct a nebula Interface but do not
  13. // exercise the datapath.
  14. type NoopTun struct{}
  15. func (NoopTun) Capabilities() tio.Capabilities {
  16. return tio.Capabilities{}
  17. }
  18. func (NoopTun) RoutesFor(addr netip.Addr) routing.Gateways {
  19. return routing.Gateways{}
  20. }
  21. func (NoopTun) Activate() error {
  22. return nil
  23. }
  24. func (NoopTun) Networks() []netip.Prefix {
  25. return []netip.Prefix{}
  26. }
  27. func (NoopTun) Name() string {
  28. return "noop"
  29. }
  30. func (NoopTun) Read(p []wire.TunPacket, mem []byte) (int, error) {
  31. return 0, nil
  32. }
  33. func (NoopTun) Write([]byte) (int, error) {
  34. return 0, nil
  35. }
  36. func (NoopTun) SupportsMultiqueue() bool {
  37. return false
  38. }
  39. func (NoopTun) NewMultiQueueReader() error {
  40. return errors.New("unsupported")
  41. }
  42. func (NoopTun) Readers() []tio.Queue {
  43. return []tio.Queue{NoopTun{}}
  44. }
  45. func (NoopTun) Close() error {
  46. return nil
  47. }