Abstract & simplify logic

pull/1795/head
Jason Rhinelander 3 years ago
parent 711038d150
commit 687b54f860

@ -1077,11 +1077,7 @@ namespace llarp
service::Address addr{};
for (const auto& [range, exitAddr] : exitEntries)
{
if (
// we permit this because it matches our rules and we allow bogons:
(range.BogonRange() and range.Contains(dst))
// allow because the destination is not a bogon and the mapped range is not a bogon
or not IsBogon(dst))
if (not IsBogon(dst) or range.BogonContains(dst))
{
addr = exitAddr;
}
@ -1274,7 +1270,7 @@ namespace llarp
bool allow = false;
for (const auto& [range, exitAddr] : mapped)
{
if ((range.BogonRange() and range.Contains(src)) or not IsBogon(src))
if (not IsBogon(src) or range.BogonContains(src))
{
// allow if this address matches the endpoint we think it should be
allow = exitAddr == fromAddr;

@ -52,6 +52,14 @@ namespace llarp
return IsBogon(addr) or IsBogon(HighestAddr());
}
/// return true if we intersect with a bogon range *and* we contain the given address
template <typename Addr>
bool
BogonContains(Addr&& addr) const
{
return BogonRange() and Contains(std::forward<Addr>(addr));
}
/// return the number of bits set in the hostmask
constexpr int
HostmaskBits() const

Loading…
Cancel
Save