mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-20 13:24:09 -07:00
Full and clearer implementation of GitHub issue #588
This commit is contained in:
parent
b92ef67e56
commit
395d8b3139
4 changed files with 77 additions and 6 deletions
|
@ -278,6 +278,13 @@ public:
|
|||
b.append((uint32_t)rules[i].v.tag.id);
|
||||
b.append((uint32_t)rules[i].v.tag.value);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_INTEGER_RANGE:
|
||||
b.append((uint8_t)19);
|
||||
b.append((uint64_t)rules[i].v.intRange.start);
|
||||
b.append((uint64_t)(rules[i].v.intRange.start + (uint64_t)rules[i].v.intRange.end)); // more future-proof
|
||||
b.append((uint16_t)rules[i].v.intRange.idx);
|
||||
b.append((uint8_t)rules[i].v.intRange.format);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -366,6 +373,12 @@ public:
|
|||
rules[ruleCount].v.tag.id = b.template at<uint32_t>(p);
|
||||
rules[ruleCount].v.tag.value = b.template at<uint32_t>(p + 4);
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_INTEGER_RANGE:
|
||||
rules[ruleCount].v.intRange.start = b.template at<uint64_t>(p);
|
||||
rules[ruleCount].v.intRange.end = (uint32_t)(b.template at<uint64_t>(p + 8) - rules[ruleCount].v.intRange.start);
|
||||
rules[ruleCount].v.intRange.idx = b.template at<uint16_t>(p + 16);
|
||||
rules[ruleCount].v.intRange.format = (uint8_t)b[p + 18];
|
||||
break;
|
||||
}
|
||||
p += fieldLen;
|
||||
++ruleCount;
|
||||
|
|
|
@ -493,6 +493,35 @@ static _doZtFilterResult _doZtFilter(
|
|||
}
|
||||
}
|
||||
} break;
|
||||
case ZT_NETWORK_RULE_MATCH_INTEGER_RANGE: {
|
||||
uint64_t integer = 0;
|
||||
const unsigned int bits = (rules[rn].v.intRange.format & 63) + 1;
|
||||
const unsigned int bytes = ((bits + 8 - 1) / 8); // integer ceiling of division by 8
|
||||
if ((rules[rn].v.intRange.format & 0x80) == 0) {
|
||||
// Big-endian
|
||||
unsigned int idx = rules[rn].v.intRange.idx + (8 - bytes);
|
||||
const unsigned int eof = idx + bytes;
|
||||
if (eof <= frameLen) {
|
||||
while (idx < eof) {
|
||||
integer <<= 8;
|
||||
integer |= frameData[idx++];
|
||||
}
|
||||
}
|
||||
integer &= 0xffffffffffffffffULL >> (64 - bits);
|
||||
} else {
|
||||
// Little-endian
|
||||
unsigned int idx = rules[rn].v.intRange.idx;
|
||||
const unsigned int eof = idx + bytes;
|
||||
if (eof <= frameLen) {
|
||||
while (idx < eof) {
|
||||
integer >>= 8;
|
||||
integer |= ((uint64_t)frameData[idx++]) << 56;
|
||||
}
|
||||
}
|
||||
integer >>= (64 - bits);
|
||||
}
|
||||
thisRuleMatches = (uint8_t)((integer >= rules[rn].v.intRange.start)&&(integer <= (rules[rn].v.intRange.start + (uint64_t)rules[rn].v.intRange.end)));
|
||||
} break;
|
||||
|
||||
// The result of an unsupported MATCH is configurable at the network
|
||||
// level via a flag.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue