Skip to content

Commit 4b524ba

Browse files
committed
dnsx: add uidself for internally originated queries
1 parent 8cfdce6 commit 4b524ba

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

intra/dns53/ipmapper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (m *ipmapper) LookupNetIPFor(ctx context.Context, network, host, uid string
100100

101101
// Implements IPMapper.
102102
func (m *ipmapper) LookupNetIPOn(ctx context.Context, network, host string, tid ...string) ([]netip.Addr, error) {
103-
return m.queryIP2(ctx, network, host, core.UNKNOWN_UID_STR, tid...)
103+
return m.queryIP2(ctx, network, host, protect.UidSelf, tid...)
104104
}
105105

106106
func (m *ipmapper) queryIP(ctx context.Context, network, host string, uid string) ([]netip.Addr, error) {
@@ -258,6 +258,7 @@ func (m *ipmapper) lookupfor(q []byte, uid string) func() (answer, error) {
258258
// lookupon always resolves on one of the chosen tids
259259
// (if empty, it may or may not use dnsx.Default;
260260
// see: dnsx.transport.go:determineTransport)
261+
// uid may be protect.UidSelf or unknown
261262
func (m *ipmapper) lookupon(q []byte, uid string, tids ...string) func() (answer, error) {
262263
return func() (answer, error) {
263264
a, tid, err := m.r.LookupFor2(q, uid, tids...)

intra/dnsx/rethinkdns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type ResolverSelf interface {
7575
LocalLookup(q []byte) (a []byte, tid string, err error)
7676
// LookupFor performs resolution for uid.
7777
LookupFor(q []byte, uid string) (a []byte, tid string, err error)
78-
// Lookup performs resolution on chosen Transport.
78+
// Lookup performs resolution on chosen Transport for uid.
7979
LookupFor2(q []byte, uid string, chosen ...string) (a []byte, tid string, err error)
8080
}
8181

intra/dnsx/transport.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ func (r *resolver) LookupFor2(q []byte, uid string, tids ...string) ([]byte, str
472472
if len(q) <= 0 {
473473
return nil, NoDNS, errNoQuestion
474474
}
475+
if uid == core.UNKNOWN_UID_STR {
476+
uid = protect.UidSelf
477+
}
475478
// if len(tids) == 0, use transport from preferences
476479
return r.forward(q, OriginInternal, uid, tids...)
477480
}
@@ -594,7 +597,7 @@ runagain:
594597
if t == nil || core.IsNil(t) {
595598
smm.Latency = time.Since(starttime).Seconds()
596599
smm.Status = TransportError
597-
smm.Msg = strings.Join([]string{id, sid, chosenids, errNoSuchTransport.Error()}, ";")
600+
smm.Msg = strings.Join(append(chosenids, id, sid, errNoSuchTransport.Error()), ";")
598601
return nil, NoDNS, errNoSuchTransport
599602
}
600603
var t2 Transport

intra/doh/doh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func (t *transport) httpClientsFor(p ipn.Proxy) (c3, c *http.Client) {
372372
t.pxcmu.RUnlock()
373373

374374
pdial := p.Dialer().Dial
375-
if c != nil {
375+
if c != nil { // use existing clients
376376
if c3 == nil {
377377
if echcfg := t.getOrCreateEchConfigIfNeeded(); echcfg != nil {
378378
c3 = new(http.Client)
@@ -505,7 +505,7 @@ func (t *transport) multifetch(req *http.Request, pid string) (res *http.Respons
505505
c3, c0 := t.httpClientsFor(px) // c3 may be nil
506506

507507
if settings.Debug {
508-
log.VV("doh: using proxy %s+%s:%s ech? %t / other? %t",
508+
log.VV("doh: using proxy %s+%s@%s ech? %t / other? %t",
509509
px.ID(), rpid, px.GetAddr(), c3 != nil, c0 != nil)
510510
}
511511

intra/protect/ipmap/ipmap.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ type IPMapper interface {
9595
LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
9696
// LookupNetIPFor is like LookupFor
9797
LookupNetIPFor(ctx context.Context, network, host, uid string) ([]netip.Addr, error)
98-
// LookupNetIPOn is like Lookup but with tids set to some preset IDs.
98+
// LookupNetIPOn is like Lookup but with tids set to some preset IDs
99+
// on behalf of protect.UidSelf (rethink).
99100
LookupNetIPOn(ctx context.Context, network, host string, tids ...string) ([]netip.Addr, error)
100101
}
101102

0 commit comments

Comments
 (0)