IrineSistiana / mosdns

一个 DNS 转发器

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

希望增加black_hole通过引用文件的方式应答

wukecheng opened this issue · comments

希望添加的功能

更改cloudflare的应答ip

  • tag: sequence_change_cloudflare
    type: sequence
    args:
    • exec: black_hole 47.74.12.137 47.74.9.123 47.245.14.160
      #- exec: black_hole $ip_cloudflare_fast #现在不能通过这种方式应答,希望增加下

似乎没有必要?因为 #717 ,所以即使支持 - exec: black_hole $ip_cloudflare_fast 且里面填写多个IP进去,真实效果只是 - exec: black_hole 47.74.12.137 首个 IP 有效。

似乎没有必要?因为 #717 ,所以即使支持 - exec: black_hole $ip_cloudflare_fast 且里面填写多个IP进去,真实效果只是 - exec: black_hole 47.74.12.137 首个 IP 有效。

// Response returns a response with given ips if query has corresponding qtypes.
// Otherwise, it returns nil.
func (b *BlackHole) Response(q *dns.Msg) *dns.Msg {
if len(q.Question) != 1 {
return nil
}
qName := q.Question[0].Name
qtype := q.Question[0].Qtype
switch {
case qtype == dns.TypeA && len(b.ipv4) > 0:
r := new(dns.Msg)
r.SetReply(q)
for _, addr := range b.ipv4 {
rr := &dns.A{
Hdr: dns.RR_Header{
Name: qName,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: 300,
},
A: addr.AsSlice(),
}
r.Answer = append(r.Answer, rr)
}
return r
case qtype == dns.TypeAAAA && len(b.ipv6) > 0:
r := new(dns.Msg)
r.SetReply(q)
for _, addr := range b.ipv6 {
rr := &dns.AAAA{
Hdr: dns.RR_Header{
Name: qName,
Rrtype: dns.TypeAAAA,
Class: dns.ClassINET,
Ttl: 300,
},
AAAA: addr.AsSlice(),
}
r.Answer = append(r.Answer, rr)
}
return r
}
return nil
}

我的测试结果是所有的 IP 都有效

config:

  - tag: blackhole_cloudflare
    type: sequence
    args:
      - exec: black_hole 104.17.19.131 104.17.28.149 172.64.34.51 172.64.52.29 # best_cloudflare_ip
      - exec: ttl 3600-0
      - exec: jump has_resp_sequence
root@OpenWrt:~# nslookup api.cloudflare.com
Server:         127.0.0.1
Address:        127.0.0.1:53

Non-authoritative answer:
Name:   api.cloudflare.com
Address: 104.17.19.131
Name:   api.cloudflare.com
Address: 172.64.34.51
Name:   api.cloudflare.com
Address: 172.64.52.29
Name:   api.cloudflare.com
Address: 104.17.28.149

Non-authoritative answer:

root@OpenWrt:~# nslookup download.yzuu.cf
Server:         127.0.0.1
Address:        127.0.0.1:53

Non-authoritative answer:
Name:   download.yzuu.cf
Address: 172.64.34.51
Name:   download.yzuu.cf
Address: 104.17.28.149
Name:   download.yzuu.cf
Address: 172.64.52.29
Name:   download.yzuu.cf
Address: 104.17.19.131

Non-authoritative answer:

root@OpenWrt:~# ping api.cloudflare.com
PING api.cloudflare.com (104.17.28.149): 56 data bytes
64 bytes from 104.17.28.149: seq=0 ttl=55 time=152.764 ms
64 bytes from 104.17.28.149: seq=1 ttl=55 time=151.667 ms
64 bytes from 104.17.28.149: seq=2 ttl=55 time=152.536 ms
64 bytes from 104.17.28.149: seq=3 ttl=55 time=153.357 ms
^C
--- api.cloudflare.com ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 151.667/152.581/153.357 ms
root@OpenWrt:~# ping download.yzuu.cf
PING download.yzuu.cf (172.64.34.51): 56 data bytes
64 bytes from 172.64.34.51: seq=0 ttl=55 time=155.588 ms
64 bytes from 172.64.34.51: seq=1 ttl=55 time=151.586 ms
64 bytes from 172.64.34.51: seq=2 ttl=55 time=151.251 ms
64 bytes from 172.64.34.51: seq=3 ttl=55 time=151.429 ms
^C
--- download.yzuu.cf ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 151.251/152.463/155.588 ms