Pull request 1744: 1472-edns-custom-ip
Merge in DNS/adguard-home from 1472-edns-custom-ip to master Updates #1472. Squashed commit of the following: commit 07460c3adf7747fd9ec1b4a3d04fb459dec44280 Merge: 65455430ae653f16Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 15:38:46 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit 65455430993e4a62c49e1f45def909b0a135af3b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 15:37:17 2023 +0300 dnsforward: add todo commit e1978ad4b6051f29185ef32973d20bc70f2a6634 Merge: 6cd98f42bb226434Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 11:32:23 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit 6cd98f4235b1b52d443c1950f2516af3cc4fb258 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 11:31:16 2023 +0300 all: fix chlog; fix field alignment commit defdec623919c23ab446324828d08839469669e1 Merge: 1130ebd5a772212dAuthor: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 28 12:17:23 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit 1130ebd509bf4f7ec25fbb53717576e273dbfff2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 28 12:13:30 2023 +0300 all: add use_custom field commit ec0cdc7af0f96f761ed85516bbcae2567fd6f7d2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 13:59:13 2023 +0300 all: fix chlog; imp code commit f8450cfcd6054f32d6ea0a5e26c551fe153a0b21 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 11:28:16 2023 +0300 dnsforward: fix fmt commit 54a344e5bb17aae7ca213ed66b85f06ef6585316 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 11:11:52 2023 +0300 all: fix chlog; add test case commit 47b5476f6621c6ea31aa496d4113445a8e8bceb4 Merge: 8724f374304f2ba2Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Feb 22 16:33:07 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit 8724f3745ccc29849a4001f79b055c7ebeb19106 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Feb 22 16:31:40 2023 +0300 all: fix comments commit d2b1528ba333e7669795a3fb80355ff7d90cf4f5 Merge: 7898c23a76a513cdAuthor: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Feb 22 11:53:25 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit 7898c23ab991bc516bcc2f41e47bed15582fd962 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Feb 22 11:52:37 2023 +0300 all: upd chlog commit 8763261dcb4187a93104955e7cb440965e2b6739 Merge: d28394b3ff9b24adAuthor: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 21 17:12:03 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit d28394b3c980b10f28c6c38ce35f368edb11d314 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 21 17:11:29 2023 +0300 home: fix default value commit 1a5da3f267706baa83eebe1923ea1b0b4e79fd6c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 21 13:37:04 2023 +0300 all: add custom ip for edns
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
// currentSchemaVersion is the current schema version.
|
||||
const currentSchemaVersion = 16
|
||||
const currentSchemaVersion = 17
|
||||
|
||||
// These aliases are provided for convenience.
|
||||
type (
|
||||
@@ -89,6 +89,7 @@ func upgradeConfigSchema(oldVersion int, diskConf yobj) (err error) {
|
||||
upgradeSchema13to14,
|
||||
upgradeSchema14to15,
|
||||
upgradeSchema15to16,
|
||||
upgradeSchema16to17,
|
||||
}
|
||||
|
||||
n := 0
|
||||
@@ -892,19 +893,56 @@ func upgradeSchema15to16(diskConf yobj) (err error) {
|
||||
"ignored": []any{},
|
||||
}
|
||||
|
||||
k := "statistics_interval"
|
||||
v, has := dns[k]
|
||||
const field = "statistics_interval"
|
||||
v, has := dns[field]
|
||||
if has {
|
||||
stats["enabled"] = v != 0
|
||||
stats["interval"] = v
|
||||
}
|
||||
delete(dns, k)
|
||||
delete(dns, field)
|
||||
|
||||
diskConf["statistics"] = stats
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// upgradeSchema16to17 performs the following changes:
|
||||
//
|
||||
// # BEFORE:
|
||||
// 'dns':
|
||||
// 'edns_client_subnet': false
|
||||
//
|
||||
// # AFTER:
|
||||
// 'dns':
|
||||
// 'edns_client_subnet':
|
||||
// 'enabled': false
|
||||
// 'use_custom': false
|
||||
// 'custom_ip': ""
|
||||
func upgradeSchema16to17(diskConf yobj) (err error) {
|
||||
log.Printf("Upgrade yaml: 16 to 17")
|
||||
diskConf["schema_version"] = 17
|
||||
|
||||
dnsVal, ok := diskConf["dns"]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
dns, ok := dnsVal.(yobj)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type of dns: %T", dnsVal)
|
||||
}
|
||||
|
||||
const field = "edns_client_subnet"
|
||||
|
||||
dns[field] = map[string]any{
|
||||
"enabled": dns[field] == true,
|
||||
"use_custom": false,
|
||||
"custom_ip": "",
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO(a.garipov): Replace with log.Output when we port it to our logging
|
||||
// package.
|
||||
func funcName() string {
|
||||
|
||||
@@ -747,3 +747,64 @@ func TestUpgradeSchema15to16(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpgradeSchema16to17(t *testing.T) {
|
||||
const newSchemaVer = 17
|
||||
|
||||
defaultWantObj := yobj{
|
||||
"dns": map[string]any{
|
||||
"edns_client_subnet": map[string]any{
|
||||
"enabled": false,
|
||||
"use_custom": false,
|
||||
"custom_ip": "",
|
||||
},
|
||||
},
|
||||
"schema_version": newSchemaVer,
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
in yobj
|
||||
want yobj
|
||||
name string
|
||||
}{{
|
||||
in: yobj{
|
||||
"dns": map[string]any{
|
||||
"edns_client_subnet": false,
|
||||
},
|
||||
},
|
||||
want: defaultWantObj,
|
||||
name: "basic",
|
||||
}, {
|
||||
in: yobj{
|
||||
"dns": map[string]any{},
|
||||
},
|
||||
want: defaultWantObj,
|
||||
name: "default_values",
|
||||
}, {
|
||||
in: yobj{
|
||||
"dns": map[string]any{
|
||||
"edns_client_subnet": true,
|
||||
},
|
||||
},
|
||||
want: yobj{
|
||||
"dns": map[string]any{
|
||||
"edns_client_subnet": map[string]any{
|
||||
"enabled": true,
|
||||
"use_custom": false,
|
||||
"custom_ip": "",
|
||||
},
|
||||
},
|
||||
"schema_version": newSchemaVer,
|
||||
},
|
||||
name: "is_true",
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := upgradeSchema16to17(tc.in)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, tc.want, tc.in)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user