New feature: query_meta

This commit is contained in:
Frank Denis 2019-09-07 16:19:47 +02:00
parent 6b1966b38f
commit 776e0d7ccc
6 changed files with 61 additions and 0 deletions

View File

@ -15,6 +15,8 @@ hashes.
- DoH servers on a non-standard port, with stamps that don't include
IP addresses, and without working system resolvers can now be properly
bootstrapped.
- A new option, `query_meta`, is now available to add optional records
to client queries.
* Version 2.0.25
- The example IP address for network probes didn't work on Windows.

View File

@ -82,6 +82,7 @@ type Config struct {
HTTPProxyURL string `toml:"http_proxy"`
RefusedCodeInResponses bool `toml:"refused_code_in_responses"`
BlockedQueryResponse string `toml:"blocked_query_response"`
QueryMeta []string `toml:"query_meta"`
}
func newConfig() Config {
@ -351,6 +352,8 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error {
proxy.cacheMinTTL = config.CacheMinTTL
proxy.cacheMaxTTL = config.CacheMaxTTL
proxy.queryMeta = config.QueryMeta
if len(config.QueryLog.Format) == 0 {
config.QueryLog.Format = "tsv"
} else {

View File

@ -230,6 +230,14 @@ netprobe_address = '9.9.9.9:53'
# offline_mode = false
## Additional data to attach to outgoing queries.
## These strings will be added as TXT records to queries.
## Do not use, except on servers explicitly asking for extra data
## to be present.
# query_meta = ["key1:value1", "key2:value2", "key3:value3"]
## Automatic log files rotation
# Maximum log files size in MB

View File

@ -0,0 +1,43 @@
package main
import (
"github.com/miekg/dns"
)
type PluginQueryMeta struct {
queryMetaRR *dns.TXT
}
func (plugin *PluginQueryMeta) Name() string {
return "query_log"
}
func (plugin *PluginQueryMeta) Description() string {
return "Log DNS queries."
}
func (plugin *PluginQueryMeta) Init(proxy *Proxy) error {
queryMetaRR := new(dns.TXT)
queryMetaRR.Hdr = dns.RR_Header{Name: ".", Rrtype: dns.TypeTXT,
Class: dns.ClassINET, Ttl: 86400}
queryMetaRR.Txt = proxy.queryMeta
plugin.queryMetaRR = queryMetaRR
return nil
}
func (plugin *PluginQueryMeta) Drop() error {
return nil
}
func (plugin *PluginQueryMeta) Reload() error {
return nil
}
func (plugin *PluginQueryMeta) Eval(pluginsState *PluginsState, msg *dns.Msg) error {
questions := msg.Question
if len(questions) == 0 {
return nil
}
msg.Extra = []dns.RR{plugin.queryMetaRR}
return nil
}

View File

@ -83,6 +83,10 @@ type PluginsState struct {
func InitPluginsGlobals(pluginsGlobals *PluginsGlobals, proxy *Proxy) error {
queryPlugins := &[]Plugin{}
if len(proxy.queryMeta) != 0 {
*queryPlugins = append(*queryPlugins, Plugin(new(PluginQueryMeta)))
}
if len(proxy.whitelistNameFile) != 0 {
*queryPlugins = append(*queryPlugins, Plugin(new(PluginWhitelistName)))
}

View File

@ -64,6 +64,7 @@ type Proxy struct {
logMaxAge int
logMaxBackups int
blockedQueryResponse string
queryMeta []string
showCerts bool
}