Remove subnets from API, since we don't use them
This commit is contained in:
1 parent
840c0b9f86
commit
ad44a8816f
4 files changed
+26
-30
No files matched your search
+16
-18
@@ -35,32 +35,30 @@ func ListenHttp(domain string, db Zone, port int) {
|
|||||||
|
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "PUT":
|
case "PUT":
|
||||||
identifier, weaveIPstr, err := parseUrl(r.URL.Path)
|
ident, weaveIPstr, err := parseUrl(r.URL.Path)
|
||||||
name := r.FormValue("fqdn")
|
name := r.FormValue("fqdn")
|
||||||
prefix := r.FormValue("routing_prefix")
|
localIPstr := r.FormValue("local_ip")
|
||||||
localIP := 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)
|
reqError("Invalid request", "Invalid request: %s, %s", r.URL, r.Form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := net.ParseIP(localIP)
|
localIP := net.ParseIP(localIPstr)
|
||||||
if ip == nil {
|
if localIP == nil {
|
||||||
reqError("Invalid IP in request", "Invalid IP in request: %s", localIP)
|
reqError("Invalid IP in request", "Invalid IP in request: %s", localIPstr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
weaveCIDR := weaveIPstr + "/" + prefix
|
weaveIP := net.ParseIP(weaveIPstr)
|
||||||
weaveIP, subnet, err := net.ParseCIDR(weaveCIDR)
|
if weaveIP == nil {
|
||||||
if err != nil {
|
reqError("Invalid weave IP", "Invalid weave IP in request: %s", weaveIPstr)
|
||||||
reqError("Invalid CIDR", "Invalid CIDR in request: %s", weaveCIDR)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if dns.IsSubDomain(domain, name) {
|
if dns.IsSubDomain(domain, name) {
|
||||||
Info.Printf("Adding %s (%s) -> %s", name, localIP, weaveCIDR)
|
Info.Printf("Adding %s (%s) -> %s", name, localIPstr, weaveIPstr)
|
||||||
err = db.AddRecord(identifier, name, ip, weaveIP, subnet)
|
err = db.AddRecord(ident, name, localIP, weaveIP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dup, ok := err.(DuplicateError)
|
dup, ok := err.(DuplicateError)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -68,7 +66,7 @@ func ListenHttp(domain string, db Zone, port int) {
|
|||||||
Error, w, "Internal error", http.StatusInternalServerError,
|
Error, w, "Internal error", http.StatusInternalServerError,
|
||||||
"Unexpected error from DB: %s", err)
|
"Unexpected error from DB: %s", err)
|
||||||
return
|
return
|
||||||
} else if dup.Ident != identifier {
|
} else if dup.Ident != ident {
|
||||||
http.Error(w, err.Error(), http.StatusConflict)
|
http.Error(w, err.Error(), http.StatusConflict)
|
||||||
return
|
return
|
||||||
} // else we are golden
|
} // else we are golden
|
||||||
@@ -78,8 +76,8 @@ func ListenHttp(domain string, db Zone, port int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
identifier, weaveIPstr, err := parseUrl(r.URL.Path)
|
ident, weaveIPstr, err := parseUrl(r.URL.Path)
|
||||||
if identifier == "" || weaveIPstr == "" {
|
if ident == "" || weaveIPstr == "" {
|
||||||
reqError("Invalid Request", "Invalid request: %s, %s", r.URL, r.Form)
|
reqError("Invalid Request", "Invalid request: %s, %s", r.URL, r.Form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -89,8 +87,8 @@ func ListenHttp(domain string, db Zone, port int) {
|
|||||||
reqError("Invalid IP in request", "Invalid IP in request: %s", weaveIPstr)
|
reqError("Invalid IP in request", "Invalid IP in request: %s", weaveIPstr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Info.Printf("Deleting %s (%s)", identifier, weaveIPstr)
|
Info.Printf("Deleting %s (%s)", ident, weaveIPstr)
|
||||||
err = db.DeleteRecord(identifier, weaveIP)
|
err = db.DeleteRecord(ident, weaveIP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(LookupError); !ok {
|
if _, ok := err.(LookupError); !ok {
|
||||||
httpErrorAndLog(
|
httpErrorAndLog(
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ func TestServerSimpleQuery(t *testing.T) {
|
|||||||
log.Println("TestServerSimpleQuery starting")
|
log.Println("TestServerSimpleQuery starting")
|
||||||
var zone = new(ZoneDb)
|
var zone = new(ZoneDb)
|
||||||
dockerIP := net.ParseIP("9.8.7.6")
|
dockerIP := net.ParseIP("9.8.7.6")
|
||||||
weaveIP, subnet, _ := net.ParseCIDR(testAddr1)
|
weaveIP, _, _ := net.ParseCIDR(testAddr1)
|
||||||
zone.AddRecord(containerID, "test.weave.", dockerIP, weaveIP, subnet)
|
zone.AddRecord(containerID, "test.weave.", dockerIP, weaveIP)
|
||||||
|
|
||||||
mdnsServer, err := NewMDNSServer(zone)
|
mdnsServer, err := NewMDNSServer(zone)
|
||||||
assertNoErr(t, err)
|
assertNoErr(t, err)
|
||||||
|
|||||||
+3
-5
@@ -7,8 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Zone interface {
|
type Zone interface {
|
||||||
AddRecord(ident string, name string, localIP net.IP,
|
AddRecord(ident string, name string, localIP net.IP, weaveIP net.IP) error
|
||||||
weaveIP net.IP, weaveSubnet *net.IPNet) error
|
|
||||||
DeleteRecord(ident string, weaveIp net.IP) error
|
DeleteRecord(ident string, weaveIp net.IP) error
|
||||||
DeleteRecordsFor(ident string) error
|
DeleteRecordsFor(ident string) error
|
||||||
MatchLocal(name string) (net.IP, error)
|
MatchLocal(name string) (net.IP, error)
|
||||||
@@ -19,7 +18,6 @@ type Record struct {
|
|||||||
Name string
|
Name string
|
||||||
LocalIP net.IP
|
LocalIP net.IP
|
||||||
WeaveIP net.IP
|
WeaveIP net.IP
|
||||||
Subnet *net.IPNet
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Very simple data structure for now, with linear searching.
|
// 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)
|
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()
|
zone.mx.Lock()
|
||||||
defer zone.mx.Unlock()
|
defer zone.mx.Unlock()
|
||||||
fqdn := dns.Fqdn(name)
|
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 {
|
func(r Record) bool { return r.Name == fqdn && r.WeaveIP.Equal(weaveIP) }); index != -1 {
|
||||||
return DuplicateError{fqdn, weaveIP, zone.recs[index].Ident}
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -16,8 +16,8 @@ func TestZone(t *testing.T) {
|
|||||||
var zone = new(ZoneDb)
|
var zone = new(ZoneDb)
|
||||||
|
|
||||||
ip := net.ParseIP(dockerIP)
|
ip := net.ParseIP(dockerIP)
|
||||||
weaveIP, subnet, _ := net.ParseCIDR(testAddr1)
|
weaveIP, _, _ := net.ParseCIDR(testAddr1)
|
||||||
err := zone.AddRecord(containerID, successTestName, ip, weaveIP, subnet)
|
err := zone.AddRecord(containerID, successTestName, ip, weaveIP)
|
||||||
assertNoErr(t, err)
|
assertNoErr(t, err)
|
||||||
|
|
||||||
// Check that the address is now there.
|
// Check that the address is now there.
|
||||||
@@ -29,7 +29,7 @@ func TestZone(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now try to add the same address again
|
// 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")
|
assertErrorType(t, err, (*DuplicateError)(nil), "duplicate add")
|
||||||
|
|
||||||
// Now delete the record
|
// Now delete the record
|
||||||
@@ -56,8 +56,8 @@ func TestDeleteFor(t *testing.T) {
|
|||||||
zone := new(ZoneDb)
|
zone := new(ZoneDb)
|
||||||
ip := net.ParseIP(dockerIP)
|
ip := net.ParseIP(dockerIP)
|
||||||
for _, addr := range []string{addr1, addr2} {
|
for _, addr := range []string{addr1, addr2} {
|
||||||
weaveIP, subnet, _ := net.ParseCIDR(addr)
|
weaveIP, _, _ := net.ParseCIDR(addr)
|
||||||
err := zone.AddRecord(id, name, ip, weaveIP, subnet)
|
err := zone.AddRecord(id, name, ip, weaveIP)
|
||||||
assertNoErr(t, err)
|
assertNoErr(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user