configuration.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <dhcpsrv/cfgmgr.h>
  15. #include <dhcpsrv/configuration.h>
  16. #include <sstream>
  17. namespace isc {
  18. namespace dhcp {
  19. std::string
  20. Configuration::getConfigSummary(const uint32_t selection) const {
  21. std::ostringstream s;
  22. size_t subnets_num;
  23. if ((selection & CFGSEL_SUBNET4) == CFGSEL_SUBNET4) {
  24. subnets_num = CfgMgr::instance().getSubnets4()->size();
  25. if (subnets_num > 0) {
  26. s << "added IPv4 subnets: " << subnets_num;
  27. } else {
  28. s << "no IPv4 subnets!";
  29. }
  30. s << "; ";
  31. }
  32. if ((selection & CFGSEL_SUBNET6) == CFGSEL_SUBNET6) {
  33. subnets_num = CfgMgr::instance().getSubnets6()->size();
  34. if (subnets_num > 0) {
  35. s << "added IPv6 subnets: " << subnets_num;
  36. } else {
  37. s << "no IPv6 subnets!";
  38. }
  39. s << "; ";
  40. }
  41. if ((selection & CFGSEL_DDNS) == CFGSEL_DDNS) {
  42. bool ddns_enabled = CfgMgr::instance().ddnsEnabled();
  43. s << "DDNS: " << (ddns_enabled ? "enabled" : "disabled") << "; ";
  44. }
  45. if (s.tellp() == 0) {
  46. s << "no config details available";
  47. }
  48. std::string summary = s.str();
  49. size_t last_separator_pos = summary.find_last_of(";");
  50. if (last_separator_pos == summary.length() - 2) {
  51. summary.erase(last_separator_pos);
  52. }
  53. return (summary);
  54. }
  55. }
  56. }