diff options
-rw-r--r-- | server/peer.go | 9 | ||||
-rw-r--r-- | table/path.go | 17 |
2 files changed, 26 insertions, 0 deletions
diff --git a/server/peer.go b/server/peer.go index d56e3e34..d7c3ac07 100644 --- a/server/peer.go +++ b/server/peer.go @@ -551,6 +551,15 @@ func (peer *Peer) sendUpdateMsgFromPaths(pList []table.Path) { continue } + if peer.peerConfig.PeerAs == path.GetSourceAs() { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": peer.peerConfig.NeighborAddress, + "Data": path, + }).Debug("AS PATH loop, ignore.") + continue + } + if !path.IsWithdraw() { applied, path := peer.applyPolicies(peer.exportPolicies, path) if applied && path == nil { diff --git a/table/path.go b/table/path.go index 62a98aab..29d8a92d 100644 --- a/table/path.go +++ b/table/path.go @@ -35,6 +35,7 @@ type Path interface { GetRouteFamily() bgp.RouteFamily setSource(source *PeerInfo) GetSource() *PeerInfo + GetSourceAs() uint32 GetNexthop() net.IP SetNexthop(net.IP) setWithdraw(withdraw bool) @@ -224,6 +225,22 @@ func (pd *PathDefault) GetSource() *PeerInfo { return pd.source } +func (pd *PathDefault) GetSourceAs() uint32 { + _, attr := pd.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) + if attr != nil { + asPathParam := attr.(*bgp.PathAttributeAsPath).Value + if len(asPathParam) == 0 { + return 0 + } + asPath := asPathParam[len(asPathParam)-1].(*bgp.As4PathParam) + if asPath.Num == 0 { + return 0 + } + return asPath.AS[asPath.Num-1] + } + return 0 +} + func (pd *PathDefault) GetNexthop() net.IP { _, attr := pd.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP) if attr != nil { |