From 45f6071e43f8857ea07205a513942eefbc02845b Mon Sep 17 00:00:00 2001
From: Maximilian Wilhelm <max@sdn.clinic>
Date: Tue, 26 Jun 2018 21:49:50 +0200
Subject: [PATCH] AddPath capability related code path should only used when
 capability is present

  This code previously failed to remove and therefore withdraw routes from
  non AddPathRX capable neighbors as there could no PathID be found for them.

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
---
 routingtable/adjRIBOut/adj_rib_out.go | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/routingtable/adjRIBOut/adj_rib_out.go b/routingtable/adjRIBOut/adj_rib_out.go
index d55f98e1..e211479b 100644
--- a/routingtable/adjRIBOut/adj_rib_out.go
+++ b/routingtable/adjRIBOut/adj_rib_out.go
@@ -111,14 +111,19 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool {
 	}
 
 	a.rt.RemovePath(pfx, p)
-	pathID, err := a.pathIDManager.releasePath(p)
-	if err != nil {
-		log.Warningf("Unable to release path: %v", err)
-		return true
+
+	// If the neighbar has AddPath capabilities, try to find the PathID
+	if a.neighbor.CapAddPathRX {
+		pathID, err := a.pathIDManager.releasePath(p)
+		if err != nil {
+			log.Warningf("Unable to release path for prefix %s: %v", pfx.String(), err)
+			return true
+		}
+
+		p = p.Copy()
+		p.BGPPath.PathIdentifier = pathID
 	}
 
-	p = p.Copy()
-	p.BGPPath.PathIdentifier = pathID
 	a.removePathFromClients(pfx, p)
 	return true
 }
-- 
GitLab