예제 #1
0
파일: resolver.go 프로젝트: jwhonce/docker
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

}
예제 #2
0
파일: etcd.go 프로젝트: jkingyens/skydns2
func parseValue(t uint16, value string, h dns.RR_Header) dns.RR {
	switch t {
	case dns.TypeA:
		a := new(dns.A)
		a.Hdr = h
		a.A, _ = parseA(value)
		return a
	case dns.TypeAAAA:
		aaaa := new(dns.AAAA)
		aaaa.Hdr = h
		aaaa.AAAA, _ = parseAAAA(value)
		return aaaa
	case dns.TypeSRV:
		srv := new(dns.SRV)
		srv.Hdr = h
		srv.Priority, srv.Weight, srv.Port, srv.Target, _ = parseSRV(value)
		return srv
	}
	return nil
}