coredns_filter

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

README

coredns-filter

filter plugin of coredns

Name

filter - Filter DNS response message.

Compilation

filter:github.com/owent/coredns-filter

This plugin should be add right after cache.

sed -i.bak -r '/filter:.*/d' plugin.cfg
sed -i.bak '/cache:.*/i filter:github.com/owent/coredns-filter' plugin.cfg
go get github.com/owent/coredns-filter

go generate

Syntax

filter [command options...] {
  [command options...]
}

Available options:

  • prefer <none/ipv4/ipv6> : Return all/A/AAAA records when get both A and AAAA record in a answer.
  • bogus-nxdomain [ip address/ip prefix...] : Remove ip and set response code to NXDOMAIN .

Examples

Enable filter:

example.org {
    whoami
    forward . 8.8.8.8
    filter prefer ipv4 {
      bogus-nxdomain 127.0.0.1/30 123.125.81.12
    }
}

See Also

For Developers

Debug Build
git clone --depth 1 https://github.com/coredns/coredns.git coredns
cd coredns
git reset --hard
sed -i.bak -r '/filter:.*/d' plugin.cfg
sed -i.bak '/cache:.*/a filter:github.com/owent/coredns-filter' plugin.cfg
go get -u github.com/owent/coredns-filter@main
# go get github.com/owent/coredns-filter@latest
go generate

env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags=all="-N -l" -o build/linux/amd64/coredns
Configure File For Debug
(default_dns_ip) {
  debug
  # errors
  forward . 119.29.29.29 223.5.5.5 1.0.0.1 94.140.14.140 2402:4e00:: 2400:3200::1 2400:3200:baba::1 2606:4700:4700::1001 2a10:50c0::1:ff {
    policy sequential
  }
  loop
  log
}

. {
  import default_dns_ip

  filter prefer ipv4
  filter {
    bogus-nxdomain 127.0.0.1/30 123.125.81.12
  }
}
VSCode lanch example
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Package",
      "type": "go",
      "request": "launch",
      "mode": "debug",
      "program": "${workspaceFolder}",
      "args": [
        "-dns.port=6813",
        "-conf=${workspaceFolder}/.vscode/test-coredns.conf",
        "-alsologtostderr"
      ],
      "showLog": true
    },
    {
      "name": "Launch Executable",
      "type": "go",
      "request": "launch",
      "mode": "exec",
      "program": "${workspaceFolder}/build/linux/amd64/coredns",
      "args": [
        "-dns.port=6813",
        "-conf=${workspaceFolder}/.vscode/test-coredns.conf",
        "-alsologtostderr"
      ],
      "cwd": "${workspaceFolder}/build",
      "showLog": true
    }
  ]
}
Run
go get -v github.com/go-delve/delve/cmd/dlv

sudo build/linux/amd64/coredns -dns.port=6813 -conf test-coredns.conf

dig owent.net @127.0.0.1 -p 6813

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BogusNxDomain

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

type Filter

type Filter struct {
	Next          plugin.Handler
	Prefer        FilterHandler
	BugosNxDomain FilterHandler
}

Filter implements the plugin.Handler interface.

func NewFilterHandler

func NewFilterHandler() Filter

func (*Filter) AddBogusNxDomainHandler

func (m *Filter) AddBogusNxDomainHandler(options []string) error

func (*Filter) AddCommand

func (m *Filter) AddCommand(cmd string, options []string) error

func (*Filter) AddPreferHandler

func (m *Filter) AddPreferHandler(options []string) error

func (*Filter) Name

func (m *Filter) Name() string

func (*Filter) ServeDNS

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

type FilterHandler

type FilterHandler interface {
	// contains filtered or unexported methods
}

type PreferIPv4

type PreferIPv4 struct {
}

type PreferIPv6

type PreferIPv6 struct {
}

Jump to

Keyboard shortcuts

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