本文整理汇总了Golang中github.com/miekg/dns.A.A方法的典型用法代码示例。如果您正苦于以下问题:Golang A.A方法的具体用法?Golang A.A怎么用?Golang A.A使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/miekg/dns.A
的用法示例。
在下文中一共展示了A.A方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GenerateServeDNS
func (c *Config) GenerateServeDNS(hostname string) func(dns.ResponseWriter, *dns.Msg) {
if len(hostname) > 0 {
if hostname[len(hostname)-1] != '.' {
hostname += "."
}
}
return func(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.SetReply(r)
m.Authoritative = true
ip, err := c.GetOrLaunchInstance()
if err != nil {
// TODO: error handling
log.Println("Error in GetOrLaunchInstance:", err)
w.Close()
return
}
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: hostname, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: uint32(c.MaxIdleTime.Seconds())}
rr.A = ip
m.Answer = []dns.RR{rr}
w.WriteMsg(m)
}
}
示例2: handleIPQuery
func (r *resolver) handleIPQuery(name string, query *dns.Msg, ipType int) (*dns.Msg, error) {
addr, ipv6Miss := r.sb.ResolveName(name, ipType)
if addr == nil && ipv6Miss {
// Send a reply without any Answer sections
log.Debugf("Lookup name %s present without IPv6 address", name)
resp := createRespMsg(query)
return resp, nil
}
if addr == nil {
return nil, nil
}
log.Debugf("Lookup for %s: IP %v", name, addr)
resp := createRespMsg(query)
if len(addr) > 1 {
addr = shuffleAddr(addr)
}
if ipType == types.IPv4 {
for _, ip := range addr {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
rr.A = ip
resp.Answer = append(resp.Answer, rr)
}
} else {
for _, ip := range addr {
rr := new(dns.AAAA)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: respTTL}
rr.AAAA = ip
resp.Answer = append(resp.Answer, rr)
}
}
return resp, nil
}
示例3: handleARequest
func (s *DNSServer) handleARequest(r *dns.Msg, m *dns.Msg) {
m.Answer = make([]dns.RR, 0, 2)
query := r.Question[0].Name
if query[len(query)-1] == '.' {
query = query[:len(query)-1]
}
for service := range s.queryServices(query) {
rr := new(dns.A)
var ttl int
if service.Ttl != -1 {
ttl = service.Ttl
} else {
ttl = s.config.ttl
}
rr.Hdr = dns.RR_Header{
Name: r.Question[0].Name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: uint32(ttl),
}
rr.A = service.Ip
m.Answer = append(m.Answer, rr)
}
}
示例4: handleIPQuery
func (r *resolver) handleIPQuery(name string, query *dns.Msg, ipType int) (*dns.Msg, error) {
addr := r.sb.ResolveName(name, ipType)
if addr == nil {
return nil, nil
}
log.Debugf("Lookup for %s: IP %v", name, addr)
resp := new(dns.Msg)
resp.SetReply(query)
setCommonFlags(resp)
if len(addr) > 1 {
addr = shuffleAddr(addr)
}
if ipType == netutils.IPv4 {
for _, ip := range addr {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
rr.A = ip
resp.Answer = append(resp.Answer, rr)
}
} else {
for _, ip := range addr {
rr := new(dns.AAAA)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: respTTL}
rr.AAAA = ip
resp.Answer = append(resp.Answer, rr)
}
}
return resp, nil
}
示例5: handleSRVQuery
func (r *resolver) handleSRVQuery(svc string, query *dns.Msg) (*dns.Msg, error) {
srv, ip := r.backend.ResolveService(svc)
if len(srv) == 0 {
return nil, nil
}
if len(srv) != len(ip) {
return nil, fmt.Errorf("invalid reply for SRV query %s", svc)
}
resp := createRespMsg(query)
for i, r := range srv {
rr := new(dns.SRV)
rr.Hdr = dns.RR_Header{Name: svc, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: respTTL}
rr.Port = r.Port
rr.Target = r.Target
resp.Answer = append(resp.Answer, rr)
rr1 := new(dns.A)
rr1.Hdr = dns.RR_Header{Name: r.Target, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
rr1.A = ip[i]
resp.Extra = append(resp.Extra, rr1)
}
return resp, nil
}
示例6: answerA
func answerA(q dns.Question, value net.IP) dns.RR {
answer := new(dns.A)
answer.Header().Name = q.Name
answer.Header().Rrtype = dns.TypeA
answer.Header().Class = dns.ClassINET
answer.A = value
return answer
}
示例7: answerA
func answerA(q *dns.Question, v *DNSValue) dns.RR {
answer := new(dns.A)
answer.Header().Name = q.Name
answer.Header().Rrtype = dns.TypeA
answer.Header().Class = dns.ClassINET
answer.A = net.ParseIP(v.Value)
return answer
}
示例8: dnsHandle
// DNS requests go to this function
func dnsHandle(w dns.ResponseWriter, r *dns.Msg) {
name := r.Question[0].Name
if !namePattern.MatchString(name) {
kilog.Debug("%v does not match pattern, forwarding", name)
dnsForward(w, r)
return
}
// otherwise
kilog.Debug("%v matches pattern, handling", name)
dnsLock.Lock()
defer dnsLock.Unlock()
// check in table first
fakeIP, ok := nameToIP[name]
if !ok {
// place in table
var nwIP string
for {
haha := ipAlloc().String()
_, exists := ipToName[haha]
if exists {
continue
}
nwIP = haha
break
}
fakeIP = nwIP
nameToIP[name] = fakeIP
ipToName[fakeIP] = name
// remove in 30 minutes
go func() {
time.Sleep(time.Minute * 30)
dnsLock.Lock()
defer dnsLock.Unlock()
delete(nameToIP, name)
delete(ipToName, fakeIP)
}()
}
// return the fake IP to the user
resp := new(dns.A)
resp.Hdr.Name = name
resp.Hdr.Ttl = 1 // very short
resp.Hdr.Class = dns.ClassINET
resp.Hdr.Rrtype = dns.TypeA
resp.A = net.ParseIP(fakeIP)
towrite := new(dns.Msg)
towrite.Id = r.Id
towrite.RecursionAvailable = true
towrite.RecursionDesired = true
towrite.Response = true
towrite.Question = r.Question
towrite.Answer = make([]dns.RR, 1)
towrite.Answer[0] = resp
w.WriteMsg(towrite)
kilog.Debug("returning mapping %v -> %v", name, fakeIP)
}
示例9: newRR
func newRR(host string, addr net.IP) dns.RR {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{
Name: host,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: 0}
rr.A = addr.To4()
return rr
}
示例10: hijackResponse
// hijackResponse returns a modified version on the input dns.Msg with the A record modified
// to point to our server
func hijackResponse(r *dns.Msg) (m *dns.Msg) {
m = new(dns.Msg)
m.SetReply(r)
m.Answer = make([]dns.RR, 1)
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: m.Question[0].Name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 600}
rr.A = net.ParseIP(config.EXTERNAL_ADDRESS)
m.Answer[0] = rr
return m
}
示例11: dnsAddressRecord
func dnsAddressRecord(query *dns.Msg, name string, addrs []net.IP) *dns.Msg {
resp := new(dns.Msg)
resp.SetReply(query)
for _, addr := range addrs {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}
rr.A = addr
resp.Answer = append(resp.Answer, rr)
}
return resp
}
示例12: handleIPv4Query
func (r *resolver) handleIPv4Query(name string, query *dns.Msg) (*dns.Msg, error) {
addr := r.sb.ResolveName(name)
if addr == nil {
return nil, nil
}
log.Debugf("Lookup for %s: IP %s", name, addr.String())
resp := new(dns.Msg)
resp.SetReply(query)
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
rr.A = addr
resp.Answer = append(resp.Answer, rr)
return resp, nil
}
示例13: serveResponse
/* ----------------------------------------------------------------------------
FUNCTION
Name: Serve Response
Prototype: func serveResponse(w dns.ResponseWriter, r *dns.Msg)
Developer: Andrew Burian
Created On: 2015-09-24
Parameters:
w dns.ResponseWriter
the writer that will respond to the dns query
r dns.Msg
the dns query to respond to
Return Values:
(none)
Description:
Handles a single dns request by generating and writing
a response to the provided writer.
Also strips out the contained data and sends it over a
channel
Revisions:
(none)
---------------------------------------------------------------------------- */
func serveResponse(w dns.ResponseWriter, r *dns.Msg) {
// create a message to respond with
respMsg := new(dns.Msg)
// set this message to be a response to the first
respMsg.SetReply(r)
// create a new record to respond with
respRec := new(dns.A)
respRec.Hdr = dns.RR_Header{
Name: r.Question[0].Name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: 0} // 0 TTL to avoid caching
// pseudo random IP
rand_bytes := make([]byte, 4)
rand.Read(rand_bytes)
respRec.A = rand_bytes
respMsg.Answer = append(respMsg.Answer, respRec)
w.WriteMsg(respMsg)
// now that the response has been handled
// process the covert data
// get the data from the query
data := (strings.Split(r.Question[0].Name, "."))[0]
// create the new message channel
datachan := make(chan byte, len(data))
// send it to the main
messages <- datachan
// read all the bytes into the channel
for _, b := range []byte(data) {
datachan <- b
}
close(datachan)
}
示例14: route
func route(w dns.ResponseWriter, req *dns.Msg) {
if len(req.Question) != 1 {
failWithRcode(w, req, dns.RcodeRefused)
return
}
question := req.Question[0]
qtype := question.Qtype
if question.Qclass != dns.ClassINET {
failWithRcode(w, req, dns.RcodeRefused)
return
}
remoteIP := w.RemoteAddr().(*net.UDPAddr).IP
m := new(dns.Msg)
m.Id = req.Id
switch qtype {
case dns.TypeA:
if remoteIP4 := remoteIP.To4(); remoteIP4 != nil {
rr := new(dns.A)
rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: question.Qtype,
Class: dns.ClassINET, Ttl: 10}
rr.A = remoteIP4
m.Answer = []dns.RR{rr}
}
case dns.TypeAAAA:
if remoteIP16 := remoteIP.To16(); remoteIP16 != nil {
rr := new(dns.AAAA)
rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: question.Qtype,
Class: dns.ClassINET, Ttl: 10}
rr.AAAA = remoteIP16
m.Answer = []dns.RR{rr}
}
case dns.TypeTXT:
rr := new(dns.TXT)
rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: question.Qtype,
Class: dns.ClassINET, Ttl: 10}
rr.Txt = []string{fmt.Sprintf("Resolver IP: %v", remoteIP.String())}
m.Answer = []dns.RR{rr}
}
m.Question = req.Question
m.Response = true
m.Authoritative = true
w.WriteMsg(m)
}
示例15: fillWithData
func (s *SenseDNS) fillWithData(pairs api.KVPairs, network string) {
zs := s.dnsServer.zones
zs.Lock()
defer zs.Unlock()
key := s.dnsServer.getNetDomain(network)
zs.store[key] = make(map[dns.RR_Header][]dns.RR)
for _, value := range pairs {
path := strings.Split(value.Key, "/")
hostname := fmt.Sprintf("%s.%s.%s", path[3], network, s.dnsServer.networkTLD)
ip := string(value.Value)
rr := new(dns.A)
rr.A = net.ParseIP(ip)
rr.Hdr = dns.RR_Header{Name: dns.Fqdn(hostname), Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 3600}
key2 := dns.RR_Header{Name: dns.Fqdn(rr.Header().Name), Rrtype: rr.Header().Rrtype, Class: rr.Header().Class}
zs.store[key][key2] = append(zs.store[key][key2], rr)
}
if log.Level == logrus.DebugLevel {
s.dnsServer.printRoutingTable()
}
}