summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gobgp/cmd/common.go19
-rw-r--r--gobgp/cmd/global.go2
-rw-r--r--gobgp/cmd/monitor.go3
-rw-r--r--gobgp/cmd/mrt.go2
-rw-r--r--gobgp/cmd/neighbor.go8
-rw-r--r--gobgp/cmd/rpki.go3
6 files changed, 21 insertions, 16 deletions
diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go
index e67b0a26..ece1f53b 100644
--- a/gobgp/cmd/common.go
+++ b/gobgp/cmd/common.go
@@ -442,7 +442,16 @@ func connGrpc() *grpc.ClientConn {
return conn
}
-func checkAddressFamily(ip net.IP) (bgp.RouteFamily, error) {
+func addr2AddressFamily(a net.IP) bgp.RouteFamily {
+ if a == nil {
+ return bgp.RouteFamily(0)
+ } else if a.To4() != nil {
+ return bgp.RF_IPv4_UC
+ }
+ return bgp.RF_IPv6_UC
+}
+
+func checkAddressFamily(def bgp.RouteFamily) (bgp.RouteFamily, error) {
var rf bgp.RouteFamily
var e error
switch subOpts.AddressFamily {
@@ -465,13 +474,7 @@ func checkAddressFamily(ip net.IP) (bgp.RouteFamily, error) {
case "ipv6-flowspec", "ipv6-flow", "flow6":
rf = bgp.RF_FS_IPv6_UC
case "":
- if ip == nil {
- return rf, nil
- } else if len(ip) == 0 || ip.To4() != nil {
- rf = bgp.RF_IPv4_UC
- } else {
- rf = bgp.RF_IPv6_UC
- }
+ rf = def
default:
e = fmt.Errorf("unsupported address family: %s", subOpts.AddressFamily)
}
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go
index bfc18adb..5d819ef7 100644
--- a/gobgp/cmd/global.go
+++ b/gobgp/cmd/global.go
@@ -501,7 +501,7 @@ func showGlobalRib(args []string) error {
}
func modPath(resource api.Resource, name, modtype string, args []string) error {
- rf, err := checkAddressFamily(net.IP{})
+ rf, err := checkAddressFamily(bgp.RF_IPv4_UC)
if err != nil {
return err
}
diff --git a/gobgp/cmd/monitor.go b/gobgp/cmd/monitor.go
index 9924c38e..5d0d201e 100644
--- a/gobgp/cmd/monitor.go
+++ b/gobgp/cmd/monitor.go
@@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"github.com/osrg/gobgp/api"
+ "github.com/osrg/gobgp/packet"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"io"
@@ -29,7 +30,7 @@ func NewMonitorCmd() *cobra.Command {
ribCmd := &cobra.Command{
Use: CMD_RIB,
Run: func(cmd *cobra.Command, args []string) {
- rf, err := checkAddressFamily(nil)
+ rf, err := checkAddressFamily(bgp.RouteFamily(0))
if err != nil {
fmt.Println(err)
os.Exit(1)
diff --git a/gobgp/cmd/mrt.go b/gobgp/cmd/mrt.go
index 97b456f6..65fb6452 100644
--- a/gobgp/cmd/mrt.go
+++ b/gobgp/cmd/mrt.go
@@ -81,7 +81,7 @@ func dumpRib(r string, remoteIP net.IP, args []string) error {
return fmt.Errorf("unknown resource type: %s", r)
}
- rf, err := checkAddressFamily(remoteIP)
+ rf, err := checkAddressFamily(addr2AddressFamily(remoteIP))
if err != nil {
return err
}
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go
index cbf0a592..79717cbf 100644
--- a/gobgp/cmd/neighbor.go
+++ b/gobgp/cmd/neighbor.go
@@ -410,6 +410,7 @@ func showNeighborRib(r string, name string, args []string) error {
showBest := false
showAge := true
showLabel := false
+ def := addr2AddressFamily(net.ParseIP(name))
switch r {
case CMD_GLOBAL:
showBest = true
@@ -423,10 +424,11 @@ func showNeighborRib(r string, name string, args []string) error {
showAge = false
resource = api.Resource_ADJ_OUT
case CMD_VRF:
+ def = bgp.RF_IPv4_UC
showLabel = true
resource = api.Resource_VRF
}
- rf, err := checkAddressFamily(net.ParseIP(name))
+ rf, err := checkAddressFamily(def)
if err != nil {
return err
}
@@ -566,7 +568,7 @@ func showNeighborRib(r string, name string, args []string) error {
}
func resetNeighbor(cmd string, remoteIP string, args []string) error {
- rf, err := checkAddressFamily(net.ParseIP(remoteIP))
+ rf, err := checkAddressFamily(addr2AddressFamily(net.ParseIP(remoteIP)))
if err != nil {
return err
}
@@ -605,7 +607,7 @@ func stateChangeNeighbor(cmd string, remoteIP string, args []string) error {
}
func showNeighborPolicy(remoteIP net.IP) error {
- rf, err := checkAddressFamily(net.IP{})
+ rf, err := checkAddressFamily(addr2AddressFamily(remoteIP))
if err != nil {
return err
}
diff --git a/gobgp/cmd/rpki.go b/gobgp/cmd/rpki.go
index 6ead5eb5..7d206b6e 100644
--- a/gobgp/cmd/rpki.go
+++ b/gobgp/cmd/rpki.go
@@ -22,7 +22,6 @@ import (
"github.com/spf13/cobra"
"golang.org/x/net/context"
"io"
- "net"
"os"
"time"
)
@@ -56,7 +55,7 @@ func showRPKITable(args []string) error {
if len(args) == 0 {
return fmt.Errorf("Needs to specify RPKI server address")
}
- rf, err := checkAddressFamily(net.IP{})
+ rf, err := checkAddressFamily(bgp.RF_IPv4_UC)
if err != nil {
fmt.Println(err)
os.Exit(1)