diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-12-20 13:37:48 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-12-20 13:37:48 +0900 |
commit | eaef2a30aa9720848387819fc9daf21ec1f2b8f0 (patch) | |
tree | 8da242ac3cd330686aede6023a28754827781a42 /table | |
parent | a44dd5d4116b7b42b5e97b268d30fc7904c25b77 (diff) |
table: fix converting 2bytes to 4bytes AS PATH
On some conditions, we add some ASes to As4PathParam.AS but don't
update As4PathParam.Num (the number of ASes). It breaks serialization
of AS4PathParam.
Instead of modifying the internal of As4PathParam, let's create a new
As4PathParam object.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/message.go | 10 | ||||
-rw-r--r-- | table/message_test.go | 44 |
2 files changed, 48 insertions, 6 deletions
diff --git a/table/message.go b/table/message.go index 0e4acc7d..0909d08f 100644 --- a/table/message.go +++ b/table/message.go @@ -169,8 +169,7 @@ func UpdatePathAttrs4ByteAs(msg *bgp.BGPUpdate) error { keepNum -= param.ASLen() } else { // only SEQ param reaches here - param.AS = param.AS[:keepNum] - newParams = append(newParams, param) + newParams = append(newParams, bgp.NewAs4PathParam(param.Type, param.AS[:keepNum])) keepNum = 0 } @@ -183,11 +182,10 @@ func UpdatePathAttrs4ByteAs(msg *bgp.BGPUpdate) error { lastParam := newParams[len(newParams)-1] if param.Type == lastParam.Type && param.Type == bgp.BGP_ASPATH_ATTR_TYPE_SEQ { if len(lastParam.AS)+len(param.AS) > 255 { - lastParam.AS = append(lastParam.AS, param.AS[:255-len(lastParam.AS)]...) - param.AS = param.AS[255-len(lastParam.AS):] - newParams = append(newParams, param) + newParams[len(newParams)-1] = bgp.NewAs4PathParam(param.Type, append(lastParam.AS, param.AS[:255-len(lastParam.AS)]...)) + newParams = append(newParams, bgp.NewAs4PathParam(param.Type, param.AS[255-len(lastParam.AS):])) } else { - lastParam.AS = append(lastParam.AS, param.AS...) + newParams[len(newParams)-1] = bgp.NewAs4PathParam(param.Type, append(lastParam.AS, param.AS...)) } } else { newParams = append(newParams, param) diff --git a/table/message_test.go b/table/message_test.go index 81e70c9c..f7cb6f5e 100644 --- a/table/message_test.go +++ b/table/message_test.go @@ -327,6 +327,50 @@ func TestAsPathAs4TransInvalid4(t *testing.T) { assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[4], uint32(40001)) } +func TestASPathAs4TransMultipleParams(t *testing.T) { + as1 := []uint16{17676, 2914, 174, 50607} + as2 := []uint16{bgp.AS_TRANS, bgp.AS_TRANS} + params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as1), bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as2)} + aspath := bgp.NewPathAttributeAsPath(params) + + as41 := []uint32{2914, 174, 50607} + as42 := []uint32{198035, 198035} + as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as41) + as4param2 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as42) + param4s := []*bgp.As4PathParam{as4param1, as4param2} + as4path := bgp.NewPathAttributeAs4Path(param4s) + msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path}, nil).Body.(*bgp.BGPUpdate) + UpdatePathAttrs4ByteAs(msg) + for _, param := range msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value { + p := param.(*bgp.As4PathParam) + assert.Equal(t, p.Num, uint8(len(p.AS))) + } +} + +func TestASPathAs4TransMultipleLargeParams(t *testing.T) { + as1 := make([]uint16, 0, 255) + for i := 0; i < 255-5; i++ { + as1 = append(as1, uint16(i+1)) + } + as1 = append(as1, []uint16{17676, 2914, 174, 50607}...) + as2 := []uint16{bgp.AS_TRANS, bgp.AS_TRANS} + params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as1), bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as2)} + aspath := bgp.NewPathAttributeAsPath(params) + + as41 := []uint32{2914, 174, 50607} + as42 := []uint32{198035, 198035} + as4param1 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as41) + as4param2 := bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as42) + param4s := []*bgp.As4PathParam{as4param1, as4param2} + as4path := bgp.NewPathAttributeAs4Path(param4s) + msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path}, nil).Body.(*bgp.BGPUpdate) + UpdatePathAttrs4ByteAs(msg) + for _, param := range msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value { + p := param.(*bgp.As4PathParam) + assert.Equal(t, p.Num, uint8(len(p.AS))) + } +} + func TestAggregator4BytesASes(t *testing.T) { getAggr := func(msg *bgp.BGPUpdate) *bgp.PathAttributeAggregator { for _, attr := range msg.PathAttributes { |