]> granicus.if.org Git - pdns/commitdiff
Use NetmaskTree<bool> in NetmaskGroup
authorAki Tuomi <cmouse@desteem.org>
Sun, 15 Nov 2015 10:34:50 +0000 (12:34 +0200)
committerAki Tuomi <cmouse@desteem.org>
Tue, 17 Nov 2015 18:28:49 +0000 (20:28 +0200)
pdns/iputils.hh

index 97a02c171a7790a52f0b06a743b9fa3bedeeefb4..ddc84141638ef7b26dd671011c4bce8c5b6df291 100644 (file)
@@ -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<<iter->toString();
+      str<<(*iter)->first.toString();
     }
     return str.str();
   }
 
   void toStringVector(vector<string>* 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<Netmask> container_t;
-  container_t d_masks;
+  NetmaskTree<bool> tree;
 };