Skip to content

pspacek/bind-dynamic_db-examples

Repository files navigation

1) Compile and install BIND 9 with patches from
https://github.com/spacekpe/bind-dynamic_db

2) Compile this sample driver:
$ make

3) Copy resulting binary sample.so to BIND library directory:
$ cp sample.so /usr/lib64/bind/

4) Add driver configuration to named.conf:
$ cat >> /etc/named.conf <<EOF
dynamic-db "sample" {
        library "sample.so";
        arg "test.";
        arg "arpa.";
};
EOF

5) Run named and see logs.
$ named -g -u named

You should be able to see something like
zone test/IN: loaded serial 0
zone arpa/IN: loaded serial 0

It means that the sample driver created empty zones test. and arpa. as defined
by "arg" parameters.

$ dig @localhost test.
should work as usual and you should be able to see dummy zone with NS record
pointing to zone apex and A record for 127.0.0.1:

;; ANSWER SECTION:
test.			86400	IN	A	127.0.0.1
test.			86400	IN	NS	test.
test.			86400	IN	SOA	test. test. 0 28800 7200 604800 86400

This driver creates two empty zones and allows query/transfer/update to all
IP addresses for demonstrational purposes.

The driver wraps RBT database implementation used natively by BIND and modifies
addrdataset() and substractrdataset() functions to do additional work during
dynamic updates.

Dynamic update modifies the target zone as usual. After that the driver detects
if modified RR was A or AAAA and attempts to generate or delete matching
PTR record in one of the two zones managed by the driver.

E.g.
update add a.test. 300 IN A 192.0.2.1
will add the A record
a.test.			300	IN	A	192.0.2.1
and also automatically generate record
1.2.0.192.in-addr.arpa.	300	IN	PTR	a.test.


Feel free to test AXFR and RR deletion via dynamic updates, both should work
as usual + deletion of A/AAAA record should delete relevant PTR record too.

The zone is stored only in memory and all changes will be lost on reload.


Hints for code readers:
- Driver initialization starts in driver.c: dynamic_driver_init() function.
- New database implementation is registered by calling dns_db_register() and
  passing function pointer to it. This sample uses own function create_db()
  to initialize the database.
- Zones are created later in instance.c: load_sample_instance_zones().
- Database entry points are in structure db.c: dns_dbmethods_t sampledb_methods
- Sampledb_methods points to own implementation of database interface.
  See db.c: addrdataset() implementation and look how RBT database instance is
  wrapped into an additional layer of logic.

About

Example drivers for BIND 9 dynamic_db interface

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published