]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
minor changes
authorRazvan Becheriu <razvan.becheriu@qualitance.com>
Thu, 15 Feb 2018 08:41:47 +0000 (10:41 +0200)
committerRazvan Becheriu <razvan.becheriu@qualitance.com>
Thu, 15 Feb 2018 08:41:47 +0000 (10:41 +0200)
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/pgsql_lease_mgr.cc
src/share/database/scripts/pgsql/dhcpdb_create.pgsql

index 5fbde36b3e2915ace4dac686728298b1c81f4ffa..b32d0b7130ec1d00386ffd355e1cd9c26ed0c95a 100644 (file)
@@ -471,6 +471,7 @@ public:
             bind_[9].is_unsigned = MLM_TRUE;
             // bind_[9].is_null = &MLM_FALSE; // commented out for performance
                                               // reasons, see memset() above
+
             // Add the error flags
             setErrorIndicators(bind_, error_, LEASE_COLUMNS);
 
@@ -623,7 +624,10 @@ public:
                                      client_id_buffer_, client_id_length_,
                                      valid_lifetime_, 0, 0, cltt, subnet_id_,
                                      fqdn_fwd_, fqdn_rev_, hostname));
+
+        // Set state.
         lease->state_ = state_;
+
         return (lease);
     }
 
@@ -648,8 +652,8 @@ private:
     // Note: Arrays are declared fixed length for speed of creation
     uint32_t        addr4_;             ///< IPv4 address
     MYSQL_BIND      bind_[LEASE_COLUMNS]; ///< Bind array
-    std::string     columns_[LEASE_COLUMNS];///< Column names
-    my_bool         error_[LEASE_COLUMNS];  ///< Error array
+    std::string     columns_[LEASE_COLUMNS]; ///< Column names
+    my_bool         error_[LEASE_COLUMNS]; ///< Error array
     std::vector<uint8_t> hwaddr_;       ///< Hardware address
     uint8_t         hwaddr_buffer_[HWAddr::MAX_HWADDR_LEN];
                                         ///< Hardware address buffer
@@ -673,11 +677,9 @@ private:
                                         ///< Client hostname
     unsigned long   hostname_length_;   ///< Client hostname length
     uint32_t        state_;             ///< Lease state
-
 };
 
 
-
 /// @brief Exchange MySQL and Lease6 Data
 ///
 /// On any MySQL operation, arrays of MYSQL_BIND structures must be built to
@@ -698,7 +700,7 @@ class MySqlLease6Exchange : public MySqlLeaseExchange {
 public:
     /// @brief Constructor
     ///
-    /// The initialization of the variables here is nonly to satisfy cppcheck -
+    /// The initialization of the variables here is only to satisfy cppcheck -
     /// all variables are initialized/set in the methods before they are used.
     MySqlLease6Exchange() : addr6_length_(0), duid_length_(0),
                             iaid_(0), lease_type_(0), prefixlen_(0),
@@ -981,7 +983,7 @@ public:
         // code that explicitly sets is_null is there, but is commented out.
         memset(bind_, 0, sizeof(bind_));
 
-        // address:  varchar(39)
+        // address: varchar(39)
         // A Lease6_ address has a maximum of 39 characters.  The array is
         // one byte longer than this to guarantee that we can always null
         // terminate it whatever is returned.
@@ -1100,6 +1102,7 @@ public:
         bind_[15].is_unsigned = MLM_TRUE;
         // bind_[15].is_null = &MLM_FALSE; // commented out for performance
                                            // reasons, see memset() above
+
         // Add the error flags
         setErrorIndicators(bind_, error_, LEASE_COLUMNS);
 
@@ -1202,11 +1205,11 @@ private:
     // schema.
     // Note: arrays are declared fixed length for speed of creation
     std::string     addr6_;             ///< String form of address
-    char            addr6_buffer_[ADDRESS6_TEXT_MAX_LEN + 1];  ///< Character
+    char            addr6_buffer_[ADDRESS6_TEXT_MAX_LEN + 1]; ///< Character
                                         ///< array form of V6 address
     unsigned long   addr6_length_;      ///< Length of the address
     MYSQL_BIND      bind_[LEASE_COLUMNS]; ///< Bind array
-    std::string     columns_[LEASE_COLUMNS];///< Column names
+    std::string     columns_[LEASE_COLUMNS]; ///< Column names
     std::vector<uint8_t> duid_;         ///< Client identification
     uint8_t         duid_buffer_[DUID::MAX_DUID_LEN]; ///< Buffer form of DUID
     unsigned long   duid_length_;       ///< Length of the DUID
@@ -1323,7 +1326,6 @@ public:
         conn_.checkError(status, statement_index_, "results storage failed");
     }
 
