本文整理汇总了Golang中github.com/miekg/dns.EDNS0_LOCAL.Data方法的典型用法代码示例。如果您正苦于以下问题:Golang EDNS0_LOCAL.Data方法的具体用法?Golang EDNS0_LOCAL.Data怎么用?Golang EDNS0_LOCAL.Data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/miekg/dns.EDNS0_LOCAL
的用法示例。
在下文中一共展示了EDNS0_LOCAL.Data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpdateStubZones
"github.com/miekg/dns"
"github.com/skynetservices/skydns/msg"
)
const ednsStubCode = dns.EDNS0LOCALSTART + 10
// ednsStub is the EDNS0 record we add to stub queries. Queries which have this record are
// not forwarded again.
var ednsStub = func() *dns.OPT {
o := new(dns.OPT)
o.Hdr.Name = "."
o.Hdr.Rrtype = dns.TypeOPT
e := new(dns.EDNS0_LOCAL)
e.Code = ednsStubCode
e.Data = []byte{1}
o.Option = append(o.Option, e)
return o
}()
// Look in .../dns/stub/<domain>/xx for msg.Services. Loop through them
// extract <domain> and add them as forwarders (ip:port-combos) for
// the stub zones. Only numeric (i.e. IP address) hosts are used.
func (s *server) UpdateStubZones() {
stubmap := make(map[string][]string)
services, err := s.backend.Records("stub.dns."+s.config.Domain, false, net.IP{})
if err != nil {
logf("stub zone update failed: %s", err)
return
}
示例2: frag
/*
For fragmentation, we use a naive algorithm.
We use the same header for every fragment, and include the same EDNS0
section in every additional section.
We add one RR at a time, until our fragment is larger than 512 bytes,
then we remove the last RR so that it fits in the 512 byte size limit.
If we discover that one of the fragments ends up with 0 RR in it (for
example because a single RR is too big), then we return a single
truncated response instead of the set of fragments.
We could perhaps make the process of building fragments faster by
bisecting the set of RR that we include in an answer. So, if we have 8
RR we could try all, then if that is too big, 4 RR, and if that fits
then 6 RR, until an optimal set of RR is found.
We could also possibly produce a smaller set of responses by
optimizing how we combine RR. Just taking account the various sizes is
the same as the bin packing problem, which is NP-hard:
https://en.wikipedia.org/wiki/Bin_packing_problem
While some non-optimal but reasonable heuristics exist, in the case of
DNS we would have to use some sophisticated algorithm to also consider
name compression.
*/
func frag(reply *dns.Msg) []dns.Msg {
// create a return value
all_frags := []dns.Msg{}
HasEdns0 := true
// get each RR section and save a copy out
remaining_answer := make([]dns.RR, len(reply.Answer))
copy(remaining_answer, reply.Answer)
remaining_ns := make([]dns.RR, len(reply.Ns))
copy(remaining_ns, reply.Ns)
remaining_extra := make([]dns.RR, len(reply.Extra))
copy(remaining_extra, reply.Extra)
// if we don't have EDNS0 in the packet, add it now
if reply.IsEdns0() == nil {
reply.SetEdns0(512, false)
}
// the EDNS option for later use
var edns0_rr dns.RR = nil
// remove the EDNS0 option from our additional ("extra") section
// (we will include it separately on every fragment)
for ofs, r := range remaining_extra {
// found the EDNS option
if r.Header().Rrtype == dns.TypeOPT {
// save the EDNS option
edns0_rr = r
// remove from the set of extra RR
remaining_extra = append(remaining_extra[0:ofs], remaining_extra[ofs+1:]...)
// in principle we should only have one EDNS0 section
break
}
}
if edns0_rr == nil {
log.Printf("Server reply missing EDNS0 option")
return []dns.Msg{}
//HasEdns0 = false
}
// now build fragments
for {
// make a shallow copy of our reply packet, and prepare space for our RR
frag := *reply
frag.Answer = []dns.RR{}
frag.Ns = []dns.RR{}
frag.Extra = []dns.RR{}
// add our custom EDNS0 option (needed in every fragment)
local_opt := new(dns.EDNS0_LOCAL)
local_opt.Code = dns.EDNS0LOCALSTART + 1
local_opt.Data = []byte{0, 0}
if HasEdns0 == true {
edns0_rr_copy := dns.Copy(edns0_rr)
edns0_rr_copy.(*dns.OPT).Option = append(edns0_rr_copy.(*dns.OPT).Option, local_opt)
frag.Extra = append(frag.Extra, edns0_rr_copy)
}
//if HasEdns0 == false {
// frag.Extra = append(frag.Extra, local_opt)
//}
// add as many RR to the answer as we can
for len(remaining_answer) > 0 {
frag.Answer = append(frag.Answer, remaining_answer[0])
if frag.Len() <= 512 {
// if the new answer fits, then remove it from our remaining list
remaining_answer = remaining_answer[1:]
} else {
// otherwise we are full, remove it from our fragment and stop
frag.Answer = frag.Answer[0 : len(frag.Answer)-1]
break
}
//.........这里部分代码省略.........