2020-11-25 14:01:53 +03:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
2024-06-29 21:32:57 +03:00
|
|
|
"github.com/xtls/xray-core/common/errors"
|
2020-12-04 04:36:16 +03:00
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
"github.com/xtls/xray-core/proxy/dns"
|
2023-08-10 07:43:34 +03:00
|
|
|
"google.golang.org/protobuf/proto"
|
2020-11-25 14:01:53 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type DNSOutboundConfig struct {
|
2023-06-18 20:20:16 +03:00
|
|
|
Network Network `json:"network"`
|
|
|
|
Address *Address `json:"address"`
|
|
|
|
Port uint16 `json:"port"`
|
|
|
|
UserLevel uint32 `json:"userLevel"`
|
|
|
|
NonIPQuery string `json:"nonIPQuery"`
|
2024-09-15 07:21:51 +03:00
|
|
|
BlockTypes []int32 `json:"blockTypes"`
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *DNSOutboundConfig) Build() (proto.Message, error) {
|
|
|
|
config := &dns.Config{
|
|
|
|
Server: &net.Endpoint{
|
|
|
|
Network: c.Network.Build(),
|
|
|
|
Port: uint32(c.Port),
|
|
|
|
},
|
2021-10-16 16:02:51 +03:00
|
|
|
UserLevel: c.UserLevel,
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
|
|
|
if c.Address != nil {
|
|
|
|
config.Server.Address = c.Address.Build()
|
|
|
|
}
|
2023-06-18 20:20:16 +03:00
|
|
|
switch c.NonIPQuery {
|
|
|
|
case "":
|
|
|
|
c.NonIPQuery = "drop"
|
|
|
|
case "drop", "skip":
|
|
|
|
default:
|
2024-06-29 21:32:57 +03:00
|
|
|
return nil, errors.New(`unknown "nonIPQuery": `, c.NonIPQuery)
|
2023-06-18 20:20:16 +03:00
|
|
|
}
|
2023-06-19 03:33:59 +03:00
|
|
|
config.Non_IPQuery = c.NonIPQuery
|
2024-09-15 07:21:51 +03:00
|
|
|
config.BlockTypes = c.BlockTypes
|
2020-11-25 14:01:53 +03:00
|
|
|
return config, nil
|
|
|
|
}
|