Commit fe668b6d authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3636] Trivial fixes to comply with the coding standards/guidelines.

parent 4b087069
// Copyright (C) 2011-2014 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
// //
// Permission to use, copy, modify, and/or distribute this software for any // Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above // purpose with or without fee is hereby granted, provided that the above
...@@ -816,8 +816,12 @@ Dhcpv4Srv::processHostnameOption(const OptionStringPtr& opt_hostname, ...@@ -816,8 +816,12 @@ Dhcpv4Srv::processHostnameOption(const OptionStringPtr& opt_hostname,
} else if (label_count == 2) { } else if (label_count == 2) {
// If there are two labels, it means that the client has specified // If there are two labels, it means that the client has specified
// the unqualified name. We have to concatenate the unqalified name // the unqualified name. We have to concatenate the unqalified name
// with the domain name. // with the domain name. The false value passed as a second argument
opt_hostname_resp->setValue(d2_mgr.qualifyName(hostname,false)); // indicates that the trailing dot should not be appended to the
// hostname. We don't want to append the trailing dot because
// we don't know whether the hostname is partial or not and some
// clients do not handle the hostnames with the trailing dot.
opt_hostname_resp->setValue(d2_mgr.qualifyName(hostname, false));
} }
answer->addOption(opt_hostname_resp); answer->addOption(opt_hostname_resp);
...@@ -1071,13 +1075,15 @@ Dhcpv4Srv::assignLease(const Pkt4Ptr& question, Pkt4Ptr& answer) { ...@@ -1071,13 +1075,15 @@ Dhcpv4Srv::assignLease(const Pkt4Ptr& question, Pkt4Ptr& answer) {
// hostname is empty, it means that server is responsible for // hostname is empty, it means that server is responsible for
// generating the entire hostname for the client. The example of the // generating the entire hostname for the client. The example of the
// client's name, generated from the IP address is: host-192-0-2-3. // client's name, generated from the IP address is: host-192-0-2-3.
if ((fqdn || opt_hostname) && lease->hostname_.empty()) { if ((fqdn || opt_hostname) && lease->hostname_.empty()) {
if(fqdn) { // Note that if we have received the hostname option, rather than
lease->hostname_ = CfgMgr::instance().getD2ClientMgr().generateFqdn(lease->addr_,true); // Client FQDN the trailing dot is not appended to the generated
} // hostname because some clients don't handle the trailing dot in
if(opt_hostname) { // the hostname. Whether the trailing dot is appended or not is
lease->hostname_ = CfgMgr::instance().getD2ClientMgr().generateFqdn(lease->addr_,false); // controlled by the second argument to the generateFqdn().
} lease->hostname_ = CfgMgr::instance().getD2ClientMgr()
.generateFqdn(lease->addr_, static_cast<bool>(fqdn));
// The operations below are rather safe, but we want to catch // The operations below are rather safe, but we want to catch
// any potential exceptions (e.g. invalid lease database backend // any potential exceptions (e.g. invalid lease database backend
// implementation) and log an error. // implementation) and log an error.
......
// Copyright (C) 2011-2014 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
// //
// Permission to use, copy, modify, and/or distribute this software for any // Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above // purpose with or without fee is hereby granted, provided that the above
...@@ -2609,7 +2609,7 @@ Dhcpv6Srv::generateFqdn(const Pkt6Ptr& answer) { ...@@ -2609,7 +2609,7 @@ Dhcpv6Srv::generateFqdn(const Pkt6Ptr& answer) {
// Get the IPv6 address acquired by the client. // Get the IPv6 address acquired by the client.
IOAddress addr = iaaddr->getAddress(); IOAddress addr = iaaddr->getAddress();
std::string generated_name = std::string generated_name =
CfgMgr::instance().getD2ClientMgr().generateFqdn(addr,true); CfgMgr::instance().getD2ClientMgr().generateFqdn(addr);
try { try {
// The lease has been acquired but the FQDN for this lease hasn't // The lease has been acquired but the FQDN for this lease hasn't
// been updated in the lease database. We now have new FQDN // been updated in the lease database. We now have new FQDN
......
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
// //
// Permission to use, copy, modify, and/or distribute this software for any // Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above // purpose with or without fee is hereby granted, provided that the above
...@@ -171,43 +171,47 @@ D2ClientMgr::analyzeFqdn(const bool client_s, const bool client_n, ...@@ -171,43 +171,47 @@ D2ClientMgr::analyzeFqdn(const bool client_s, const bool client_n,
} }
std::string std::string
D2ClientMgr::generateFqdn(const asiolink::IOAddress& address, bool appendDot) const { D2ClientMgr::generateFqdn(const asiolink::IOAddress& address,
const bool trailing_dot) const {
std::string hostname = address.toText(); std::string hostname = address.toText();
std::replace(hostname.begin(), hostname.end(), std::replace(hostname.begin(), hostname.end(),
(address.isV4() ? '.' : ':'), '-'); (address.isV4() ? '.' : ':'), '-');
std::ostringstream gen_name; std::ostringstream gen_name;
gen_name << d2_client_config_->getGeneratedPrefix() << "-" << hostname; gen_name << d2_client_config_->getGeneratedPrefix() << "-" << hostname;
return (qualifyName(gen_name.str(),appendDot)); return (qualifyName(gen_name.str(), trailing_dot));
} }
std::string std::string
D2ClientMgr::qualifyName(const std::string& partial_name, bool appendDot) const { D2ClientMgr::qualifyName(const std::string& partial_name,
const bool trailing_dot) const {
std::ostringstream gen_name; std::ostringstream gen_name;
gen_name << partial_name << "." << d2_client_config_->getQualifyingSuffix(); gen_name << partial_name << "." << d2_client_config_->getQualifyingSuffix();
std::string str = gen_name.str(); std::string str = gen_name.str();
size_t len = str.length(); size_t len = str.length();
//unless it's forced, will append trailing dot
if(appendDot) { if(trailing_dot) {
// Tack on a trailing dot in case suffix doesn't have one. // If trailing dot should be added but there is no trailing dot,
if ((len > 0) && (str[len - 1] != '.')) { // append it.
gen_name << "."; if ((len > 0) && (str[len - 1] != '.')) {
} gen_name << ".";
}
} else { } else {
//if a call with appendDot is false, remove the dot if exists // If the trailing dot should not be appended but it is present,
if ((len > 0) && (str[len - 1] == '.')) { // remove it.
gen_name.str(str.substr(0,len-1)); if ((len > 0) && (str[len - 1] == '.')) {
} gen_name.str(str.substr(0,len-1));
}
} }
return (gen_name.str()); return (gen_name.str());
} }
void void
D2ClientMgr::startSender(D2ClientErrorHandler error_handler) { D2ClientMgr::startSender(D2ClientErrorHandler error_handler) {
if (amSending()) { if (amSending()) {
......
...@@ -172,10 +172,12 @@ public: ...@@ -172,10 +172,12 @@ public:
/// ('.' for IPv4 or ':' for IPv6) replaced with a hyphen, '-'. /// ('.' for IPv4 or ':' for IPv6) replaced with a hyphen, '-'.
/// ///
/// @param address IP address from which to derive the name (IPv4 or IPv6) /// @param address IP address from which to derive the name (IPv4 or IPv6)
/// @param appendDot wether if a trailing dot should be appended or not /// @param trailing_dot A boolean value which indicates whether trailing
/// dot should be appended (if true) or not (false).
/// ///
/// @return std::string containing the generated name. /// @return std::string containing the generated name.
std::string generateFqdn(const asiolink::IOAddress& address, bool appendDot) const; std::string generateFqdn(const asiolink::IOAddress& address,
const bool trailing_dot = true) const;
/// @brief Adds a qualifying suffix to a given domain name /// @brief Adds a qualifying suffix to a given domain name
/// ///
...@@ -183,14 +185,14 @@ public: ...@@ -183,14 +185,14 @@ public:
/// a partial domain name as follows: /// a partial domain name as follows:
/// ///
/// <partial_name>.<qualifying-suffix>. /// <partial_name>.<qualifying-suffix>.
/// Note it will add a trailing '.' should qualifying-suffix not end with
/// one.
/// ///
/// @param partial_name domain name to qualify /// @param partial_name domain name to qualify
/// @param appendDot wether if a trailing dot should be appended or not /// @param trailing_dot A boolean value which indicates whether trailing
/// dot should be appended (if true) or not (false).
/// ///
/// @return std::string containing the qualified name. /// @return std::string containing the qualified name.
std::string qualifyName(const std::string& partial_name, bool appendDot) const; std::string qualifyName(const std::string& partial_name,
const bool trailing_dot) const;
/// @brief Set server FQDN flags based on configuration and a given FQDN /// @brief Set server FQDN flags based on configuration and a given FQDN
/// ///
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment