Fix custom policy parsing bug mentioned in issue #1507

This commit is contained in:
Joseph Henry 2021-12-14 11:49:43 -08:00
parent f0e824416b
commit 1c6fd4125d
No known key found for this signature in database
GPG Key ID: C45B33FF5EBC9344
3 changed files with 7 additions and 5 deletions

View File

@ -95,7 +95,6 @@ SharedPtr<Bond> Bond::createTransportTriggeredBond(const RuntimeEnvironment* ren
int64_t identity = peer->identity().address().toInt();
Bond* bond = nullptr;
if (! _bonds.count(identity)) {
std::string policyAlias;
if (! _policyTemplateAssignments.count(identity)) {
if (_defaultPolicy) {
bond = new Bond(renv, _defaultPolicy, peer);
@ -1717,6 +1716,7 @@ void Bond::setBondParameters(int policy, SharedPtr<Bond> templateBond, bool useT
/* If a user has specified custom parameters for this bonding policy, overlay them onto the defaults */
if (useTemplate) {
_policyAlias = templateBond->_policyAlias;
_policy = templateBond->policy();
_failoverInterval = templateBond->_failoverInterval >= ZT_BOND_FAILOVER_MIN_INTERVAL ? templateBond->_failoverInterval : ZT_BOND_FAILOVER_MIN_INTERVAL;
_downDelay = templateBond->_downDelay;
_upDelay = templateBond->_upDelay;

View File

@ -1000,12 +1000,12 @@ class Bond {
/**
* @param policy Bonding policy for this bond
*/
/*
inline void setPolicy(uint8_t policy)
{
_policy = policy;
}
*/
/**
* @return the current bonding policy
*/

View File

@ -1769,7 +1769,8 @@ public:
if (basePolicyStr.empty()) {
fprintf(stderr, "error: no base policy was specified for custom policy (%s)\n", customPolicyStr.c_str());
}
if (_node->bondController()->getPolicyCodeByStr(basePolicyStr) == ZT_BOND_POLICY_NONE) {
int basePolicyCode = _node->bondController()->getPolicyCodeByStr(basePolicyStr);
if (basePolicyCode == ZT_BOND_POLICY_NONE) {
fprintf(stderr, "error: custom policy (%s) is invalid, unknown base policy (%s).\n",
customPolicyStr.c_str(), basePolicyStr.c_str());
continue;
@ -1781,6 +1782,7 @@ public:
// New bond, used as a copy template for new instances
SharedPtr<Bond> newTemplateBond = new Bond(NULL, basePolicyStr, customPolicyStr, SharedPtr<Peer>());
// Acceptable ranges
newTemplateBond->setPolicy(basePolicyCode);
newTemplateBond->setMaxAcceptableLatency(OSUtils::jsonInt(customPolicy["maxAcceptableLatency"],-1));
newTemplateBond->setMaxAcceptableMeanLatency(OSUtils::jsonInt(customPolicy["maxAcceptableMeanLatency"],-1));
newTemplateBond->setMaxAcceptablePacketDelayVariance(OSUtils::jsonInt(customPolicy["maxAcceptablePacketDelayVariance"],-1));
@ -1805,7 +1807,7 @@ public:
newTemplateBond->setUpDelay(OSUtils::jsonInt(customPolicy["upDelay"],-1));
newTemplateBond->setDownDelay(OSUtils::jsonInt(customPolicy["downDelay"],-1));
newTemplateBond->setFlowRebalanceStrategy(OSUtils::jsonInt(customPolicy["flowRebalanceStrategy"],(uint64_t)0));
newTemplateBond->setFailoverInterval(OSUtils::jsonInt(customPolicy["failoverInterval"],(uint64_t)0));
newTemplateBond->setFailoverInterval(OSUtils::jsonInt(customPolicy["failoverInterval"],ZT_BOND_FAILOVER_DEFAULT_INTERVAL));
newTemplateBond->setPacketsPerLink(OSUtils::jsonInt(customPolicy["packetsPerLink"],-1));
// Policy-Specific link set