From: Aki Tuomi Date: Sun, 15 Nov 2015 10:34:50 +0000 (+0200) Subject: Use NetmaskTree in NetmaskGroup X-Git-Tag: dnsdist-1.0.0-alpha1~215^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ac553e19377ec7857218b4e6537eb42da673025;p=thirdparty%2Fpdns.git Use NetmaskTree in NetmaskGroup --- diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 97a02c171a..ddc8414163 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; };