diff options
-rw-r--r-- | server/peer.go | 6 | ||||
-rw-r--r-- | server/server.go | 14 | ||||
-rw-r--r-- | table/destination.go | 2 | ||||
-rw-r--r-- | table/path.go | 24 | ||||
-rw-r--r-- | table/policy.go | 14 |
5 files changed, 27 insertions, 33 deletions
diff --git a/server/peer.go b/server/peer.go index c4e09617..ef08a4d8 100644 --- a/server/peer.go +++ b/server/peer.go @@ -105,13 +105,17 @@ func (peer *Peer) getAccepted(rfList []bgp.RouteFamily) []*table.Path { func (peer *Peer) getBestFromLocal(rfList []bgp.RouteFamily) ([]*table.Path, []*table.Path) { pathList := []*table.Path{} filtered := []*table.Path{} + options := &table.PolicyOptions{ + Neighbor: peer.fsm.peerInfo.Address, + } for _, path := range peer.localRib.GetBestPathList(peer.TableID(), rfList) { - p := peer.policy.ApplyPolicy(peer.TableID(), table.POLICY_DIRECTION_EXPORT, filterpath(peer, path), nil) + p := peer.policy.ApplyPolicy(peer.TableID(), table.POLICY_DIRECTION_EXPORT, filterpath(peer, path), options) if p == nil { filtered = append(filtered, path) continue } if !peer.isRouteServerClient() { + p = p.Clone(p.IsWithdraw) p.UpdatePathAttrs(&peer.gConf, &peer.conf) } pathList = append(pathList, p) diff --git a/server/server.go b/server/server.go index 7c18f088..bdf8988a 100644 --- a/server/server.go +++ b/server/server.go @@ -556,7 +556,7 @@ func filterpath(peer *Peer, path *table.Path) *table.Path { if !peer.isRouteServerClient() && isASLoop(peer, path) { return nil } - return path.Clone(peer.fsm.peerInfo.Address, path.IsWithdraw) + return path } func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg { @@ -765,6 +765,7 @@ func (server *BgpServer) propagateUpdate(peer *Peer, pathList []*table.Path) ([] msgs := make([]*SenderMsg, 0) rib := server.globalRib var alteredPathList []*table.Path + options := &table.PolicyOptions{} if peer != nil && peer.isRouteServerClient() { for _, path := range pathList { path.Filter(peer.ID(), table.POLICY_DIRECTION_IMPORT) @@ -783,8 +784,9 @@ func (server *BgpServer) propagateUpdate(peer *Peer, pathList []*table.Path) ([] continue } sendPathList := make([]*table.Path, 0, len(dsts)) + options.Neighbor = targetPeer.fsm.peerInfo.Address for _, dst := range dsts { - path := server.policy.ApplyPolicy(targetPeer.TableID(), table.POLICY_DIRECTION_EXPORT, filterpath(targetPeer, dst.NewFeed(targetPeer.TableID())), nil) + path := server.policy.ApplyPolicy(targetPeer.TableID(), table.POLICY_DIRECTION_EXPORT, filterpath(targetPeer, dst.NewFeed(targetPeer.TableID())), options) if path != nil { sendPathList = append(sendPathList, path) } @@ -818,9 +820,11 @@ func (server *BgpServer) propagateUpdate(peer *Peer, pathList []*table.Path) ([] } pathList := make([]*table.Path, len(sendPathList)) copy(pathList, sendPathList) + options.Neighbor = targetPeer.fsm.peerInfo.Address for idx, path := range pathList { - path = server.policy.ApplyPolicy(table.GLOBAL_RIB_NAME, table.POLICY_DIRECTION_EXPORT, filterpath(targetPeer, path), nil) + path = server.policy.ApplyPolicy(table.GLOBAL_RIB_NAME, table.POLICY_DIRECTION_EXPORT, filterpath(targetPeer, path), options) if path != nil { + path = path.Clone(path.IsWithdraw) path.UpdatePathAttrs(&server.bgpConfig.Global, &targetPeer.conf) } pathList[idx] = path @@ -1276,7 +1280,7 @@ func (server *BgpServer) handleModPathRequest(grpcReq *GrpcRequest) []*table.Pat return nil }() if path != nil { - paths = append(paths, path.Clone(path.Owner, true)) + paths = append(paths, path.Clone(true)) } else { err = fmt.Errorf("Can't find a specified path") } @@ -1818,7 +1822,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { pathList := []*table.Path{} for _, path := range peer.adjRibIn.PathList([]bgp.RouteFamily{grpcReq.RouteFamily}, false) { if path = server.policy.ApplyPolicy(peer.ID(), table.POLICY_DIRECTION_IN, path, nil); path != nil { - pathList = append(pathList, path.Clone(net.ParseIP(peer.conf.Config.NeighborAddress), false)) + pathList = append(pathList, path.Clone(false)) } } m, _ := server.propagateUpdate(peer, pathList) diff --git a/table/destination.go b/table/destination.go index d6f1f1de..78c54ba0 100644 --- a/table/destination.go +++ b/table/destination.go @@ -258,7 +258,7 @@ func (dest *Destination) NewFeed(id string) *Path { if old == nil { return nil } - return old.Clone(old.Owner, true) + return old.Clone(true) } return best } diff --git a/table/path.go b/table/path.go index c647a7cc..10b33448 100644 --- a/table/path.go +++ b/table/path.go @@ -17,7 +17,6 @@ package table import ( "bytes" - "encoding/json" "fmt" log "github.com/Sirupsen/logrus" api "github.com/osrg/gobgp/api" @@ -61,7 +60,6 @@ type Path struct { info *originInfo IsWithdraw bool pathAttrs []bgp.PathAttributeInterface - Owner net.IP reason BestPathReason parent *Path dels []bgp.BGPAttrType @@ -78,11 +76,6 @@ func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pa return nil } - var owner net.IP - if source != nil { - owner = source.Address - } - return &Path{ info: &originInfo{ nlri: nlri, @@ -92,7 +85,6 @@ func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pa }, IsWithdraw: isWithdraw, pathAttrs: pattrs, - Owner: owner, filtered: make(map[string]PolicyDirection), } } @@ -228,11 +220,10 @@ func (path *Path) ToApiStruct(id string) *api.Path { } // create new PathAttributes -func (path *Path) Clone(owner net.IP, isWithdraw bool) *Path { +func (path *Path) Clone(isWithdraw bool) *Path { return &Path{ parent: path, IsWithdraw: isWithdraw, - Owner: owner, filtered: make(map[string]PolicyDirection), } } @@ -714,16 +705,5 @@ func (path *Path) GetClusterList() []net.IP { } func (lhs *Path) Equal(rhs *Path) bool { - if rhs == nil { - return false - } else if lhs == rhs { - return true - } - f := func(p *Path) []byte { - s := p.ToApiStruct(GLOBAL_RIB_NAME) - s.Age = 0 - buf, _ := json.Marshal(s) - return buf - } - return bytes.Equal(f(lhs), f(rhs)) + return lhs == rhs } diff --git a/table/policy.go b/table/policy.go index a8192a58..81010a9d 100644 --- a/table/policy.go +++ b/table/policy.go @@ -32,6 +32,7 @@ import ( ) type PolicyOptions struct { + Neighbor net.IP } type DefinedType int @@ -1152,19 +1153,24 @@ func (c *NeighborCondition) Option() MatchOption { // compare neighbor ipaddress of this condition and source address of path // and, subsequent comparisons are skipped if that matches the conditions. // If NeighborList's length is zero, return true. -func (c *NeighborCondition) Evaluate(path *Path, _ *PolicyOptions) bool { +func (c *NeighborCondition) Evaluate(path *Path, options *PolicyOptions) bool { if len(c.set.list) == 0 { log.Debug("NeighborList doesn't have elements") return true } - if path.Owner == nil { + neighbor := path.GetSource().Address + if options != nil && options.Neighbor != nil { + neighbor = options.Neighbor + } + + if neighbor == nil { return false } result := false for _, n := range c.set.list { - if path.Owner.Equal(n) { + if neighbor.Equal(n) { result = true break } @@ -2094,7 +2100,7 @@ func (s *Statement) Apply(path *Path, options *PolicyOptions) (RouteType, *Path) if result { if len(s.ModActions) != 0 { // apply all modification actions - path = path.Clone(path.Owner, path.IsWithdraw) + path = path.Clone(path.IsWithdraw) for _, action := range s.ModActions { path = action.Apply(path) } |