cfgmgr.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright (C) 2012 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 <asiolink/io_address.h>
  15. #include <dhcp/cfgmgr.h>
  16. using namespace isc::asiolink;
  17. using namespace isc::util;
  18. namespace isc {
  19. namespace dhcp {
  20. CfgMgr&
  21. CfgMgr::instance() {
  22. static CfgMgr cfg_mgr;
  23. return (cfg_mgr);
  24. }
  25. Subnet6Ptr
  26. CfgMgr::getSubnet6(const isc::asiolink::IOAddress& hint) {
  27. // If there's only one subnet configured, let's just use it
  28. // The idea is to keep small deployments easy. In a small network - one
  29. // router that also runs DHCPv6 server. Users specifies a single pool and
  30. // expects it to just work. Without this, the server would complain that it
  31. // doesn't have IP address on its interfaces that matches that
  32. // configuration. Such requirement makes sense in IPv4, but not in IPv6.
  33. // The server does not need to have a global address (using just link-local
  34. // is ok for DHCPv6 server) from the pool it serves.
  35. if (subnets6_.size() == 1) {
  36. return (subnets6_[0]);
  37. }
  38. // If there is more than one, we need to choose the proper one
  39. for (Subnet6Collection::iterator subnet = subnets6_.begin();
  40. subnet != subnets6_.end(); ++subnet) {
  41. if ((*subnet)->inRange(hint)) {
  42. return (*subnet);
  43. }
  44. }
  45. // sorry, we don't support that subnet
  46. return (Subnet6Ptr());
  47. }
  48. Subnet6Ptr CfgMgr::getSubnet6(OptionPtr /*interfaceId*/) {
  49. /// @todo: Implement get subnet6 by interface-id (for relayed traffic)
  50. isc_throw(NotImplemented, "Relayed DHCPv6 traffic is not supported yet.");
  51. }
  52. void CfgMgr::addSubnet6(const Subnet6Ptr& subnet) {
  53. /// @todo: Check that this new subnet does not cross boundaries of any
  54. /// other already defined subnet.
  55. subnets6_.push_back(subnet);
  56. }
  57. Subnet4Ptr
  58. CfgMgr::getSubnet4(const isc::asiolink::IOAddress& hint) {
  59. // If there's only one subnet configured, let's just use it
  60. // The idea is to keep small deployments easy. In a small network - one
  61. // router that also runs DHCPv6 server. Users specifies a single pool and
  62. // expects it to just work. Without this, the server would complain that it
  63. // doesn't have IP address on its interfaces that matches that
  64. // configuration. Such requirement makes sense in IPv4, but not in IPv6.
  65. // The server does not need to have a global address (using just link-local
  66. // is ok for DHCPv6 server) from the pool it serves.
  67. if (subnets4_.size() == 1) {
  68. return (subnets4_[0]);
  69. }
  70. // If there is more than one, we need to choose the proper one
  71. for (Subnet4Collection::iterator subnet = subnets4_.begin();
  72. subnet != subnets4_.end(); ++subnet) {
  73. if ((*subnet)->inRange(hint)) {
  74. return (*subnet);
  75. }
  76. }
  77. // sorry, we don't support that subnet
  78. return (Subnet4Ptr());
  79. }
  80. void CfgMgr::addSubnet4(const Subnet4Ptr& subnet) {
  81. /// @todo: Check that this new subnet does not cross boundaries of any
  82. /// other already defined subnet.
  83. subnets4_.push_back(subnet);
  84. }
  85. CfgMgr::CfgMgr() {
  86. }
  87. CfgMgr::~CfgMgr() {
  88. }
  89. }; // end of isc::dhcp namespace
  90. }; // end of isc namespace