diff --git a/nameserver/http.go b/nameserver/http.go index 885e9434..7ab19550 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -45,22 +45,22 @@ func ListenHttp(domain string, db Zone, port int) { switch r.Method { case "PUT": - ident, weaveIPstr, err := parseUrl(r.URL.Path) + ident, ipStr, err := parseUrl(r.URL.Path) name := r.FormValue("fqdn") - if ident == "" || weaveIPstr == "" || name == "" { + if ident == "" || ipStr == "" || name == "" { reqError("Invalid request", "Invalid request: %s, %s", r.URL, r.Form) return } - weaveIP := net.ParseIP(weaveIPstr) - if weaveIP == nil { - reqError("Invalid weave IP", "Invalid weave IP in request: %s", weaveIPstr) + ip := net.ParseIP(ipStr) + if ip == nil { + reqError("Invalid IP", "Invalid IP in request: %s", ipStr) return } if dns.IsSubDomain(domain, name) { - Info.Printf("Adding %s -> %s", name, weaveIPstr) - if err = db.AddRecord(ident, name, weaveIP); err != nil { + Info.Printf("Adding %s -> %s", name, ipStr) + if err = db.AddRecord(ident, name, ip); err != nil { if dup, ok := err.(DuplicateError); !ok { httpErrorAndLog( Error, w, "Internal error", http.StatusInternalServerError, @@ -76,19 +76,19 @@ func ListenHttp(domain string, db Zone, port int) { } case "DELETE": - ident, weaveIPstr, err := parseUrl(r.URL.Path) - if ident == "" || weaveIPstr == "" { + ident, ipStr, err := parseUrl(r.URL.Path) + if ident == "" || ipStr == "" { reqError("Invalid Request", "Invalid request: %s, %s", r.URL, r.Form) return } - weaveIP := net.ParseIP(weaveIPstr) - if weaveIP == nil { - reqError("Invalid IP in request", "Invalid IP in request: %s", weaveIPstr) + ip := net.ParseIP(ipStr) + if ip == nil { + reqError("Invalid IP in request", "Invalid IP in request: %s", ipStr) return } - Info.Printf("Deleting %s (%s)", ident, weaveIPstr) - if err = db.DeleteRecord(ident, weaveIP); err != nil { + Info.Printf("Deleting %s (%s)", ident, ipStr) + if err = db.DeleteRecord(ident, ip); err != nil { if _, ok := err.(LookupError); !ok { httpErrorAndLog( Error, w, "Internal error", http.StatusInternalServerError, diff --git a/nameserver/http_test.go b/nameserver/http_test.go index 9e41dbd8..b7b300e7 100644 --- a/nameserver/http_test.go +++ b/nameserver/http_test.go @@ -42,11 +42,11 @@ func TestHttp(t *testing.T) { assertStatus(t, resp.StatusCode, http.StatusOK, "http response") // Check that the address is now there. - ip, err := zone.MatchLocal(successTestName) + foundIP, err := zone.MatchLocal(successTestName) assertNoErr(t, err) - weaveIP, _, _ := net.ParseCIDR(testAddr1) - if !ip.Equal(weaveIP) { - t.Fatal("Unexpected result for", successTestName, ip) + ip, _, _ := net.ParseCIDR(testAddr1) + if !foundIP.Equal(ip) { + t.Fatal("Unexpected result for", successTestName, foundIP) } // Adding exactly the same address should be OK diff --git a/nameserver/mdns_server_test.go b/nameserver/mdns_server_test.go index d1019fb5..b3550ec8 100644 --- a/nameserver/mdns_server_test.go +++ b/nameserver/mdns_server_test.go @@ -32,8 +32,8 @@ func sendQuery(name string, querytype uint16) error { func TestServerSimpleQuery(t *testing.T) { log.Println("TestServerSimpleQuery starting") var zone = new(ZoneDb) - weaveIP, _, _ := net.ParseCIDR(testAddr1) - zone.AddRecord(containerID, "test.weave.", weaveIP) + ip, _, _ := net.ParseCIDR(testAddr1) + zone.AddRecord(containerID, "test.weave.", ip) mdnsServer, err := NewMDNSServer(zone) assertNoErr(t, err) @@ -73,7 +73,7 @@ func TestServerSimpleQuery(t *testing.T) { if receivedCount != 1 { t.Fatal("Unexpected result count for test.weave", receivedCount) } - if !receivedAddr.Equal(weaveIP) { + if !receivedAddr.Equal(ip) { t.Fatal("Unexpected result for test.weave", receivedAddr) } diff --git a/nameserver/zone.go b/nameserver/zone.go index 6f0d12fd..051ac497 100644 --- a/nameserver/zone.go +++ b/nameserver/zone.go @@ -7,17 +7,17 @@ import ( ) type Zone interface { - AddRecord(ident string, name string, weaveIP net.IP) error - DeleteRecord(ident string, weaveIp net.IP) error + 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) } type Record struct { - Ident string - Name string - WeaveIP net.IP + Ident string + Name string + IP net.IP } // Very simple data structure for now, with linear searching. @@ -34,13 +34,13 @@ func (ops LookupError) Error() string { } type DuplicateError struct { - Name string - WeaveIP net.IP - Ident string + Name string + IP net.IP + Ident string } func (err DuplicateError) Error() string { - return "Duplicate " + err.Name + "," + err.WeaveIP.String() + " for identity " + err.Ident + return "Duplicate " + err.Name + "," + err.IP.String() + " for identity " + err.Ident } func (zone *ZoneDb) indexOf(match func(Record) bool) int { @@ -57,7 +57,7 @@ func (zone *ZoneDb) MatchLocal(name string) (net.IP, error) { defer zone.mx.RUnlock() for _, r := range zone.recs { if r.Name == name { - return r.WeaveIP, nil + return r.IP, nil } } return nil, LookupError(name) @@ -67,30 +67,30 @@ func (zone *ZoneDb) MatchLocalIP(ip net.IP) (string, error) { zone.mx.RLock() defer zone.mx.RUnlock() for _, r := range zone.recs { - if r.WeaveIP.Equal(ip) { + if r.IP.Equal(ip) { return r.Name, nil } } return "", LookupError(ip.String()) } -func (zone *ZoneDb) AddRecord(ident string, name string, weaveIP net.IP) error { +func (zone *ZoneDb) AddRecord(ident string, name string, ip net.IP) error { zone.mx.Lock() defer zone.mx.Unlock() fqdn := dns.Fqdn(name) if index := zone.indexOf( - func(r Record) bool { return r.Name == fqdn && r.WeaveIP.Equal(weaveIP) }); index != -1 { - return DuplicateError{fqdn, weaveIP, zone.recs[index].Ident} + func(r Record) bool { return r.Name == fqdn && r.IP.Equal(ip) }); index != -1 { + return DuplicateError{fqdn, ip, zone.recs[index].Ident} } - zone.recs = append(zone.recs, Record{ident, fqdn, weaveIP}) + zone.recs = append(zone.recs, Record{ident, fqdn, ip}) return nil } -func (zone *ZoneDb) DeleteRecord(ident string, weaveIP net.IP) error { +func (zone *ZoneDb) DeleteRecord(ident string, ip net.IP) error { zone.mx.Lock() defer zone.mx.Unlock() if index := zone.indexOf( - func(r Record) bool { return r.Ident == ident && r.WeaveIP.Equal(weaveIP) }); index == -1 { + func(r Record) bool { return r.Ident == ident && r.IP.Equal(ip) }); index == -1 { return LookupError(ident) } else { zone.recs = append(zone.recs[:index], zone.recs[index+1:]...) diff --git a/nameserver/zone_test.go b/nameserver/zone_test.go index d9f7842d..66c7cdd7 100644 --- a/nameserver/zone_test.go +++ b/nameserver/zone_test.go @@ -14,8 +14,8 @@ func TestZone(t *testing.T) { var zone = new(ZoneDb) - weaveIP, _, _ := net.ParseCIDR(testAddr1) - err := zone.AddRecord(containerID, successTestName, weaveIP) + ip, _, _ := net.ParseCIDR(testAddr1) + err := zone.AddRecord(containerID, successTestName, ip) assertNoErr(t, err) // Add a few more records to make the job harder @@ -28,24 +28,24 @@ func TestZone(t *testing.T) { foundIP, err := zone.MatchLocal(successTestName) assertNoErr(t, err) - if !foundIP.Equal(weaveIP) { + if !foundIP.Equal(ip) { t.Fatal("Unexpected result for", successTestName, foundIP) } // See if we can find the address by IP. - foundName, err := zone.MatchLocalIP(weaveIP) + foundName, err := zone.MatchLocalIP(ip) assertNoErr(t, err) if foundName != successTestName { - t.Fatal("Unexpected result for", weaveIP, foundName) + t.Fatal("Unexpected result for", ip, foundName) } // Now try to add the same address again - err = zone.AddRecord(containerID, successTestName, weaveIP) + err = zone.AddRecord(containerID, successTestName, ip) assertErrorType(t, err, (*DuplicateError)(nil), "duplicate add") // Now delete the record - err = zone.DeleteRecord(containerID, weaveIP) + err = zone.DeleteRecord(containerID, ip) assertNoErr(t, err) // Check that the address is not there now. @@ -66,8 +66,8 @@ func TestDeleteFor(t *testing.T) { ) zone := new(ZoneDb) for _, addr := range []string{addr1, addr2} { - weaveIP, _, _ := net.ParseCIDR(addr) - err := zone.AddRecord(id, name, weaveIP) + ip, _, _ := net.ParseCIDR(addr) + err := zone.AddRecord(id, name, ip) assertNoErr(t, err) }