router.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package adapter
  2. import (
  3. "context"
  4. "net"
  5. "net/netip"
  6. "github.com/sagernet/sing-box/common/geoip"
  7. C "github.com/sagernet/sing-box/constant"
  8. N "github.com/sagernet/sing/common/network"
  9. "golang.org/x/net/dns/dnsmessage"
  10. )
  11. type Router interface {
  12. Service
  13. Outbound(tag string) (Outbound, bool)
  14. DefaultOutbound(network string) Outbound
  15. RouteConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
  16. RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
  17. GeoIPReader() *geoip.Reader
  18. LoadGeosite(code string) (Rule, error)
  19. Exchange(ctx context.Context, message *dnsmessage.Message) (*dnsmessage.Message, error)
  20. Lookup(ctx context.Context, domain string, strategy C.DomainStrategy) ([]netip.Addr, error)
  21. LookupDefault(ctx context.Context, domain string) ([]netip.Addr, error)
  22. AutoDetectInterface() bool
  23. DefaultInterfaceName() string
  24. DefaultInterfaceIndex() int
  25. }
  26. type Rule interface {
  27. Service
  28. UpdateGeosite() error
  29. Match(metadata *InboundContext) bool
  30. Outbound() string
  31. String() string
  32. }