]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add bunch of netmask/netmaskgroup tests
authorbert hubert <bert.hubert@netherlabs.nl>
Tue, 7 May 2013 11:55:27 +0000 (13:55 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Tue, 7 May 2013 11:55:27 +0000 (13:55 +0200)
pdns/iputils.hh
pdns/test-iputils_hh.cc

index 312f68ad8288cebf57e0980bf0b916aaec9f6c07..8619eaeaa76177da072bd63140c40eb13f10f137 100644 (file)
@@ -318,6 +318,7 @@ class NetmaskGroup
 {
 public:
   //! If this IP address is matched by any of the classes within
+
   bool match(const ComboAddress *ip)
   {
     for(container_t::const_iterator i=d_masks.begin();i!=d_masks.end();++i)
@@ -326,6 +327,12 @@ public:
 
     return false;
   }
+
+  bool match(const ComboAddress& ip)
+  {
+    return match(&ip);
+  }
+
   //! Add this Netmask to the list of possible matches
   void addMask(const string &ip)
   {
index b65fb5478e19fb2c2c9b125216b767301e4decab..d3f735d2e8dbb02be406fdd4546e38de087494d0 100644 (file)
@@ -18,4 +18,48 @@ BOOST_AUTO_TEST_CASE(test_ComboAddress) {
   BOOST_CHECK(!(local == remote));
 }
 
+BOOST_AUTO_TEST_CASE(test_Netmask) {
+  ComboAddress local("127.0.0.1", 53);
+  ComboAddress remote("130.161.252.29", 53);
+  
+  Netmask nm("127.0.0.1/24");
+  BOOST_CHECK(nm.match(local));
+  BOOST_CHECK(!nm.match(remote));
+
+  Netmask nm6("fe80::92fb:a6ff:fe4a:51da/64");
+  BOOST_CHECK(nm6.match("fe80::92fb:a6ff:fe4a:51db"));
+  BOOST_CHECK(!nm6.match("fe81::92fb:a6ff:fe4a:51db"));
+
+  Netmask nmp("130.161.252.29/32");
+  BOOST_CHECK(nmp.match(remote));
+
+  Netmask nmp6("fe80::92fb:a6ff:fe4a:51da/128");
+  BOOST_CHECK(nmp6.match("fe80::92fb:a6ff:fe4a:51da"));
+  BOOST_CHECK(!nmp6.match("fe81::92fb:a6ff:fe4a:51db"));
+
+  Netmask all("0.0.0.0/0");
+  BOOST_CHECK(all.match(local) && all.match(remote));
+
+  Netmask all6("::/0");
+  BOOST_CHECK(all6.match("::1") && all6.match("fe80::92fb:a6ff:fe4a:51da"));
+}
+
+BOOST_AUTO_TEST_CASE(test_NetmaskGroup) {
+  NetmaskGroup ng;
+  ng.addMask("127.0.0.0/8");
+  ng.addMask("10.0.0.0/24");
+  BOOST_CHECK(ng.match(ComboAddress("127.0.0.1")));
+  BOOST_CHECK(ng.match(ComboAddress("10.0.0.3")));
+  BOOST_CHECK(!ng.match(ComboAddress("128.1.2.3")));
+  BOOST_CHECK(!ng.match(ComboAddress("10.0.1.0")));
+  BOOST_CHECK(!ng.match(ComboAddress("::1")));
+  ng.addMask("::1");
+  BOOST_CHECK(ng.match(ComboAddress("::1")));
+  BOOST_CHECK(!ng.match(ComboAddress("::2")));
+  ng.addMask("fe80::/16");
+  BOOST_CHECK(ng.match(ComboAddress("fe80::1")));
+  BOOST_CHECK(!ng.match(ComboAddress("fe81::1")));
+}
+
+
 BOOST_AUTO_TEST_SUITE_END()