From 5ac553e19377ec7857218b4e6537eb42da673025 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Sun, 15 Nov 2015 12:34:50 +0200 Subject: [PATCH] Use NetmaskTree in NetmaskGroup --- pdns/iputils.hh | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 97a02c171..ddc841416 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -699,11 +699,7 @@ public: bool match(const ComboAddress *ip) const { - for(container_t::const_iterator i=d_masks.begin();i!=d_masks.end();++i) - if(i->match(ip) || (ip->isMappedIPv4() && i->match(ip->mapToIPv4()) )) - return true; - - return false; + return tree.match(*ip); } bool match(const ComboAddress& ip) const @@ -714,46 +710,45 @@ public: //! Add this string to the list of possible matches void addMask(const string &ip) { - d_masks.push_back(Netmask(ip)); + addMask(Netmask(ip)); } //! Add this Netmask to the list of possible matches void addMask(const Netmask& nm) { - d_masks.push_back(nm); + tree.insert(nm); } void clear() { - d_masks.clear(); + tree.clear(); } - bool empty() + bool empty() const { - return d_masks.empty(); + return tree.empty(); } - unsigned int size() + size_t size() const { - return (unsigned int)d_masks.size(); + return tree.size(); } string toString() const { ostringstream str; - for(container_t::const_iterator iter = d_masks.begin(); iter != d_masks.end(); ++iter) { - if(iter != d_masks.begin()) + for(auto iter = tree.begin(); iter != tree.end(); ++iter) { + if(iter != tree.begin()) str <<", "; - str<toString(); + str<<(*iter)->first.toString(); } return str.str(); } void toStringVector(vector* vec) const { - for(container_t::const_iterator iter = d_masks.begin(); iter != d_masks.end(); ++iter) { - vec->push_back(iter->toString()); - } + for(auto iter = tree.begin(); iter != tree.end(); ++iter) + vec->push_back((*iter)->first.toString()); } void toMasks(const string &ips) @@ -766,8 +761,7 @@ public: } private: - typedef vector container_t; - container_t d_masks; + NetmaskTree tree; }; -- 2.40.0