@@ -12,6 +12,7 @@ import (
1212
1313type NameServerConfig struct {
1414 Address * Address
15+ ClientIP * Address
1516 Port uint16
1617 Domains []string
1718 ExpectIPs StringList
@@ -26,12 +27,14 @@ func (c *NameServerConfig) UnmarshalJSON(data []byte) error {
2627
2728 var advanced struct {
2829 Address * Address `json:"address"`
30+ ClientIP * Address `json:"clientIp"`
2931 Port uint16 `json:"port"`
3032 Domains []string `json:"domains"`
3133 ExpectIPs StringList `json:"expectIps"`
3234 }
3335 if err := json .Unmarshal (data , & advanced ); err == nil {
3436 c .Address = advanced .Address
37+ c .ClientIP = advanced .ClientIP
3538 c .Port = advanced .Port
3639 c .Domains = advanced .Domains
3740 c .ExpectIPs = advanced .ExpectIPs
@@ -87,12 +90,20 @@ func (c *NameServerConfig) Build() (*dns.NameServer, error) {
8790 return nil , newError ("invalid IP rule: " , c .ExpectIPs ).Base (err )
8891 }
8992
93+ var myClientIP []byte
94+ if c .ClientIP != nil {
95+ if ! c .ClientIP .Family ().IsIP () {
96+ return nil , newError ("not an IP address:" , c .ClientIP .String ())
97+ }
98+ myClientIP = []byte (c .ClientIP .IP ())
99+ }
90100 return & dns.NameServer {
91101 Address : & net.Endpoint {
92102 Network : net .Network_UDP ,
93103 Address : c .Address .Build (),
94104 Port : uint32 (c .Port ),
95105 },
106+ ClientIp : myClientIP ,
96107 PrioritizedDomain : domains ,
97108 Geoip : geoipList ,
98109 OriginalRules : originalRules ,
0 commit comments