summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2017-02-22 06:00:05 +0000
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2017-02-22 06:00:05 +0000
commitba75b7386948a4c2f6f281c7c93897ee5e3b4e84 (patch)
treef3c64b891feef3d4ac8c136d2eadc3ca5cd248d3
parent844cfba67ed62cbb13c91831672def55ccb8df60 (diff)
cli: return error with invalid input
before: $ gobgp n 10.0.0.1 adj-in foo Network not in table after: $ gobgp n 10.0.0.1 adj-in foo invalid CIDR/IP Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--gobgp/cmd/neighbor.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go
index 6952f282..eb31050c 100644
--- a/gobgp/cmd/neighbor.go
+++ b/gobgp/cmd/neighbor.go
@@ -500,6 +500,18 @@ func showRibInfo(r, name string) error {
}
+func parseCIDRorIP(str string) (net.IP, *net.IPNet, error) {
+ ip, n, err := net.ParseCIDR(str)
+ if err == nil {
+ return ip, n, nil
+ }
+ ip = net.ParseIP(str)
+ if ip == nil {
+ return ip, nil, fmt.Errorf("invalid CIDR/IP")
+ }
+ return ip, nil, nil
+}
+
func showNeighborRib(r string, name string, args []string) error {
showBest := false
showAge := true
@@ -527,6 +539,9 @@ func showNeighborRib(r string, name string, args []string) error {
var filter []*table.LookupPrefix
if len(args) > 0 {
+ if _, _, err = parseCIDRorIP(args[0]); err != nil {
+ return err
+ }
var option table.LookupOption
if len(args) > 1 {
if args[1] == "longer-prefixes" {