Documentation update
This commit is contained in:
parent
64fea017a2
commit
126ee2f0c5
491
doc.go
491
doc.go
|
@ -1,246 +1,247 @@
|
||||||
// Package dns implements a full featured interface to the Domain Name System.
|
/*
|
||||||
// Server- and client-side programming is supported.
|
Package dns implements a full featured interface to the Domain Name System.
|
||||||
// The package allows complete control over what is send out to the DNS. The package
|
Server- and client-side programming is supported.
|
||||||
// API follows the less-is-more principle, by presenting a small, clean interface.
|
The package allows complete control over what is send out to the DNS. The package
|
||||||
//
|
API follows the less-is-more principle, by presenting a small, clean interface.
|
||||||
// The package dns supports (asynchronous) querying/replying, incoming/outgoing zone transfers,
|
|
||||||
// TSIG, EDNS0, dynamic updates, notifies and DNSSEC validation/signing.
|
The package dns supports (asynchronous) querying/replying, incoming/outgoing zone transfers,
|
||||||
// Note that domain names MUST be fully qualified, before sending them, unqualified
|
TSIG, EDNS0, dynamic updates, notifies and DNSSEC validation/signing.
|
||||||
// names in a message will result in a packing failure.
|
Note that domain names MUST be fully qualified, before sending them, unqualified
|
||||||
//
|
names in a message will result in a packing failure.
|
||||||
// Resource records are native types. They are not stored in wire format.
|
|
||||||
// Basic usage pattern for creating a new resource record:
|
Resource records are native types. They are not stored in wire format.
|
||||||
//
|
Basic usage pattern for creating a new resource record:
|
||||||
// r := new(dns.MX)
|
|
||||||
// r.Hdr = dns.RR_Header{Name: "miek.nl.", Rrtype: dns.TypeMX, Class: dns.ClassINET, Ttl: 3600}
|
r := new(dns.MX)
|
||||||
// r.Preference = 10
|
r.Hdr = dns.RR_Header{Name: "miek.nl.", Rrtype: dns.TypeMX, Class: dns.ClassINET, Ttl: 3600}
|
||||||
// r.Mx = "mx.miek.nl."
|
r.Preference = 10
|
||||||
//
|
r.Mx = "mx.miek.nl."
|
||||||
// Or directly from a string:
|
|
||||||
//
|
Or directly from a string:
|
||||||
// mx, err := dns.NewRR("miek.nl. 3600 IN MX 10 mx.miek.nl.")
|
|
||||||
//
|
mx, err := dns.NewRR("miek.nl. 3600 IN MX 10 mx.miek.nl.")
|
||||||
// Or when the default TTL (3600) and class (IN) suit you:
|
|
||||||
//
|
Or when the default TTL (3600) and class (IN) suit you:
|
||||||
// mx, err := dns.NewRR("miek.nl. MX 10 mx.miek.nl.")
|
|
||||||
//
|
mx, err := dns.NewRR("miek.nl. MX 10 mx.miek.nl.")
|
||||||
// Or even:
|
|
||||||
//
|
Or even:
|
||||||
// mx, err := dns.NewRR("$ORIGIN nl.\nmiek 1H IN MX 10 mx.miek")
|
|
||||||
//
|
mx, err := dns.NewRR("$ORIGIN nl.\nmiek 1H IN MX 10 mx.miek")
|
||||||
// In the DNS messages are exchanged, these messages contain resource
|
|
||||||
// records (sets). Use pattern for creating a message:
|
In the DNS messages are exchanged, these messages contain resource
|
||||||
//
|
records (sets). Use pattern for creating a message:
|
||||||
// m := new(dns.Msg)
|
|
||||||
// m.SetQuestion("miek.nl.", dns.TypeMX)
|
m := new(dns.Msg)
|
||||||
//
|
m.SetQuestion("miek.nl.", dns.TypeMX)
|
||||||
// Or when not certain if the domain name is fully qualified:
|
|
||||||
//
|
Or when not certain if the domain name is fully qualified:
|
||||||
// m.SetQuestion(dns.Fqdn("miek.nl"), dns.TypeMX)
|
|
||||||
//
|
m.SetQuestion(dns.Fqdn("miek.nl"), dns.TypeMX)
|
||||||
// The message m is now a message with the question section set to ask
|
|
||||||
// the MX records for the miek.nl. zone.
|
The message m is now a message with the question section set to ask
|
||||||
//
|
the MX records for the miek.nl. zone.
|
||||||
// The following is slightly more verbose, but more flexible:
|
|
||||||
//
|
The following is slightly more verbose, but more flexible:
|
||||||
// m1 := new(dns.Msg)
|
|
||||||
// m1.Id = dns.Id()
|
m1 := new(dns.Msg)
|
||||||
// m1.RecursionDesired = true
|
m1.Id = dns.Id()
|
||||||
// m1.Question = make([]dns.Question, 1)
|
m1.RecursionDesired = true
|
||||||
// m1.Question[0] = dns.Question{"miek.nl.", dns.TypeMX, dns.ClassINET}
|
m1.Question = make([]dns.Question, 1)
|
||||||
//
|
m1.Question[0] = dns.Question{"miek.nl.", dns.TypeMX, dns.ClassINET}
|
||||||
// After creating a message it can be send.
|
|
||||||
// Basic use pattern for synchronous querying the DNS at a
|
After creating a message it can be send.
|
||||||
// server configured on 127.0.0.1 and port 53:
|
Basic use pattern for synchronous querying the DNS at a
|
||||||
//
|
server configured on 127.0.0.1 and port 53:
|
||||||
// c := new(dns.Client)
|
|
||||||
// in, rtt, err := c.Exchange(m1, "127.0.0.1:53")
|
c := new(dns.Client)
|
||||||
//
|
in, rtt, err := c.Exchange(m1, "127.0.0.1:53")
|
||||||
// Suppressing
|
|
||||||
// multiple outstanding queries (with the same question, type and class) is as easy as setting:
|
Suppressing
|
||||||
//
|
multiple outstanding queries (with the same question, type and class) is as easy as setting:
|
||||||
// c.SingleInflight = true
|
|
||||||
//
|
c.SingleInflight = true
|
||||||
// If these "advanced" features are not needed, a simple UDP query can be send,
|
|
||||||
// with:
|
If these "advanced" features are not needed, a simple UDP query can be send,
|
||||||
//
|
with:
|
||||||
// in, err := dns.Exchange(m1, "127.0.0.1:53")
|
|
||||||
//
|
in, err := dns.Exchange(m1, "127.0.0.1:53")
|
||||||
// When this functions returns you will get dns message. A dns message consists
|
|
||||||
// out of four sections.
|
When this functions returns you will get dns message. A dns message consists
|
||||||
// The question section: in.Question, the answer section: in.Answer,
|
out of four sections.
|
||||||
// the authority section: in.Ns and the additional section: in.Extra.
|
The question section: in.Question, the answer section: in.Answer,
|
||||||
//
|
the authority section: in.Ns and the additional section: in.Extra.
|
||||||
// Each of these sections (except the Question section) contain a []RR. Basic
|
|
||||||
// use pattern for accessing the rdata of a TXT RR as the first RR in
|
Each of these sections (except the Question section) contain a []RR. Basic
|
||||||
// the Answer section:
|
use pattern for accessing the rdata of a TXT RR as the first RR in
|
||||||
//
|
the Answer section:
|
||||||
// if t, ok := in.Answer[0].(*dns.TXT); ok {
|
|
||||||
// // do something with t.Txt
|
if t, ok := in.Answer[0].(*dns.TXT); ok {
|
||||||
// }
|
// do something with t.Txt
|
||||||
//
|
}
|
||||||
// Domain Name and TXT Character String Representations
|
|
||||||
//
|
Domain Name and TXT Character String Representations
|
||||||
// Both domain names and TXT character strings are converted to presentation
|
|
||||||
// form both when unpacked and when converted to strings.
|
Both domain names and TXT character strings are converted to presentation
|
||||||
//
|
form both when unpacked and when converted to strings.
|
||||||
// For TXT character strings, tabs, carriage returns and line feeds will be
|
|
||||||
// converted to \t, \r and \n respectively. Back slashes and quotations marks
|
For TXT character strings, tabs, carriage returns and line feeds will be
|
||||||
// will be escaped. Bytes below 32 and above 127 will be converted to \DDD
|
converted to \t, \r and \n respectively. Back slashes and quotations marks
|
||||||
// form.
|
will be escaped. Bytes below 32 and above 127 will be converted to \DDD
|
||||||
//
|
form.
|
||||||
// For domain names, in addition to the above rules brackets, periods,
|
|
||||||
// spaces, semicolons and the at symbol are escaped.
|
For domain names, in addition to the above rules brackets, periods,
|
||||||
//
|
spaces, semicolons and the at symbol are escaped.
|
||||||
// DNSSEC
|
|
||||||
//
|
DNSSEC
|
||||||
// DNSSEC (DNS Security Extension) adds a layer of security to the DNS. It
|
|
||||||
// uses public key cryptography to sign resource records. The
|
DNSSEC (DNS Security Extension) adds a layer of security to the DNS. It
|
||||||
// public keys are stored in DNSKEY records and the signatures in RRSIG records.
|
uses public key cryptography to sign resource records. The
|
||||||
//
|
public keys are stored in DNSKEY records and the signatures in RRSIG records.
|
||||||
// Requesting DNSSEC information for a zone is done by adding the DO (DNSSEC OK) bit
|
|
||||||
// to an request.
|
Requesting DNSSEC information for a zone is done by adding the DO (DNSSEC OK) bit
|
||||||
//
|
to an request.
|
||||||
// m := new(dns.Msg)
|
|
||||||
// m.SetEdns0(4096, true)
|
m := new(dns.Msg)
|
||||||
//
|
m.SetEdns0(4096, true)
|
||||||
// Signature generation, signature verification and key generation are all supported.
|
|
||||||
//
|
Signature generation, signature verification and key generation are all supported.
|
||||||
// DYNAMIC UPDATES
|
|
||||||
//
|
DYNAMIC UPDATES
|
||||||
// Dynamic updates reuses the DNS message format, but renames three of
|
|
||||||
// the sections. Question is Zone, Answer is Prerequisite, Authority is
|
Dynamic updates reuses the DNS message format, but renames three of
|
||||||
// Update, only the Additional is not renamed. See RFC 2136 for the gory details.
|
the sections. Question is Zone, Answer is Prerequisite, Authority is
|
||||||
//
|
Update, only the Additional is not renamed. See RFC 2136 for the gory details.
|
||||||
// You can set a rather complex set of rules for the existence of absence of
|
|
||||||
// certain resource records or names in a zone to specify if resource records
|
You can set a rather complex set of rules for the existence of absence of
|
||||||
// should be added or removed. The table from RFC 2136 supplemented with the Go
|
certain resource records or names in a zone to specify if resource records
|
||||||
// DNS function shows which functions exist to specify the prerequisites.
|
should be added or removed. The table from RFC 2136 supplemented with the Go
|
||||||
//
|
DNS function shows which functions exist to specify the prerequisites.
|
||||||
// 3.2.4 - Table Of Metavalues Used In Prerequisite Section
|
|
||||||
//
|
3.2.4 - Table Of Metavalues Used In Prerequisite Section
|
||||||
// CLASS TYPE RDATA Meaning Function
|
|
||||||
// --------------------------------------------------------------
|
CLASS TYPE RDATA Meaning Function
|
||||||
// ANY ANY empty Name is in use dns.NameUsed
|
--------------------------------------------------------------
|
||||||
// ANY rrset empty RRset exists (value indep) dns.RRsetUsed
|
ANY ANY empty Name is in use dns.NameUsed
|
||||||
// NONE ANY empty Name is not in use dns.NameNotUsed
|
ANY rrset empty RRset exists (value indep) dns.RRsetUsed
|
||||||
// NONE rrset empty RRset does not exist dns.RRsetNotUsed
|
NONE ANY empty Name is not in use dns.NameNotUsed
|
||||||
// zone rrset rr RRset exists (value dep) dns.Used
|
NONE rrset empty RRset does not exist dns.RRsetNotUsed
|
||||||
//
|
zone rrset rr RRset exists (value dep) dns.Used
|
||||||
// The prerequisite section can also be left empty.
|
|
||||||
// If you have decided on the prerequisites you can tell what RRs should
|
The prerequisite section can also be left empty.
|
||||||
// be added or deleted. The next table shows the options you have and
|
If you have decided on the prerequisites you can tell what RRs should
|
||||||
// what functions to call.
|
be added or deleted. The next table shows the options you have and
|
||||||
//
|
what functions to call.
|
||||||
// 3.4.2.6 - Table Of Metavalues Used In Update Section
|
|
||||||
//
|
3.4.2.6 - Table Of Metavalues Used In Update Section
|
||||||
// CLASS TYPE RDATA Meaning Function
|
|
||||||
// ---------------------------------------------------------------
|
CLASS TYPE RDATA Meaning Function
|
||||||
// ANY ANY empty Delete all RRsets from name dns.RemoveName
|
---------------------------------------------------------------
|
||||||
// ANY rrset empty Delete an RRset dns.RemoveRRset
|
ANY ANY empty Delete all RRsets from name dns.RemoveName
|
||||||
// NONE rrset rr Delete an RR from RRset dns.Remove
|
ANY rrset empty Delete an RRset dns.RemoveRRset
|
||||||
// zone rrset rr Add to an RRset dns.Insert
|
NONE rrset rr Delete an RR from RRset dns.Remove
|
||||||
//
|
zone rrset rr Add to an RRset dns.Insert
|
||||||
// TRANSACTION SIGNATURE
|
|
||||||
//
|
TRANSACTION SIGNATURE
|
||||||
// An TSIG or transaction signature adds a HMAC TSIG record to each message sent.
|
|
||||||
// The supported algorithms include: HmacMD5, HmacSHA1, HmacSHA256 and HmacSHA512.
|
An TSIG or transaction signature adds a HMAC TSIG record to each message sent.
|
||||||
//
|
The supported algorithms include: HmacMD5, HmacSHA1, HmacSHA256 and HmacSHA512.
|
||||||
// Basic use pattern when querying with a TSIG name "axfr." (note that these key names
|
|
||||||
// must be fully qualified - as they are domain names) and the base64 secret
|
Basic use pattern when querying with a TSIG name "axfr." (note that these key names
|
||||||
// "so6ZGir4GPAqINNh9U5c3A==":
|
must be fully qualified - as they are domain names) and the base64 secret
|
||||||
//
|
"so6ZGir4GPAqINNh9U5c3A==":
|
||||||
// c := new(dns.Client)
|
|
||||||
// c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
c := new(dns.Client)
|
||||||
// m := new(dns.Msg)
|
c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
||||||
// m.SetQuestion("miek.nl.", dns.TypeMX)
|
m := new(dns.Msg)
|
||||||
// m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
|
m.SetQuestion("miek.nl.", dns.TypeMX)
|
||||||
// ...
|
m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
|
||||||
// // When sending the TSIG RR is calculated and filled in before sending
|
...
|
||||||
//
|
// When sending the TSIG RR is calculated and filled in before sending
|
||||||
// When requesting an zone transfer (almost all TSIG usage is when requesting zone transfers), with
|
|
||||||
// TSIG, this is the basic use pattern. In this example we request an AXFR for
|
When requesting an zone transfer (almost all TSIG usage is when requesting zone transfers), with
|
||||||
// miek.nl. with TSIG key named "axfr." and secret "so6ZGir4GPAqINNh9U5c3A=="
|
TSIG, this is the basic use pattern. In this example we request an AXFR for
|
||||||
// and using the server 176.58.119.54:
|
miek.nl. with TSIG key named "axfr." and secret "so6ZGir4GPAqINNh9U5c3A=="
|
||||||
//
|
and using the server 176.58.119.54:
|
||||||
// t := new(dns.Transfer)
|
|
||||||
// m := new(dns.Msg)
|
t := new(dns.Transfer)
|
||||||
// t.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
m := new(dns.Msg)
|
||||||
// m.SetAxfr("miek.nl.")
|
t.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
||||||
// m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
|
m.SetAxfr("miek.nl.")
|
||||||
// c, err := t.In(m, "176.58.119.54:53")
|
m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
|
||||||
// for r := range c { /* r.RR */ }
|
c, err := t.In(m, "176.58.119.54:53")
|
||||||
//
|
for r := range c { ... }
|
||||||
// You can now read the records from the transfer as they come in. Each envelope is checked with TSIG.
|
|
||||||
// If something is not correct an error is returned.
|
You can now read the records from the transfer as they come in. Each envelope is checked with TSIG.
|
||||||
//
|
If something is not correct an error is returned.
|
||||||
// Basic use pattern validating and replying to a message that has TSIG set.
|
|
||||||
//
|
Basic use pattern validating and replying to a message that has TSIG set.
|
||||||
// server := &dns.Server{Addr: ":53", Net: "udp"}
|
|
||||||
// server.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
server := &dns.Server{Addr: ":53", Net: "udp"}
|
||||||
// go server.ListenAndServe()
|
server.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
||||||
// dns.HandleFunc(".", handleRequest)
|
go server.ListenAndServe()
|
||||||
//
|
dns.HandleFunc(".", handleRequest)
|
||||||
// func handleRequest(w dns.ResponseWriter, r *dns.Msg) {
|
|
||||||
// m := new(Msg)
|
func handleRequest(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
// m.SetReply(r)
|
m := new(Msg)
|
||||||
// if r.IsTsig() {
|
m.SetReply(r)
|
||||||
// if w.TsigStatus() == nil {
|
if r.IsTsig() {
|
||||||
// // *Msg r has an TSIG record and it was validated
|
if w.TsigStatus() == nil {
|
||||||
// m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
|
// *Msg r has an TSIG record and it was validated
|
||||||
// } else {
|
m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
|
||||||
// // *Msg r has an TSIG records and it was not valided
|
} else {
|
||||||
// }
|
// *Msg r has an TSIG records and it was not valided
|
||||||
// }
|
}
|
||||||
// w.WriteMsg(m)
|
}
|
||||||
// }
|
w.WriteMsg(m)
|
||||||
//
|
}
|
||||||
// PRIVATE RRS
|
|
||||||
//
|
PRIVATE RRS
|
||||||
// RFC 6895 sets aside a range of type codes for private use. This range
|
|
||||||
// is 65,280 - 65,534 (0xFF00 - 0xFFFE). When experimenting with new Resource Records these
|
RFC 6895 sets aside a range of type codes for private use. This range
|
||||||
// can be used, before requesting an official type code from IANA.
|
is 65,280 - 65,534 (0xFF00 - 0xFFFE). When experimenting with new Resource Records these
|
||||||
//
|
can be used, before requesting an official type code from IANA.
|
||||||
// EDNS0
|
|
||||||
//
|
EDNS0
|
||||||
// EDNS0 is an extension mechanism for the DNS defined in RFC 2671 and updated
|
|
||||||
// by RFC 6891. It defines an new RR type, the OPT RR, which is then completely
|
EDNS0 is an extension mechanism for the DNS defined in RFC 2671 and updated
|
||||||
// abused.
|
by RFC 6891. It defines an new RR type, the OPT RR, which is then completely
|
||||||
// Basic use pattern for creating an (empty) OPT RR:
|
abused.
|
||||||
//
|
Basic use pattern for creating an (empty) OPT RR:
|
||||||
// o := new(dns.OPT)
|
|
||||||
// o.Hdr.Name = "." // MUST be the root zone, per definition.
|
o := new(dns.OPT)
|
||||||
// o.Hdr.Rrtype = dns.TypeOPT
|
o.Hdr.Name = "." // MUST be the root zone, per definition.
|
||||||
//
|
o.Hdr.Rrtype = dns.TypeOPT
|
||||||
// The rdata of an OPT RR consists out of a slice of EDNS0 (RFC 6891)
|
|
||||||
// interfaces. Currently only a few have been standardized: EDNS0_NSID
|
The rdata of an OPT RR consists out of a slice of EDNS0 (RFC 6891)
|
||||||
// (RFC 5001) and EDNS0_SUBNET (draft-vandergaast-edns-client-subnet-02). Note
|
interfaces. Currently only a few have been standardized: EDNS0_NSID
|
||||||
// that these options may be combined in an OPT RR.
|
(RFC 5001) and EDNS0_SUBNET (draft-vandergaast-edns-client-subnet-02). Note
|
||||||
// Basic use pattern for a server to check if (and which) options are set:
|
that these options may be combined in an OPT RR.
|
||||||
//
|
Basic use pattern for a server to check if (and which) options are set:
|
||||||
// // o is a dns.OPT
|
|
||||||
// for _, s := range o.Option {
|
// o is a dns.OPT
|
||||||
// switch e := s.(type) {
|
for _, s := range o.Option {
|
||||||
// case *dns.EDNS0_NSID:
|
switch e := s.(type) {
|
||||||
// // do stuff with e.Nsid
|
case *dns.EDNS0_NSID:
|
||||||
// case *dns.EDNS0_SUBNET:
|
// do stuff with e.Nsid
|
||||||
// // access e.Family, e.Address, etc.
|
case *dns.EDNS0_SUBNET:
|
||||||
// }
|
// access e.Family, e.Address, etc.
|
||||||
// }
|
}
|
||||||
//
|
}
|
||||||
// SIG(0)
|
|
||||||
//
|
SIG(0)
|
||||||
// From RFC 2931:
|
|
||||||
//
|
From RFC 2931:
|
||||||
// SIG(0) provides protection for DNS transactions and requests ....
|
|
||||||
// ... protection for glue records, DNS requests, protection for message headers
|
SIG(0) provides protection for DNS transactions and requests ....
|
||||||
// on requests and responses, and protection of the overall integrity of a response.
|
... protection for glue records, DNS requests, protection for message headers
|
||||||
//
|
on requests and responses, and protection of the overall integrity of a response.
|
||||||
// It works like TSIG, except that SIG(0) uses public key cryptography, instead of the shared
|
|
||||||
// secret approach in TSIG.
|
It works like TSIG, except that SIG(0) uses public key cryptography, instead of the shared
|
||||||
// Supported algorithms: DSA, ECDSAP256SHA256, ECDSAP384SHA384, RSASHA1, RSASHA256 and
|
secret approach in TSIG.
|
||||||
// RSASHA512.
|
Supported algorithms: DSA, ECDSAP256SHA256, ECDSAP384SHA384, RSASHA1, RSASHA256 and
|
||||||
//
|
RSASHA512.
|
||||||
// Signing subsequent messages in multi-message sessions is not implemented.
|
|
||||||
//
|
Signing subsequent messages in multi-message sessions is not implemented.
|
||||||
|
*/
|
||||||
package dns
|
package dns
|
||||||
|
|
Loading…
Reference in New Issue