Documentation
¶
Index ¶
- Constants
- Variables
- func AnswerToString(answer []dns.RR) string
- func CidrContainsIP(cidr string, ip net.IP) bool
- func ClientNameMatchesGroupName(group, clientName string) bool
- func CreateAnswerFromQuestion(question dns.Question, ip net.IP, remainingTTL uint32) (dns.RR, error)
- func CreateHeader(question dns.Question, remainingTTL uint32) dns.RR_Header
- func CtxSend[T any](ctx context.Context, ch chan T, val T) (ok bool)
- func DefaultHTTPTransport() *http.Transport
- func ExtractCacheKey(key string) (qType dns.Type, qName string)
- func ExtractDomain(question dns.Question) string
- func ExtractDomainOnly(in string) string
- func FatalOnError(message string, err error)
- func GenerateCacheKey(qType dns.Type, qName string) string
- func GetEdns0Option[T EDNS0Option](msg *dns.Msg) T
- func HTTPClientIP(r *http.Request) net.IP
- func IterateValueSorted(in map[string]int, fn func(string, int))
- func LogOnError(ctx context.Context, message string, err error)
- func LogOnErrorWithEntry(logEntry *logrus.Entry, message string, err error)
- func NewMsgWithAnswer(domain string, ttl uint, dnsType dns.Type, address string) (*dns.Msg, error)
- func NewMsgWithQuestion(question string, qType dns.Type) *dns.Msg
- func Obfuscate(in string) string
- func ParseIPFromArpaAddr(arpa string) (net.IP, error)
- func QuestionToString(questions []dns.Question) string
- func RemoveEdns0Option[T EDNS0Option](msg *dns.Msg) bool
- func RemoveEdns0Record(msg *dns.Msg) bool
- func SetEdns0Option(msg *dns.Msg, opt dns.EDNS0) bool
- func TLSGenerateSelfSignedCert(domains []string) (tls.Certificate, error)
- type EDNS0Option
Constants ¶
const ( IPv4PtrSuffix = ".in-addr.arpa." IPv6PtrSuffix = ".ip6.arpa." )
Variables ¶
var ( // Version current version number Version = "undefined" // BuildTime build time of the binary BuildTime = "undefined" // Architecture current CPU architecture Architecture = "undefined" )
var ErrInvalidArpaAddrLen = errors.New("arpa hostname is not of expected length")
var ( // To avoid making this package depend on config, we use a global // that is set at config load. // Ideally we'd move the obfuscate code somewhere else (maybe into `log`), // but that would require also moving all its dependencies. // This is good enough for now. LogPrivacy atomic.Bool )
Functions ¶
func AnswerToString ¶
AnswerToString creates a user-friendly representation of an answer
func CidrContainsIP ¶
CidrContainsIP checks if CIDR contains a single IP
func ClientNameMatchesGroupName ¶
ClientNameMatchesGroupName checks if a group with optional wildcards contains a client name
func CreateAnswerFromQuestion ¶
func CreateAnswerFromQuestion(question dns.Question, ip net.IP, remainingTTL uint32) (dns.RR, error)
CreateAnswerFromQuestion creates new answer from a question
func CreateHeader ¶
CreateHeader creates DNS header for passed question
func CtxSend ¶
CtxSend sends a value to a channel while the context isn't done. If the message is sent, it returns true. If the context is done or the channel is closed, it returns false.
func DefaultHTTPTransport ¶
DefaultHTTPTransport returns a new Transport with the same defaults as net/http.
func ExtractCacheKey ¶
ExtractCacheKey return query type/domain from cacheKey
func ExtractDomain ¶
ExtractDomain returns domain string from the question
func ExtractDomainOnly ¶
ExtractDomainOnly extracts domain from the DNS query
func FatalOnError ¶
FatalOnError logs the message only if error is not nil and exits the program execution
func GenerateCacheKey ¶
GenerateCacheKey return cacheKey by query type/domain
func GetEdns0Option ¶
func GetEdns0Option[T EDNS0Option](msg *dns.Msg) T
GetEdns0Option returns the option with the given code from the OPT record in the Extra section of the given message. If the option is not found, nil will be returned.
func IterateValueSorted ¶
IterateValueSorted iterates over maps value in a sorted order and applies the passed function
func LogOnError ¶
LogOnError logs the message only if error is not nil
func LogOnErrorWithEntry ¶
LogOnErrorWithEntry logs the message only if error is not nil
func NewMsgWithAnswer ¶
NewMsgWithAnswer creates new DNS message with answer
func NewMsgWithQuestion ¶
NewMsgWithQuestion creates new DNS message with question
func Obfuscate ¶
Obfuscate replaces all alphanumeric characters with * to obfuscate user sensitive data if LogPrivacy is enabled
func QuestionToString ¶
QuestionToString creates a user-friendly representation of a question
func RemoveEdns0Option ¶
func RemoveEdns0Option[T EDNS0Option](msg *dns.Msg) bool
RemoveEdns0Option removes the option according to the given type from the OPT record in the Extra section of the given message. If there are no more options in the OPT record, the OPT record will be removed. If the option is successfully removed, true will be returned.
func RemoveEdns0Record ¶
RemoveEdns0Record removes the OPT record from the Extra section of the given message. If the OPT record is removed, true will be returned.
func SetEdns0Option ¶
SetEdns0Option adds the given option to the OPT record in the Extra section of the given message. If the option already exists, it will be replaced. If the option is successfully set, true will be returned.
func TLSGenerateSelfSignedCert ¶
func TLSGenerateSelfSignedCert(domains []string) (tls.Certificate, error)
TLSGenerateSelfSignedCert returns a new self-signed cert for the given domains.
Being self-signed, no client will trust this certificate.
Types ¶
type EDNS0Option ¶
type EDNS0Option interface { *dns.EDNS0_SUBNET | *dns.EDNS0_EDE | *dns.EDNS0_LOCAL | *dns.EDNS0_NSID | *dns.EDNS0_COOKIE | *dns.EDNS0_UL Option() uint16 }
EDNS0Option is an interface for all EDNS0 options as type constraint for generics.