summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-05-11 12:22:35 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-05-11 12:22:35 +0900
commitd5defb589b79974342d53cc59404b4a1c6b7405d (patch)
tree4e8f434b2c7377bbe0731f74998b855c9457a317
parent1f13176bc1e39f626725882a3d6b03eb7b6e38c1 (diff)
cli: set wisely address family if not specified
Use transport address (ipv4 or v6) as a hint. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--gobgp/main.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/gobgp/main.go b/gobgp/main.go
index 797ac703..d86ae7b3 100644
--- a/gobgp/main.go
+++ b/gobgp/main.go
@@ -225,7 +225,7 @@ func extractArgs(head string) []string {
return eArgs
}
-func checkAddressFamily() (*api.AddressFamily, error) {
+func checkAddressFamily(ip net.IP) (*api.AddressFamily, error) {
var rf *api.AddressFamily
var e error
switch subOpts.AddressFamily {
@@ -240,7 +240,12 @@ func checkAddressFamily() (*api.AddressFamily, error) {
case "rtc":
rf = api.AF_RTC
case "":
- e = fmt.Errorf("address family is not specified")
+ fmt.Println("hello", ip.To16())
+ if len(ip) == 0 || ip.To4() != nil {
+ rf = api.AF_IPV4_UC
+ } else {
+ rf = api.AF_IPV6_UC
+ }
default:
e = fmt.Errorf("unsupported address family: %s", subOpts.AddressFamily)
}
@@ -273,7 +278,7 @@ func NewGlobalRibCommand(resource api.Resource) *GlobalRibCommand {
}
}
func showGlobalRib() error {
- rt, err := checkAddressFamily()
+ rt, err := checkAddressFamily(net.IP{})
if err != nil {
return err
}
@@ -351,7 +356,7 @@ func NewGlobalRibAddCommand(resource api.Resource) *GlobalRibAddCommand {
}
func modPath(modtype string, eArgs []string) error {
- rf, err := checkAddressFamily()
+ rf, err := checkAddressFamily(net.IP{})
if err != nil {
return err
}
@@ -906,7 +911,7 @@ func showRoute(pathList []*api.Path, showAge bool, showBest bool) {
}
func showNeighborRib(resource api.Resource, remoteIP net.IP) error {
- rt, err := checkAddressFamily()
+ rt, err := checkAddressFamily(remoteIP)
if err != nil {
return err
}
@@ -1008,7 +1013,7 @@ func NewNeighborResetCommand(addr string, cmd string) *NeighborResetCommand {
}
func resetNeighbor(cmd string, remoteIP net.IP) error {
- rt, err := checkAddressFamily()
+ rt, err := checkAddressFamily(remoteIP)
if err != nil {
return err
}
@@ -1087,7 +1092,7 @@ var globalOpts struct {
}
var subOpts struct {
- AddressFamily string `short:"a" long:"address-family" description:"specifying an address family" default:"ipv4"`
+ AddressFamily string `short:"a" long:"address-family" description:"specifying an address family"`
}
var neighborsOpts struct {