MCPcopy
hub / github.com/AdguardTeam/dnsproxy / msgToKeyWithSubnet

Function msgToKeyWithSubnet

proxy/cache.go:565–596  ·  view source on GitHub ↗

msgToKeyWithSubnet constructs the cache key from DO bit, type, class, subnet mask, client's IP address and question's name of m. ecsIP is expected to be masked already.

(m *dns.Msg, ecsIP net.IP, mask int)

Source from the content-addressed store, hash-verified

563// mask, client's IP address and question's name of m. ecsIP is expected to be
564// masked already.
565func msgToKeyWithSubnet(m *dns.Msg, ecsIP net.IP, mask int) (key []byte) {
566 q := m.Question[0]
567 keyLen := keyIPIndex + len(q.Name)
568 masked := mask != 0
569 if masked {
570 keyLen += len(ecsIP)
571 }
572
573 // Initialize the slice.
574 key = make([]byte, keyLen)
575
576 // Put DO.
577 opt := m.IsEdns0()
578 key[0] = mathutil.BoolToNumber[byte](opt != nil && opt.Do())
579
580 // Put Qtype.
581 binary.BigEndian.PutUint16(key[1:], q.Qtype)
582
583 // Put Qclass.
584 binary.BigEndian.PutUint16(key[1+packedMsgLenSz:], q.Qclass)
585
586 // Add mask.
587 key[keyMaskIndex] = uint8(mask)
588 k := keyIPIndex
589 if masked {
590 k += copy(key[keyIPIndex:], ecsIP)
591 }
592
593 copy(key[k:], strings.ToLower(q.Name))
594
595 return key
596}
597
598// isDNSSEC returns true if r is a DNSSEC RR. NSEC, NSEC3, DS, DNSKEY and
599// RRSIG/SIG are DNSSEC records.

Callers 7

getWithSubnetMethod · 0.85
setWithSubnetMethod · 0.85
queueMethod · 0.85
doneMethod · 0.85
TestCache_getWithSubnetFunction · 0.85

Calls

no outgoing calls

Tested by 3

TestCache_getWithSubnetFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…