diff --git a/server/http.go b/server/http.go index a98fd5d5..2e67899a 100644 --- a/server/http.go +++ b/server/http.go @@ -35,32 +35,30 @@ func ListenHttp(domain string, db Zone, port int) { switch r.Method { case "PUT": - identifier, weaveIPstr, err := parseUrl(r.URL.Path) + ident, weaveIPstr, err := parseUrl(r.URL.Path) name := r.FormValue("fqdn") - prefix := r.FormValue("routing_prefix") - localIP := r.FormValue("local_ip") + localIPstr := r.FormValue("local_ip") - if identifier == "" || weaveIPstr == "" || name == "" || prefix == "" || localIP == "" { + if ident == "" || weaveIPstr == "" || name == "" || localIPstr == "" { reqError("Invalid request", "Invalid request: %s, %s", r.URL, r.Form) return } - ip := net.ParseIP(localIP) - if ip == nil { - reqError("Invalid IP in request", "Invalid IP in request: %s", localIP) + localIP := net.ParseIP(localIPstr) + if localIP == nil { + reqError("Invalid IP in request", "Invalid IP in request: %s", localIPstr) return } - weaveCIDR := weaveIPstr + "/" + prefix - weaveIP, subnet, err := net.ParseCIDR(weaveCIDR) - if err != nil { - reqError("Invalid CIDR", "Invalid CIDR in request: %s", weaveCIDR) + weaveIP := net.ParseIP(weaveIPstr) + if weaveIP == nil { + reqError("Invalid weave IP", "Invalid weave IP in request: %s", weaveIPstr) return } if dns.IsSubDomain(domain, name) { - Info.Printf("Adding %s (%s) -> %s", name, localIP, weaveCIDR) - err = db.AddRecord(identifier, name, ip, weaveIP, subnet) + Info.Printf("Adding %s (%s) -> %s", name, localIPstr, weaveIPstr) + err = db.AddRecord(ident, name, localIP, weaveIP) if err != nil { dup, ok := err.(DuplicateError) if !ok { @@ -68,7 +66,7 @@ func ListenHttp(domain string, db Zone, port int) { Error, w, "Internal error", http.StatusInternalServerError, "Unexpected error from DB: %s", err) return - } else if dup.Ident != identifier { + } else if dup.Ident != ident { http.Error(w, err.Error(), http.StatusConflict) return } // else we are golden @@ -78,8 +76,8 @@ func ListenHttp(domain string, db Zone, port int) { } case "DELETE": - identifier, weaveIPstr, err := parseUrl(r.URL.Path) - if identifier == "" || weaveIPstr == "" { + ident, weaveIPstr, err := parseUrl(r.URL.Path) + if ident == "" || weaveIPstr == "" { reqError("Invalid Request", "Invalid request: %s, %s", r.URL, r.Form) return } @@ -89,8 +87,8 @@ func ListenHttp(domain string, db Zone, port int) { reqError("Invalid IP in request", "Invalid IP in request: %s", weaveIPstr) return } - Info.Printf("Deleting %s (%s)", identifier, weaveIPstr) - err = db.DeleteRecord(identifier, weaveIP) + Info.Printf("Deleting %s (%s)", ident, weaveIPstr) + err = db.DeleteRecord(ident, weaveIP) if err != nil { if _, ok := err.(LookupError); !ok { httpErrorAndLog( diff --git a/server/mdns_server_test.go b/server/mdns_server_test.go index f77ed5ab..1fc8afb6 100644 --- a/server/mdns_server_test.go +++ b/server/mdns_server_test.go @@ -33,8 +33,8 @@ func TestServerSimpleQuery(t *testing.T) { log.Println("TestServerSimpleQuery starting") var zone = new(ZoneDb) dockerIP := net.ParseIP("9.8.7.6") - weaveIP, subnet, _ := net.ParseCIDR(testAddr1) - zone.AddRecord(containerID, "test.weave.", dockerIP, weaveIP, subnet) + weaveIP, _, _ := net.ParseCIDR(testAddr1) + zone.AddRecord(containerID, "test.weave.", dockerIP, weaveIP) mdnsServer, err := NewMDNSServer(zone) assertNoErr(t, err) diff --git a/server/zone.go b/server/zone.go index bf7ff5a8..d577917b 100644 --- a/server/zone.go +++ b/server/zone.go @@ -7,8 +7,7 @@ import ( ) type Zone interface { - AddRecord(ident string, name string, localIP net.IP, - weaveIP net.IP, weaveSubnet *net.IPNet) error + AddRecord(ident string, name string, localIP net.IP, weaveIP net.IP) error DeleteRecord(ident string, weaveIp net.IP) error DeleteRecordsFor(ident string) error MatchLocal(name string) (net.IP, error) @@ -19,7 +18,6 @@ type Record struct { Name string LocalIP net.IP WeaveIP net.IP - Subnet *net.IPNet } // Very simple data structure for now, with linear searching. @@ -65,7 +63,7 @@ func (zone *ZoneDb) MatchLocal(name string) (net.IP, error) { return nil, LookupError(name) } -func (zone *ZoneDb) AddRecord(ident string, name string, localIP net.IP, weaveIP net.IP, weaveSubnet *net.IPNet) error { +func (zone *ZoneDb) AddRecord(ident string, name string, localIP net.IP, weaveIP net.IP) error { zone.mx.Lock() defer zone.mx.Unlock() fqdn := dns.Fqdn(name) @@ -73,7 +71,7 @@ func (zone *ZoneDb) AddRecord(ident string, name string, localIP net.IP, weaveIP func(r Record) bool { return r.Name == fqdn && r.WeaveIP.Equal(weaveIP) }); index != -1 { return DuplicateError{fqdn, weaveIP, zone.recs[index].Ident} } - zone.recs = append(zone.recs, Record{ident, fqdn, localIP, weaveIP, weaveSubnet}) + zone.recs = append(zone.recs, Record{ident, fqdn, localIP, weaveIP}) return nil } diff --git a/server/zone_test.go b/server/zone_test.go index 60d06cbd..c43b8b79 100644 --- a/server/zone_test.go +++ b/server/zone_test.go @@ -16,8 +16,8 @@ func TestZone(t *testing.T) { var zone = new(ZoneDb) ip := net.ParseIP(dockerIP) - weaveIP, subnet, _ := net.ParseCIDR(testAddr1) - err := zone.AddRecord(containerID, successTestName, ip, weaveIP, subnet) + weaveIP, _, _ := net.ParseCIDR(testAddr1) + err := zone.AddRecord(containerID, successTestName, ip, weaveIP) assertNoErr(t, err) // Check that the address is now there. @@ -29,7 +29,7 @@ func TestZone(t *testing.T) { } // Now try to add the same address again - err = zone.AddRecord(containerID, successTestName, ip, weaveIP, subnet) + err = zone.AddRecord(containerID, successTestName, ip, weaveIP) assertErrorType(t, err, (*DuplicateError)(nil), "duplicate add") // Now delete the record @@ -56,8 +56,8 @@ func TestDeleteFor(t *testing.T) { zone := new(ZoneDb) ip := net.ParseIP(dockerIP) for _, addr := range []string{addr1, addr2} { - weaveIP, subnet, _ := net.ParseCIDR(addr) - err := zone.AddRecord(id, name, ip, weaveIP, subnet) + weaveIP, _, _ := net.ParseCIDR(addr) + err := zone.AddRecord(id, name, ip, weaveIP) assertNoErr(t, err) }