当前位置: 首页>>代码示例>>Golang>>正文


Golang Msg.SetRcode方法代码示例

本文整理汇总了Golang中github.com/abh/geodns/Godeps/_workspace/src/github.com/miekg/dns.Msg.SetRcode方法的典型用法代码示例。如果您正苦于以下问题:Golang Msg.SetRcode方法的具体用法?Golang Msg.SetRcode怎么用?Golang Msg.SetRcode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/abh/geodns/Godeps/_workspace/src/github.com/miekg/dns.Msg的用法示例。


在下文中一共展示了Msg.SetRcode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: setupRootZone

func setupRootZone() {
	dns.HandleFunc(".", func(w dns.ResponseWriter, r *dns.Msg) {
		m := new(dns.Msg)
		m.SetRcode(r, dns.RcodeRefused)
		w.WriteMsg(m)
	})
}
开发者ID:bluehawksky,项目名称:geodns,代码行数:7,代码来源:zones.go

示例2: serve


//.........这里部分代码省略.........
	targets, netmask := z.Options.Targeting.GetTargets(ip)

	m := new(dns.Msg)
	m.SetReply(req)
	if e := m.IsEdns0(); e != nil {
		m.SetEdns0(4096, e.Do())
	}
	m.Authoritative = true

	// TODO: set scope to 0 if there are no alternate responses
	if edns != nil {
		if edns.Family != 0 {
			if netmask < 16 {
				netmask = 16
			}
			edns.SourceScope = uint8(netmask)
			m.Extra = append(m.Extra, opt_rr)
		}
	}

	labels, labelQtype := z.findLabels(label, targets, qTypes{dns.TypeMF, dns.TypeCNAME, qtype})
	if labelQtype == 0 {
		labelQtype = qtype
	}

	if labels == nil {

		firstLabel := (strings.Split(label, "."))[0]

		if firstLabel == "_status" {
			if qtype == dns.TypeANY || qtype == dns.TypeTXT {
				m.Answer = statusRR(label + "." + z.Origin + ".")
			} else {
				m.Ns = append(m.Ns, z.SoaRR())
			}
			m.Authoritative = true
			w.WriteMsg(m)
			return
		}

		if firstLabel == "_country" {
			if qtype == dns.TypeANY || qtype == dns.TypeTXT {
				h := dns.RR_Header{Ttl: 1, Class: dns.ClassINET, Rrtype: dns.TypeTXT}
				h.Name = label + "." + z.Origin + "."

				txt := []string{
					w.RemoteAddr().String(),
					ip.String(),
				}

				targets, netmask := z.Options.Targeting.GetTargets(ip)
				txt = append(txt, strings.Join(targets, " "))
				txt = append(txt, fmt.Sprintf("/%d", netmask), serverID, serverIP)

				m.Answer = []dns.RR{&dns.TXT{Hdr: h,
					Txt: txt,
				}}
			} else {
				m.Ns = append(m.Ns, z.SoaRR())
			}

			m.Authoritative = true
			w.WriteMsg(m)
			return
		}

		// return NXDOMAIN
		m.SetRcode(req, dns.RcodeNameError)
		m.Authoritative = true

		m.Ns = []dns.RR{z.SoaRR()}

		w.WriteMsg(m)
		return
	}

	if servers := labels.Picker(labelQtype, labels.MaxHosts); servers != nil {
		var rrs []dns.RR
		for _, record := range servers {
			rr := record.RR
			rr.Header().Name = req.Question[0].Name
			rrs = append(rrs, rr)
		}
		m.Answer = rrs
	}

	if len(m.Answer) == 0 {
		m.Ns = append(m.Ns, z.SoaRR())
	}

	logPrintln(m)

	err := w.WriteMsg(m)
	if err != nil {
		// if Pack'ing fails the Write fails. Return SERVFAIL.
		log.Println("Error writing packet", m)
		dns.HandleFailed(w, req)
	}
	return
}
开发者ID:eeertekin,项目名称:geodns,代码行数:101,代码来源:serve.go

示例3: serve


