dns_proxy.go 953 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package conf
  2. import (
  3. "github.com/xtls/xray-core/common/errors"
  4. "github.com/xtls/xray-core/common/net"
  5. "github.com/xtls/xray-core/proxy/dns"
  6. "google.golang.org/protobuf/proto"
  7. )
  8. type DNSOutboundConfig struct {
  9. Network Network `json:"network"`
  10. Address *Address `json:"address"`
  11. Port uint16 `json:"port"`
  12. UserLevel uint32 `json:"userLevel"`
  13. NonIPQuery string `json:"nonIPQuery"`
  14. BlockTypes []int32 `json:"blockTypes"`
  15. }
  16. func (c *DNSOutboundConfig) Build() (proto.Message, error) {
  17. config := &dns.Config{
  18. Server: &net.Endpoint{
  19. Network: c.Network.Build(),
  20. Port: uint32(c.Port),
  21. },
  22. UserLevel: c.UserLevel,
  23. }
  24. if c.Address != nil {
  25. config.Server.Address = c.Address.Build()
  26. }
  27. switch c.NonIPQuery {
  28. case "", "reject", "drop", "skip":
  29. default:
  30. return nil, errors.New(`unknown "nonIPQuery": `, c.NonIPQuery)
  31. }
  32. config.Non_IPQuery = c.NonIPQuery
  33. config.BlockTypes = c.BlockTypes
  34. return config, nil
  35. }