filter

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2020 License: MIT Imports: 15 Imported by: 1

README

Filter plugin

Build Status codecov Go Report Card

CoreDNS plugin that blocks requests based on lists and rules

Usage

.:53 {
    filter {
        allow ./lists/whitelist.txt
        block ./lists/blacklist.txt
    }
    forward . 1.1.1.1
}

Building

$ git clone https://github.com/coredns/coredns
$ cd coredns

Then modify plugin.cfg.

...
cache:cache
filter:github.com/milgradesec/filter
forward:forward
...

And build coredns as usual.

$ go generate && go build

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BlockCount = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "filter",
		Name:      "blocked_total",
		Help:      "The total count of blocked requests.",
	}, []string{"server"})
)

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Lists []*List

	Next plugin.Handler
	// contains filtered or unexported fields
}

Filter represents a plugin instance that can filter and block requests based on predefined lists.

func (*Filter) Load

func (f *Filter) Load() error

Load loads the lists from disk.

func (*Filter) Match

func (f *Filter) Match(qname string) bool

Match determines if the requested domain should be blocked.

func (*Filter) Name

func (f *Filter) Name() string

Name implements plugin.Handler.

func (*Filter) OnStartup added in v1.1.0

func (f *Filter) OnStartup() error

OnStartup loads lists at plugin startup.

func (*Filter) ServeDNS

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

ServeDNS implements plugin.Handler.

type List added in v1.1.0

type List struct {
	Path  string
	Block bool
}

func (*List) Open added in v1.1.0

func (l *List) Open() (src io.ReadCloser, err error)

type PatternMatcher

type PatternMatcher struct {
	// contains filtered or unexported fields
}

func NewPatternMatcher

func NewPatternMatcher() *PatternMatcher

func (*PatternMatcher) Match

func (l *PatternMatcher) Match(str string) bool

func (*PatternMatcher) ReadFrom added in v1.1.0

func (l *PatternMatcher) ReadFrom(r io.Reader) (n int64, err error)

type ResponseWriter

type ResponseWriter struct {
	dns.ResponseWriter
	*Filter
	// contains filtered or unexported fields
}

ResponseWriter detects and blocks cname cloaking.

func (*ResponseWriter) WriteMsg

func (w *ResponseWriter) WriteMsg(m *dns.Msg) error

WriteMsg implements dns.ResponseWriter.

Jump to

Keyboard shortcuts

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