//.........这里部分代码省略.........
		labelQtype = qtype
	}

	if labels == nil {

		permitDebug := !*flagPrivateDebug || (realIP != nil && realIP.IsLoopback())

		firstLabel := (strings.Split(label, "."))[0]

		if permitDebug && firstLabel == "_status" {
			if qtype == dns.TypeANY || qtype == dns.TypeTXT {
				m.Answer = statusRR(label + "." + z.Origin + ".")
			} else {
				m.Ns = append(m.Ns, z.SoaRR())
			}
			m.Authoritative = true
			w.WriteMsg(m)

			t := time.Now()
			logAccessPrintf("%s [%02d/%02d/%04d:%02d:%02d:%02d] %s %s %s\n", w.RemoteAddr(), t.Day(), t.Month(), t.Year(), t.Hour(), t.Minute(), t.Second(), req.Question[0].Name, dns.TypeToString[qtype], m.Answer)

			return
		}

		if firstLabel == "_country" {
			if qtype == dns.TypeANY || qtype == dns.TypeTXT {
				h := dns.RR_Header{Ttl: 1, Class: dns.ClassINET, Rrtype: dns.TypeTXT}
				h.Name = label + "." + z.Origin + "."

				txt := []string{
					w.RemoteAddr().String(),
					ip.String(),
				}

				targets, netmask := z.Options.Targeting.GetTargets(ip)
				txt = append(txt, strings.Join(targets, " "))
				txt = append(txt, fmt.Sprintf("/%d", netmask), serverID, serverIP)

				m.Answer = []dns.RR{&dns.TXT{Hdr: h,
					Txt: txt,
				}}
			} else {
				m.Ns = append(m.Ns, z.SoaRR())
			}

			m.Authoritative = true
			w.WriteMsg(m)

			t := time.Now()
			logAccessPrintf("%s [%02d/%02d/%04d:%02d:%02d:%02d] %s %s %s\n", w.RemoteAddr(), t.Day(), t.Month(), t.Year(), t.Hour(), t.Minute(), t.Second(), req.Question[0].Name, dns.TypeToString[qtype], m.Answer)

			return
		}

		// return NXDOMAIN
		m.SetRcode(req, dns.RcodeNameError)
		m.Authoritative = true

		m.Ns = []dns.RR{z.SoaRR()}
		w.WriteMsg(m)

		t := time.Now()
		logAccessPrintf("%s [%02d/%02d/%04d:%02d:%02d:%02d] %s %s %s\n", w.RemoteAddr(), t.Day(), t.Month(), t.Year(), t.Hour(), t.Minute(), t.Second(), req.Question[0].Name, dns.TypeToString[qtype], m.Answer)

		return
	}

	if servers := labels.Picker(labelQtype, labels.MaxHosts); servers != nil {
		var rrs []dns.RR
		for _, record := range servers {
			rr := dns.Copy(record.RR)
			rr.Header().Name = req.Question[0].Name
			rrs = append(rrs, rr)
		}
		m.Answer = rrs
	}

	if len(m.Answer) == 0 {
		m.Ns = append(m.Ns, z.SoaRR())
	} else {
		if z.Labels[label] != nil {
			z.Labels[label].Hits++
			logPrintln("*********** ", z.Labels[label].Hits)
		}
	}

	//logPrintln(m)

	err := w.WriteMsg(m)
	if err != nil {
		// if Pack'ing fails the Write fails. Return SERVFAIL.
		log.Println("Error writing packet", m)
		dns.HandleFailed(w, req)
	}

	t := time.Now()
	logAccessPrintf("%s [%02d/%02d/%04d:%02d:%02d:%02d] %s %s %s\n", w.RemoteAddr(), t.Day(), t.Month(), t.Year(), t.Hour(), t.Minute(), t.Second(), req.Question[0].Name, dns.TypeToString[qtype], m.Answer)

	return
}
开发者ID:cpronier,项目名称:geodns,代码行数:101,代码来源:serve.go


注:本文中的github.com/abh/geodns/Godeps/_workspace/src/github.com/miekg/dns.Msg.SetRcode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。