nshandle_others.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //go:build !linux
  2. // +build !linux
  3. package netns
  4. // NsHandle is a handle to a network namespace. It can only be used on Linux,
  5. // but provides stub methods on other platforms.
  6. type NsHandle int
  7. // Equal determines if two network handles refer to the same network
  8. // namespace. It is only implemented on Linux.
  9. func (ns NsHandle) Equal(_ NsHandle) bool {
  10. return false
  11. }
  12. // String shows the file descriptor number and its dev and inode.
  13. // It is only implemented on Linux, and returns "NS(none)" on other
  14. // platforms.
  15. func (ns NsHandle) String() string {
  16. return "NS(none)"
  17. }
  18. // UniqueId returns a string which uniquely identifies the namespace
  19. // associated with the network handle. It is only implemented on Linux,
  20. // and returns "NS(none)" on other platforms.
  21. func (ns NsHandle) UniqueId() string {
  22. return "NS(none)"
  23. }
  24. // IsOpen returns true if Close() has not been called. It is only implemented
  25. // on Linux and always returns false on other platforms.
  26. func (ns NsHandle) IsOpen() bool {
  27. return false
  28. }
  29. // Close closes the NsHandle and resets its file descriptor to -1.
  30. // It is only implemented on Linux.
  31. func (ns *NsHandle) Close() error {
  32. return nil
  33. }
  34. // None gets an empty (closed) NsHandle.
  35. func None() NsHandle {
  36. return NsHandle(-1)
  37. }