]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#628,!341] interface-id is supported by the mysql_cb.
authorMarcin Siodelski <marcin@isc.org>
Mon, 27 May 2019 12:18:16 +0000 (14:18 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 27 May 2019 14:25:50 +0000 (10:25 -0400)
src/bin/admin/tests/mysql_tests.sh.in
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc
src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
src/lib/config_backend/constants.h
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in

index 9d9e9d83bbfb07fa687ebfddd3f1781c7bb40c36..48f14363a7be36764fc6e93c6cf916db95e7753d 100644 (file)
@@ -563,7 +563,7 @@ EOF
     run_statement "dhcp6_option_def_server" "$qry"
 
     # table: dhcp6_shared_network
-    qry="select id, name, client_class, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, user_context, valid_lifetime, calculate_tee_times, t1_percent, t2_percent from dhcp6_shared_network"
+    qry="select id, name, client_class, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, user_context, valid_lifetime, calculate_tee_times, t1_percent, t2_percent, interface_id from dhcp6_shared_network"
     run_statement "dhcp6_shared_network" "$qry"
 
     # table: dhcp6_shared_network_server
@@ -571,7 +571,7 @@ EOF
     run_statement "dhcp6_shared_network" "$qry"
 
     # table: dhcp6_subnet
-    qry="select subnet_prefix, client_class, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, shared_network_name, subnet_id, user_context, valid_lifetime, calculate_tee_times, t1_percent, t2_percent from dhcp6_subnet"
+    qry="select subnet_prefix, client_class, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, shared_network_name, subnet_id, user_context, valid_lifetime, calculate_tee_times, t1_percent, t2_percent, interface_id from dhcp6_subnet"
     run_statement "dhcp6_subnet" "$qry"
 
     # table: dhcp6_subnet_server
index a15c0a838e025db67845efbc521b6b1eae6ed5e6..789ae7e06fd6c0d7abec1c409f29883e74c8b122 100644 (file)
@@ -307,6 +307,7 @@ public:
             MySqlBinding::createInteger<uint8_t>(), // calculate_tee_times
             MySqlBinding::createInteger<float>(), // t1_percent
             MySqlBinding::createInteger<float>(), // t2_percent
+            MySqlBinding::createBlob(INTERFACE_ID_BUF_LENGTH), // interface_id
             MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
         };
 
@@ -458,8 +459,18 @@ public:
                     last_subnet->setT2Percent(out_bindings[67]->getFloat());
                 }
 
+                // interface_id
+                if (!out_bindings[68]->amNull()) {
+                    auto iface_id_data = out_bindings[68]->getBlob();
+                    if (!iface_id_data.empty()) {
+                        OptionPtr opt_iface_id(new Option(Option::V6, D6O_INTERFACE_ID,
+                                                          iface_id_data));
+                        last_subnet->setInterfaceId(opt_iface_id);
+                    }
+                }
+
                 // server_tag
-                last_subnet->setServerTag(out_bindings[68]->getString());
+                last_subnet->setServerTag(out_bindings[69]->getString());
 
                 // Subnet ready. Add it to the list.
                 subnets.push_back(last_subnet);
@@ -910,6 +921,17 @@ public:
              shared_network_binding = MySqlBinding::createNull();
         }
 
+        // Create the binding holding interface_id.
+        MySqlBindingPtr interface_id_binding = MySqlBinding::createNull();
+        auto opt_iface_id = subnet->getInterfaceId();
+        if (opt_iface_id) {
+            auto iface_id_data = opt_iface_id->getData();
+            if (!iface_id_data.empty()) {
+                interface_id_binding = MySqlBinding::createBlob(iface_id_data.begin(),
+                                                                iface_id_data.end());
+            }
+        }
+
         // Create input bindings.
         MySqlBindingCollection in_bindings = {
             MySqlBinding::createInteger<uint32_t>(subnet->getID()),
@@ -929,7 +951,8 @@ public:
             createBinding(subnet->getValid(Network::Inheritance::NONE)),
             MySqlBinding::condCreateBool(subnet->getCalculateTeeTimes(Network::Inheritance::NONE)),
             MySqlBinding::condCreateFloat(subnet->getT1Percent(Network::Inheritance::NONE)),
-            MySqlBinding::condCreateFloat(subnet->getT2Percent(Network::Inheritance::NONE))
+            MySqlBinding::condCreateFloat(subnet->getT2Percent(Network::Inheritance::NONE)),
+            interface_id_binding
         };
 
         MySqlTransaction transaction(conn_);
@@ -1193,6 +1216,7 @@ public:
             MySqlBinding::createInteger<uint8_t>(), // calculate_tee_times
             MySqlBinding::createInteger<float>(), // t1_percent
             MySqlBinding::createInteger<float>(), // t2_percent
+            MySqlBinding::createBlob(INTERFACE_ID_BUF_LENGTH), // interface_id
             MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
         };
 
@@ -1314,8 +1338,18 @@ public:
                     last_network->setT2Percent(out_bindings[29]->getFloat());
                 }
 
