ads

package module
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

README

CoreDNS - ads Plugin

Build Status codecov

DNS AdBlocker plugin for CoreDNS.

IMPORTANT! - ads has been archived

The project is no longer maintained, due to the lack of free time. I have therefore archived it. Feel free to fork it.

Compiling

First get the CoreDNS source code by running, after you cloned this repository into the proper path in your GOPATH

go get github.com/coredns/coredns

Then navigate to the coredns directory

cd $(go env GOPATH)/src/github.com/coredns/coredns

Next update the plugin.cfg in the root of the coredns repository as follows

sed -i 's|loadbalance:loadbalance|ads:github.com/c-mueller/ads\nloadbalance:loadbalance|g' plugin.cfg

while I would suggest having the ads plugin before the cache plugin because it will cause the changes in the blocklists to be applied instantly. However the overall performance of the DNS server could degrade when having many regex rules. In that case I recommend putting the plugin before the hosts plugin:

sed -i 's|hosts:hosts|ads:github.com/c-mueller/ads\nhosts:hosts|g' plugin.cfg

Finally run make to build CoreDNS with the ads plugin

The releases section also contains binaries of the latest CoreDNS with the ads plugin. These get built automatically using drone. Once they have been triggered.

Building development binaries

Building untagged code is complicated. The simplest way i've stumbled upon for CoreDNS is mimicing a in tree plugin using symlinks.

For this you have to create a symlink to the ads repository in the plugins/ folder using a command similar to the following: Assuming you are in the plugins/ directory

ln -s ~/go/src/github.com/c-mueller/ads ads

Make sure to replace ~/go/src/github.com/c-mueller/ads with the proper path to the ads repo.

Next we have to insert the plugin into the plugin.cfg. here we use the following command, instead of the one above:

sed -i 's|loadbalance:loadbalance|ads:ads\nloadbalance:loadbalance|g' plugin.cfg

Before running make in the CoreDNS repo we have to make sure the ads repo does not contain a go.mod file. to do this we rename it to go.mod.old. If you want to continue developing using Goland for example. The file should be renamed again to make sure syntax highlighting works.

A note on go modules

To prevent version conflicts between CoreDNS and the ads plugin it is important to keep the go.mod file empty or if dependencies have been added that are not used by coreDNS only these should be added in the go.mod file on master. For reference the empty go.mod file looks like this:

module github.com/c-mueller/ads

go 1.12

The go sum file should get deleted.

Because this strategy will make development annoying you can run go mod tidy to regenerate a proper go,mod file.

Configuring

The following shows how to use the ads plugin with default parameters, if you want to configure it further take a look at This Document.

Default settings

Running the ads plugin with all defaults is done by just adding the ads keyword to your Corefile.

For example:

.:53 {
    ads
    forward . 1.1.1.1
    log
    errors
}

License

This plugin is licensed under Apache 2 License. See LICENSE for more information.

Documentation

Overview

* Copyright 2018 - 2020 Christian Müller <dev@c-mueller.xyz> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

View Source
const Version = "0.2.5"

Variables

View Source
var ValidateQName = regexp.MustCompile("([a-zA-Z0-9]|\\.|-)*").MatchString

Functions

This section is empty.

Types

type BlockingResponseWriter added in v0.2.6

type BlockingResponseWriter struct {
	Writer       dns.ResponseWriter
	Plugin       *DNSAdBlock
	Request      *dns.Msg
	RequestState *request.Request
}

func (*BlockingResponseWriter) Close added in v0.2.6

func (b *BlockingResponseWriter) Close() error

func (*BlockingResponseWriter) Hijack added in v0.2.6

func (b *BlockingResponseWriter) Hijack()

func (*BlockingResponseWriter) LocalAddr added in v0.2.6

func (b *BlockingResponseWriter) LocalAddr() net.Addr

func (*BlockingResponseWriter) RemoteAddr added in v0.2.6

func (b *BlockingResponseWriter) RemoteAddr() net.Addr

func (*BlockingResponseWriter) TsigStatus added in v0.2.6

func (b *BlockingResponseWriter) TsigStatus() error

func (*BlockingResponseWriter) TsigTimersOnly added in v0.2.6

func (b *BlockingResponseWriter) TsigTimersOnly(b2 bool)

func (*BlockingResponseWriter) Write added in v0.2.6

func (b *BlockingResponseWriter) Write(bytes []byte) (int, error)

func (*BlockingResponseWriter) WriteMsg added in v0.2.6

func (b *BlockingResponseWriter) WriteMsg(msg *dns.Msg) error

type ConfiguredRuleSet added in v0.2.6

