mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-11 05:48:17 +03:00
Add dns client
This commit is contained in:
@@ -12,6 +12,7 @@ type _Options struct {
|
||||
Log *LogOption `json:"log,omitempty"`
|
||||
Inbounds []Inbound `json:"inbounds,omitempty"`
|
||||
Outbounds []Outbound `json:"outbounds,omitempty"`
|
||||
DNS *DNSOptions `json:"dns,omitempty"`
|
||||
Route *RouteOptions `json:"route,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
12
option/dns.go
Normal file
12
option/dns.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package option
|
||||
|
||||
type DNSOptions struct {
|
||||
Servers []DNSServerOptions `json:"servers,omitempty"`
|
||||
}
|
||||
|
||||
type DNSServerOptions struct {
|
||||
Tag string `json:"tag,omitempty"`
|
||||
Address string `json:"address"`
|
||||
Detour string `json:"detour,omitempty"`
|
||||
AddressResolver string `json:"address_resolver,omitempty"`
|
||||
}
|
||||
@@ -101,9 +101,7 @@ type DefaultRule struct {
|
||||
IPCIDR Listable[string] `json:"ip_cidr,omitempty"`
|
||||
SourcePort Listable[uint16] `json:"source_port,omitempty"`
|
||||
Port Listable[uint16] `json:"port,omitempty"`
|
||||
// ProcessName Listable[string] `json:"process_name,omitempty"`
|
||||
// ProcessPath Listable[string] `json:"process_path,omitempty"`
|
||||
Outbound string `json:"outbound,omitempty"`
|
||||
Outbound string `json:"outbound,omitempty"`
|
||||
}
|
||||
|
||||
func (r DefaultRule) IsValid() bool {
|
||||
|
||||
@@ -90,3 +90,47 @@ func (l *Listable[T]) UnmarshalJSON(content []byte) error {
|
||||
*l = []T{singleItem}
|
||||
return nil
|
||||
}
|
||||
|
||||
type DomainStrategy C.DomainStrategy
|
||||
|
||||
func (s DomainStrategy) MarshalJSON() ([]byte, error) {
|
||||
var value string
|
||||
switch C.DomainStrategy(s) {
|
||||
case C.DomainStrategyAsIS:
|
||||
value = "AsIS"
|
||||
case C.DomainStrategyPreferIPv4:
|
||||
value = "PreferIPv4"
|
||||
case C.DomainStrategyPreferIPv6:
|
||||
value = "PreferIPv6"
|
||||
case C.DomainStrategyUseIPv4:
|
||||
value = "UseIPv4"
|
||||
case C.DomainStrategyUseIPv6:
|
||||
value = "UseIPv6"
|
||||
default:
|
||||
return nil, E.New("unknown domain strategy: ", s)
|
||||
}
|
||||
return json.Marshal(value)
|
||||
}
|
||||
|
||||
func (s *DomainStrategy) UnmarshalJSON(bytes []byte) error {
|
||||
var value string
|
||||
err := json.Unmarshal(bytes, &value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch value {
|
||||
case "AsIS":
|
||||
*s = DomainStrategy(C.DomainStrategyAsIS)
|
||||
case "PreferIPv4":
|
||||
*s = DomainStrategy(C.DomainStrategyPreferIPv4)
|
||||
case "PreferIPv6":
|
||||
*s = DomainStrategy(C.DomainStrategyPreferIPv6)
|
||||
case "UseIPv4":
|
||||
*s = DomainStrategy(C.DomainStrategyUseIPv4)
|
||||
case "UseIPv6":
|
||||
*s = DomainStrategy(C.DomainStrategyUseIPv6)
|
||||
default:
|
||||
return E.New("unknown domain strategy: ", value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user