summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/gobgp.pb.go1
-rw-r--r--api/gobgp.proto1
-rw-r--r--gobgp/cmd/common.go6
-rw-r--r--gobgp/cmd/neighbor.go34
-rw-r--r--server/peer.go1
-rw-r--r--table/path.go4
-rw-r--r--table/table_manager.go46
7 files changed, 56 insertions, 37 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go
index fe6949f4..97ededd1 100644
--- a/api/gobgp.pb.go
+++ b/api/gobgp.pb.go
@@ -249,6 +249,7 @@ type Path struct {
Rf uint32 `protobuf:"varint,8,opt,name=rf" json:"rf,omitempty"`
SourceAsn uint32 `protobuf:"varint,9,opt,name=source_asn" json:"source_asn,omitempty"`
SourceId string `protobuf:"bytes,10,opt,name=source_id" json:"source_id,omitempty"`
+ Filtered bool `protobuf:"varint,11,opt,name=filtered" json:"filtered,omitempty"`
}
func (m *Path) Reset() { *m = Path{} }
diff --git a/api/gobgp.proto b/api/gobgp.proto
index 0ce3cf36..ec480470 100644
--- a/api/gobgp.proto
+++ b/api/gobgp.proto
@@ -118,6 +118,7 @@ message Path {
uint32 rf = 8;
uint32 source_asn = 9;
string source_id = 10;
+ bool filtered = 11;
}
message Destination {
diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go
index 67c37543..327b204c 100644
--- a/gobgp/cmd/common.go
+++ b/gobgp/cmd/common.go
@@ -63,6 +63,8 @@ const (
CMD_RPKI_TABLE = "table"
CMD_RPKI_SERVER = "server"
CMD_VRF = "vrf"
+ CMD_ACCEPTED = "accepted"
+ CMD_REJECTED = "rejected"
)
var subOpts struct {
@@ -154,7 +156,8 @@ type Path struct {
Age int64 `json:"age"`
Best bool `json:"best"`
IsWithdraw bool `json:"isWithdraw"`
- Validation int32
+ Validation int32 `json:"validation"`
+ Filtered bool `json:"filtered"`
}
func ApiStruct2Path(p *gobgpapi.Path) (*Path, error) {
@@ -197,6 +200,7 @@ func ApiStruct2Path(p *gobgpapi.Path) (*Path, error) {
Best: p.Best,
IsWithdraw: p.IsWithdraw,
Validation: p.Validation,
+ Filtered: p.Filtered,
}, nil
}
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go
index 85dd0cd4..748e3731 100644
--- a/gobgp/cmd/neighbor.go
+++ b/gobgp/cmd/neighbor.go
@@ -417,7 +417,7 @@ func showNeighborRib(r string, name string, args []string) error {
case CMD_LOCAL:
showBest = true
resource = api.Resource_LOCAL
- case CMD_ADJ_IN:
+ case CMD_ADJ_IN, CMD_ACCEPTED, CMD_REJECTED:
resource = api.Resource_ADJ_IN
case CMD_ADJ_OUT:
showAge = false
@@ -501,7 +501,20 @@ func showNeighborRib(r string, name string, args []string) error {
}
if isResultSorted(rf) && !globalOpts.Json && len(dst.Paths) > 0 {
ps := paths{}
- ps = append(ps, dst.Paths...)
+ for _, p := range dst.Paths {
+ switch r {
+ case CMD_ACCEPTED:
+ if !p.Filtered {
+ ps = append(ps, p)
+ }
+ case CMD_REJECTED:
+ if p.Filtered {
+ ps = append(ps, p)
+ }
+ default:
+ ps = append(ps, p)
+ }
+ }
sort.Sort(ps)
if counter == 0 {
showRoute(ps, showAge, showBest, showLabel, false, true)
@@ -526,7 +539,20 @@ func showNeighborRib(r string, name string, args []string) error {
ps := paths{}
for _, dst := range dsts {
- ps = append(ps, dst.Paths...)
+ for _, p := range dst.Paths {
+ switch r {
+ case CMD_ACCEPTED:
+ if !p.Filtered {
+ ps = append(ps, p)
+ }
+ case CMD_REJECTED:
+ if p.Filtered {
+ ps = append(ps, p)
+ }
+ default:
+ ps = append(ps, p)
+ }
+ }
}
if len(ps) == 0 {
@@ -700,7 +726,7 @@ func NewNeighborCmd() *cobra.Command {
}
c := make([]cmds, 0, 3)
- c = append(c, cmds{[]string{CMD_LOCAL, CMD_ADJ_IN, CMD_ADJ_OUT}, showNeighborRib})
+ c = append(c, cmds{[]string{CMD_LOCAL, CMD_ADJ_IN, CMD_ADJ_OUT, CMD_ACCEPTED, CMD_REJECTED}, showNeighborRib})
c = append(c, cmds{[]string{CMD_RESET, CMD_SOFT_RESET, CMD_SOFT_RESET_IN, CMD_SOFT_RESET_OUT}, resetNeighbor})
c = append(c, cmds{[]string{CMD_SHUTDOWN, CMD_ENABLE, CMD_DISABLE}, stateChangeNeighbor})
diff --git a/server/peer.go b/server/peer.go
index a36c44a2..7029553a 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -446,6 +446,7 @@ func (peer *Peer) ApplyPolicy(d PolicyDirection, paths []*table.Path) []*table.P
peer.accepted += 1
}
case policy.ROUTE_TYPE_REJECT:
+ path.Filtered = true
log.WithFields(log.Fields{
"Topic": "Peer",
"Key": peer.conf.NeighborConfig.NeighborAddress,
diff --git a/table/path.go b/table/path.go
index 8997af67..02b24416 100644
--- a/table/path.go
+++ b/table/path.go
@@ -38,6 +38,7 @@ type Path struct {
NoImplicitWithdraw bool
Validation config.RpkiValidationResultType
IsFromZebra bool
+ Filtered bool
}
func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pattrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool, timestamp time.Time, noImplicitWithdraw bool) *Path {
@@ -190,6 +191,7 @@ func (path *Path) ToApiStruct() *api.Path {
Age: int64(time.Now().Sub(path.timestamp).Seconds()),
IsWithdraw: path.IsWithdraw,
Validation: int32(path.Validation),
+ Filtered: path.Filtered,
Rf: rf,
}
}
@@ -200,11 +202,13 @@ func (path *Path) MarshalJSON() ([]byte, error) {
IsWithdraw bool `json:"is_withdraw"`
Nlri bgp.AddrPrefixInterface `json:"nlri"`
Pathattrs []bgp.PathAttributeInterface `json:"pattrs"`
+ Filtered bool `json:"filtered"`
}{
Source: path.source,
IsWithdraw: path.IsWithdraw,
Nlri: path.nlri,
Pathattrs: path.pathAttrs,
+ Filtered: path.Filtered,
})
}
diff --git a/table/table_manager.go b/table/table_manager.go
index 01651e1c..25807566 100644
--- a/table/table_manager.go
+++ b/table/table_manager.go
@@ -412,23 +412,23 @@ func (manager *TableManager) ProcessUpdate(fromPeer *PeerInfo, message *bgp.BGPM
}
type AdjRib struct {
- adjRibIn map[bgp.RouteFamily]map[string]*ReceivedRoute
- adjRibOut map[bgp.RouteFamily]map[string]*ReceivedRoute
+ adjRibIn map[bgp.RouteFamily]map[string]*Path
+ adjRibOut map[bgp.RouteFamily]map[string]*Path
}
func NewAdjRib(rfList []bgp.RouteFamily) *AdjRib {
r := &AdjRib{
- adjRibIn: make(map[bgp.RouteFamily]map[string]*ReceivedRoute),
- adjRibOut: make(map[bgp.RouteFamily]map[string]*ReceivedRoute),
+ adjRibIn: make(map[bgp.RouteFamily]map[string]*Path),
+ adjRibOut: make(map[bgp.RouteFamily]map[string]*Path),
}
for _, rf := range rfList {
- r.adjRibIn[rf] = make(map[string]*ReceivedRoute)
- r.adjRibOut[rf] = make(map[string]*ReceivedRoute)
+ r.adjRibIn[rf] = make(map[string]*Path)
+ r.adjRibOut[rf] = make(map[string]*Path)
}
return r
}
-func (adj *AdjRib) update(rib map[bgp.RouteFamily]map[string]*ReceivedRoute, pathList []*Path) {
+func (adj *AdjRib) update(rib map[bgp.RouteFamily]map[string]*Path, pathList []*Path) {
for _, path := range pathList {
rf := path.GetRouteFamily()
key := path.getPrefix()
@@ -438,10 +438,10 @@ func (adj *AdjRib) update(rib map[bgp.RouteFamily]map[string]*ReceivedRoute, pat
delete(rib[rf], key)
}
} else {
- if found && reflect.DeepEqual(old.path.GetPathAttrs(), path.GetPathAttrs()) {
- path.setTimestamp(old.path.GetTimestamp())
+ if found && reflect.DeepEqual(old.GetPathAttrs(), path.GetPathAttrs()) {
+ path.setTimestamp(old.GetTimestamp())
}
- rib[rf][key] = NewReceivedRoute(path, false)
+ rib[rf][key] = path
}
}
}
@@ -454,10 +454,10 @@ func (adj *AdjRib) UpdateOut(pathList []*Path) {
adj.update(adj.adjRibOut, pathList)
}
-func (adj *AdjRib) getPathList(rib map[string]*ReceivedRoute) []*Path {
+func (adj *AdjRib) getPathList(rib map[string]*Path) []*Path {
pathList := make([]*Path, 0, len(rib))
for _, rr := range rib {
- pathList = append(pathList, rr.path)
+ pathList = append(pathList, rr)
}
return pathList
}
@@ -493,25 +493,7 @@ func (adj *AdjRib) GetOutCount(rf bgp.RouteFamily) int {
func (adj *AdjRib) DropAll(rf bgp.RouteFamily) {
if _, ok := adj.adjRibIn[rf]; ok {
// replace old one
- adj.adjRibIn[rf] = make(map[string]*ReceivedRoute)
- adj.adjRibOut[rf] = make(map[string]*ReceivedRoute)
+ adj.adjRibIn[rf] = make(map[string]*Path)
+ adj.adjRibOut[rf] = make(map[string]*Path)
}
}
-
-type ReceivedRoute struct {
- path *Path
- filtered bool
-}
-
-func (rr *ReceivedRoute) String() string {
- return rr.path.getPrefix()
-}
-
-func NewReceivedRoute(path *Path, filtered bool) *ReceivedRoute {
-
- rroute := &ReceivedRoute{
- path: path,
- filtered: filtered,
- }
- return rroute
-}