From 14b7bebfde4505b00701451427d6271cc266163b Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Tue, 24 Aug 2021 15:01:00 -0400 Subject: pkg/packet/bgp: add mutex to PrefixDefault to avoid data race Signed-off-by: Matt Layher --- pkg/packet/bgp/bgp.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/packet/bgp/bgp.go b/pkg/packet/bgp/bgp.go index ac7b77d2..c46bc878 100644 --- a/pkg/packet/bgp/bgp.go +++ b/pkg/packet/bgp/bgp.go @@ -28,6 +28,7 @@ import ( "sort" "strconv" "strings" + "sync" ) type MarshallingOption struct { @@ -1229,23 +1230,36 @@ func LabelString(nlri AddrPrefixInterface) string { } type PrefixDefault struct { + mu sync.Mutex id uint32 localId uint32 } func (p *PrefixDefault) PathIdentifier() uint32 { + p.mu.Lock() + defer p.mu.Unlock() + return p.id } func (p *PrefixDefault) SetPathIdentifier(id uint32) { + p.mu.Lock() + defer p.mu.Unlock() + p.id = id } func (p *PrefixDefault) PathLocalIdentifier() uint32 { + p.mu.Lock() + defer p.mu.Unlock() + return p.localId } func (p *PrefixDefault) SetPathLocalIdentifier(id uint32) { + p.mu.Lock() + defer p.mu.Unlock() + p.localId = id } -- cgit v1.2.3