Skip to content

Commit

Permalink
removed deprecated configuration parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
0xERR0R committed Mar 28, 2022
1 parent 476dd7d commit d1289e8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 129 deletions.
46 changes: 0 additions & 46 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 20,6 @@ import (
)

// NetProtocol resolver protocol ENUM(
// udp // Deprecated: use tcp udp instead
// tcp // Deprecated: use tcp udp instead
// tcp udp // TCP and UDP protocols
// tcp-tls // TCP-TLS protocol
// https // HTTPS protocol
Expand Down Expand Up @@ -236,17 234,6 @@ func extractPath(in string) (path string, upstream string) {
}

func extractNet(upstream string) (NetProtocol, string) {
if strings.HasPrefix(upstream, NetProtocolTcp.String() ":") {
log.Log().Warnf("net prefix tcp is deprecated, using tcp udp as default fallback")

return NetProtocolTcpUdp, strings.Replace(upstream, NetProtocolTcp.String() ":", "", 1)
}

if strings.HasPrefix(upstream, NetProtocolUdp.String() ":") {
log.Log().Warnf("net prefix udp is deprecated, using tcp udp as default fallback")
return NetProtocolTcpUdp, strings.Replace(upstream, NetProtocolUdp.String() ":", "", 1)
}

if strings.HasPrefix(upstream, NetProtocolTcpUdp.String() ":") {
return NetProtocolTcpUdp, strings.Replace(upstream, NetProtocolTcpUdp.String() ":", "", 1)
}
Expand Down Expand Up @@ -288,10 275,6 @@ type Config struct {
KeyFile string `yaml:"keyFile"`
BootstrapDNS Upstream `yaml:"bootstrapDns"`
HostsFile HostsFileConfig `yaml:"hostsFile"`
// Deprecated
HTTPCertFile string `yaml:"httpsCertFile"`
// Deprecated
HTTPKeyFile string `yaml:"httpsKeyFile"`
}

// PrometheusConfig contains the config values for prometheus
Expand Down Expand Up @@ -369,10 352,6 @@ type CachingConfig struct {

// QueryLogConfig configuration for the query logging
type QueryLogConfig struct {
// Deprecated
Dir string `yaml:"dir"`
// Deprecated
PerClient bool `yaml:"perClient" default:"false"`
Target string `yaml:"target"`
Type QueryLogType `yaml:"type"`
LogRetentionDays uint64 `yaml:"logRetentionDays"`
Expand Down Expand Up @@ -434,31 413,6 @@ func unmarshalConfig(data []byte, cfg Config) {
}

func validateConfig(cfg *Config) {
if cfg.QueryLog.Dir != "" {
log.Log().Warnf("queryLog.Dir is deprecated, use 'queryLog.target' instead")

if cfg.QueryLog.Target == "" {
cfg.QueryLog.Target = cfg.QueryLog.Dir
}

if cfg.QueryLog.Type == QueryLogTypeConsole {
if cfg.QueryLog.PerClient {
cfg.QueryLog.Type = QueryLogTypeCsvClient
} else {
cfg.QueryLog.Type = QueryLogTypeCsv
}
}
}

if cfg.HTTPKeyFile != "" || cfg.HTTPCertFile != "" {
log.Log().Warnf("'httpsCertFile'/'httpsKeyFile' are deprecated, use 'certFile'/'keyFile' instead")

if cfg.CertFile == "" && cfg.KeyFile == "" {
cfg.CertFile = cfg.HTTPCertFile
cfg.KeyFile = cfg.HTTPKeyFile
}
}

if len(cfg.TLSPorts) != 0 && (cfg.CertFile == "" || cfg.KeyFile == "") {
log.Log().Fatal("certFile and keyFile parameters are mandatory for TLS")
}
Expand Down
34 changes: 11 additions & 23 deletions config/config_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 12 additions & 55 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 97,7 @@ var _ = Describe("Config", func() {
data :=
`conditional:
mapping:
multiple.resolvers: udp:192.168.178.1,wrongprotocol:4.4.4.4:53`
multiple.resolvers: 192.168.178.1,wrongprotocol:4.4.4.4:53`
helpertest.ShouldLogFatal(func() {
unmarshalConfig([]byte(data), cfg)
})
Expand All @@ -109,9 109,9 @@ var _ = Describe("Config", func() {
data :=
`upstream:
default:
- udp:8.8.8.8
- 8.8.8.8
- wrongprotocol:8.8.4.4
- udp:1.1.1.1`
- 1.1.1.1`
helpertest.ShouldLogFatal(func() {
unmarshalConfig([]byte(data), cfg)
})
Expand All @@ -129,49 129,6 @@ var _ = Describe("Config", func() {
})
})

When("deprecated querylog.dir parameter is used", func() {
It("should be mapped to csv writer", func() {
By("per client", func() {
c := &Config{
QueryLog: QueryLogConfig{
Dir: "/somedir",
PerClient: true,
}}
validateConfig(c)

Expect(c.QueryLog.Target).Should(Equal("/somedir"))
Expect(c.QueryLog.Type).Should(Equal(QueryLogTypeCsvClient))
})

By("one file", func() {
c := &Config{
QueryLog: QueryLogConfig{
Dir: "/somedir",
PerClient: false,
}}
validateConfig(c)

Expect(c.QueryLog.Target).Should(Equal("/somedir"))
Expect(c.QueryLog.Type).Should(Equal(QueryLogTypeCsv))
})

})
})

When("deprecated httpsCertFile/httpsKeyFile parameter is used", func() {
It("should be mapped to certFile/keyFile", func() {

c := &Config{
HTTPKeyFile: "key",
HTTPCertFile: "cert",
}
validateConfig(c)

Expect(c.KeyFile).Should(Equal("key"))
Expect(c.CertFile).Should(Equal("cert"))
})
})

When("TlsPort is defined", func() {
It("certFile/keyFile must be set", func() {

Expand Down Expand Up @@ -373,20 330,20 @@ var _ = Describe("Config", func() {
}
Expect(result).Should(Equal(wantResult), in)
},
Entry("udp with port",
"udp:4.4.4.4:531",
Entry("udp tcp with port",
"4.4.4.4:531",
Upstream{Net: NetProtocolTcpUdp, Host: "4.4.4.4", Port: 531},
false),
Entry("udp without port, use default",
"udp:4.4.4.4",
Entry("udp tcü without port, use default",
"4.4.4.4",
Upstream{Net: NetProtocolTcpUdp, Host: "4.4.4.4", Port: 53},
false),
Entry("tcp with port",
"tcp:4.4.4.4:4711",
Entry("udp tcp with port",
"tcp udp:4.4.4.4:4711",
Upstream{Net: NetProtocolTcpUdp, Host: "4.4.4.4", Port: 4711},
false),
Entry("tcp without port, use default",
"tcp:4.4.4.4",
"4.4.4.4",
Upstream{Net: NetProtocolTcpUdp, Host: "4.4.4.4", Port: 53},
false),
Entry("tcp-tls without port, use default",
Expand Down Expand Up @@ -418,11 375,11 @@ var _ = Describe("Config", func() {
Upstream{Net: 0},
true),
Entry("udpIpv6WithPort",
"udp:[fd00::6cd4:d7e0:d99d:2952]:53",
"tcp udp:[fd00::6cd4:d7e0:d99d:2952]:53",
Upstream{Net: NetProtocolTcpUdp, Host: "fd00::6cd4:d7e0:d99d:2952", Port: 53},
false),
Entry("udpIpv6WithPort2",
"udp:[2001:4860:4860::8888]:53",
"[2001:4860:4860::8888]:53",
Upstream{Net: NetProtocolTcpUdp, Host: "2001:4860:4860::8888", Port: 53},
false),
Entry("default net, default port",
Expand Down
6 changes: 3 additions & 3 deletions docs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 39,8 @@ conditional:
rewrite:
example.com: fritz.box
mapping:
fritz.box: udp:192.168.178.1
lan.net: udp:192.168.178.1,udp:192.168.178.2
fritz.box: 192.168.178.1
lan.net: 192.168.178.1,192.168.178.2

# optional: use black and white lists to block queries (for example ads, trackers, adult pages etc.)
blocking:
Expand Down Expand Up @@ -132,7 132,7 @@ caching:
# optional: configuration of client name resolution
clientLookup:
# optional: this DNS resolver will be used to perform reverse DNS lookup (typically local router)
upstream: udp:192.168.178.1
upstream: 192.168.178.1
# optional: some routers return multiple names for client (host name and user defined name). Define which single name should be used.
# Example: take second name if present, if not take first name
singleNameOrder:
Expand Down
4 changes: 2 additions & 2 deletions testdata/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@ upstream:
default:
- tcp udp:8.8.8.8
- tcp udp:8.8.4.4
- udp:1.1.1.1 # deprecated
- 1.1.1.1
customDNS:
mapping:
my.duckdns.org: 192.168.178.3
Expand Down Expand Up @@ -35,7 35,7 @@ blocking:
# without unit -> use minutes
refreshPeriod: 120
clientLookup:
upstream: udp:192.168.178.1
upstream: 192.168.178.1
singleNameOrder:
- 2
- 1
Expand Down

0 comments on commit d1289e8

Please sign in to comment.