summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/gobgp.pb.go7
-rw-r--r--api/gobgp.proto1
-rw-r--r--docs/sources/cli-command-syntax.md4
-rw-r--r--gobgp/cmd/neighbor.go13
-rw-r--r--server/server.go24
5 files changed, 31 insertions, 18 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go
index 8edf8624..0021c995 100644
--- a/api/gobgp.pb.go
+++ b/api/gobgp.pb.go
@@ -1502,9 +1502,10 @@ func (*Path) ProtoMessage() {}
func (*Path) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{92} }
type Destination struct {
- Prefix string `protobuf:"bytes,1,opt,name=prefix" json:"prefix,omitempty"`
- Paths []*Path `protobuf:"bytes,2,rep,name=paths" json:"paths,omitempty"`
- LongerPrefixes bool `protobuf:"varint,3,opt,name=longer_prefixes,json=longerPrefixes" json:"longer_prefixes,omitempty"`
+ Prefix string `protobuf:"bytes,1,opt,name=prefix" json:"prefix,omitempty"`
+ Paths []*Path `protobuf:"bytes,2,rep,name=paths" json:"paths,omitempty"`
+ LongerPrefixes bool `protobuf:"varint,3,opt,name=longer_prefixes,json=longerPrefixes" json:"longer_prefixes,omitempty"`
+ ShorterPrefixes bool `protobuf:"varint,4,opt,name=shorter_prefixes,json=shorterPrefixes" json:"shorter_prefixes,omitempty"`
}
func (m *Destination) Reset() { *m = Destination{} }
diff --git a/api/gobgp.proto b/api/gobgp.proto
index 8f6f87d6..71a30185 100644
--- a/api/gobgp.proto
+++ b/api/gobgp.proto
@@ -489,6 +489,7 @@ message Destination {
string prefix = 1;
repeated Path paths = 2;
bool longer_prefixes = 3;
+ bool shorter_prefixes = 4;
}
message Table {
diff --git a/docs/sources/cli-command-syntax.md b/docs/sources/cli-command-syntax.md
index 2ebfec23..c7e359a2 100644
--- a/docs/sources/cli-command-syntax.md
+++ b/docs/sources/cli-command-syntax.md
@@ -40,7 +40,7 @@ gobgp has six subcommands.
# show all Route information
% gobgp global rib [-a <address family>]
# show a specific route information
-% gobgp global rib [<prefix>|<host>] [longer-prefixes] [-a <address family>]
+% gobgp global rib [<prefix>|<host>] [longer-prefixes|shorter-prefixes] [-a <address family>]
```
#### - example
@@ -118,7 +118,7 @@ The following options can be specified in the global subcommand:
# show all routes in [local|adj-in|adj-out] table
% gobgp neighbor <neighbor address> [local|adj-in|adj-out] [-a <address family>]
# show a specific route in [local|adj-in|adj-out] table
-% gobgp neighbor <neighbor address> [local|adj-in|adj-out] [<prefix>|<host>] [longer-prefixes] [-a <address family>]
+% gobgp neighbor <neighbor address> [local|adj-in|adj-out] [<prefix>|<host>] [longer-prefixes|shorter-prefixes] [-a <address family>]
```
#### - example
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go
index 9c93bbd2..bf687772 100644
--- a/gobgp/cmd/neighbor.go
+++ b/gobgp/cmd/neighbor.go
@@ -483,16 +483,21 @@ func showNeighborRib(r string, name string, args []string) error {
return fmt.Errorf("route filtering is only supported for IPv4/IPv6 unicast routes")
}
longerPrefixes := false
+ shorterPrefixes := false
if len(args) > 1 {
- if args[1] != "longer-prefixes" {
+ if args[1] == "longer-prefixes" {
+ longerPrefixes = true
+ } else if args[1] == "shorter-prefixes" {
+ shorterPrefixes = true
+ } else {
return fmt.Errorf("invalid format for route filtering")
}
- longerPrefixes = true
}
arg.Destinations = []*api.Destination{
&api.Destination{
- Prefix: args[0],
- LongerPrefixes: longerPrefixes,
+ Prefix: args[0],
+ LongerPrefixes: longerPrefixes,
+ ShorterPrefixes: shorterPrefixes,
},
}
}
diff --git a/server/server.go b/server/server.go
index 6a766261..286ff85b 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1605,7 +1605,21 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) {
}
for _, dst := range arg.Table.Destinations {
key := dst.Prefix
- if _, err := f(id, key); err != nil {
+ if dst.LongerPrefixes {
+ _, prefix, _ := net.ParseCIDR(key)
+ for _, dst := range rib.Tables[af].GetLongerPrefixDestinations(prefix.String()) {
+ if d := dst.ToApiStruct(id); d != nil {
+ dsts = append(dsts, d)
+ }
+ }
+ } else if dst.ShorterPrefixes {
+ _, prefix, _ := net.ParseCIDR(key)
+ ones, bits := prefix.Mask.Size()
+ for i := ones; i > 0; i-- {
+ prefix.Mask = net.CIDRMask(i, bits)
+ f(id, prefix.String())
+ }
+ } else if _, err := f(id, key); err != nil {
if host := net.ParseIP(key); host != nil {
masklen := 32
if af == bgp.RF_IPv6_UC {
@@ -1617,14 +1631,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) {
}
}
}
- } else if dst.LongerPrefixes {
- _, prefix, _ := net.ParseCIDR(key)
-
- for _, dst := range rib.Tables[af].GetLongerPrefixDestinations(prefix.String()) {
- if d := dst.ToApiStruct(id); d != nil {
- dsts = append(dsts, d)
- }
- }
}
}
} else {