summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-03-31 08:56:49 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-04-04 21:50:50 +0900
commit6f8db811e0958acda8dd1ea31028083abfd597e0 (patch)
tree53d365db30a8a2ea604ba325df1dd9384a333704 /server
parentef65699c8c8bfc2b0177a645ea9e12df097285ab (diff)
server: clone paths before storing to adj-rib-out
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/peer.go96
1 files changed, 51 insertions, 45 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