Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
9683209
init
kwitsch Apr 26, 2023
162c3a3
added optional ecs forward
kwitsch Apr 26, 2023
e74f62b
added config validation
kwitsch Apr 26, 2023
b9b6eb0
added config unit test
kwitsch Apr 26, 2023
7c7f644
start ecs resolver unit tests
kwitsch Apr 26, 2023
da1088a
add documentation
kwitsch Apr 30, 2023
d1fa17a
Merge remote-tracking branch 'origin/main' into issues/952
kwitsch May 28, 2023
d62d83c
test start
kwitsch Sep 25, 2023
fd9fc63
Merge remote-tracking branch 'origin/main' into issues/952
kwitsch Sep 25, 2023
9108a09
init container
kwitsch Sep 30, 2023
2e0d7fc
wip
kwitsch Sep 30, 2023
335f23c
added go settings
kwitsch Oct 1, 2023
3b2ce2f
exclude devcontainer from docker
kwitsch Oct 1, 2023
f589b3d
added markdown config
kwitsch Oct 1, 2023
c76344b
use compose v2
kwitsch Oct 1, 2023
61d2fdf
added lineending lf to gitattributes
kwitsch Oct 1, 2023
bc8250f
reset acceidental commit
kwitsch Oct 1, 2023
b3f3aac
readded missing newline
kwitsch Oct 1, 2023
04163ea
Merge branch 'feature/devcontainer' into issues/952
kwitsch Oct 1, 2023
4454601
Merge remote-tracking branch 'origin/main' into issues/952
kwitsch Oct 7, 2023
9f8852e
Merge commit '210900b25dac042c7eb0bef6a9ad862d04d8989c' into issues/952
kwitsch Oct 9, 2023
399c567
Merge remote-tracking branch 'origin/main' into issues/952
kwitsch Oct 14, 2023
907339b
Merge remote-tracking branch 'origin/main' into issues/952
kwitsch Oct 28, 2023
c5b824d
devcontainer fixes
kwitsch Oct 28, 2023
2377b18
comment out getDefaultConfig to fix linter
kwitsch Oct 28, 2023
e2cfeb5
errorlens is broken and defaultFormatter bugs if generally set to pre…
kwitsch Oct 29, 2023
98dc655
golangci-lint bugs on file level for package types
kwitsch Oct 29, 2023
b2c3e59
otherwise golangci-lint ignores the config
kwitsch Oct 29, 2023
92a27ad
added edns0 util & reference implementation in ede resolver
kwitsch Oct 29, 2023
cad5195
dot-imports are bugged in lint _test files
kwitsch Oct 29, 2023
b4bed11
dont cache requests with subnet mask edns0 requests
kwitsch Oct 29, 2023
f5e0b0e
call ValidateConfig
kwitsch Oct 29, 2023
ceac1a9
fix nullpointer
kwitsch Oct 29, 2023
67145a3
Merge remote-tracking branch 'origin/main' into issues/952
kwitsch Oct 30, 2023
6256bb7
extension cleanup & added ginkgo watch
kwitsch Oct 31, 2023
3535fca
added gcov2lcov
kwitsch Oct 31, 2023
5c25df8
added test explorer and reworked scripts
kwitsch Oct 31, 2023
8bab322
go mod tidy
kwitsch Oct 31, 2023
e1af27e
use package cache volume
kwitsch Oct 31, 2023
010134f
script rework
kwitsch Oct 31, 2023
ec52289
defined tasks
kwitsch Oct 31, 2023
f6f8e55
defined launch
kwitsch Oct 31, 2023
4c709b7
don't try to convert if test was canceld
kwitsch Oct 31, 2023
30a2d5e
generate lcov only in devcontainer
kwitsch Oct 31, 2023
293b4b9
disable coverage upload on forks
kwitsch Oct 31, 2023
9759b01
Merge branch 'feature/devcontainer-extension' into issues/952
kwitsch Oct 31, 2023
55d30bc
added ResponseTypeOTHER & run generate
kwitsch Oct 31, 2023
ce43bee
added missing test for ede resolver
kwitsch Oct 31, 2023
63548bf
unit tests & bug fixes
kwitsch Oct 31, 2023
576540e
fix linter
kwitsch Nov 1, 2023
a981d7c
ignore ginkgo report
kwitsch Nov 2, 2023
4fbcfa9
startet edns0 unit tests
kwitsch Nov 2, 2023
fa674a5
let HaveEdnsOption accept dns.Msg
kwitsch Nov 2, 2023
c6288c4
more unit tests
kwitsch Nov 2, 2023
dd40842
restructured config
kwitsch Nov 2, 2023
c49ca35
refactoring
kwitsch Nov 2, 2023
80eef83
Merge remote-tracking branch 'origin/main' into issues/952
kwitsch Nov 11, 2023
fef1cbf
merge conflict
kwitsch Nov 11, 2023
b1f4764
merge conflict patch 2
kwitsch Nov 11, 2023
0280353
added ginkgolinter to golangci config
kwitsch Nov 12, 2023
a4677f3
removed default value comments
kwitsch Nov 12, 2023
2dd17b3
fixed ginkgolinter errors
kwitsch Nov 12, 2023
5437b67
added dot-import-whitelist
kwitsch Nov 12, 2023
4384c09
removed old scripts
kwitsch Nov 12, 2023
e8e9633
bugfix
kwitsch Nov 12, 2023
1efaed1
Whietlist dot imports for test packages
kwitsch Nov 12, 2023
2eaf10f
improved generate-lcov script
kwitsch Nov 12, 2023
5790925
moved mock_call_sequence to helpertest
kwitsch Nov 12, 2023
bf01a4a
removed default config for markdown
kwitsch Nov 12, 2023
b5cbb98
generate seperate lcov.info for each directory
kwitsch Nov 13, 2023
dc0f92e
path fix in lcov generation script
kwitsch Nov 13, 2023
668be05
ginkgo -> v2.13.1
kwitsch Nov 13, 2023
f002c8a
fixed redundant strings
kwitsch Nov 13, 2023
adbf050
added exampleComKey
kwitsch Nov 13, 2023
b506b36
added folder name to finish message
kwitsch Nov 13, 2023
228efd5
hide lcov.info in devcontainer
kwitsch Nov 14, 2023
7f37a82
Merge branch 'feature/test-cleanup' into issues/952
kwitsch Nov 14, 2023
f962e4d
fixed constant in test
kwitsch Nov 14, 2023
ffb77a6
coverage plugin is bugged if lcov file is excluded
kwitsch Nov 14, 2023
1ce45a2
Merge branch 'feature/test-cleanup' into issues/952
kwitsch Nov 14, 2023
f2f8ed9
added config tests
kwitsch Nov 14, 2023
f18d988
race fix in log test
kwitsch Nov 14, 2023
a84ec02
more config tests
kwitsch Nov 14, 2023
1f5e5f9
Merge remote-tracking branch 'origin/main' into issues/952
kwitsch Nov 15, 2023
6a0dcab
go mod tidy
kwitsch Nov 15, 2023
ca65394
idk why this changes every time O.o
kwitsch Nov 15, 2023
4a2c58f
removed gcov2lcov from tools
kwitsch Nov 15, 2023
3380dae
intendation fix
kwitsch Nov 15, 2023
194136c
more tests
kwitsch Nov 15, 2023
bbd460b
Update config/ecs.go
kwitsch Nov 16, 2023
39f3824
Update helpertest/helper.go
kwitsch Nov 16, 2023
6268c67
Update resolver/caching_resolver.go
kwitsch Nov 16, 2023
02169b9
Update util/edns0.go
kwitsch Nov 16, 2023
2781ef1
Update util/edns0.go
kwitsch Nov 16, 2023
ae33686
fmt fix
kwitsch Nov 17, 2023
1b98b81
edns0 generics refactoring
kwitsch Nov 17, 2023
e8597d6
Update util/edns0.go
kwitsch Nov 17, 2023
a28de83
Update resolver/ecs_resolver.go
kwitsch Nov 17, 2023
fbd21ce
fixed merge errors
kwitsch Nov 17, 2023
ddc5bd2
removed typecast
kwitsch Nov 17, 2023
72fca33
Merge remote-tracking branch 'origin/main' into issues/952
kwitsch Nov 17, 2023
74ac926
Merge remote-tracking branch 'origin/main' into issues/952
kwitsch Nov 19, 2023
f0f49cb
fixed ip check in setSubnet
kwitsch Nov 19, 2023
fcb9723
removed option code setting
kwitsch Nov 19, 2023
6d49d3f
Update resolver/caching_resolver.go
kwitsch Nov 19, 2023
feb3745
Update resolver/caching_resolver.go
kwitsch Nov 19, 2023
3463122
Update resolver/caching_resolver.go
kwitsch Nov 19, 2023
a418e0e
Update resolver/caching_resolver.go
kwitsch Nov 19, 2023
563dcf5
Update resolver/caching_resolver.go
kwitsch Nov 19, 2023
c1be854
Update resolver/caching_resolver.go
kwitsch Nov 19, 2023
8ce0411
fix IsEnabled of caching (0 is still enabled)
kwitsch Nov 19, 2023
f1bde74
IsEnabled test fix
kwitsch Nov 19, 2023
a927672
added missing unit test
kwitsch Nov 19, 2023
42614c0
added ip masking
kwitsch Nov 19, 2023
41d99f2
add unit test for isRequestCacheable
kwitsch Nov 19, 2023
7bd326b
Update util/edns0.go
kwitsch Nov 19, 2023
92bb282
Update util/edns0.go
kwitsch Nov 19, 2023
d3478bb
Update resolver/ecs_resolver.go
kwitsch Nov 19, 2023
2621bbe
Update docs/configuration.md
kwitsch Nov 19, 2023
cc9e1bd
Update resolver/ede_resolver_test.go
kwitsch Nov 19, 2023
7d671d0
Merge branch '0xERR0R:main' into issues/952
kwitsch Nov 19, 2023
ab1d128
added missing dependency
kwitsch Nov 19, 2023
76ea35f
fix ede test
kwitsch Nov 19, 2023
abeb49c
Update ede_resolver_test.go
kwitsch Nov 19, 2023
066f950
fix extractEdeOption
kwitsch Nov 20, 2023
228adc7
edns0 refactoring
kwitsch Nov 20, 2023
8be6c3c
rename all the things
kwitsch Nov 20, 2023
dbe4801
removed ResponseTypeOTHER
kwitsch Nov 20, 2023
c49a894
fix documentation
kwitsch Nov 20, 2023
4ce48f3
fix double import
kwitsch Nov 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
"GitHub.vscode-github-actions"
],
"settings": {
"go.lintFlags": [
"--config=${containerWorkspaceFolder}/.golangci.yml"
],
"go.lintFlags": ["--config=${containerWorkspaceFolder}/.golangci.yml"],
"go.alternateTools": {
"go-langserver": "gopls"
},
Expand Down
8 changes: 4 additions & 4 deletions .devcontainer/scripts/runItOnGo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

FOLDER_PATH=$1
if [ -z "${FOLDER_PATH}" ]; then
FOLDER_PATH=$PWD
FOLDER_PATH=$PWD
fi

BASE_PATH=$2
if [ -z "${BASE_PATH}" ]; then
BASE_PATH=$WORKSPACE_FOLDER
BASE_PATH=$WORKSPACE_FOLDER
fi

if [ "$FOLDER_PATH" = "$BASE_PATH" ]; then
echo "Skipping lcov creation for base path"
exit 1
echo "Skipping lcov creation for base path"
exit 1
fi

FOLDER_NAME=${FOLDER_PATH#"$BASE_PATH/"}
Expand Down
2 changes: 1 addition & 1 deletion config/caching.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type CachingConfig struct {

// IsEnabled implements `config.Configurable`.
func (c *CachingConfig) IsEnabled() bool {
return c.MaxCachingTime.IsAboveZero()
return c.MaxCachingTime.IsAtLeastZero()
}

// LogConfig implements `config.Configurable`.
Expand Down
17 changes: 14 additions & 3 deletions config/caching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@ var _ = Describe("CachingConfig", func() {
})

Describe("IsEnabled", func() {
It("should be false by default", func() {
It("should be true by default", func() {
cfg := CachingConfig{}
Expect(defaults.Set(&cfg)).Should(Succeed())

Expect(cfg.IsEnabled()).Should(BeFalse())
Expect(cfg.IsEnabled()).Should(BeTrue())
})

When("the config is disabled", func() {
BeforeEach(func() {
cfg = CachingConfig{
MaxCachingTime: Duration(time.Hour * -1),
}
})
It("should be false", func() {
Expect(cfg.IsEnabled()).Should(BeFalse())
})
})

When("the config is enabled", func() {
Expand Down Expand Up @@ -72,7 +83,7 @@ var _ = Describe("CachingConfig", func() {

Expect(cfg.Prefetching).Should(BeTrue())
Expect(cfg.PrefetchThreshold).Should(Equal(0))
Expect(cfg.MaxCachingTime).ShouldNot(BeZero())
Expect(cfg.MaxCachingTime).Should(BeZero())
})
})
})
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ type Config struct {
FqdnOnly FqdnOnlyConfig `yaml:"fqdnOnly"`
Filtering FilteringConfig `yaml:"filtering"`
Ede EdeConfig `yaml:"ede"`
ECS ECSConfig `yaml:"ecs"`
SUDN SUDNConfig `yaml:"specialUseDomains"`

// Deprecated options
Expand Down
11 changes: 11 additions & 0 deletions config/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,35 @@ import (
"github.com/hako/durafmt"
)

// Duration is a wrapper for time.Duration to support yaml unmarshalling
type Duration time.Duration

// ToDuration converts Duration to time.Duration
func (c Duration) ToDuration() time.Duration {
return time.Duration(c)
}

// IsAboveZero returns true if duration is above zero
func (c Duration) IsAboveZero() bool {
return c.ToDuration() > 0
}

// IsAtLeastZero returns true if duration is at least zero
func (c Duration) IsAtLeastZero() bool {
return c.ToDuration() >= 0
}

// Seconds returns duration in seconds
func (c Duration) Seconds() float64 {
return c.ToDuration().Seconds()
}

// SecondsU32 returns duration in seconds as uint32
func (c Duration) SecondsU32() uint32 {
return uint32(c.Seconds())
}

// String implements `fmt.Stringer`
func (c Duration) String() string {
return durafmt.Parse(c.ToDuration()).String()
}
Expand Down
81 changes: 81 additions & 0 deletions config/ecs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package config

import (
"fmt"
"strconv"

"github.com/sirupsen/logrus"
)

const (
ecsIpv4MaskMax = uint8(32)
ecsIpv6MaskMax = uint8(128)
)

// ECSv4Mask is the subnet mask to be added as EDNS0 option for IPv4
type ECSv4Mask uint8

// UnmarshalText implements the encoding.TextUnmarshaler interface
func (x *ECSv4Mask) UnmarshalText(text []byte) error {
res, err := unmarshalInternal(text, ecsIpv4MaskMax, "IPv4")
if err != nil {
return err
}

*x = ECSv4Mask(res)

return nil
}

// ECSv6Mask is the subnet mask to be added as EDNS0 option for IPv6
type ECSv6Mask uint8

// UnmarshalText implements the encoding.TextUnmarshaler interface
func (x *ECSv6Mask) UnmarshalText(text []byte) error {
res, err := unmarshalInternal(text, ecsIpv6MaskMax, "IPv6")
if err != nil {
return err
}

*x = ECSv6Mask(res)

return nil
}

// ECSConfig is the configuration of the ECS resolver
type ECSConfig 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 {
return c.UseAsClient || c.Forward || c.IPv4Mask > 0 || c.IPv6Mask > 0
}

// LogConfig logs the configuration
func (c *ECSConfig) 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)
logger.Infof("IPv6 netmask = %d", c.IPv6Mask)
}

// unmarshalInternal unmarshals the subnet mask from the given text and checks if the value is valid
// it is used by the UnmarshalText methods of ECSv4Mask and ECSv6Mask
func unmarshalInternal(text []byte, maxvalue uint8, name string) (uint8, error) {
strVal := string(text)

uiVal, err := strconv.ParseUint(strVal, 10, 8)
if err != nil {
return 0, err
}

if uiVal > uint64(maxvalue) {
return 0, fmt.Errorf("mask value (%s) is too large for %s(max: %d)", strVal, name, maxvalue)
}

return uint8(uiVal), nil
}
167 changes: 167 additions & 0 deletions config/ecs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package config

import (
"github.com/0xERR0R/blocky/log"
"github.com/creasty/defaults"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"gopkg.in/yaml.v2"
)

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

BeforeEach(func() {
err = defaults.Set(&c)
Expect(err).Should(Succeed())
})

Describe("IsEnabled", func() {
When("all fields are default", func() {
It("should be disabled", func() {
Expect(c.IsEnabled()).Should(BeFalse())
})
})

When("UseEcsAsClient is true", func() {
BeforeEach(func() {
c.UseAsClient = true
})

It("should be enabled", func() {
Expect(c.IsEnabled()).Should(BeTrue())
})
})

When("ForwardEcs is true", func() {
BeforeEach(func() {
c.Forward = true
})

It("should be enabled", func() {
Expect(c.IsEnabled()).Should(BeTrue())
})
})

When("IPv4Mask is set", func() {
BeforeEach(func() {
c.IPv4Mask = 24
})

It("should be enabled", func() {
Expect(c.IsEnabled()).Should(BeTrue())
})
})

When("IPv6Mask is set", func() {
BeforeEach(func() {
c.IPv6Mask = 64
})

It("should be enabled", func() {
Expect(c.IsEnabled()).Should(BeTrue())
})
})
})

Describe("LogConfig", func() {
BeforeEach(func() {
logger, hook = log.NewMockEntry()
})

It("should log configuration", func() {
c.LogConfig(logger)

Expect(hook.Calls).Should(HaveLen(4))
Expect(hook.Messages).Should(SatisfyAll(
ContainElement(ContainSubstring("Use as client")),
ContainElement(ContainSubstring("Forward")),
ContainElement(ContainSubstring("IPv4 netmask")),
ContainElement(ContainSubstring("IPv6 netmask")),
))
})
})

Describe("Parse", func() {
var data []byte

Context("IPv4Mask", func() {
var ipmask ECSv4Mask

When("Parse correct value", func() {
BeforeEach(func() {
data = []byte("24")
err = yaml.Unmarshal(data, &ipmask)
Expect(err).Should(Succeed())
})

It("should be value", func() {
Expect(ipmask).Should(Equal(ECSv4Mask(24)))
})
})

When("Parse NaN value", func() {
BeforeEach(func() {
data = []byte("FALSE")
err = yaml.Unmarshal(data, &ipmask)
})

It("should be error", func() {
Expect(err).Should(HaveOccurred())
})
})

When("Parse incorrect value", func() {
BeforeEach(func() {
data = []byte("35")
err = yaml.Unmarshal(data, &ipmask)
})

It("should be error", func() {
Expect(err).Should(HaveOccurred())
})
})
})

Context("IPv6Mask", func() {
var ipmask ECSv6Mask

When("Parse correct value", func() {
BeforeEach(func() {
data = []byte("64")
err = yaml.Unmarshal(data, &ipmask)
Expect(err).Should(Succeed())
})

It("should be value", func() {
Expect(ipmask).Should(Equal(ECSv6Mask(64)))
})
})

When("Parse NaN value", func() {
BeforeEach(func() {
data = []byte("FALSE")
err = yaml.Unmarshal(data, &ipmask)
})

It("should be error", func() {
Expect(err).Should(HaveOccurred())
})
})

When("Parse incorrect value", func() {
BeforeEach(func() {
data = []byte("130")
err = yaml.Unmarshal(data, &ipmask)
})

It("should be error", func() {
Expect(err).Should(HaveOccurred())
})
})
})
})
})
Loading