type ConfiguredRuleSet struct {
	Blacklist      map[string]bool
	Whitelist      map[string]bool
	WhitelistRegex []*regexp.Regexp
	BlacklistRegex []*regexp.Regexp
}

func BuildRuleset

func BuildRuleset(whitelist, blacklist []string) ConfiguredRuleSet

func (*ConfiguredRuleSet) AddRegexToBlacklist added in v0.2.6

func (r *ConfiguredRuleSet) AddRegexToBlacklist(regex string) error

func (*ConfiguredRuleSet) AddRegexToWhitelist added in v0.2.6

func (r *ConfiguredRuleSet) AddRegexToWhitelist(regex string) error

func (*ConfiguredRuleSet) AddToBlacklist added in v0.2.6

func (r *ConfiguredRuleSet) AddToBlacklist(qname string)

func (*ConfiguredRuleSet) AddToWhitelist added in v0.2.6

func (r *ConfiguredRuleSet) AddToWhitelist(qname string)

func (*ConfiguredRuleSet) IsBlacklisted added in v0.2.6

func (r *ConfiguredRuleSet) IsBlacklisted(qname string) bool

func (*ConfiguredRuleSet) IsWhitelisted added in v0.2.6

func (r *ConfiguredRuleSet) IsWhitelisted(qname string) bool

type DNSAdBlock

type DNSAdBlock struct {
	Next              plugin.Handler
	ConfiguredRuleSet ConfiguredRuleSet
	FileRuleSet       UpdateableRuleset
	// contains filtered or unexported fields
}

func (*DNSAdBlock) IsBlacklisted added in v0.2.6

func (e *DNSAdBlock) IsBlacklisted(qname string) bool

func (*DNSAdBlock) IsWhitelisted added in v0.2.6

func (e *DNSAdBlock) IsWhitelisted(qname string) bool

func (*DNSAdBlock) Name

func (e *DNSAdBlock) Name() string

Name implements the Handler interface.

func (*DNSAdBlock) ServeDNS

func (e *DNSAdBlock) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

func (*DNSAdBlock) ShouldBlock added in v0.2.6

func (e *DNSAdBlock) ShouldBlock(qname string) bool

type IRuleset added in v0.2.6

type IRuleset interface {
	IsBlacklisted(qn string) bool
	IsWhitelisted(qn string) bool
}

type ListMap added in v0.2.6

type ListMap map[string]bool

func GenerateListMap added in v0.2.6

func GenerateListMap(urls []string, fetchFunc func(ref string) ([]byte, error)) (ListMap, error)

func GenerateListMapFromFileUrls added in v0.2.6

func GenerateListMapFromFileUrls(listUrls []string) (ListMap, error)

func GenerateListMapFromHTTPUrls added in v0.2.6

func GenerateListMapFromHTTPUrls(listUrls []string) (ListMap, error)

type ListUpdater added in v0.2.6

type ListUpdater struct {
	Enabled        bool
	UpdateInterval time.Duration
	RetryCount     int
	RetryDelay     time.Duration

	Plugin *DNSAdBlock
	// contains filtered or unexported fields
}

func (*ListUpdater) Start added in v0.2.6

func (u *ListUpdater) Start()

type StoredListConfiguration added in v0.2.6

type StoredListConfiguration struct {
	UpdateTimestamp int      `json:"update_timestamp"`
	BlacklistURLs   []string `json:"blacklist_urls"`
	WhitelistURLs   []string `json:"whitelist_urls"`
	Blacklist       ListMap  `json:"blacklist"`
	Whitelist       ListMap  `json:"whitelist"`
}

func ReadListConfiguration added in v0.2.6

func ReadListConfiguration(path string) (*StoredListConfiguration, error)

func (*StoredListConfiguration) NeedsUpdate added in v0.2.6

func (s *StoredListConfiguration) NeedsUpdate(updateDuration time.Duration) bool

func (*StoredListConfiguration) Persist added in v0.2.6

func (s *StoredListConfiguration) Persist(path string) error

type UpdateableRuleset added in v0.2.6

type UpdateableRuleset struct {
	Blacklist        map[string]bool
	Whitelist        map[string]bool
	BlacklistSources []string
	WhitelistSources []string
}

func NewFileRuleSet added in v0.2.6

func NewFileRuleSet(whitelist, blacklist []string) *UpdateableRuleset

func (*UpdateableRuleset) IsBlacklisted added in v0.2.6

func (u *UpdateableRuleset) IsBlacklisted(qn string) bool

func (*UpdateableRuleset) IsWhitelisted added in v0.2.6

func (u *UpdateableRuleset) IsWhitelisted(qn string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL