blocked

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MPL-2.0 Imports: 22 Imported by: 1

README

blocked

TEST RELEASE (in docker)

A coredns plugin to block domains/query.

Usage

.:1053 {
    errors
    bind 127.0.0.1
    forward . 223.5.5.5:53

    log . {
        class all
    }

    blocked {
        # to reload cache_data/black_list/white_list, default: 5days. 
        # Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
        reload 86400s
        
        # bloom filter capacity & rate. default: 250_000 0.001
        size_rate 250_000 0.001
    
        # enable log, remove is disable
        log
        
        # hostname query, default: refused. Options: ignore / refused
        hostname_query refused
        
        # blocked_query_response, default: soa. Options: soa / zero / hinfo / no-ans / refused
        #  can config some special for qtypes
        resp_type zero {
            refused ANY AAAA HTTPS MX PTR SRV CNAME
            zero AAAA
        }
        
        # covert domain in wildcard, and compare all to filter
        #  if use it black_list must used `local+` prefix to skip domain valid
        wildcard
        
        # (the last cache-data will be ues) load cache file from local or remote
        cache_data https://example.com/rules.data
        cache_data <AbsolutePath>/rules.data
        
        # black list to block query, load rules from local or remote.
        #  use `local+` will skip the domain verify means allow any line exclude comment
        black_list <AbsolutePath>/list.txt
        black_list local+<AbsolutePath>/list.txt
        black_list https://example.com/reject-list.txt
        
        # white list to disable block
        white_list <AbsolutePath>/white-list.txt
        white_list https://example.com/white-list.txt
    }
}

Feature

  • 大规则小内存匹配快,Thanks: bits-and-blooms
  • 支持从远端/本地加载缓存
  • 支持黑/白名单的规则,并可从远端/本地加载规则
    • 默认远端加载会检查域名合法性;本地使用local+前缀,跳过合法性检查
  • 支持多种屏蔽的返回报文
    • SOA
    • HINFO
    • ZERO
    • No-Ans
    • NX - NXDOMAIN
    • REFUSED
  • 支持屏蔽指定查询类型
  • 支持多种格式的规则文件
    • hosts - HostParser
    • surge - SurgeParser
    • dnsmasq - DnsmasqParser
    • domain - DomainParser
    • abnf - ABNFParser, 需要使用abnf+前缀指定解析器

TODO

  • Github Action 创建缓存文件
  • Github Action 创建bin文件
  • 使用缓存文件
  • 增加response的报文类型
  • expose过滤器的参数
  • 增加white_list
  • 屏蔽指定类型的dns查询
  • 支持泛域名屏蔽规则(需要考虑n级域名的问题)
  • 引入AdGuard的过滤器
  • ...

Changelog & Note

Documentation

Index

Constants

View Source
const (
	MINUTE = 60
	HOUR   = 60 * MINUTE
	DAY    = 24 * HOUR
)
View Source
const (
	NXDOMAIN = NX
)

Variables

This section is empty.

Functions

func CreateHINFO added in v1.0.1

func CreateHINFO(q dns.Question, r *dns.Msg) *dns.Msg

func CreateNOANS added in v1.0.1

func CreateNOANS(_ dns.Question, r *dns.Msg) *dns.Msg

func CreateNXDOMAIN added in v1.0.1

func CreateNXDOMAIN(_ dns.Question, r *dns.Msg) *dns.Msg

func CreateREFUSED added in v1.0.1

func CreateREFUSED(_ dns.Question, r *dns.Msg) *dns.Msg

func CreateSOA added in v1.0.1

func CreateSOA(q dns.Question, r *dns.Msg) *dns.Msg

func CreateZERO added in v1.0.1

func CreateZERO(q dns.Question, r *dns.Msg) *dns.Msg

func FileToLines

func FileToLines(path string) ([]string, error)

func GetWild added in v1.1.0

func GetWild(h string) []string

func IsBlocked added in v1.0.1

func IsBlocked(cfg *Configs, host string) bool

func IsHostname added in v1.1.0

func IsHostname(s string) bool

func LinesFromReader

func LinesFromReader(r io.Reader) ([]string, error)

func LocalCacheLoader added in v1.1.4

func LocalCacheLoader(path string) (*bloom.Filter, error)

func LocalRuleLoader added in v1.1.4

func LocalRuleLoader(path string, filter *bloom.Filter, strictMode bool) error

func PureDomain added in v1.1.0

func PureDomain(s string) string

func RemoteCacheLoader added in v1.1.4

func RemoteCacheLoader(uri string) (*bloom.Filter, error)

func RemoteRuleLoader added in v1.1.4

func RemoteRuleLoader(uri string, filter *bloom.Filter) error

func UrlToLines

func UrlToLines(url string) ([]string, error)

Types

type Blocked

type Blocked struct {
	Next    plugin.Handler
	Configs *Configs
}

func (Blocked) Name

func (app Blocked) Name() string

func (Blocked) Ready

func (app Blocked) Ready() bool

Ready implements the ready.Readiness interface, once this flips to true CoreDNS assumes this plugin is ready for queries; it is not checked again.

func (Blocked) ServeDNS

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

type Configs

type Configs struct {
	sync.RWMutex

	Size int
	Rate float64
	// contains filtered or unexported fields
}

func NewConfigs added in v1.1.0

func NewConfigs() *Configs

type RespFunc added in v1.1.0

type RespFunc func(q dns.Question, r *dns.Msg) *dns.Msg

func RespType2RespFunc added in v1.1.0

func RespType2RespFunc(rt RespType) RespFunc

type RespType added in v1.1.0

type RespType int8
const (
	/*
	 * respType: using by switch logic
	 */
	NoAns RespType = iota
	SOA
	HINFO
	ZERO
	NX
	REFUSED
	IGNORE
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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