diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-03-20 13:57:26 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-04-03 08:32:46 +0900 |
commit | 3645e7dee68faff9bd4fbadbb47dc89ecd06058a (patch) | |
tree | ef5414421a1aaf4b20d773707e69e1d3bfd36856 /packet/bgp/helper.go | |
parent | b41d6b810b7658e503fa7f6fd0bf8571d0c83957 (diff) |
packet/bgp: Avoid data races when serializing
Because "Serialize()" functions of NLRIs or PathAttributes can be called
from some different goroutines, updating fields of a structure can cause
data races.
This patch moves the normalization for each field (mostly length and
flags calculation) into "NewXxx()" or "DecodeFromBytes()" and avoids the
data races.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'packet/bgp/helper.go')
-rw-r--r-- | packet/bgp/helper.go | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/packet/bgp/helper.go b/packet/bgp/helper.go index 5271a70c..34648b2d 100644 --- a/packet/bgp/helper.go +++ b/packet/bgp/helper.go @@ -119,13 +119,7 @@ func NewTestBGPUpdateMessage() *BGPMessage { NewPathAttributeMpUnreachNLRI(prefixes1), //NewPathAttributeMpReachNLRI("112.22.2.0", []AddrPrefixInterface{}), //NewPathAttributeMpUnreachNLRI([]AddrPrefixInterface{}), - &PathAttributeUnknown{ - PathAttribute: PathAttribute{ - Flags: BGP_ATTR_FLAG_TRANSITIVE, - Type: 100, - }, - Value: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, - }, + NewPathAttributeUnknown(BGP_ATTR_FLAG_TRANSITIVE, 100, []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}), } n := []*IPAddrPrefix{NewIPAddrPrefix(24, "13.2.3.1")} return NewBGPUpdateMessage(w, p, n) |