diff --git a/protocols/bgp/packet/nlri.go b/protocols/bgp/packet/nlri.go index bd55739c034a9a368ca129101ddc4308d897a8c4..526ab712fdd85b360fad0891913a2b99129de848 100644 --- a/protocols/bgp/packet/nlri.go +++ b/protocols/bgp/packet/nlri.go @@ -12,7 +12,7 @@ import ( ) const ( - pathIdentifierLen = 4 + PathIdentifierLen = 4 ) // NLRI represents a Network Layer Reachability Information @@ -63,7 +63,7 @@ func decodeNLRI(buf *bytes.Buffer, afi uint16, addPath bool) (*NLRI, uint8, erro return nil, consumed, errors.Wrap(err, "Unable to decode path identifier") } - consumed += pathIdentifierLen + consumed += PathIdentifierLen } pfxLen, err := buf.ReadByte() diff --git a/protocols/bgp/server/update_sender.go b/protocols/bgp/server/update_sender.go index a113069e8a578e8f5ef1f31571b0d34b1225aedf..86c7601dc70097b68b78784bfcdd794d9a2da9d6 100644 --- a/protocols/bgp/server/update_sender.go +++ b/protocols/bgp/server/update_sender.go @@ -117,11 +117,8 @@ func (u *UpdateSender) sender(aggrTime time.Duration) { } u.toSendMu.Lock() - - overhead := u.updateOverhead() - for key, pathNLRIs := range u.toSend { - budget = packet.MaxLen - packet.HeaderLen - packet.MinUpdateLen - int(pathNLRIs.path.BGPPath.Length()) - overhead + budget = u.getBudget(pathNLRIs) pathAttrs, err = packet.PathAttributes(pathNLRIs.path, u.iBGP, u.rrClient) if err != nil { @@ -135,13 +132,13 @@ func (u *UpdateSender) sender(aggrTime time.Duration) { budget -= int(packet.BytesInAddr(pfx.Pfxlen())) + 1 if u.options.UseAddPath { - budget -= 4 + budget -= packet.PathIdentifierLen } if budget < 0 { updatesPrefixes = append(updatesPrefixes, prefixes) prefixes = make([]*bnet.Prefix, 0, 1) - budget = packet.MaxLen - int(pathNLRIs.path.BGPPath.Length()) - overhead + budget = u.getBudget(pathNLRIs) } prefixes = append(prefixes, pfx) @@ -160,6 +157,10 @@ func (u *UpdateSender) sender(aggrTime time.Duration) { } } +func (u *UpdateSender) getBudget(pathNLRIs *pathPfxs) int { + return packet.MaxLen - packet.HeaderLen - packet.MinUpdateLen - int(pathNLRIs.path.BGPPath.Length()) - u.updateOverhead() +} + func (u *UpdateSender) updateOverhead() int { if u.addressFamily.afi == packet.IPv4AFI && !u.addressFamily.multiProtocol { return 0