Skip to content

Commit

Permalink
symbol name refactoring (#1263)
Browse files Browse the repository at this point in the history
* ECSConfig -> ECS

* EdeConfig -> EDE

* EdeResolver -> EDEResolver

* SUDNConfig -> SUDN

* FqdnOnlyConfig -> FQDNOnly

* FqdnOnlyResolver -> FQDNOnlyResolver
  • Loading branch information
kwitsch authored Nov 21, 2023
1 parent d37d183 commit 1a1891c
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 58 deletions.
12 changes: 6 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ type Config struct {
KeyFile string `yaml:"keyFile"`
BootstrapDNS BootstrapDNSConfig `yaml:"bootstrapDns"`
HostsFile HostsFileConfig `yaml:"hostsFile"`
FqdnOnly FqdnOnlyConfig `yaml:"fqdnOnly"`
FQDNOnly FQDNOnly `yaml:"fqdnOnly"`
Filtering FilteringConfig `yaml:"filtering"`
Ede EdeConfig `yaml:"ede"`
ECS ECSConfig `yaml:"ecs"`
SUDN SUDNConfig `yaml:"specialUseDomains"`
EDE EDE `yaml:"ede"`
ECS ECS `yaml:"ecs"`
SUDN SUDN `yaml:"specialUseDomains"`

// Deprecated options
Deprecated struct {
Expand Down Expand Up @@ -274,8 +274,8 @@ type RedisConfig struct {
}

type (
FqdnOnlyConfig = toEnable
EdeConfig = toEnable
FQDNOnly = toEnable
EDE = toEnable
)

type toEnable struct {
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ func defaultTestFileConfig() {
Expect(config.Blocking.BlockTTL).Should(Equal(Duration(time.Minute)))
Expect(config.Blocking.Loading.RefreshPeriod).Should(Equal(Duration(2 * time.Hour)))
Expect(config.Filtering.QueryTypes).Should(HaveLen(2))
Expect(config.FqdnOnly.Enable).Should(BeTrue())
Expect(config.FQDNOnly.Enable).Should(BeTrue())

Expect(config.Caching.MaxCachingTime).Should(BeZero())
Expect(config.Caching.MinCachingTime).Should(BeZero())
Expand Down
8 changes: 4 additions & 4 deletions config/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ func (x *ECSv6Mask) UnmarshalText(text []byte) error {
return nil
}

// ECSConfig is the configuration of the ECS resolver
type ECSConfig struct {
// ECS is the configuration of the ECS resolver
type ECS struct {
UseAsClient bool `yaml:"useAsClient" default:"false"`
Forward bool `yaml:"forward" default:"false"`
IPv4Mask ECSv4Mask `yaml:"ipv4Mask" default:"0"`
IPv6Mask ECSv6Mask `yaml:"ipv6Mask" default:"0"`
}

// IsEnabled returns true if the ECS resolver is enabled
func (c *ECSConfig) IsEnabled() bool {
func (c *ECS) IsEnabled() bool {
return c.UseAsClient || c.Forward || c.IPv4Mask > 0 || c.IPv6Mask > 0
}

// LogConfig logs the configuration
func (c *ECSConfig) LogConfig(logger *logrus.Entry) {
func (c *ECS) LogConfig(logger *logrus.Entry) {
logger.Infof("Use as client = %t", c.UseAsClient)
logger.Infof("Forward = %t", c.Forward)
logger.Infof("IPv4 netmask = %d", c.IPv4Mask)
Expand Down
8 changes: 4 additions & 4 deletions config/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"gopkg.in/yaml.v2"
)

var _ = Describe("ECSConfig", func() {
var _ = Describe("ECS", func() {
var (
c ECSConfig
c ECS
err error
)

Expand All @@ -26,7 +26,7 @@ var _ = Describe("ECSConfig", func() {
})
})

When("UseEcsAsClient is true", func() {
When("UseAsClient is true", func() {
BeforeEach(func() {
c.UseAsClient = true
})
Expand All @@ -36,7 +36,7 @@ var _ = Describe("ECSConfig", func() {
})
})

When("ForwardEcs is true", func() {
When("Forward is true", func() {
BeforeEach(func() {
c.Forward = true
})
Expand Down
8 changes: 4 additions & 4 deletions config/sudn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/sirupsen/logrus"
)

// SUDNConfig configuration for Special Use Domain Names
type SUDNConfig struct {
// SUDN configuration for Special Use Domain Names
type SUDN struct {
// These are "recommended for private use" but not mandatory.
// If a user wishes to use one, it will most likely be via conditional
// upstream or custom DNS, which come before SUDN in the resolver chain.
Expand All @@ -14,12 +14,12 @@ type SUDNConfig struct {
}

// IsEnabled implements `config.Configurable`.
func (c *SUDNConfig) IsEnabled() bool {
func (c *SUDN) IsEnabled() bool {
// The Special Use RFCs are always active
return true
}

// LogConfig implements `config.Configurable`.
func (c *SUDNConfig) LogConfig(logger *logrus.Entry) {
func (c *SUDN) LogConfig(logger *logrus.Entry) {
logger.Debugf("rfc6762-appendixG = %v", c.RFC6762AppendixG)
}
4 changes: 2 additions & 2 deletions config/sudn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
)

var _ = Describe("SUDNConfig", func() {
var cfg SUDNConfig
var cfg SUDN

suiteBeforeEach()

BeforeEach(func() {
var err error

cfg, err = WithDefaults[SUDNConfig]()
cfg, err = WithDefaults[SUDN]()
Expect(err).Should(Succeed())
})

Expand Down
4 changes: 2 additions & 2 deletions resolver/ecs_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ type ECSMask interface {

// ECSResolver is responsible for adding the EDNS Client Subnet information as EDNS0 option.
type ECSResolver struct {
configurable[*config.ECSConfig]
configurable[*config.ECS]
NextResolver
typed
}

// NewECSResolver creates new resolver instance which adds the subnet information as EDNS0 option
func NewECSResolver(cfg config.ECSConfig) ChainedResolver {
func NewECSResolver(cfg config.ECS) ChainedResolver {
return &ECSResolver{
configurable: withConfig(&cfg),
typed: withType("extended_client_subnet"),
Expand Down
2 changes: 1 addition & 1 deletion resolver/ecs_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
var _ = Describe("EcsResolver", func() {
var (
sut *ECSResolver
sutConfig config.ECSConfig
sutConfig config.ECS
m *mockResolver
mockAnswer *dns.Msg
err error
Expand Down
16 changes: 8 additions & 8 deletions resolver/ede_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import (
"github.com/miekg/dns"
)

// A EdeResolver is responsible for adding the reason for the response as EDNS0 option
type EdeResolver struct {
configurable[*config.EdeConfig]
// A EDEResolver is responsible for adding the reason for the response as EDNS0 option
type EDEResolver struct {
configurable[*config.EDE]
NextResolver
typed
}

// NewEdeResolver creates new resolver instance which adds the reason for
// NewEDEResolver creates new resolver instance which adds the reason for
// the response as EDNS0 option to the response if it is enabled in the configuration
func NewEdeResolver(cfg config.EdeConfig) *EdeResolver {
return &EdeResolver{
func NewEDEResolver(cfg config.EDE) *EDEResolver {
return &EDEResolver{
configurable: withConfig(&cfg),
typed: withType("extended_error_code"),
}
}

// Resolve adds the reason as EDNS0 option to the response of the next resolver
// if it is enabled in the configuration
func (r *EdeResolver) Resolve(request *model.Request) (*model.Response, error) {
func (r *EDEResolver) Resolve(request *model.Request) (*model.Response, error) {
if !r.cfg.Enable {
return r.next.Resolve(request)
}
Expand All @@ -41,7 +41,7 @@ func (r *EdeResolver) Resolve(request *model.Request) (*model.Response, error) {
}

// addExtraReasoning adds the reason for the response as EDNS0 option
func (r *EdeResolver) addExtraReasoning(res *model.Response) {
func (r *EDEResolver) addExtraReasoning(res *model.Response) {
infocode := res.RType.ToExtendedErrorCode()

if infocode == dns.ExtendedErrorCodeOther {
Expand Down
10 changes: 5 additions & 5 deletions resolver/ede_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

var _ = Describe("EdeResolver", func() {
var (
sut *EdeResolver
sutConfig config.EdeConfig
sut *EDEResolver
sutConfig config.EDE
m *mockResolver
mockAnswer *dns.Msg
)
Expand All @@ -46,13 +46,13 @@ var _ = Describe("EdeResolver", func() {
}, nil)
}

sut = NewEdeResolver(sutConfig)
sut = NewEDEResolver(sutConfig)
sut.Next(m)
})

When("ede is disabled", func() {
BeforeEach(func() {
sutConfig = config.EdeConfig{
sutConfig = config.EDE{
Enable: false,
}
})
Expand All @@ -79,7 +79,7 @@ var _ = Describe("EdeResolver", func() {

When("ede is enabled", func() {
BeforeEach(func() {
sutConfig = config.EdeConfig{
sutConfig = config.EDE{
Enable: true,
}
})
Expand Down
10 changes: 5 additions & 5 deletions resolver/fqdn_only_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import (
"github.com/miekg/dns"
)

type FqdnOnlyResolver struct {
configurable[*config.FqdnOnlyConfig]
type FQDNOnlyResolver struct {
configurable[*config.FQDNOnly]
NextResolver
typed
}

func NewFqdnOnlyResolver(cfg config.FqdnOnlyConfig) *FqdnOnlyResolver {
return &FqdnOnlyResolver{
func NewFQDNOnlyResolver(cfg config.FQDNOnly) *FQDNOnlyResolver {
return &FQDNOnlyResolver{
configurable: withConfig(&cfg),
typed: withType("fqdn_only"),
}
}

func (r *FqdnOnlyResolver) Resolve(request *model.Request) (*model.Response, error) {
func (r *FQDNOnlyResolver) Resolve(request *model.Request) (*model.Response, error) {
if r.IsEnabled() {
domainFromQuestion := util.ExtractDomain(request.Req.Question[0])
if !strings.Contains(domainFromQuestion, ".") {
Expand Down
10 changes: 5 additions & 5 deletions resolver/fqdn_only_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

var _ = Describe("FqdnOnlyResolver", func() {
var (
sut *FqdnOnlyResolver
sutConfig config.FqdnOnlyConfig
sut *FQDNOnlyResolver
sutConfig config.FQDNOnly
m *mockResolver
mockAnswer *dns.Msg
)
Expand All @@ -30,7 +30,7 @@ var _ = Describe("FqdnOnlyResolver", func() {
})

JustBeforeEach(func() {
sut = NewFqdnOnlyResolver(sutConfig)
sut = NewFQDNOnlyResolver(sutConfig)
m = &mockResolver{}
m.On("Resolve", mock.Anything).Return(&Response{Res: mockAnswer}, nil)
sut.Next(m)
Expand All @@ -54,7 +54,7 @@ var _ = Describe("FqdnOnlyResolver", func() {

When("Fqdn only is enabled", func() {
BeforeEach(func() {
sutConfig = config.FqdnOnlyConfig{Enable: true}
sutConfig = config.FQDNOnly{Enable: true}
})
It("Should delegate to next resolver if request query is fqdn", func() {
Expect(sut.Resolve(newRequest("example.com", A))).
Expand Down Expand Up @@ -100,7 +100,7 @@ var _ = Describe("FqdnOnlyResolver", func() {

When("Fqdn only is disabled", func() {
BeforeEach(func() {
sutConfig = config.FqdnOnlyConfig{Enable: false}
sutConfig = config.FQDNOnly{Enable: false}
})
It("Should delegate to next resolver if request query is fqdn", func() {
Expect(sut.Resolve(newRequest("example.com", A))).
Expand Down
14 changes: 7 additions & 7 deletions resolver/sudn_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/miekg/dns"
)

type sudnHandler = func(request *model.Request, cfg *config.SUDNConfig) *model.Response
type sudnHandler = func(request *model.Request, cfg *config.SUDN) *model.Response

//nolint:gochecknoglobals
var (
Expand Down Expand Up @@ -89,10 +89,10 @@ var (
type SpecialUseDomainNamesResolver struct {
NextResolver
typed
configurable[*config.SUDNConfig]
configurable[*config.SUDN]
}

func NewSpecialUseDomainNamesResolver(cfg config.SUDNConfig) *SpecialUseDomainNamesResolver {
func NewSpecialUseDomainNamesResolver(cfg config.SUDN) *SpecialUseDomainNamesResolver {
return &SpecialUseDomainNamesResolver{
typed: withType("special_use_domains"),
configurable: withConfig(&cfg),
Expand Down Expand Up @@ -134,11 +134,11 @@ func newSUDNResponse(response *model.Request, rcode int) *model.Response {
return newResponse(response, rcode, model.ResponseTypeSPECIAL, "Special-Use Domain Name")
}

func sudnNXDomain(request *model.Request, _ *config.SUDNConfig) *model.Response {
func sudnNXDomain(request *model.Request, _ *config.SUDN) *model.Response {
return newSUDNResponse(request, dns.RcodeNameError)
}

func sudnLocalhost(request *model.Request, cfg *config.SUDNConfig) *model.Response {
func sudnLocalhost(request *model.Request, cfg *config.SUDN) *model.Response {
q := request.Req.Question[0]

var rr dns.RR
Expand All @@ -165,15 +165,15 @@ func sudnLocalhost(request *model.Request, cfg *config.SUDNConfig) *model.Respon
return response
}

func sudnRFC6762AppendixG(request *model.Request, cfg *config.SUDNConfig) *model.Response {
func sudnRFC6762AppendixG(request *model.Request, cfg *config.SUDN) *model.Response {
if !cfg.RFC6762AppendixG {
return nil
}

return sudnNXDomain(request, cfg)
}

func sudnHomeArpa(request *model.Request, cfg *config.SUDNConfig) *model.Response {
func sudnHomeArpa(request *model.Request, cfg *config.SUDN) *model.Response {
if request.Req.Question[0].Qtype == dns.TypeDS {
// DS queries must be forwarded
return nil
Expand Down
4 changes: 2 additions & 2 deletions resolver/sudn_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
var _ = Describe("SudnResolver", Label("sudnResolver"), func() {
var (
sut *SpecialUseDomainNamesResolver
sutConfig config.SUDNConfig
sutConfig config.SUDN
m *mockResolver
)

Expand All @@ -30,7 +30,7 @@ var _ = Describe("SudnResolver", Label("sudnResolver"), func() {
BeforeEach(func() {
var err error

sutConfig, err = config.WithDefaults[config.SUDNConfig]()
sutConfig, err = config.WithDefaults[config.SUDN]()
Expect(err).Should(Succeed())
})

Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,10 @@ func createQueryResolver(

r = resolver.Chain(
resolver.NewFilteringResolver(cfg.Filtering),
resolver.NewFqdnOnlyResolver(cfg.FqdnOnly),
resolver.NewFQDNOnlyResolver(cfg.FQDNOnly),
resolver.NewECSResolver(cfg.ECS),
clientNames,
resolver.NewEdeResolver(cfg.Ede),
resolver.NewEDEResolver(cfg.EDE),
resolver.NewQueryLoggingResolver(ctx, cfg.QueryLog),
resolver.NewMetricsResolver(cfg.Prometheus),
resolver.NewRewriterResolver(cfg.CustomDNS.RewriterConfig, resolver.NewCustomDNSResolver(cfg.CustomDNS)),
Expand Down

0 comments on commit 1a1891c

Please sign in to comment.