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

Method processECS

proxy/proxy.go:818–844  ·  view source on GitHub ↗

processECS adds EDNS Client Subnet data into the request from d.

(cliIP net.IP, l *slog.Logger)

Source from the content-addressed store, hash-verified

816
817// processECS adds EDNS Client Subnet data into the request from d.
818func (dctx *DNSContext) processECS(cliIP net.IP, l *slog.Logger) {
819 if ecs, _ := ecsFromMsg(dctx.Req); ecs != nil {
820 if ones, _ := ecs.Mask.Size(); ones != 0 {
821 dctx.ReqECS = ecs
822
823 l.Debug("passing through ecs", "subnet", dctx.ReqECS)
824
825 return
826 }
827 }
828
829 var cliAddr netip.Addr
830 if cliIP == nil {
831 cliAddr = dctx.Addr.Addr()
832 cliIP = cliAddr.AsSlice()
833 } else {
834 cliAddr, _ = netip.AddrFromSlice(cliIP)
835 }
836
837 if !netutil.IsSpecialPurpose(cliAddr) {
838 // A Stub Resolver MUST set SCOPE PREFIX-LENGTH to 0. See RFC 7871
839 // Section 6.
840 dctx.ReqECS = setECS(dctx.Req, cliIP, 0)
841
842 l.Debug("setting ecs", "subnet", dctx.ReqECS)
843 }
844}

Callers 1

ResolveMethod · 0.80

Calls 3

ecsFromMsgFunction · 0.85
setECSFunction · 0.85
AddrMethod · 0.80

Tested by

no test coverage detected