Skip to content

Commit 7fb8214

Browse files
authored
AGDNS-4357 Do not embed config
1 parent acf2b30 commit 7fb8214

19 files changed

Lines changed: 389 additions & 198 deletions

proxy/bogusnxdomain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
// isBogusNXDomain returns true if m contains at least a single IP address in
1010
// the Answer section contained in BogusNXDomain subnets of p.
1111
func (p *Proxy) isBogusNXDomain(m *dns.Msg) (ok bool) {
12-
if m == nil || len(p.BogusNXDomain) == 0 || len(m.Question) == 0 {
12+
if m == nil || len(p.bogusNXDomain) == 0 || len(m.Question) == 0 {
1313
return false
1414
} else if qt := m.Question[0].Qtype; qt != dns.TypeA && qt != dns.TypeAAAA {
1515
return false
1616
}
1717

18-
set := netutil.SliceSubnetSet(p.BogusNXDomain)
18+
set := netutil.SliceSubnetSet(p.bogusNXDomain)
1919
for _, rr := range m.Answer {
2020
ip := proxyutil.IPFromRR(rr)
2121
if set.Contains(ip) {

proxy/bogusnxdomain_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestProxy_IsBogusNXDomain(t *testing.T) {
7878
}}
7979

8080
u := testUpstream{}
81-
prx.UpstreamConfig.Upstreams = []upstream.Upstream{&u}
81+
prx.upstreamConf.Upstreams = []upstream.Upstream{&u}
8282

8383
servicetest.RequireRun(t, prx, testTimeout)
8484

proxy/cache.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,20 @@ func (c *cache) unpackItem(data []byte, req *dns.Msg) (ci *cacheItem, expired bo
165165

166166
// initCache initializes cache if it's enabled.
167167
func (p *Proxy) initCache() {
168-
if !p.CacheEnabled {
168+
if !p.cacheEnabled {
169169
p.logger.Info("cache disabled")
170170

171171
return
172172
}
173173

174-
size := p.CacheSizeBytes
174+
size := p.cacheSizeBytes
175175
p.logger.Info("cache enabled", "size", size)
176176
p.cache = newCache(&cacheConfig{
177177
size: size,
178-
optimisticTTL: p.CacheOptimisticAnswerTTL,
179-
optimisticMaxAge: p.CacheOptimisticMaxAge,
180-
withECS: p.EnableEDNSClientSubnet,
181-
optimistic: p.CacheOptimistic,
178+
optimisticTTL: p.cacheOptimisticAnswerTTL,
179+
optimisticMaxAge: p.cacheOptimisticMaxAge,
180+
withECS: p.enableEDNSClientSubnet,
181+
optimistic: p.cacheOptimistic,
182182
})
183183
p.shortFlighter = newOptimisticResolver(p)
184184
}

proxy/cache_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ func TestCacheExpirationWithTTLOverride(t *testing.T) {
402402
assert.Equal(t, msgToKey(d.Req), key)
403403

404404
require.NotNil(t, ci)
405-
assert.Equal(t, dnsProxy.CacheMinTTL, ci.m.Answer[0].Header().Ttl)
405+
assert.Equal(t, dnsProxy.cacheMinTTL, ci.m.Answer[0].Header().Ttl)
406406
})
407407

408408
t.Run("replace_max", func(t *testing.T) {
@@ -426,7 +426,7 @@ func TestCacheExpirationWithTTLOverride(t *testing.T) {
426426
assert.Equal(t, msgToKey(d.Req), key)
427427

428428
require.NotNil(t, ci)
429-
assert.Equal(t, dnsProxy.CacheMaxTTL, ci.m.Answer[0].Header().Ttl)
429+
assert.Equal(t, dnsProxy.cacheMaxTTL, ci.m.Answer[0].Header().Ttl)
430430
})
431431
}
432432

proxy/config.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -274,38 +274,38 @@ type HTTPConfig struct {
274274
}
275275

276276
// validateConfig verifies that the supplied configuration is valid and returns
277-
// an error if it's not.
277+
// an error if it's not. c must be non-nil and valid.
278278
//
279279
// TODO(s.chzhen): Use [validate.Interface] from golibs.
280-
func (p *Proxy) validateConfig() (err error) {
281-
err = p.UpstreamConfig.validate()
280+
func (p *Proxy) validateConfig(c *Config) (err error) {
281+
err = c.UpstreamConfig.validate()
282282
if err != nil {
283283
return fmt.Errorf("general upstreams: %w", err)
284284
}
285285

286-
err = ValidatePrivateConfig(p.PrivateRDNSUpstreamConfig, p.privateNets)
286+
err = ValidatePrivateConfig(c.PrivateRDNSUpstreamConfig, c.PrivateSubnets)
287287
if err != nil {
288-
if p.UsePrivateRDNS || errors.Is(err, upstream.ErrNoUpstreams) {
288+
if c.UsePrivateRDNS || errors.Is(err, upstream.ErrNoUpstreams) {
289289
return fmt.Errorf("private rdns upstreams: %w", err)
290290
}
291291
}
292292

293-
err = p.Fallbacks.validate()
294-
// Allow [Proxy.Fallbacks] to be nil, but not empty. nil means not to use
293+
err = c.Fallbacks.validate()
294+
// Allow [Config.Fallbacks] to be nil, but not empty. nil means not to use
295295
// fallbacks at all.
296296
if errors.Is(err, upstream.ErrNoUpstreams) {
297297
return fmt.Errorf("fallbacks: %w", err)
298298
}
299299

300-
switch p.UpstreamMode {
300+
switch c.UpstreamMode {
301301
case
302302
"",
303303
UpstreamModeFastestAddr,
304304
UpstreamModeLoadBalance,
305305
UpstreamModeParallel:
306306
// Go on.
307307
default:
308-
return fmt.Errorf("upstream mode: %w: %q", errors.ErrBadEnumValue, p.UpstreamMode)
308+
return fmt.Errorf("upstream mode: %w: %q", errors.ErrBadEnumValue, c.UpstreamMode)
309309
}
310310

311311
err = p.validateBasicAuth()
@@ -320,20 +320,20 @@ func (p *Proxy) validateConfig() (err error) {
320320

321321
// logConfigInfo logs proxy configuration information.
322322
func (p *Proxy) logConfigInfo() {
323-
if p.CacheMinTTL > 0 || p.CacheMaxTTL > 0 {
324-
p.logger.Info("cache ttl override is enabled", "min", p.CacheMinTTL, "max", p.CacheMaxTTL)
323+
if p.cacheMinTTL > 0 || p.cacheMaxTTL > 0 {
324+
p.logger.Info("cache ttl override is enabled", "min", p.cacheMinTTL, "max", p.cacheMaxTTL)
325325
}
326326

327-
if p.RefuseAny {
327+
if p.refuseAny {
328328
p.logger.Info("server will refuse requests of type any")
329329
}
330330

331-
if len(p.BogusNXDomain) > 0 {
332-
p.logger.Info("bogus-nxdomain ip specified", "prefix_len", len(p.BogusNXDomain))
331+
if len(p.bogusNXDomain) > 0 {
332+
p.logger.Info("bogus-nxdomain ip specified", "prefix_len", len(p.bogusNXDomain))
333333
}
334334

335-
if p.UpstreamMode != "" {
336-
p.logger.Info("upstream mode is set", "mode", p.UpstreamMode)
335+
if p.upstreamMode != "" {
336+
p.logger.Info("upstream mode is set", "mode", p.upstreamMode)
337337
}
338338
}
339339

@@ -351,12 +351,12 @@ func (p *Proxy) validateListenAddrs() (err error) {
351351
return fmt.Errorf("invalid tls configuration: %w", err)
352352
}
353353

354-
if p.DNSCryptResolverCert == nil || p.DNSCryptProviderName == "" {
355-
if p.DNSCryptTCPListenAddr != nil {
354+
if p.dnsCryptResolverCert == nil || p.dnsCryptProviderName == "" {
355+
if p.dnsCryptTCPListenAddr != nil {
356356
return errors.Error("cannot create dnscrypt tcp listener without dnscrypt config")
357357
}
358358

359-
if p.DNSCryptUDPListenAddr != nil {
359+
if p.dnsCryptUDPListenAddr != nil {
360360
return errors.Error("cannot create dnscrypt udp listener without dnscrypt config")
361361
}
362362
}
@@ -367,19 +367,19 @@ func (p *Proxy) validateListenAddrs() (err error) {
367367
// validateTLSConfig returns an error if proxy TLS configuration parameters are
368368
// needed but aren't provided.
369369
func (p *Proxy) validateTLSConfig() (err error) {
370-
if p.TLSConfig != nil {
370+
if p.tlsConf != nil {
371371
return nil
372372
}
373373

374-
if p.TLSListenAddr != nil {
374+
if p.tlsListenAddr != nil {
375375
return errors.Error("tls listener configuration not found")
376376
}
377377

378-
if p.HTTPConfig != nil && p.HTTPConfig.ListenAddresses != nil {
378+
if p.httpConf != nil && p.httpConf.ListenAddresses != nil {
379379
return errors.Error("https listener configuration not found")
380380
}
381381

382-
if p.QUICListenAddr != nil {
382+
if p.quicListenAddr != nil {
383383
return errors.Error("quic listener configuration not found")
384384
}
385385

@@ -388,11 +388,11 @@ func (p *Proxy) validateTLSConfig() (err error) {
388388

389389
// hasListenAddrs - is there any addresses to listen to?
390390
func (p *Proxy) hasListenAddrs() (ok bool) {
391-
return p.UDPListenAddr != nil ||
392-
p.TCPListenAddr != nil ||
393-
p.TLSListenAddr != nil ||
394-
(p.HTTPConfig != nil && p.HTTPConfig.ListenAddresses != nil) ||
395-
p.QUICListenAddr != nil ||
396-
p.DNSCryptUDPListenAddr != nil ||
397-
p.DNSCryptTCPListenAddr != nil
391+
return p.udpListenAddr != nil ||
392+
p.tcpListenAddr != nil ||
393+
p.tlsListenAddr != nil ||
394+
(p.httpConf != nil && p.httpConf.ListenAddresses != nil) ||
395+
p.quicListenAddr != nil ||
396+
p.dnsCryptUDPListenAddr != nil ||
397+
p.dnsCryptTCPListenAddr != nil
398398
}

proxy/dns64.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ const (
4040
// synthesize AAAA records.
4141
//
4242
// TODO(e.burkov): Split validation and initialization.
43-
func (p *Proxy) setupDNS64() (err error) {
44-
if !p.Config.UseDNS64 {
43+
func (p *Proxy) setupDNS64(dns64Prefs netutil.SliceSubnetSet) (err error) {
44+
if !p.useDNS64 {
4545
return nil
4646
}
4747

48-
if len(p.Config.DNS64Prefs) == 0 {
48+
if len(dns64Prefs) == 0 {
4949
p.dns64Prefs = netutil.SliceSubnetSet{dns64WellKnownPref}
5050

5151
return nil
5252
}
5353

54-
for i, pref := range p.Config.DNS64Prefs {
54+
for i, pref := range dns64Prefs {
5555
if !pref.Addr().Is6() {
56-
return fmt.Errorf("prefix at index %d: %q is not an IPv6 prefix", i, pref)
56+
return fmt.Errorf("prefix at index %d: %q is not an ipv6 prefix", i, pref)
5757
}
5858

5959
if pref.Bits() > maxNAT64PrefixBitLen {
60-
return fmt.Errorf("prefix at index %d: %q is too long for DNS64", i, pref)
60+
return fmt.Errorf("prefix at index %d: %q is too long for dns64", i, pref)
6161
}
6262

6363
p.dns64Prefs = append(p.dns64Prefs, pref.Masked())

proxy/exchange.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (p *Proxy) exchangeUpstreams(
1818
req *dns.Msg,
1919
ups []upstream.Upstream,
2020
) (resp *dns.Msg, u upstream.Upstream, err error) {
21-
switch p.UpstreamMode {
21+
switch p.upstreamMode {
2222
case UpstreamModeParallel:
2323
return upstream.ExchangeParallel(ups, req)
2424
case UpstreamModeFastestAddr:

proxy/lookup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (p *Proxy) LookupNetIP(
8181
return addrs, errors.Join(errs...)
8282
}
8383

84-
if p.Config.PreferIPv6 {
84+
if p.preferIPv6 {
8585
slices.SortStableFunc(addrs, netutil.PreferIPv6)
8686
} else {
8787
slices.SortStableFunc(addrs, netutil.PreferIPv4)

0 commit comments

Comments
 (0)