-
     /// @brief Fetches the next row in the result set
     ///
     /// Once the internal result set has been populated by invoking the
@@ -1404,7 +1406,6 @@ MySqlLeaseMgr::MySqlLeaseMgr(const MySqlConnection::ParameterMap& parameters)
     exchange6_.reset(new MySqlLease6Exchange());
 }
 
-
 MySqlLeaseMgr::~MySqlLeaseMgr() {
     // There is no need to close the database in this destructor: it is
     // closed in the destructor of the mysql_ member variable.
@@ -1562,7 +1563,6 @@ void MySqlLeaseMgr::getLeaseCollection(StatementIndex stindex,
     }
 }
 
-
 void MySqlLeaseMgr::getLease(StatementIndex stindex, MYSQL_BIND* bind,
                              Lease4Ptr& result) const {
     // Create appropriate collection object and get all leases matching
@@ -1581,7 +1581,6 @@ void MySqlLeaseMgr::getLease(StatementIndex stindex, MYSQL_BIND* bind,
     }
 }
 
-
 void MySqlLeaseMgr::getLease(StatementIndex stindex, MYSQL_BIND* bind,
                              Lease6Ptr& result) const {
     // Create appropriate collection object and get all leases matching
@@ -1600,7 +1599,6 @@ void MySqlLeaseMgr::getLease(StatementIndex stindex, MYSQL_BIND* bind,
     }
 }
 
-
 // Basic lease access methods.  Obtain leases from the database using various
 // criteria.
 
@@ -1625,7 +1623,6 @@ MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& addr) const {
     return (result);
 }
 
-
 Lease4Collection
 MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
@@ -1655,7 +1652,6 @@ MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const {
     return (result);
 }
 
-
 Lease4Ptr
 MySqlLeaseMgr::getLease4(const HWAddr& hwaddr, SubnetID subnet_id) const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
@@ -1690,7 +1686,6 @@ MySqlLeaseMgr::getLease4(const HWAddr& hwaddr, SubnetID subnet_id) const {
     return (result);
 }
 
-
 Lease4Collection
 MySqlLeaseMgr::getLease4(const ClientId& clientid) const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
@@ -1815,7 +1810,6 @@ MySqlLeaseMgr::getLease6(Lease::Type lease_type,
     return (result);
 }
 
-
 Lease6Collection
 MySqlLeaseMgr::getLeases6(Lease::Type lease_type,
                           const DUID& duid, uint32_t iaid) const {
@@ -1959,8 +1953,6 @@ MySqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
     getLeaseCollection(statement_index, inbind, expired_leases);
 }
 
-
-
 // Update lease methods.  These comprise common code that handles the actual
 // update, and type-specific methods that set up the parameters for the prepared
 // statement depending on the type of lease.
@@ -1992,7 +1984,6 @@ MySqlLeaseMgr::updateLeaseCommon(StatementIndex stindex, MYSQL_BIND* bind,
     }
 }
 
