diff --git a/common/iputils.hh b/common/iputils.hh index 8c199748..1d388bb2 100644 --- a/common/iputils.hh +++ b/common/iputils.hh @@ -722,13 +722,31 @@ public: return ret; } - //left || node->right || node->node6 || node->node4)) { + // get parent node ptr + TreeNode* parent = node->parent; + // delete this node + if (parent) { + if (parent->left.get() == node) + parent->left.reset(); + else + parent->right.reset(); + // now recurse up to the parent + cleanup_tree(parent); + } + } + } + + // addr(be32toh(key.getNetwork().sin4.sin_addr.s_addr)); @@ -750,6 +768,7 @@ public: it++; } node->node4.reset(); + if (cleanup) cleanup_tree(node); } } else { uint64_t* addr = (uint64_t*)key.getNetwork().sin6.sin6_addr.s6_addr; @@ -775,6 +794,7 @@ public: it++; } node->node6.reset(); + if (cleanup) cleanup_tree(node); } } } @@ -839,6 +859,21 @@ public: return match(&ip); } + bool lookup(const ComboAddress* ip, Netmask* nmp) const + { + const auto &ret = tree.lookup(*ip); + if (ret) { + if (nmp) *nmp = ret->first; + return ret->second; + } + return false; + } + + bool lookup(const ComboAddress& ip, Netmask* nmp) const + { + return lookup(&ip, nmp); + } + //! Add this string to the list of possible matches void addMask(const std::string &ip, bool positive=true) { @@ -855,6 +890,18 @@ public: tree.insert(nm).second=positive; } + //! Delete this Netmask from the list of possible matches + void deleteMask(const Netmask& nm) + { + tree.erase(nm, true); + } + + void deleteMask(const std::string& ip) + { + if (!ip.empty()) + deleteMask(Netmask(ip)); + } + void clear() { tree.clear();