diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-05-09 23:57:58 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-05-10 00:01:08 +0900 |
commit | 7cbb6bbd32ad37ceae89c23bc79ff9cf5fe6a01d (patch) | |
tree | cee6ee1174dce7b7fe816e184351c5aeeda40218 | |
parent | eab6a03899da60794aab5fd2b0387ccfcc360687 (diff) |
cli: support specifying a transport for neighbor command
Added '-t' (--transport) option, which can take "ipv4" or "ipv6":
fujita@ubuntu:~/git/gobgp/gobgp$ gobgp neighbor
Peer AS Up/Down State |#Advertised Received Accepted
10.0.255.1 65001 01:59:53 Establ | 1 2 2
10.0.255.2 65002 01:59:53 Establ | 2 1 1
2001:db8::7 65007 never Active | 0 0 0
fujita@ubuntu:~/git/gobgp/gobgp$ gobgp neighbor -t ipv4
Peer AS Up/Down State |#Advertised Received Accepted
10.0.255.1 65001 02:02:20 Establ | 1 2 2
10.0.255.2 65002 02:02:20 Establ | 2 1 1
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | gobgp/main.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/gobgp/main.go b/gobgp/main.go index e8735104..244e1f01 100644 --- a/gobgp/main.go +++ b/gobgp/main.go @@ -536,6 +536,18 @@ func showNeighbors() error { } else if e != nil { return e } + if neighborsOpts.Transport != "" { + addr := net.ParseIP(p.Conf.RemoteIp) + if addr.To4() != nil { + if neighborsOpts.Transport != "ipv4" { + continue + } + } else { + if neighborsOpts.Transport != "ipv6" { + continue + } + } + } m = append(m, p) } @@ -699,8 +711,12 @@ func showNeighbor(args []string) error { func (x *NeighborCommand) Execute(args []string) error { eArgs := extractArgs(CMD_NEIGHBOR) - if len(eArgs) == 0 { - if err := requestGrpc(CMD_NEIGHBOR, eArgs, nil); err != nil { + if len(eArgs) == 0 || (strings.HasPrefix(eArgs[0], "-") && !(eArgs[0] == "-h" || eArgs[0] == "--help")) { + parser := flags.NewParser(&neighborsOpts, flags.Default) + if _, err := parser.ParseArgs(eArgs); err != nil { + os.Exit(1) + } + if err := requestGrpc(CMD_NEIGHBOR, []string{}, nil); err != nil { return err } } else if len(eArgs) == 1 && !(eArgs[0] == "-h" || eArgs[0] == "--help") { @@ -1038,6 +1054,10 @@ var subOpts struct { AddressFamily string `short:"a" long:"address-family" description:"specifying an address family" default:"ipv4"` } +var neighborsOpts struct { + Transport string `short:"t" long:"transport" description:"specifying a transport protocol"` +} + func main() { cmds = []string{CMD_GLOBAL, CMD_NEIGHBOR, CMD_RIB, CMD_ADD, CMD_DEL, CMD_LOCAL, CMD_ADJ_IN, CMD_ADJ_OUT, CMD_RESET, CMD_SOFT_RESET, CMD_SOFT_RESET_IN, CMD_SOFT_RESET_OUT, CMD_SHUTDOWN, CMD_ENABLE, CMD_DISABLE} |