Tighten error checking

This commit is contained in:
Bryan Boreham committed 2015-06-10 17:21:16 +01:00
1 parent 50eaccc60c
commit ecbd514a83
2 files changed
+9 -2

No files matched your search

+5 -1
View File
@@ -67,11 +67,15 @@ func (alloc *Allocator) HandleHTTP(router *mux.Router) {
vars := mux.Vars(r)
ident := vars["id"]
cidrStr := vars["ip"] + "/" + vars["prefixlen"]
_, cidr, err := address.ParseCIDR(cidrStr)
subnetAddr, cidr, err := address.ParseCIDR(cidrStr)
if err != nil {
badRequest(w, err)
return
}
if cidr.Start != subnetAddr {
badRequest(w, fmt.Errorf("Invalid subnet %s - bits after network prefix are not all zero", cidrStr))
return
}
addr, err := alloc.Allocate(ident, cidr, closedChan)
if err != nil {
badRequest(w, fmt.Errorf("Unable to allocate: %s", err))