Tighten error checking
This commit is contained in:
1 parent
50eaccc60c
commit
ecbd514a83
2 files changed
+9
-2
No files matched your search
+5
-1
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user