Changed to accept a CIDR address and use net.IP

* In general we'll have an IP address and a subnet mask for the weave
   network address; account for this in the zone DB and in the HTTP
   server.

 * Use the net.IP type rather than string, which gives us a bit more
   generality (in theory it'll deal with Ipv6 too) and validation (we
   attempt to parse the input)
This commit is contained in:
Michael Bridgen committed 2014-10-07 12:49:52 +01:00
1 parent e7ac6dafb3
commit e8e86dadc0
3 files changed
+27 -23

No files matched your search

+14 -5
View File
@@ -3,6 +3,7 @@ package weavedns
import (
"fmt"
"log"
"net"
"net/http"
)
@@ -14,12 +15,20 @@ func ListenHttp(db Zone) {
http.HandleFunc("/add", func(w http.ResponseWriter, r *http.Request) {
name := r.FormValue("name")
addr := r.FormValue("ip")
weave_ip := r.FormValue("weave_ip")
if name != "" && addr != "" && weave_ip != "" {
log.Printf("Adding %s, %s, %s", name, addr, weave_ip)
db.AddRecord(name, addr, weave_ip)
weave_cidr := r.FormValue("weave_cidr")
if name != "" && addr != "" && weave_cidr != "" {
ip := net.ParseIP(addr)
weave_ip, subnet, err := net.ParseCIDR(weave_cidr)
if err == nil && ip != nil {
log.Printf("Adding %s (%s) -> %s", name, addr, weave_cidr)
db.AddRecord(name, ip, weave_ip, subnet)
} else if err != nil {
log.Printf("Invalid CIDR in request: %s", weave_cidr)
} else {
log.Printf("Invalid IP in request: %s", addr)
}
} else {
log.Printf("Invalid request: %s, %s, %s", name, addr, weave_ip)
log.Printf("Invalid request: %s, %s, %s", name, addr, weave_cidr)
}
})
address := fmt.Sprintf(":%d", UPDATE_PORT)