dnsfmt

package module
v0.0.0-...-0f5595b Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

README

Opiniated DNS zone file formatter

This tools (re)formats zone files keeping comments and $-pragmas intact. It does remove in-RR comments, i.e '; serial' and friends, although for SOA records these get added back. TTLs are converted to human readable form. Types and classes are uppercased.

Builds up-on: https://github.com/bwesterb/go-zonefile which is butchered and vendored in ./zonefile. (Only needed half of the functionality and comments weren't fleshed out.)

dnsfmt is a filter. See dnsfmt.1.md for more information.

asciicast

Why not miekg/dns?

Pondered this, and yes, it has a better parser, but then re-arranging the []dns.RR and pretty printing would have been (IMO) more work. Also miekg/dns does not have an option to leave $-directives as-is.

Development

zonefile/* is the parsing, everything in main is the assembling of the formatted zone.

Documentation

Index

Constants

View Source
const (
	Space3 = "   "
	Indent = 29
)
View Source
const (
	Second = 1
	Minute = Second * 60
	Hour   = Minute * 60
	Day    = Hour * 24
	Week   = Day * 7
)
View Source
const Year15 = time.Duration(24*time.Hour*365) * 15
View Source
const Year5 = time.Duration(24*time.Hour*365) * 5

Variables

This section is empty.

Functions

func Increase

func Increase(s []byte) []byte

func Reformat

func Reformat(data, origin []byte, w io.Writer, incrementSerial bool) error

func SerialToHuman

func SerialToHuman(s []byte) string

SerialToHuman will detect if a number is epoch, or a coded date, ie:

1712989081 is epoch, because, when converted is less than 15 years ago, and not more than 5 years in the future.

If not epoch, we assume a "date" format: 2024041300. Every sequence number 00, 01, is assumed to be an hour.

Both are converted to a more human readable string.

func Split

func Split(buf []byte, lim int) [][]byte

func StripOrigin

func StripOrigin(origin, name []byte) []byte

func TimeToHuman

func TimeToHuman(ttl *int) string

func TimeToHumanByte

func TimeToHumanByte(ttl []byte) []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

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