summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-08-17 17:28:18 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-19 13:29:33 +0900
commit856f867aea28dcee4d2f7b6d312cefe6808202de (patch)
tree7ff4ee7ff4ffa3b785b2f564d34ad7b89f09f610
parent2f1e599c75b3954d798d16e6c924bc38fc61dbea (diff)
vrf: withdraw route-target constraint routes when deleting a vrf
another partial implementation of RFC4686 Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--table/table.go25
-rw-r--r--table/table_manager.go4
-rw-r--r--table/vrf.go11
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
+}