+                // interface_id
+                if (!out_bindings[30]->amNull()) {
+                    auto iface_id_data = out_bindings[30]->getBlob();
+                    if (!iface_id_data.empty()) {
+                        OptionPtr opt_iface_id(new Option(Option::V6, D6O_INTERFACE_ID,
+                                                          iface_id_data));
+                        last_network->setInterfaceId(opt_iface_id);
+                    }
+                }
+
                 // server_tag
-                last_network->setServerTag(out_bindings[30]->getString());
+                last_network->setServerTag(out_bindings[31]->getString());
 
                 shared_networks.push_back(last_network);
             }
@@ -1425,6 +1459,17 @@ public:
             hr_mode_binding = MySqlBinding::createNull();
         }
 
+        // Create the binding holding interface_id.
+        MySqlBindingPtr interface_id_binding = MySqlBinding::createNull();
+        auto opt_iface_id = shared_network->getInterfaceId();
+        if (opt_iface_id) {
+            auto iface_id_data = opt_iface_id->getData();
+            if (!iface_id_data.empty()) {
+                interface_id_binding = MySqlBinding::createBlob(iface_id_data.begin(),
+                                                                iface_id_data.end());
+            }
+        }
+
         MySqlBindingCollection in_bindings = {
             MySqlBinding::createString(shared_network->getName()),
             MySqlBinding::condCreateString(shared_network->getClientClass(Network::Inheritance::NONE)),
@@ -1441,7 +1486,8 @@ public:
             createBinding(shared_network->getValid(Network::Inheritance::NONE)),
             MySqlBinding::condCreateBool(shared_network->getCalculateTeeTimes(Network::Inheritance::NONE)),
             MySqlBinding::condCreateFloat(shared_network->getT1Percent(Network::Inheritance::NONE)),
-            MySqlBinding::condCreateFloat(shared_network->getT2Percent(Network::Inheritance::NONE))
+            MySqlBinding::condCreateFloat(shared_network->getT2Percent(Network::Inheritance::NONE)),
+            interface_id_binding
         };
 
         MySqlTransaction transaction(conn_);
