Check specific addresses differently to networks

For a network, as used by IPAM, we care if *any* address in the range
could possibly conflict with an existing address routed by the host.
When given a single address, we only care if *that specific address*
conflicts with an existing route.
This commit is contained in:
Bryan Boreham committed 2015-07-01 12:15:04 +01:00
1 parent 6403e7a11c
commit f05225da22
2 files changed
+25 -5

No files matched your search

+9 -4
View File
@@ -1,4 +1,4 @@
/* netcheck: check whether a given network overlaps with any existing routes */
/* netcheck: check whether a given network or address overlaps with any existing routes */
package main
import (
@@ -19,12 +19,17 @@ func main() {
os.Exit(0)
}
ipRangeStr := os.Args[1]
_, ipnet, err := net.ParseCIDR(ipRangeStr)
cidrStr := os.Args[1]
addr, ipnet, err := net.ParseCIDR(cidrStr)
if err != nil {
fatal(err)
}
if err := weavenet.CheckNetworkFree(ipnet); err != nil {
if ipnet.IP.Equal(addr) {
err = weavenet.CheckNetworkFree(ipnet)
} else {
err = weavenet.CheckAddressOverlap(addr)
}
if err != nil {
fatal(err)
}
os.Exit(0)