Hello,
I've been asked to send this patch to the list for review which I originally posted at rhbz#913446 [0].
My main motivation is to be able to set a saner default for dhcp leases in Boxes for development machines where the instant volatility of the dhcp lease makes it impossible to reliably work with services after the machines have to be rebooted. One has to discover the ip again... setup ssh keys...
This patch is a first attempt so feel free to let me know if I'm aiming at the right direction.
Thanks!
I've been asked to send this patch to the list for review which I originally posted at rhbz#913446 [0].
My main motivation is to be able to set a saner default for dhcp leases in Boxes for development machines where the instant volatility of the dhcp lease makes it impossible to reliably work with services after the machines have to be rebooted. One has to discover the ip again... setup ssh keys...
This patch is a first attempt so feel free to let me know if I'm aiming at the right direction.
Thanks!
[0]https://bugzilla.redhat.com/show_bug.cgi?id=913446
--
Red Hat
Alberto Ruiz
Associate Engineering Manager - Desktop Management ToolsFrom 112f61ec5cfdc39f7a157825c4209f7bae34c483 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz <aruiz@xxxxxxxxx> Date: Wed, 13 Apr 2016 17:00:45 +0100 Subject: [PATCH] network: Add support for dhcp-range lease time in the network XML configuration format and dnsmasq --- docs/schemas/basictypes.rng | 5 +++++ docs/schemas/network.rng | 3 +++ src/conf/network_conf.c | 8 +++++++- src/network/bridge_driver.c | 10 ++++++++-- src/util/virsocketaddr.h | 5 +++-- .../isolated-network-with-lease-time.conf | 17 +++++++++++++++++ .../isolated-network-with-lease-time.xml | 11 +++++++++++ tests/networkxml2conftest.c | 1 + 8 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 tests/networkxml2confdata/isolated-network-with-lease-time.conf create mode 100644 tests/networkxml2confdata/isolated-network-with-lease-time.xml diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng index a83063a..07aeba4 100644 --- a/docs/schemas/basictypes.rng +++ b/docs/schemas/basictypes.rng @@ -470,4 +470,9 @@ </choice> </define> + <define name="leaseTime"> + <data type="string"> + <param name="pattern">[1-9][0-9]*[hm]?|infinite</param> + </data> + </define> </grammar> diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng index 4edb6eb..6434c1b 100644 --- a/docs/schemas/network.rng +++ b/docs/schemas/network.rng @@ -330,6 +330,9 @@ <element name="range"> <attribute name="start"><ref name="ipAddr"/></attribute> <attribute name="end"><ref name="ipAddr"/></attribute> + <optional> + <attribute name="lease"><ref name="leaseTime"/></attribute> + </optional> </element> </zeroOrMore> <zeroOrMore> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 4fb2e2a..449c9ed 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -313,6 +313,10 @@ static void virNetworkIpDefClear(virNetworkIpDefPtr def) { VIR_FREE(def->family); + + while (def->nranges) + VIR_FREE(def->ranges[--def->nranges].lease); + VIR_FREE(def->ranges); while (def->nhosts) @@ -855,7 +859,6 @@ int virNetworkIpDefNetmask(const virNetworkIpDef *def, VIR_SOCKET_ADDR_FAMILY(&def->address)); } - static int virSocketAddrRangeParseXML(const char *networkName, virNetworkIpDefPtr ipdef, @@ -890,6 +893,9 @@ virSocketAddrRangeParseXML(const char *networkName, virNetworkIpDefPrefix(ipdef)) < 0) goto cleanup; + /* TODO: Sanity check the lease string */ + range->lease = virXMLPropString(node, "lease"); + ret = 0; cleanup: diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 73236ff..afb79f4 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1187,8 +1187,14 @@ networkDnsmasqConfContents(virNetworkObjPtr network, !(eaddr = virSocketAddrFormat(&ipdef->ranges[r].end))) goto cleanup; - virBufferAsprintf(&configbuf, "dhcp-range=%s,%s\n", - saddr, eaddr); + if (ipdef->ranges[r].lease) { + virBufferAsprintf(&configbuf, "dhcp-range=%s,%s,%s\n", + saddr, eaddr, ipdef->ranges[r].lease); + } else { + virBufferAsprintf(&configbuf, "dhcp-range=%s,%s\n", + saddr, eaddr); + } + VIR_FREE(saddr); VIR_FREE(eaddr); thisRange = virSocketAddrGetRange(&ipdef->ranges[r].start, diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index c7aaa61..4baeda5 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -63,8 +63,9 @@ typedef virSocketAddr *virSocketAddrPtr; typedef struct _virSocketAddrRange virSocketAddrRange; typedef virSocketAddrRange *virSocketAddrRangePtr; struct _virSocketAddrRange { - virSocketAddr start; - virSocketAddr end; + virSocketAddr start; + virSocketAddr end; + char *lease; }; typedef struct _virPortRange virPortRange; diff --git a/tests/networkxml2confdata/isolated-network-with-lease-time.conf b/tests/networkxml2confdata/isolated-network-with-lease-time.conf new file mode 100644 index 0000000..a02dadc --- /dev/null +++ b/tests/networkxml2confdata/isolated-network-with-lease-time.conf @@ -0,0 +1,17 @@ +##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE +##OVERWRITTEN AND LOST. Changes to this configuration should be made using: +## virsh net-edit private +## or other application using the libvirt API. +## +## dnsmasq conf file created by libvirt +strict-order +except-interface=lo +bind-interfaces +listen-address=192.168.152.1 +dhcp-option=3 +no-resolv +dhcp-range=192.168.152.2,192.168.152.254,12h +dhcp-no-override +dhcp-lease-max=253 +dhcp-hostsfile=/var/lib/libvirt/dnsmasq/private.hostsfile +addn-hosts=/var/lib/libvirt/dnsmasq/private.addnhosts diff --git a/tests/networkxml2confdata/isolated-network-with-lease-time.xml b/tests/networkxml2confdata/isolated-network-with-lease-time.xml new file mode 100644 index 0000000..66ae801 --- /dev/null +++ b/tests/networkxml2confdata/isolated-network-with-lease-time.xml @@ -0,0 +1,11 @@ +<network> + <name>private</name> + <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid> + <bridge name='virbr2' stp='on' delay='0'/> + <mac address='52:54:00:17:3F:37'/> + <ip address='192.168.152.1' netmask='255.255.255.0'> + <dhcp> + <range start='192.168.152.2' end='192.168.152.254' lease='12h'/> + </dhcp> + </ip> +</network> diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index a5f2711..ee80b41 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -112,6 +112,7 @@ mymain(void) } while (0) DO_TEST("isolated-network", restricted); + DO_TEST("isolated-network-with-lease-time", restricted); DO_TEST("netboot-network", restricted); DO_TEST("netboot-proxy-network", restricted); DO_TEST("nat-network-dns-srv-record-minimal", restricted); -- 2.7.3
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list