dns_proxy.go 973 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 "":
  29. c.NonIPQuery = "drop"
  30. case "drop", "skip":
  31. default:
  32. return nil, errors.New(`unknown "nonIPQuery": `, c.NonIPQuery)
  33. }
  34. config.Non_IPQuery = c.NonIPQuery
  35. config.BlockTypes = c.BlockTypes
  36. return config, nil
  37. }