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