spflib

package
v3.31.6 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunks added in v3.3.0

func Chunks(s string, chunkSize int) []string

Chunks splits strings into arrays of a certain chunk size. We use this to split TXT records into 255 sized chunks for RFC 4408 https://tools.ietf.org/html/rfc4408#section-3.1.3 Borrowed from https://stackoverflow.com/a/61469854/11477663

Types

type CachingResolver

type CachingResolver interface {
	Resolver
	ChangedRecords() []string
	ResolveErrors() []error
	Save(filename string) error
}

CachingResolver wraps a live resolver and adds caching to it. GetSPF will always return the cached value, if present. It will also query the inner resolver and compare results. If a given lookup has inconsistencies between cache and live, GetSPF will return the cached result. All records queries will be stored for the lifetime of the resolver, and can be flushed to disk at the end. All resolution errors from the inner resolver will be saved and can be retreived later.

func NewCache

func NewCache(filename string) (CachingResolver, error)

NewCache creates a new cache file named filename.

type LiveResolver

type LiveResolver struct{}

LiveResolver simply queries DNS to resolve SPF records.

func (LiveResolver) GetSPF

func (l LiveResolver) GetSPF(name string) (string, error)

GetSPF looks up the SPF record named "name".

type Resolver

type Resolver interface {
	GetSPF(string) (string, error)
}

Resolver looks up spf txt records associated with a FQDN.

type SPFPart

type SPFPart struct {
	Text          string
	IsLookup      bool
	IncludeRecord *SPFRecord
	IncludeDomain string
}

SPFPart stores a part of an SPF record, with attributes.

type SPFRecord

type SPFRecord struct {
	Parts []*SPFPart
}

SPFRecord stores the parts of an SPF record.

func Parse

func Parse(text string, dnsres Resolver) (*SPFRecord, error)

Parse parses a raw SPF record.

func (*SPFRecord) Flatten

func (s *SPFRecord) Flatten(spec string) *SPFRecord

Flatten optimizes s.

func (*SPFRecord) Lookups

func (s *SPFRecord) Lookups() int

Lookups returns the number of DNS lookups required by s.

func (*SPFRecord) Print

func (s *SPFRecord) Print() string

Print prints an SPFRecord.

func (*SPFRecord) TXT

func (s *SPFRecord) TXT() string

TXT outputs s as a TXT record.

func (*SPFRecord) TXTSplit

func (s *SPFRecord) TXTSplit(pattern string, overhead int, txtMaxSize int) map[string][]string

TXTSplit returns a set of txt records to use for SPF. pattern given is used to name all chained spf records. patern should include %d, which will be replaced by a counter. should result in fqdn after replacement returned map will have keys with fqdn of resulting records. root record will be under key "@" overhead specifies that the first split part should assume an overhead of that many bytes. For example, if there are other txt records and you wish to reduce the first SPF record size to prevent DNS over TCP.

Jump to

Keyboard shortcuts

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