conn.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package udp
  2. import (
  3. "net/netip"
  4. "github.com/slackhq/nebula/config"
  5. )
  6. const MTU = 9001
  7. type EncReader func(
  8. addr netip.AddrPort,
  9. payload []byte,
  10. )
  11. type Conn interface {
  12. Rebind() error
  13. LocalAddr() (netip.AddrPort, error)
  14. ListenOut(r EncReader) error
  15. WriteTo(b []byte, addr netip.AddrPort) error
  16. ReloadConfig(c *config.C)
  17. SupportsMultipleReaders() bool
  18. // EnablePathMTUDiscovery sets the don't-fragment bit on outgoing packets for
  19. // this socket. Called by the pmtud manager when PMTUD is enabled. A no-op on
  20. // platforms that don't support it; nebula's default behavior (no DF, kernel
  21. // fragmentation allowed) is preserved on those platforms and on this one when
  22. // PMTUD is disabled.
  23. EnablePathMTUDiscovery() error
  24. Close() error
  25. }
  26. type NoopConn struct{}
  27. func (NoopConn) Rebind() error {
  28. return nil
  29. }
  30. func (NoopConn) LocalAddr() (netip.AddrPort, error) {
  31. return netip.AddrPort{}, nil
  32. }
  33. func (NoopConn) ListenOut(_ EncReader) error {
  34. return nil
  35. }
  36. func (NoopConn) SupportsMultipleReaders() bool {
  37. return false
  38. }
  39. func (NoopConn) WriteTo(_ []byte, _ netip.AddrPort) error {
  40. return nil
  41. }
  42. func (NoopConn) ReloadConfig(_ *config.C) {
  43. return
  44. }
  45. func (NoopConn) EnablePathMTUDiscovery() error {
  46. return nil
  47. }
  48. func (NoopConn) Close() error {
  49. return nil
  50. }