pdsql

package module
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 16 Imported by: 0

README


title: "pdsql" description: "pdsql use powerdns generic sql as backend." weight: 10 tags: [ "plugin" , "pdsql" ] categories: [ "plugin", "external" ] date: "2017-12-09T10:26:00+08:00" repo: "https://github.com/fredshema/coredns-pdsql" home: "https://github.com/fredshema/coredns-pdsql/blob/master/README.md"

Automated Testing

pdsql

pdsql - Connect CoreDNS to PowerDNS generic sql zone backends.

Use gorm.io/gorm to handle database, support many database as gorm dose.

Compatibility

The plugin aims to be compatible with PowerDNS backend databases.

It also aims to provide the same feature scope as the file plugin or other CoreDNS zone backends.

It also supports multiple sub zones on different backends like:

  • coredns-pdsql.local
  • sub.coredns-pdsql.local
  • file.sub.coredns-pdsql.local

Syntax

pdsql <dialect> <arg> {
    # enable debug mode
    debug [db]
    # create table for test
    auto-migrate
}

Install Driver

pdsql need db driver for dialect, current gorm do not support auto install driver, the supported driver is bundled with this plugin.

  • sqlite,sqlite3
  • mysql
  • postgres

Examples

Start a server on the 1053 port, use test.db as backend.

test.:1053 {
    pdsql sqlite3 ./test.db {
        debug db
        auto-migrate
    }   
}

coredns-pdsql.local.:1053 {
   pdsql postgres "host=db dbname=coredns user=coredns password=coredns.secret sslmode=disable" {
       debug db
       auto-migrate
   }

   whoami
   log
   errors
}
 
sub.coredns-pdsql.local.:1053 {
   pdsql postgres "host=db dbname=coredns user=coredns password=coredns.secret sslmode=disable" {
       debug db
       auto-migrate
   }

   whoami
   log
   errors
}

file.sub.coredns-pdsql.local.:1053 {
   file /etc/coredns/zones/file-sub-coredns-pdsql-local.db

   whoami
   log
   errors
}

Prepare data for test.

# Insert records for wener.test
sqlite3 ./test.db 'insert into records(name,type,content,ttl,disabled)values("wener.test","A","192.168.1.1",3600,0)'
sqlite3 ./test.db 'insert into records(name,type,content,ttl,disabled)values("wener.test","TXT","TXT Here",3600,0)'

When queried for "wener.test. A", CoreDNS will respond with:

;; QUESTION SECTION:
;wener.test.			IN	A

;; ANSWER SECTION:
wener.test.		3600	IN	A	192.168.1.1

When queried for "wener.test. ANY", CoreDNS will respond with:

;; QUESTION SECTION:
;wener.test.			IN	ANY

;; ANSWER SECTION:
wener.test.		3600	IN	A	192.168.1.1
wener.test.		3600	IN	TXT	"TXT Here"

Wildcard

# domain id 1
sqlite3 ./test.db 'insert into domains(name,type)values("example.test","NATIVE")'
sqlite3 ./test.db 'insert into records(domain_id,name,type,content,ttl,disabled)values(1,"*.example.test","A","192.168.1.1",3600,0)'

When queried for "first.example.test. A", CoreDNS will respond with:

;; QUESTION SECTION:
;first.example.test.		IN	A

;; ANSWER SECTION:
first.example.test.	3600	IN	A	192.168.1.1

Documentation

Overview

Package pdsql implements a plugin that query powerdns database to resolve the coredns query

Index

Constants

View Source
const Name = "pdsql"

Variables

This section is empty.

Functions

func ParseSOA

func ParseSOA(rr *dns.SOA, line string) bool

func WildcardMatch

func WildcardMatch(s1, s2 string) bool

Dummy wildcard match

Types

type PowerDNSGenericSQLBackend

type PowerDNSGenericSQLBackend struct {
	*gorm.DB
	Debug bool
	Next  plugin.Handler
}

func (PowerDNSGenericSQLBackend) AutoMigrate

func (pdb PowerDNSGenericSQLBackend) AutoMigrate() error

func (PowerDNSGenericSQLBackend) Name

func (pdb PowerDNSGenericSQLBackend) Name() string

func (*PowerDNSGenericSQLBackend) ResolveCNAMEs

func (pdb *PowerDNSGenericSQLBackend) ResolveCNAMEs(cname string, qtype uint16) ([]*pdnsmodel.Record, error)

func (*PowerDNSGenericSQLBackend) ResolveRequest

func (pdb *PowerDNSGenericSQLBackend) ResolveRequest(qname string, qtype uint16) ([]*pdnsmodel.Record, error)

func (*PowerDNSGenericSQLBackend) ResolveSOA

func (pdb *PowerDNSGenericSQLBackend) ResolveSOA(qname string) (*pdnsmodel.Record, error)

func (*PowerDNSGenericSQLBackend) SearchDomain

func (pdb *PowerDNSGenericSQLBackend) SearchDomain(qname string) (*pdnsmodel.Domain, error)

func (*PowerDNSGenericSQLBackend) SearchWildcard

func (pdb *PowerDNSGenericSQLBackend) SearchWildcard(qname string, qtype uint16) ([]*pdnsmodel.Record, error)

func (PowerDNSGenericSQLBackend) ServeDNS

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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