-
 void
 MySqlLeaseMgr::updateLease4(const Lease4Ptr& lease) {
     const StatementIndex stindex = UPDATE_LEASE4;
@@ -2017,7 +2008,6 @@ MySqlLeaseMgr::updateLease4(const Lease4Ptr& lease) {
     updateLeaseCommon(stindex, &bind[0], lease);
 }
 
-
 void
 MySqlLeaseMgr::updateLease6(const Lease6Ptr& lease) {
     const StatementIndex stindex = UPDATE_LEASE6;
@@ -2188,13 +2178,11 @@ MySqlLeaseMgr::getName() const {
     return (name);
 }
 
-
 std::string
 MySqlLeaseMgr::getDescription() const {
     return (std::string("MySQL Database"));
 }
 
-
 std::pair<uint32_t, uint32_t>
 MySqlLeaseMgr::getVersion() const {
     const StatementIndex stindex = GET_VERSION;
@@ -2253,7 +2241,6 @@ MySqlLeaseMgr::commit() {
     }
 }
 
-
 void
 MySqlLeaseMgr::rollback() {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_ROLLBACK);
index 50170a9304e98848e4234f1eba19797b0227e43e..8e208acc1d6c83fd895718c1310d571394047243 100644 (file)
@@ -68,7 +68,8 @@ PgSqlTaggedStatement tagged_statements[] = {
       "get_lease4_addr",
       "SELECT address, hwaddr, client_id, "
         "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
-        "fqdn_fwd, fqdn_rev, hostname, state "
+        "fqdn_fwd, fqdn_rev, hostname, "
+        "state "
       "FROM lease4 "
       "WHERE address = $1"},
 
@@ -77,7 +78,8 @@ PgSqlTaggedStatement tagged_statements[] = {
       "get_lease4_clientid",
       "SELECT address, hwaddr, client_id, "
         "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
-        "fqdn_fwd, fqdn_rev, hostname, state "
+        "fqdn_fwd, fqdn_rev, hostname, "
+        "state "
       "FROM lease4 "
       "WHERE client_id = $1"},
 
@@ -86,7 +88,8 @@ PgSqlTaggedStatement tagged_statements[] = {
       "get_lease4_clientid_subid",
       "SELECT address, hwaddr, client_id, "
         "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
-        "fqdn_fwd, fqdn_rev, hostname, state "
+        "fqdn_fwd, fqdn_rev, hostname, "
+        "state "
       "FROM lease4 "
       "WHERE client_id = $1 AND subnet_id = $2"},
 
@@ -95,7 +98,8 @@ PgSqlTaggedStatement tagged_statements[] = {
       "get_lease4_hwaddr",
       "SELECT address, hwaddr, client_id, "
         "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
-        "fqdn_fwd, fqdn_rev, hostname, state "
+        "fqdn_fwd, fqdn_rev, hostname, "
+        "state "
       "FROM lease4 "
       "WHERE hwaddr = $1"},
 
@@ -104,7 +108,8 @@ PgSqlTaggedStatement tagged_statements[] = {
       "get_lease4_hwaddr_subid",
       "SELECT address, hwaddr, client_id, "
         "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
-        "fqdn_fwd, fqdn_rev, hostname, state "
+        "fqdn_fwd, fqdn_rev, hostname, "
+        "state "
       "FROM lease4 "
       "WHERE hwaddr = $1 AND subnet_id = $2"},
 
@@ -121,12 +126,13 @@ PgSqlTaggedStatement tagged_statements[] = {
     { 3, { OID_INT8, OID_TIMESTAMP, OID_INT8 },
       "get_lease4_expire",
       "SELECT address, hwaddr, client_id, "
-          "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
-          "fqdn_fwd, fqdn_rev, hostname, state "
-              "FROM lease4 "
-              "WHERE state != $1 AND expire < $2 "
-              "ORDER BY expire "
-              "LIMIT $3"},
+        "valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
+        "fqdn_fwd, fqdn_rev, hostname, "
+        "state "
+      "FROM lease4 "
+      "WHERE state != $1 AND expire < $2 "
+      "ORDER BY expire "
+      "LIMIT $3"},
 
     // GET_LEASE6_ADDR
     { 2, { OID_VARCHAR, OID_INT2 },
@@ -163,14 +169,14 @@ PgSqlTaggedStatement tagged_statements[] = {
     { 3, { OID_INT8, OID_TIMESTAMP, OID_INT8 },
       "get_lease6_expire",
       "SELECT address, duid, valid_lifetime, "
-          "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
-          "lease_type, iaid, prefix_len, "
-          "fqdn_fwd, fqdn_rev, hostname, state "
-          "state "
-              "FROM lease6 "
-              "WHERE state != $1 AND expire < $2 "
-              "ORDER BY expire "
-              "LIMIT $3"},
+        "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
+        "lease_type, iaid, prefix_len, "
+        "fqdn_fwd, fqdn_rev, hostname, "
+        "state "
+      "FROM lease6 "
+      "WHERE state != $1 AND expire < $2 "
+      "ORDER BY expire "
+      "LIMIT $3"},
 
     // GET_VERSION
     { 0, { OID_NONE },
@@ -275,7 +281,6 @@ protected:
 
 };
 
-
 /// @brief Supports exchanging IPv4 leases with PostgreSQL.
 class PgSqlLease4Exchange : public PgSqlLeaseExchange {
 private:
@@ -437,7 +442,9 @@ public:
                                          valid_lifetime_, 0, 0, cltt_,
                                          subnet_id_, fqdn_fwd_, fqdn_rev_,
                                          hostname_));
+
             result->state_ = state;
+
             return (result);
         } catch (const std::exception& ex) {
             isc_throw(DbOperationError,
@@ -646,7 +653,9 @@ public:
                                         subnet_id_, fqdn_fwd_, fqdn_rev_,
                                         hostname_, hwaddr, prefix_len_));
             result->cltt_ = cltt_;
+
             result->state_ = state;
+
             return (result);
         } catch (const std::exception& ex) {
             isc_throw(DbOperationError,
@@ -929,7 +938,6 @@ void PgSqlLeaseMgr::getLeaseCollection(StatementIndex stindex,
     }
 }
 
-
 void
 PgSqlLeaseMgr::getLease(StatementIndex stindex, PsqlBindArray& bind_array,
                              Lease4Ptr& result) const {
@@ -949,7 +957,6 @@ PgSqlLeaseMgr::getLease(StatementIndex stindex, PsqlBindArray& bind_array,
     }
 }
 
-
 void
 PgSqlLeaseMgr::getLease(StatementIndex stindex, PsqlBindArray& bind_array,
                              Lease6Ptr& result) const {
@@ -1247,7 +1254,6 @@ PgSqlLeaseMgr::getExpiredLeasesCommon(LeaseCollection& expired_leases,
     getLeaseCollection(statement_index, bind_array, expired_leases);
 }
 
-
 template<typename LeasePtr>
 void
 PgSqlLeaseMgr::updateLeaseCommon(StatementIndex stindex,
@@ -1283,7 +1289,6 @@ PgSqlLeaseMgr::updateLeaseCommon(StatementIndex stindex,
                   "that had the address " << lease->addr_.toText());
 }
 
-
 void
 PgSqlLeaseMgr::updateLease4(const Lease4Ptr& lease) {
     const StatementIndex stindex = UPDATE_LEASE4;
index dff092d7908ea449f86cfe0c7f965d1f25a04fd0..e2b8060518655b39cfe08de3317d96e72ec2b19b 100644 (file)
@@ -61,7 +61,7 @@ CREATE TABLE lease6 (
     hostname VARCHAR(255)                       -- The FQDN of the client
     );
 
--- Create search indexes for lease4 table
+-- Create search indexes for lease6 table
 -- index by iaid, subnet_id, and duid
 CREATE INDEX lease6_by_iaid_subnet_id_duid ON lease6 (iaid, subnet_id, duid);