This commit is contained in:
Matthias Radestock committed 2014-11-28 16:27:11 +00:00
1 parent 7187d38047
commit 2680e594dd
5 files changed
+14 -14

No files matched your search

+2 -2
View File
@@ -42,7 +42,7 @@ func TestHttp(t *testing.T) {
assertStatus(t, resp.StatusCode, http.StatusOK, "http response")
// Check that the address is now there.
foundIP, err := zone.MatchLocal(successTestName)
foundIP, err := zone.LookupLocal(successTestName)
assertNoErr(t, err)
ip, _, _ := net.ParseCIDR(testAddr1)
if !foundIP.Equal(ip) {
@@ -68,7 +68,7 @@ func TestHttp(t *testing.T) {
assertStatus(t, resp.StatusCode, http.StatusOK, "http response")
// Check that the address is not there now.
_, err = zone.MatchLocal(successTestName)
_, err = zone.LookupLocal(successTestName)
assertErrorType(t, err, (*LookupError)(nil), "nonexistent lookup")
// Delete the address again, it should accept this
+1 -1
View File
@@ -53,7 +53,7 @@ func (s *MDNSServer) Start(ifi *net.Interface) error {
// Ignore answers to other questions
if len(r.Answer) == 0 && len(r.Question) > 0 {
q := r.Question[0]
if ip, err := s.zone.MatchLocal(q.Name); err == nil {
if ip, err := s.zone.LookupLocal(q.Name); err == nil {
m := makeAddressReply(r, &q, []net.IP{ip})
if err = s.sendResponse(m); err != nil {
Warning.Printf("Error writing to %s", w)
+2 -2
View File
@@ -39,7 +39,7 @@ func queryHandler(zone Zone, mdnsClient *MDNSClient) dns.HandlerFunc {
q := r.Question[0]
Debug.Printf("Local query: %+v", q)
if q.Qtype == dns.TypeA {
if ip, err := zone.MatchLocal(q.Name); err == nil {
if ip, err := zone.LookupLocal(q.Name); err == nil {
m := makeAddressReply(r, &q, []net.IP{ip})
w.WriteMsg(m)
} else {
@@ -80,7 +80,7 @@ func rdnsHandler(zone Zone, mdnsClient *MDNSClient) dns.HandlerFunc {
ip4 := ip.To4()
revIP := []byte{ip4[3], ip4[2], ip4[1], ip4[0]}
Debug.Printf("Looking for address: %+v", revIP)
if name, err := zone.MatchLocalIP(revIP); err == nil {
if name, err := zone.ReverseLookupLocal(revIP); err == nil {
Debug.Printf("Found name: %s", name)
m := makePTRReply(r, &q, []string{name})
w.WriteMsg(m)
+4 -4
View File
@@ -10,8 +10,8 @@ type Zone interface {
AddRecord(ident string, name string, ip net.IP) error
DeleteRecord(ident string, ip net.IP) error
DeleteRecordsFor(ident string) error
MatchLocal(name string) (net.IP, error)
MatchLocalIP(ip net.IP) (string, error)
LookupLocal(name string) (net.IP, error)
ReverseLookupLocal(ip net.IP) (string, error)
}
type Record struct {
@@ -52,7 +52,7 @@ func (zone *ZoneDb) indexOf(match func(Record) bool) int {
return -1
}
func (zone *ZoneDb) MatchLocal(name string) (net.IP, error) {
func (zone *ZoneDb) LookupLocal(name string) (net.IP, error) {
zone.mx.RLock()
defer zone.mx.RUnlock()
for _, r := range zone.recs {
@@ -63,7 +63,7 @@ func (zone *ZoneDb) MatchLocal(name string) (net.IP, error) {
return nil, LookupError(name)
}
func (zone *ZoneDb) MatchLocalIP(ip net.IP) (string, error) {
func (zone *ZoneDb) ReverseLookupLocal(ip net.IP) (string, error) {
zone.mx.RLock()
defer zone.mx.RUnlock()
for _, r := range zone.recs {
+5 -5
View File
@@ -25,7 +25,7 @@ func TestZone(t *testing.T) {
assertNoErr(t, err)
// Check that the address is now there.
foundIP, err := zone.MatchLocal(successTestName)
foundIP, err := zone.LookupLocal(successTestName)
assertNoErr(t, err)
if !foundIP.Equal(ip) {
@@ -33,7 +33,7 @@ func TestZone(t *testing.T) {
}
// See if we can find the address by IP.
foundName, err := zone.MatchLocalIP(ip)
foundName, err := zone.ReverseLookupLocal(ip)
assertNoErr(t, err)
if foundName != successTestName {
@@ -49,7 +49,7 @@ func TestZone(t *testing.T) {
assertNoErr(t, err)
// Check that the address is not there now.
_, err = zone.MatchLocal(successTestName)
_, err = zone.LookupLocal(successTestName)
assertErrorType(t, err, (*LookupError)(nil), "after deleting record")
// Delete a record that isn't there
@@ -71,10 +71,10 @@ func TestDeleteFor(t *testing.T) {
assertNoErr(t, err)
}
_, err := zone.MatchLocal(name)
_, err := zone.LookupLocal(name)
assertNoErr(t, err)
err = zone.DeleteRecordsFor(id)
_, err = zone.MatchLocal(name)
_, err = zone.LookupLocal(name)
assertErrorType(t, err, (*LookupError)(nil), "after deleting records for ident")
}