From aeec7dae36cae6c6825f47e089d6b726b0cbef40 Mon Sep 17 00:00:00 2001 From: Andrej Binder Date: Wed, 15 Dec 2021 22:22:02 +0100 Subject: [PATCH] Prevent arithmetic error on interface change. --- node/Bond.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/node/Bond.cpp b/node/Bond.cpp index c88f22170..f74d4a570 100644 --- a/node/Bond.cpp +++ b/node/Bond.cpp @@ -488,6 +488,10 @@ int32_t Bond::generateQoSPacket(int pathIdx, int64_t now, char* qosBuffer) bool Bond::assignFlowToBondedPath(SharedPtr& flow, int64_t now) { + if (! _numBondedPaths) { + log("unable to assign flow %x (bond has no links)\n", flow->id); + return false; + } unsigned int idx = ZT_MAX_PEER_NETWORK_PATHS; if (_policy == ZT_BOND_POLICY_BALANCE_XOR) { idx = abs((int)(flow->id % (_numBondedPaths))); @@ -500,10 +504,6 @@ bool Bond::assignFlowToBondedPath(SharedPtr& flow, int64_t now) if (_totalBondUnderload) { entropy %= _totalBondUnderload; } - if (! _numBondedPaths) { - log("unable to assign flow %x (bond has no links)\n", flow->id); - return false; - } /* Since there may be scenarios where a path is removed before we can re-estimate relative qualities (and thus allocations) we need to down-modulate the entropy value that we use to randomly assign among the surviving paths, otherwise we risk