blocklist

package module
v0.0.0-...-20d1000 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2019 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

blocklist

Name

blocklist - uses pi-hole-like block lists to block nefarious domains.

Description

The blocklist plugin will fetch configured blocklists from the internet and block local clients from resolving the domains listed on them.

For a domain that is blocked we will return a NXDOMAIN response.

This plugin is a WIP.

Syntax

blocklist https://hosts-file.net/ad_servers.txt
blocklist override {
    always_allow employer.com
    block competitor.com
}

(see also the sample Corefile in this directory)

Metrics

If monitoring is enabled (via the prometheus directive) the following metric is exported:

  • coredns_blocklist_count_total{server} - counter of total number of blocked domains.
  • coredns_blocklist_fetch{list, result} - counter of list fetch attempts and the results of the fetch operation.
  • coredns_blocklist_list_size{list} - number of blocked domains on each configured list.

The list label contains the URL of the blocklist in question; the result label is either OK or a brief error string.

The server label indicates which server handled the request, see the metrics plugin for details.

Documentation

Overview

Package blocklist contains a blocklist plugin for CoreDNS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blocker

type Blocker interface {
	Block(string) bool
}

Blocker returns true for blocked DNS domains.

type Blocklist

type Blocklist struct {
	Next plugin.Handler
	// contains filtered or unexported fields
}

Blocklist is the blocklist plugin.

func New

func New(db *MemoryDB) *Blocklist

New returns a new Blocklist.

func (*Blocklist) Name

func (b *Blocklist) Name() string

Name implements the Handler interface.

func (*Blocklist) ServeDNS

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

ServeDNS implements the plugin.Handler interface.

func (*Blocklist) Start

func (b *Blocklist) Start() error

Start starts the internals of Blocklist.

func (*Blocklist) Stop

func (b *Blocklist) Stop() error

Stop stops the internals of Blocklist.

type HashDB

type HashDB map[string]bool

HashDB is a hash-backed static list of blocked domains.

func (HashDB) Block

func (h HashDB) Block(domain string) bool

type List

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

List represents a single blocklist.

func NewList

func NewList(source string) *List

NewList returns a new List representing the blocklist at source.

func (*List) Run

func (l *List) Run(db ListDB, stop <-chan struct{}, poke chan<- struct{})

Run periodically downloads the blocklist and updates the internal database.

type ListDB

type ListDB interface {
	LastFetched(string) time.Time
	Update(string, time.Time, []string) error
}

ListDB is the persistent store of blocklist data.

type MemoryDB

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

MemoryDB is an in-memory store of blocklist data.

func NewMemoryDB

func NewMemoryDB() *MemoryDB

NewMemoryDB returns a new MemoryDB. A client must call Pokee on a separate goroutine.

func (*MemoryDB) Block

func (db *MemoryDB) Block(domain string) bool

Block returns true if domain is blocked.

func (*MemoryDB) LastFetched

func (db *MemoryDB) LastFetched(source string) time.Time

LastFetched returns the time that the given source was last fetched, or the zero time if it has never been fetched.

func (*MemoryDB) Pokee

func (db *MemoryDB) Pokee(stop, poke <-chan struct{})

func (*MemoryDB) Update

func (db *MemoryDB) Update(source string, fetched time.Time, blocked []string) error

Update sets the contents of the source to blocked as of time fetched.

Jump to

Keyboard shortcuts

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