Files
weave/prog/netcheck/netcheck.go
T
Bryan Boreham f05225da22 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.
2015-07-01 12:15:04 +01:00

37 lines
565 B
Go

/* netcheck: check whether a given network or address overlaps with any existing routes */
package main
import (
"fmt"
"net"
"os"
weavenet "github.com/weaveworks/weave/net"
)
func fatal(err error) {
fmt.Println(err)
os.Exit(1)
}
func main() {
if len(os.Args) <= 1 {
os.Exit(0)
}
cidrStr := os.Args[1]
addr, ipnet, err := net.ParseCIDR(cidrStr)
if err != nil {
fatal(err)
}
if ipnet.IP.Equal(addr) {
err = weavenet.CheckNetworkFree(ipnet)
} else {
err = weavenet.CheckAddressOverlap(addr)
}
if err != nil {
fatal(err)
}
os.Exit(0)
}