diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-03-31 08:56:49 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-04-04 21:50:50 +0900 |
commit | 6f8db811e0958acda8dd1ea31028083abfd597e0 (patch) | |
tree | 53d365db30a8a2ea604ba325df1dd9384a333704 | |
parent | ef65699c8c8bfc2b0177a645ea9e12df097285ab (diff) |
server: clone paths before storing to adj-rib-out
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | server/peer.go | 96 | ||||
-rw-r--r-- | table/message.go | 10 |
2 files changed, 53 insertions, 53 deletions
diff --git a/server/peer.go b/server/peer.go index bfee8f49..362482a7 100644 --- a/server/peer.go +++ b/server/peer.go @@ -359,61 +359,67 @@ func (peer *Peer) handleREST(restReq *api.RestRequest) { } func (peer *Peer) sendUpdateMsgFromPaths(pList []table.Path) { - pList = table.CloneAndUpdatePathAttrs(pList, &peer.globalConfig, &peer.peerConfig) - - paths := []table.Path{} - policies := peer.exportPolicies - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": peer.peerConfig.NeighborAddress, - }).Debug("Export Policies :", policies) - for _, p := range pList { - if p.IsWithdraw() { - paths = append(paths, p) - continue - } - log.Debug("p: ", p) - if len(policies) != 0 { - applied, newPath := peer.applyPolicies(policies, p) - - if applied { - if newPath != nil { - log.Debug("path accepted") - paths = append(paths, newPath) - } else { - log.Debug("path was rejected: ", p) - } + pList = func(arg []table.Path) []table.Path { + ret := make([]table.Path, 0, len(arg)) + for _, path := range arg { + if _, ok := peer.rfMap[path.GetRouteFamily()]; !ok { + continue + } + if peer.peerConfig.NeighborAddress.Equal(path.GetSource().Address) { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": peer.peerConfig.NeighborAddress, + "Data": path, + }).Debug("From me, ignore.") + continue + } - } else { - if peer.defaultExportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { - paths = append(paths, p) - log.Debug("path is emitted by default export policy: ", p) + if !path.IsWithdraw() { + applied, path := peer.applyPolicies(peer.exportPolicies, path) + if applied && path == nil { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": peer.peerConfig.NeighborAddress, + "Data": path, + }).Debug("Export policy applied, reject.") + continue + } else if peer.defaultExportPolicy != config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": peer.peerConfig.NeighborAddress, + "Data": path, + }).Debug("Default export policy applied, reject.") + continue } } - } else { - paths = append(paths, p) + + ret = append(ret, path.Clone(path.IsWithdraw())) } + return ret + }(pList) + peer.adjRib.UpdateOut(pList) + + if bgp.FSMState(peer.peerConfig.BgpNeighborCommonState.State) != bgp.BGP_FSM_ESTABLISHED || len(pList) == 0 { + return } - peer.adjRib.UpdateOut(paths) - sendpathList := []table.Path{} - for _, p := range paths { - _, ok := peer.rfMap[p.GetRouteFamily()] + pList = func(arg []table.Path) []table.Path { + ret := make([]table.Path, 0, len(arg)) + for _, path := range pList { + isLocal := path.GetSource().ID.Equal(peer.peerInfo.LocalID) + if isLocal { + path.SetNexthop(peer.peerConfig.LocalAddress) + } else { + table.UpdatePathAttrs(path, &peer.globalConfig, &peer.peerConfig) + } - if peer.peerConfig.NeighborAddress.Equal(p.GetSource().Address) { - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": peer.peerConfig.NeighborAddress, - }).Debugf("From me. Ignore: %s", p) - ok = false + ret = append(ret, path) } + return ret + }(pList) - if ok { - sendpathList = append(sendpathList, p) - } - } - peer.sendMessages(table.CreateUpdateMsgFromPaths(sendpathList)) + peer.sendMessages(table.CreateUpdateMsgFromPaths(pList)) } // apply policies to the path diff --git a/table/message.go b/table/message.go index 7c290780..502dbd4c 100644 --- a/table/message.go +++ b/table/message.go @@ -128,14 +128,8 @@ func cloneAttrSlice(attrs []bgp.PathAttributeInterface) []bgp.PathAttributeInter return clonedAttrs } -func CloneAndUpdatePathAttrs(pathList []Path, global *config.Global, peer *config.Neighbor) []Path { - newPathList := make([]Path, 0, len(pathList)) - for _, p := range pathList { - clone := p.Clone(p.IsWithdraw()) - clone.updatePathAttrs(global, peer) - newPathList = append(newPathList, clone) - } - return newPathList +func UpdatePathAttrs(path Path, global *config.Global, peer *config.Neighbor) { + path.updatePathAttrs(global, peer) } func createUpdateMsgFromPath(path Path, msg *bgp.BGPMessage) *bgp.BGPMessage { |