EXTRA_DIST += api/stat-lease4-get.json api/stat-lease6-get.json
EXTRA_DIST += api/subnet4-add.json api/subnet4-del.json
EXTRA_DIST += api/subnet4-get.json api/subnet4-list.json
+EXTRA_DIST += api/subnet4-update.json
EXTRA_DIST += api/subnet6-add.json api/subnet6-del.json
EXTRA_DIST += api/subnet6-get.json api/subnet6-list.json
+EXTRA_DIST += api/subnet6-update.json
EXTRA_DIST += api/_template.json api/version-get.json
devel:
--- /dev/null
+{
+ "name": "subnet4-update",
+ "brief": "This command is used to update a subnet in the existing server configuration.",
+ "description": "See <xref linkend=\"idp69\"/>",
+ "support": [ "kea-dhcp4"],
+ "avail": "1.6.0",
+ "hook": "subnet_cmds",
+ "cmd-syntax": "{
+ \"command\": \"subnet4-update\",
+ \"arguments\": {
+ \"subnets\": [ {
+ \"id\": 123,
+ \"subnet\": \"10.20.30.0/24\",
+ ...
+ } ]
+ }
+}",
+ "resp-syntax": "{
+ \"result\": 0,
+ \"text\": \"IPv4 subnet updated\",
+ \"arguments\": {
+ \"subnets\": [
+ {
+ \"id\": 123,
+ \"subnet\": \"10.20.30.0/24\"
+ }
+ ]
+ }
+}"
+}
--- /dev/null
+{
+ "name": "subnet6-update",
+ "brief": "This command is used to update a subnet in the existing server configuration. This operation has no impact on other subnets.",
+ "description": "See <xref linkend=\"idp70\"/>",
+ "support": [ "kea-dhcp6" ],
+ "avail": "1.6.0",
+ "hook": "subnet_cmds",
+ "cmd-syntax": "{
+ \"command\": \"subnet6-update\",
+ \"arguments\": {
+ \"subnet6\": [ {
+ \"id\": 234,
+ \"subnet\": \"2001:db8:1::/64\",
+ ...
+ } ]
+ }
+}",
+ "resp-syntax": "{
+ \"result\": 0,
+ \"text\": \"IPv6 subnet updated\",
+ \"arguments\": {
+ \"subnet6\": [
+ {
+ \"id\": 234,
+ \"subnet\": \"2001:db8:1::/64\"
+ }
+ ]
+ }
+}"
+}
, <command><link linkend="ref-subnet4-del">subnet4-del</link></command>
, <command><link linkend="ref-subnet4-get">subnet4-get</link></command>
, <command><link linkend="ref-subnet4-list">subnet4-list</link></command>
+, <command><link linkend="ref-subnet4-update">subnet4-update</link></command>
, <command><link linkend="ref-subnet6-add">subnet6-add</link></command>
, <command><link linkend="ref-subnet6-del">subnet6-del</link></command>
, <command><link linkend="ref-subnet6-get">subnet6-get</link></command>
, <command><link linkend="ref-subnet6-list">subnet6-list</link></command>
+, <command><link linkend="ref-subnet6-update">subnet6-update</link></command>
, <command><link linkend="ref-version-get">version-get</link></command>
.</para>
<para xml:id="commands-kea-ctrl-agent">Commands supported by kea-ctrl-agent daemon: <command><link linkend="ref-build-report">build-report</link></command>
, <command><link linkend="ref-subnet4-del">subnet4-del</link></command>
, <command><link linkend="ref-subnet4-get">subnet4-get</link></command>
, <command><link linkend="ref-subnet4-list">subnet4-list</link></command>
+, <command><link linkend="ref-subnet4-update">subnet4-update</link></command>
, <command><link linkend="ref-version-get">version-get</link></command>
.</para>
<para xml:id="commands-kea-dhcp6">Commands supported by kea-dhcp6 daemon: <command><link linkend="ref-build-report">build-report</link></command>
, <command><link linkend="ref-subnet6-del">subnet6-del</link></command>
, <command><link linkend="ref-subnet6-get">subnet6-get</link></command>
, <command><link linkend="ref-subnet6-list">subnet6-list</link></command>
+, <command><link linkend="ref-subnet6-update">subnet6-update</link></command>
, <command><link linkend="ref-version-get">version-get</link></command>
.</para>
<para xml:id="commands-class_cmds-lib">Commands supported by class_cmds hook library: <command><link linkend="ref-class-add">class-add</link></command>
, <command><link linkend="ref-subnet4-del">subnet4-del</link></command>
, <command><link linkend="ref-subnet4-get">subnet4-get</link></command>
, <command><link linkend="ref-subnet4-list">subnet4-list</link></command>
+, <command><link linkend="ref-subnet4-update">subnet4-update</link></command>
, <command><link linkend="ref-subnet6-add">subnet6-add</link></command>
, <command><link linkend="ref-subnet6-del">subnet6-del</link></command>
, <command><link linkend="ref-subnet6-get">subnet6-get</link></command>
, <command><link linkend="ref-subnet6-list">subnet6-list</link></command>
+, <command><link linkend="ref-subnet6-update">subnet6-update</link></command>
.</para>
<!-- start of build-report -->
<section xml:id="reference-build-report">
</section>
<!-- end of subnet4-list -->
+<!-- start of subnet4-update -->
+<section xml:id="reference-subnet4-update">
+<title>subnet4-update reference</title>
+<para xml:id="ref-subnet4-update"><command>subnet4-update</command> - This command is used to update a subnet in the existing server configuration.</para>
+
+<para>Supported by: <command><link linkend="commands-kea-dhcp4">kea-dhcp4</link></command></para>
+
+<para>Availability: 1.6.0 (<link linkend="commands-subnet_cmds-lib">subnet_cmds</link> hook)</para>
+
+<para>Description and examples: See <xref linkend="command-subnet4-update"/></para>
+
+<para>Command syntax:
+ <screen>{
+ "command": "subnet4-update",
+ "arguments": {
+ "subnet4": [ {
+ "id": 123,
+ "subnet": "10.20.30.0/24",
+ ...
+ } ]
+ }
+}</screen>
+</para>
+
+<para>Response syntax:
+ <screen>{
+ "result": 0,
+ "text": "IPv4 subnet updated",
+ "arguments": {
+ "subnets": [
+ {
+ "id": 123,
+ "subnet": "10.20.30.0/24"
+ }
+ ]
+ }
+}</screen>
+Result is an integer representation of the status. Currently supported statuses are:
+<itemizedlist>
+ <listitem><para>0 - success</para></listitem>
+ <listitem><para>1 - error</para></listitem>
+ <listitem><para>2 - unsupported</para></listitem>
+</itemizedlist>
+</para>
+
+</section>
+<!-- end of subnet4-update -->
+
<!-- start of subnet6-add -->
<section xml:id="reference-subnet6-add">
<title>subnet6-add reference</title>
</section>
<!-- end of subnet6-list -->
+<!-- start of subnet6-update -->
+<section xml:id="reference-subnet6-update">
+<title>subnet6-update reference</title>
+<para xml:id="ref-subnet6-update"><command>subnet6-update</command> - This command is used to update a subnet in the existing server configuration. This operation has no impact on other subnets.</para>
+
+<para>Supported by: <command><link linkend="commands-kea-dhcp6">kea-dhcp6</link></command></para>
+
+<para>Availability: 1.6.0 (<link linkend="commands-subnet_cmds-lib">subnet_cmds</link> hook)</para>
+
+<para>Description and examples: See <xref linkend="command-subnet6-update"/></para>
+
+<para>Command syntax:
+ <screen>{
+ "command": "subnet6-update",
+ "arguments": {
+ "subnet6": [ {
+ "id": 234,
+ "subnet": "2001:db8:1::/64",
+ ...
+ } ]
+ }
+}</screen>
+</para>
+
+<para>Response syntax:
+ <screen>{
+ "result": 0,
+ "text": "IPv6 subnet updated",
+ "arguments": {
+ "subnet6": [
+ {
+ "id": 234,
+ "subnet": "2001:db8:1::/64"
+ }
+ ]
+ }
+}</screen>
+Result is an integer representation of the status. Currently supported statuses are:
+<itemizedlist>
+ <listitem><para>0 - success</para></listitem>
+ <listitem><para>1 - error</para></listitem>
+ <listitem><para>2 - unsupported</para></listitem>
+</itemizedlist>
+</para>
+
+</section>
+<!-- end of subnet6-update -->
+
<!-- start of version-get -->
<section xml:id="reference-version-get">
<title>version-get reference</title>
<command>reservation-get-page</command> instead (see <xref
linkend="command-reservation-get-page"/>).
</para>
-
+
<para>
For a reference, see <xref linkend="ref-reservation-get-all"/>.
</para>
</simpara>
</listitem>
<listitem>
+ <simpara> <command>subnet4-update/subnet6-update</command>: updates subnet in server's configuration
+ </simpara>
+ </listitem>
+ <listitem>
<simpara>
<command>subnet4-del/subnet6-del</command>: removes a subnet from the server's configuration
</simpara>
</section>
+ <section id="command-subnet4-update">
+ <title>subnet4-update</title>
+ <para>
+ This command is used to update a subnet in the existing
+ server configuration. This operation has no impact on other
+ subnets. The subnet identifier is used to identify the
+ subnet to replace, it must be specified and must be unique
+ among all subnets. The subnet prefix should not be updated.
+ </para>
+ <para>
+ The subnet information within this command has the same structure
+ as the subnet information in the server configuration file with the
+ exception that static host reservations must not be specified
+ within <command>subnet4-update</command>. The commands described in
+ <xref linkend="host-cmds"/> should be used to update, remove and
+ modify static reservations.
+<screen>
+{
+ "command": "subnet4-update",
+ "arguments": {
+ "subnet4": [ {
+ "id": 123,
+ "subnet": "10.20.30.0/24",
+ ...
+ } ]
+ }
+}
+</screen>
+ </para>
+
+ <para>
+ The response to this command has the following structure:
+<screen>
+{
+ "result": 0,
+ "text": "IPv4 subnet updated",
+ "arguments": {
+ "subnet4": [
+ {
+ "id": 123,
+ "subnet": "10.20.30.0/24"
+ }
+ ]
+ }
+}
+</screen>
+ </para>
+ </section>
+
+ <section id="command-subnet6-update">
+ <title>subnet6-update</title>
+ <para>
+ This command is used to update a subnet in the existing
+ server configuration. This operation has no impact on other
+ subnets. The subnet identifier is used to identify the
+ subnet to replace, it must be specified and must be unique
+ among all subnets. The subnet prefix should not be updated.
+ </para>
+ <para>
+ The subnet information within this command has the same structure
+ as the subnet information in the server configuration file with the
+ exception that static host reservations must not be specified
+ within <command>subnet6-update</command>. The commands described in
+ <xref linkend="host-cmds"/> should be used to update, remove and
+ modify static reservations.
+<screen>
+{
+ "command": "subnet6-update",
+ "arguments": {
+ "subnet6": [ {
+ "id": 234,
+ "subnet": "2001:db8:1::/64",
+ ...
+ } ]
+ }
+}
+</screen>
+ </para>
+
+ <para>
+ The response to this command has the following structure:
+<screen>
+{
+ "result": 0,
+ "text": "IPv6 subnet updated",
+ "arguments": {
+ "subnet6": [
+ {
+ "id": 234,
+ "subnet": "2001:db8:1::/64"
+ }
+ ]
+ }
+}
+</screen>
+ </para>
+
+ </section>
+
<section id="command-subnet4-del">
<title>subnet4-del command</title>
<para>
loose track of leases assigned to the clients from this subnet.
However, removal of the subnet may still cause configuration
errors and conflicts. For example: after removal of the subnet,
- the server administrator may add a new subnet with the ID used
+ the server administrator may update a new subnet with the ID used
previously for the removed subnet. This means that the existing
leases and static reservations will be in conflict with this
new subnet. Thus, we recommend that this command is used with extreme
isc_throw(BadValue, "ID of the IPv4 subnet '" << subnet_id
<< "' is not in use");
}
+ Subnet4Ptr old = *subnet_it;
bool ret = index.replace(subnet_it, subnet);
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_UPDATE_SUBNET4)
.arg(subnet_id).arg(ret);
if (ret) {
- return (*subnet_it);
+ return (old);
} else {
return (Subnet4Ptr());
}
isc_throw(BadValue, "ID of the IPv6 subnet '" << subnet_id
<< "' is not in use");
}
+ Subnet6Ptr old = *subnet_it;
bool ret = index.replace(subnet_it, subnet);
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_UPDATE_SUBNET6)
.arg(subnet_id).arg(ret);
if (ret) {
- return (*subnet_it);
+ return (old);
} else {
return (Subnet6Ptr());
}
EXPECT_FALSE(cfg.getByPrefix("192.0.2.0/26"));
}
+// This test verifies that replace a subnet works as expected.
+TEST(CfgSubnets4Test, replaceSubnet) {
+ CfgSubnets4 cfg;
+
+ // Create 3 subnets.
+ Subnet4Ptr subnet1(new Subnet4(IOAddress("192.0.1.0"),
+ 26, 1, 2, 100, SubnetID(10)));
+ Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.0"),
+ 26, 1, 2, 100, SubnetID(2)));
+ Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.3.0"),
+ 26, 1, 2, 100, SubnetID(13)));
+
+ ASSERT_NO_THROW(cfg.add(subnet1));
+ ASSERT_NO_THROW(cfg.add(subnet2));
+ ASSERT_NO_THROW(cfg.add(subnet3));
+
+ // There should be three subnets.
+ ASSERT_EQ(3, cfg.getAll()->size());
+ // We're going to replace the subnet #2. Let's make sure it exists before
+ // we replace it.
+ ASSERT_TRUE(cfg.getByPrefix("192.0.3.0/26"));
+
+ // Replace the subnet and make sure it was updated.
+ Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"),
+ 26, 10, 20, 1000, SubnetID(2)));
+ Subnet4Ptr replaced = cfg.replace(subnet);
+ ASSERT_TRUE(replaced);
+ EXPECT_TRUE(replaced == subnet2);
+ ASSERT_EQ(3, cfg.getAll()->size());
+ Subnet4Ptr returned = cfg.getAll()->at(1);
+ ASSERT_TRUE(returned);
+ EXPECT_TRUE(returned == subnet);
+
+ // Rollback.
+ replaced = cfg.replace(replaced);
+ ASSERT_TRUE(replaced);
+ EXPECT_TRUE(replaced == subnet);
+ ASSERT_EQ(3, cfg.getAll()->size());
+ returned = cfg.getAll()->at(1);
+ ASSERT_TRUE(returned);
+ EXPECT_TRUE(returned == subnet2);
+
+ // Prefix conflict returns null.
+ subnet.reset(new Subnet4(IOAddress("192.0.3.0"),
+ 26, 10, 20, 1000, SubnetID(2)));
+ replaced = cfg.replace(subnet);
+ EXPECT_FALSE(replaced);
+ returned = cfg.getAll()->at(1);
+ ASSERT_TRUE(returned);
+ EXPECT_TRUE(returned == subnet2);
+
+ // Changing prefix works even it is highly not recommended.
+ subnet.reset(new Subnet4(IOAddress("192.0.10.0"),
+ 26, 10, 20, 1000, SubnetID(2)));
+ replaced = cfg.replace(subnet);
+ ASSERT_TRUE(replaced);
+ EXPECT_TRUE(replaced == subnet2);
+ returned = cfg.getAll()->at(1);
+ ASSERT_TRUE(returned);
+ EXPECT_TRUE(returned == subnet);
+}
+
// This test verifies that subnets configuration is properly merged.
TEST(CfgSubnets4Test, mergeSubnets) {
// Create custom options dictionary for testing merge. We're keeping it
-// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
EXPECT_FALSE(cfg.getByPrefix("2001:db8:1::/48"));
}
+// This test verifies that replace a subnet works as expected.
+TEST(CfgSubnets6Test, replaceSubnet) {
+ CfgSubnets6 cfg;
+
+ // Create 3 subnets.
+ Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"),
+ 48, 1, 2, 3, 100, SubnetID(10)));
+ Subnet6Ptr subnet2(new Subnet6(IOAddress("2001:db8:2::"),
+ 48, 1, 2, 3, 100, SubnetID(2)));
+ Subnet6Ptr subnet3(new Subnet6(IOAddress("2001:db8:3::"),
+ 48, 1, 2, 3, 100, SubnetID(13)));
+
+ ASSERT_NO_THROW(cfg.add(subnet1));
+ ASSERT_NO_THROW(cfg.add(subnet2));
+ ASSERT_NO_THROW(cfg.add(subnet3));
+
+ // There should be three subnets.
+ ASSERT_EQ(3, cfg.getAll()->size());
+ // We're going to replace the subnet #2. Let's make sure it exists before
+ // we replace it.
+ ASSERT_TRUE(cfg.getByPrefix("2001:db8:2::/48"));
+
+ // Replace the subnet and make sure it was updated.
+ Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:2::"),
+ 48, 10, 20, 30, 1000, SubnetID(2)));
+ Subnet6Ptr replaced = cfg.replace(subnet);
+ ASSERT_TRUE(replaced);
+ EXPECT_TRUE(replaced == subnet2);
+ ASSERT_EQ(3, cfg.getAll()->size());
+ Subnet6Ptr returned = cfg.getAll()->at(1);
+ ASSERT_TRUE(returned);
+ EXPECT_TRUE(returned == subnet);
+
+ // Rollback.
+ replaced = cfg.replace(replaced);
+ ASSERT_TRUE(replaced);
+ EXPECT_TRUE(replaced == subnet);
+ ASSERT_EQ(3, cfg.getAll()->size());
+ returned = cfg.getAll()->at(1);
+ ASSERT_TRUE(returned);
+ EXPECT_TRUE(returned == subnet2);
+
+ // Prefix conflict returns null.
+ subnet.reset(new Subnet6(IOAddress("2001:db8:3::"),
+ 48, 10, 20, 30, 1000, SubnetID(2)));
+ replaced = cfg.replace(subnet);
+ EXPECT_FALSE(replaced);
+ returned = cfg.getAll()->at(1);
+ ASSERT_TRUE(returned);
+ EXPECT_TRUE(returned == subnet2);
+
+ // Changing prefix works even it is highly not recommended.
+ subnet.reset(new Subnet6(IOAddress("2001:db8:10::"),
+ 48, 10, 20, 30, 1000, SubnetID(2)));
+ replaced = cfg.replace(subnet);
+ ASSERT_TRUE(replaced);
+ EXPECT_TRUE(replaced == subnet2);
+ returned = cfg.getAll()->at(1);
+ ASSERT_TRUE(returned);
+ EXPECT_TRUE(returned == subnet);
+}
+
// This test checks that the subnet can be selected using a relay agent's
// link address.
TEST(CfgSubnets6Test, selectSubnetByRelayAddress) {