summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/peer.go5
-rw-r--r--table/path.go21
-rw-r--r--table/table_manager.go16
-rw-r--r--table/table_manager_test.go2
4 files changed, 30 insertions, 14 deletions
diff --git a/server/peer.go b/server/peer.go
index ab80e9bf..4dbc6c73 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -84,6 +84,7 @@ func (peer *Peer) handlePeermessage(m *message) {
pList, wList, _ := peer.rib.ProcessPaths(m.data.([]table.Path))
// TODO: merge multiple messages
// TODO: 4bytes and 2bytes conversion.
+ adjPathLists := append([]table.Path(nil), pList...)
msgs := make([]*bgp.BGPMessage, 0)
for _, p := range pList {
@@ -98,8 +99,12 @@ func (peer *Peer) handlePeermessage(m *message) {
draw := p.GetNlri().(*bgp.WithdrawnRoute)
m := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{*draw}, []bgp.PathAttributeInterface{}, []bgp.NLRInfo{})
msgs = append(msgs, m)
+
+ adjPathLists = append(adjPathLists, p.Clone(true))
}
+ peer.adjRib.UpdateOut(adjPathLists)
+
for _, m := range msgs {
peer.outgoing <- m
}
diff --git a/table/path.go b/table/path.go
index 846c7e16..4ef9c070 100644
--- a/table/path.go
+++ b/table/path.go
@@ -39,7 +39,7 @@ type Path interface {
getPrefix() net.IP
setMedSetByTargetNeighbor(medSetByTargetNeighbor bool)
getMedSetByTargetNeighbor() bool
- Clone() Path
+ Clone(IsWithdraw bool) Path
}
type PathDefault struct {
@@ -74,15 +74,18 @@ func NewPathDefault(rf RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterfa
}
// create new PathAttributes
-func (pd *PathDefault) Clone() Path {
- copiedAttrs := append([]bgp.PathAttributeInterface(nil), pd.pathAttrs...)
- for i, attr := range copiedAttrs {
- t, v := reflect.TypeOf(attr), reflect.ValueOf(attr)
- newAttrObjp := reflect.New(t.Elem())
- newAttrObjp.Elem().Set(v.Elem())
- copiedAttrs[i] = newAttrObjp.Interface().(bgp.PathAttributeInterface)
+func (pd *PathDefault) Clone(isWithdraw bool) Path {
+ copiedAttrs := []bgp.PathAttributeInterface(nil)
+ if !isWithdraw {
+ copiedAttrs = append(copiedAttrs, pd.pathAttrs...)
+ for i, attr := range copiedAttrs {
+ t, v := reflect.TypeOf(attr), reflect.ValueOf(attr)
+ newAttrObjp := reflect.New(t.Elem())
+ newAttrObjp.Elem().Set(v.Elem())
+ copiedAttrs[i] = newAttrObjp.Interface().(bgp.PathAttributeInterface)
+ }
}
- return CreatePath(pd.source, pd.nlri, copiedAttrs, pd.withdraw)
+ return CreatePath(pd.source, pd.nlri, copiedAttrs, isWithdraw)
}
func (pd *PathDefault) getRouteFamily() RouteFamily {
diff --git a/table/table_manager.go b/table/table_manager.go
index 7a913b6d..0967f5d1 100644
--- a/table/table_manager.go
+++ b/table/table_manager.go
@@ -336,21 +336,29 @@ func NewAdjRib() *AdjRib {
return r
}
-func (adj *AdjRib) UpdateIn(pathList []Path) {
+func (adj *AdjRib) update(rib map[RouteFamily]map[string]*ReceivedRoute, pathList []Path) {
for _, path := range pathList {
rf := path.getRouteFamily()
key := path.getPrefix().String()
if path.isWithdraw() {
- _, found := adj.adjRibIn[rf][key]
+ _, found := rib[rf][key]
if found {
- delete(adj.adjRibIn[rf], key)
+ delete(rib[rf], key)
}
} else {
- adj.adjRibIn[rf][key] = NewReceivedRoute(path, false)
+ rib[rf][key] = NewReceivedRoute(path, false)
}
}
}
+func (adj *AdjRib) UpdateIn(pathList []Path) {
+ adj.update(adj.adjRibIn, pathList)
+}
+
+func (adj *AdjRib) UpdateOut(pathList []Path) {
+ adj.update(adj.adjRibOut, pathList)
+}
+
type ReceivedRoute struct {
path Path
filtered bool
diff --git a/table/table_manager_test.go b/table/table_manager_test.go
index 8c9a8ab4..f3a146a9 100644
--- a/table/table_manager_test.go
+++ b/table/table_manager_test.go
@@ -2250,7 +2250,7 @@ func TestModifyPathAttribute(t *testing.T) {
assert.NoError(t, err)
path0 := pList[0]
- path1 := path0.Clone()
+ path1 := path0.Clone(false)
_, attr1 := path1.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
mx1 := attr1.(*bgp.PathAttributeMultiExitDisc)