@@ -2317,8 +2363,9 @@ TaggedStatementArray tagged_statements = { {
       "  valid_lifetime,"
       "  calculate_tee_times,"
       "  t1_percent,"
-      "  t2_percent "
-      ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
+      "  t2_percent,"
+      "  interface_id"
+      ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
 
     // Insert association of the subnet with a server.
     { MySqlConfigBackendDHCPv6Impl::INSERT_SUBNET6_SERVER,
@@ -2353,8 +2400,9 @@ TaggedStatementArray tagged_statements = { {
       "  valid_lifetime,"
       "  calculate_tee_times,"
       "  t1_percent,"
-      "  t2_percent "
-      ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
+      "  t2_percent,"
+      "  interface_id"
+      ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
 
     // Insert association of the shared network with a server.
     { MySqlConfigBackendDHCPv6Impl::INSERT_SHARED_NETWORK6_SERVER,
@@ -2406,7 +2454,8 @@ TaggedStatementArray tagged_statements = { {
       "  valid_lifetime = ?,"
       "  calculate_tee_times = ?,"
       "  t1_percent = ?,"
-      "  t2_percent = ? "
+      "  t2_percent = ?,"
+      "  interface_id = ? "
       "WHERE subnet_id = ? OR subnet_prefix = ?" },
 
     // Update existing shared network.
@@ -2427,7 +2476,8 @@ TaggedStatementArray tagged_statements = { {
       "  valid_lifetime = ?,"
       "  calculate_tee_times = ?,"
       "  t1_percent = ?,"
-      "  t2_percent = ? "
+      "  t2_percent = ?,"
+      "  interface_id = ? "
       "WHERE name = ?" },
 
     // Update existing option definition.
index 9891efe0d3648b7152238f5784697f53c2dd3840..748ea3ce8c114aadea6744a9a92133cab24604a2 100644 (file)
@@ -188,6 +188,7 @@ namespace {
     "  s.calculate_tee_times," \
     "  s.t1_percent," \
     "  s.t2_percent," \
+    "  s.interface_id," \
     "  srv.tag " \
     "FROM dhcp6_subnet AS s " \
     "INNER JOIN dhcp6_subnet_server AS a " \
@@ -282,6 +283,7 @@ namespace {
     "  n.calculate_tee_times," \
     "  n.t1_percent," \
     "  n.t2_percent," \
+    "  n.interface_id," \
     "  s.tag " \
     "FROM dhcp6_shared_network AS n " \
     "INNER JOIN dhcp6_shared_network_server AS a " \
index ebef76a34ce8160e90c8b36a1613ec7b94d9471f..cceee99257b12afa141267c3bad80c14767ead17 100644 (file)
@@ -87,6 +87,8 @@ public:
         // First subnet includes all parameters.
         std::string interface_id_text = "whale";
         OptionBuffer interface_id(interface_id_text.begin(), interface_id_text.end());
+        OptionPtr opt_interface_id(new Option(Option::V6, D6O_INTERFACE_ID,
+                                              interface_id));
         ElementPtr user_context = Element::createMap();
         user_context->set("foo", Element::create("bar"));
 
@@ -94,6 +96,7 @@ public:
                                       64, 30, 40, 50, 60, 1024));
         subnet->allowClientClass("home");
         subnet->setIface("eth1");
+        subnet->setInterfaceId(opt_interface_id);
         subnet->setT2(323212);
         subnet->addRelayAddress(IOAddress("2001:db8:1::2"));
         subnet->addRelayAddress(IOAddress("2001:db8:3::4"));
@@ -206,9 +209,16 @@ public:
         ElementPtr user_context = Element::createMap();
         user_context->set("foo", Element::create("bar"));
 
+        std::string interface_id_text = "fish";
+        OptionBuffer interface_id(interface_id_text.begin(),
+                                  interface_id_text.end());
+        OptionPtr opt_interface_id(new Option(Option::V6, D6O_INTERFACE_ID,
+                                              interface_id));
+
         SharedNetwork6Ptr shared_network(new SharedNetwork6("level1"));
         shared_network->allowClientClass("foo");
         shared_network->setIface("eth1");
+        shared_network->setInterfaceId(opt_interface_id);
         shared_network->setT2(323212);
         shared_network->addRelayAddress(IOAddress("2001:db8:1::2"));
         shared_network->addRelayAddress(IOAddress("2001:db8:3::4"));
index 8cbd993ca5584e6d03049bc30bc01f40be20bf86..81a6307436a2faf936fd044e3ad9469de6e3ea94 100644 (file)
@@ -34,6 +34,8 @@ constexpr unsigned long CLIENT_CLASS_BUF_LENGTH = 128;
 
 constexpr unsigned long INTERFACE_BUF_LENGTH = 128;
 
+constexpr unsigned long INTERFACE_ID_BUF_LENGTH = 128;
+
 constexpr unsigned long RELAY_BUF_LENGTH = 65536;
 
 constexpr unsigned long REQUIRE_CLIENT_CLASSES_BUF_LENGTH = 65536;
index a18874dac7cac5c1d92bc367e0c7f6d9b3e2f746..f39e4be2c2a3d0c424dde74f8e59255420a22045 100644 (file)
@@ -1373,7 +1373,8 @@ ALTER TABLE dhcp4_shared_network
 ALTER TABLE dhcp6_subnet
     ADD COLUMN calculate_tee_times TINYINT(1) DEFAULT NULL,
     ADD COLUMN t1_percent FLOAT DEFAULT NULL,
-    ADD COLUMN t2_percent FLOAT DEFAULT NULL;
+    ADD COLUMN t2_percent FLOAT DEFAULT NULL,
+    ADD COLUMN interface_id VARBINARY(128) DEFAULT NULL;
 
 ALTER TABLE dhcp6_subnet
     MODIFY COLUMN reservation_mode TINYINT(3) DEFAULT NULL;
@@ -1384,7 +1385,8 @@ ALTER TABLE dhcp6_subnet
 ALTER TABLE dhcp6_shared_network
     ADD COLUMN calculate_tee_times TINYINT(1) DEFAULT NULL,
     ADD COLUMN t1_percent FLOAT DEFAULT NULL,
-    ADD COLUMN t2_percent FLOAT DEFAULT NULL;
+    ADD COLUMN t2_percent FLOAT DEFAULT NULL,
+    ADD COLUMN interface_id VARBINARY(128) DEFAULT NULL;
 
 ALTER TABLE dhcp6_shared_network
     MODIFY COLUMN reservation_mode TINYINT(3) DEFAULT NULL;
index 989f6778930c58cb5860f8b5814f228ad0569dd8..ec4f45acc0cd778c34d61c198226e96c122dd6ae 100644 (file)
@@ -56,7 +56,8 @@ ALTER TABLE dhcp4_shared_network
 ALTER TABLE dhcp6_subnet
     ADD COLUMN calculate_tee_times TINYINT(1) DEFAULT NULL,
     ADD COLUMN t1_percent FLOAT DEFAULT NULL,
-    ADD COLUMN t2_percent FLOAT DEFAULT NULL;
+    ADD COLUMN t2_percent FLOAT DEFAULT NULL,
+    ADD COLUMN interface_id VARCHAR(128) DEFAULT NULL;
 
 ALTER TABLE dhcp6_subnet
     MODIFY COLUMN reservation_mode TINYINT(3) DEFAULT NULL;
@@ -67,7 +68,8 @@ ALTER TABLE dhcp6_subnet
 ALTER TABLE dhcp6_shared_network
     ADD COLUMN calculate_tee_times TINYINT(1) DEFAULT NULL,
     ADD COLUMN t1_percent FLOAT DEFAULT NULL,
-    ADD COLUMN t2_percent FLOAT DEFAULT NULL;
+    ADD COLUMN t2_percent FLOAT DEFAULT NULL,
+    ADD COLUMN interface_id VARCHAR(128) DEFAULT NULL;
 
 ALTER TABLE dhcp6_shared_network
     MODIFY COLUMN reservation_mode TINYINT(3) DEFAULT NULL;