Refactor: fakeip pool use netip.Prefix, supports ipv6 range
This commit is contained in:
@@ -21,7 +21,7 @@ type (
|
||||
middleware func(next handler) handler
|
||||
)
|
||||
|
||||
func withHosts(hosts *trie.DomainTrie[netip.Addr], mapping *cache.LruCache[string, string]) middleware {
|
||||
func withHosts(hosts *trie.DomainTrie[netip.Addr], mapping *cache.LruCache[netip.Addr, string]) middleware {
|
||||
return func(next handler) handler {
|
||||
return func(ctx *context.DNSContext, r *D.Msg) (*D.Msg, error) {
|
||||
q := r.Question[0]
|
||||
@@ -57,7 +57,7 @@ func withHosts(hosts *trie.DomainTrie[netip.Addr], mapping *cache.LruCache[strin
|
||||
}
|
||||
|
||||
if mapping != nil {
|
||||
mapping.SetWithExpire(ip.Unmap().String(), host, time.Now().Add(time.Second*10))
|
||||
mapping.SetWithExpire(ip, host, time.Now().Add(time.Second*10))
|
||||
}
|
||||
|
||||
ctx.SetType(context.DNSTypeHost)
|
||||
@@ -70,7 +70,7 @@ func withHosts(hosts *trie.DomainTrie[netip.Addr], mapping *cache.LruCache[strin
|
||||
}
|
||||
}
|
||||
|
||||
func withMapping(mapping *cache.LruCache[string, string]) middleware {
|
||||
func withMapping(mapping *cache.LruCache[netip.Addr, string]) middleware {
|
||||
return func(next handler) handler {
|
||||
return func(ctx *context.DNSContext, r *D.Msg) (*D.Msg, error) {
|
||||
q := r.Question[0]
|
||||
@@ -101,7 +101,7 @@ func withMapping(mapping *cache.LruCache[string, string]) middleware {
|
||||
continue
|
||||
}
|
||||
|
||||
mapping.SetWithExpire(ip.String(), host, time.Now().Add(time.Second*time.Duration(ttl)))
|
||||
mapping.SetWithExpire(ipToAddr(ip), host, time.Now().Add(time.Second*time.Duration(ttl)))
|
||||
}
|
||||
|
||||
return msg, nil
|
||||
@@ -131,7 +131,7 @@ func withFakeIP(fakePool *fakeip.Pool) middleware {
|
||||
rr := &D.A{}
|
||||
rr.Hdr = D.RR_Header{Name: q.Name, Rrtype: D.TypeA, Class: D.ClassINET, Ttl: dnsDefaultTTL}
|
||||
ip := fakePool.Lookup(host)
|
||||
rr.A = ip
|
||||
rr.A = ip.AsSlice()
|
||||
msg := r.Copy()
|
||||
msg.Answer = []D.RR{rr}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user