diff options
-rw-r--r-- | table/table.go | 25 | ||||
-rw-r--r-- | table/table_manager.go | 4 | ||||
-rw-r--r-- | table/vrf.go | 11 |
3 files changed, 39 insertions, 1 deletions
diff --git a/table/table.go b/table/table.go index 3bc5bb3f..0d6abd29 100644 --- a/table/table.go +++ b/table/table.go @@ -88,6 +88,31 @@ func (t *Table) deletePathsByVrf(vrf *Vrf) []*Path { if p.IsLocal() && vrf.Rd.String() == rd.String() { p.IsWithdraw = true pathList = append(pathList, p) + break + } + } + } + return pathList +} + +func (t *Table) deleteRTCPathsByVrf(vrf *Vrf, vrfs map[string]*Vrf) []*Path { + pathList := make([]*Path, 0) + if t.routeFamily != bgp.RF_RTC_UC { + return pathList + } + for _, target := range vrf.ImportRt { + lhs := target.String() + for _, dest := range t.destinations { + nlri := dest.GetNlri().(*bgp.RouteTargetMembershipNLRI) + rhs := nlri.RouteTarget.String() + if lhs == rhs && isLastTargetUser(vrfs, target) { + for _, p := range dest.GetKnownPathList() { + if p.IsLocal() { + p.IsWithdraw = true + pathList = append(pathList, p) + break + } + } } } } diff --git a/table/table_manager.go b/table/table_manager.go index b6295498..75b68b03 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -155,7 +155,7 @@ func (manager *TableManager) AddVrf(name string, rd bgp.RouteDistinguisherInterf nexthop := "0.0.0.0" for _, target := range importRt { nlri := bgp.NewRouteTargetMembershipNLRI(info.AS, target) - pattr := make([]bgp.PathAttributeInterface, 0) + pattr := make([]bgp.PathAttributeInterface, 0, 2) pattr = append(pattr, bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_IGP)) pattr = append(pattr, bgp.NewPathAttributeMpReachNLRI(nexthop, []bgp.AddrPrefixInterface{nlri})) msgs = append(msgs, NewPath(info, nlri, false, pattr, false, time.Now(), false)) @@ -180,6 +180,8 @@ func (manager *TableManager) DeleteVrf(name string) ([]*Path, error) { "ExportRt": vrf.ExportRt, }).Debugf("delete vrf") delete(manager.Vrfs, name) + rtcTable := manager.Tables[bgp.RF_RTC_UC] + msgs = append(msgs, rtcTable.deleteRTCPathsByVrf(vrf, manager.Vrfs)...) return msgs, nil } diff --git a/table/vrf.go b/table/vrf.go index 3833ecac..4474b993 100644 --- a/table/vrf.go +++ b/table/vrf.go @@ -44,3 +44,14 @@ func (v *Vrf) ToApiStruct() *api.Vrf { ExportRt: f(v.ExportRt), } } + +func isLastTargetUser(vrfs map[string]*Vrf, target bgp.ExtendedCommunityInterface) bool { + for _, vrf := range vrfs { + for _, rt := range vrf.ImportRt { + if target.String() == rt.String() { + return false + } + } + } + return true +} |