[libvirt] [PATCH v4] leaseshelper: improvements to support all events

This patch enables the helper program to detect event(s) triggered when there is a change in lease length or expiry and client-id. This transfers complete control of leases database to libvirt and obsoletes use of the lease database file (<network-name>.leases). That file will not be created, read, or written. This is achieved by adding the option --leasefile-ro to dnsmasq and passing a custom env var to leaseshelper, which helps us map events related to leases with their corresponding network bridges, no matter what the event be. Also, this requires the addition of a new non-lease entry in our custom lease database: "server-duid". It is required to identify a DHCPv6 server. Now that dnsmasq doesn't maintain its own leases database, it relies on our helper program to tell it about previous leases and server duid. Thus, this patch makes our leases program honor an extra action: "init", in which it sends the known info in a particular format to dnsmasq by printing it to stdout. --- This is compatible with libvirt 1.2.6 as only additions have been introduced, and the old leases file (*.status) will still be supported. v4: * Removed extra data structures for segregating ipv4 and ipv6 leases. v3: * Add server-duid as an entry in the lease object for every ipv6 lease. * Remove unnecessary variables and double copies. * Take value from DNSMASQ_OLD_HOSTNAME if hostname is not known. http://www.redhat.com/archives/libvir-list/2014-August/msg00028.html v2: http://www.redhat.com/archives/libvir-list/2014-July/msg01109.html v1: https://www.redhat.com/archives/libvir-list/2014-July/msg00568.html --- src/network/bridge_driver.c | 3 + src/network/leaseshelper.c | 142 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 117 insertions(+), 28 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 6cb421c..6ecbc37 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1280,7 +1280,10 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps)); virCommandAddArgFormat(cmd, "--conf-file=%s", configfile); + /* Libvirt gains full control of leases database */ + virCommandAddArgFormat(cmd, "--leasefile-ro"); virCommandAddArgFormat(cmd, "--dhcp-script=%s", leaseshelper_path); + virCommandAddEnvPair(cmd, "VIR_BRIDGE_NAME", network->def->bridge); *cmdout = cmd; ret = 0; diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c index 5b3c9c3..fdd04a3 100644 --- a/src/network/leaseshelper.c +++ b/src/network/leaseshelper.c @@ -50,6 +50,12 @@ */ #define VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX (32 * 1024 * 1024) +/* + * Use this when passing possibly-NULL strings to printf-a-likes. + * Required for unknown parameters during init call. + */ +#define EMPTY_STR(s) ((s) ? (s) : "*") + static const char *program_name; /* Display version information. */ @@ -65,7 +71,7 @@ usage(int status) if (status) { fprintf(stderr, _("%s: try --help for more details\n"), program_name); } else { - printf(_("Usage: %s add|old|del mac|clientid ip [hostname]\n" + printf(_("Usage: %s add|old|del|init mac|clientid ip [hostname]\n" "Designed for use with 'dnsmasq --dhcp-script'\n" "Refer to man page of dnsmasq for more details'\n"), program_name); @@ -89,6 +95,7 @@ enum virLeaseActionFlags { VIR_LEASE_ACTION_ADD, /* Create new lease */ VIR_LEASE_ACTION_OLD, /* Lease already exists, renew it */ VIR_LEASE_ACTION_DEL, /* Delete the lease */ + VIR_LEASE_ACTION_INIT, /* Tell dnsmasq of existing leases on restart */ VIR_LEASE_ACTION_LAST }; @@ -96,7 +103,7 @@ enum virLeaseActionFlags { VIR_ENUM_DECL(virLeaseAction); VIR_ENUM_IMPL(virLeaseAction, VIR_LEASE_ACTION_LAST, - "add", "old", "del"); + "add", "old", "del", "init"); int main(int argc, char **argv) @@ -107,12 +114,15 @@ main(int argc, char **argv) char *custom_lease_file = NULL; const char *ip = NULL; const char *mac = NULL; + const char *ip_tmp = NULL; + const char *leases_str = NULL; + const char *server_duid_tmp = NULL; const char *iaid = virGetEnvAllowSUID("DNSMASQ_IAID"); const char *clientid = virGetEnvAllowSUID("DNSMASQ_CLIENT_ID"); const char *interface = virGetEnvAllowSUID("DNSMASQ_INTERFACE"); const char *exptime_tmp = virGetEnvAllowSUID("DNSMASQ_LEASE_EXPIRES"); const char *hostname = virGetEnvAllowSUID("DNSMASQ_SUPPLIED_HOSTNAME"); - const char *leases_str = NULL; + const char *server_duid = virGetEnvAllowSUID("DNSMASQ_SERVER_DUID"); long long currtime = 0; long long expirytime = 0; size_t i = 0; @@ -120,7 +130,6 @@ main(int argc, char **argv) int pid_file_fd = -1; int rv = EXIT_FAILURE; int custom_lease_file_len = 0; - bool add = false; bool delete = false; virJSONValuePtr lease_new = NULL; virJSONValuePtr lease_tmp = NULL; @@ -156,16 +165,17 @@ main(int argc, char **argv) } } - if (argc != 4 && argc != 5) { + if (argc != 4 && argc != 5 && argc != 2) { /* Refer man page of dnsmasq --dhcp-script for more details */ usage(EXIT_FAILURE); } /* Make sure dnsmasq knows the interface. The interface name is not known - * when dnsmasq (re)starts and throws 'del' events for expired leases. - * So, if any old lease has expired, it will be automatically removed the - * next time this program is invoked */ - if (!interface) + * via env variable set by dnsmasq when dnsmasq (re)starts and throws 'del' + * events for expired leases. So, libvirtd sets another env var for this + * purpose */ + if (!interface && + !(interface = virGetEnvAllowSUID("VIR_BRIDGE_NAME"))) goto cleanup; ip = argv[3]; @@ -176,6 +186,10 @@ main(int argc, char **argv) if (argc == 5) hostname = argv[4]; + /* In case hostname is still unknown, use the last known one */ + if (!hostname) + hostname = virGetEnvAllowSUID("DNSMASQ_OLD_HOSTNAME"); + if (VIR_STRDUP(exptime, exptime_tmp) < 0) goto cleanup; @@ -184,7 +198,7 @@ main(int argc, char **argv) exptime[strlen(exptime) - 1] = '\0'; /* Check if it is an IPv6 lease */ - if (virGetEnvAllowSUID("DNSMASQ_IAID")) { + if (iaid) { mac = virGetEnvAllowSUID("DNSMASQ_MAC"); clientid = argv[2]; } @@ -234,7 +248,6 @@ main(int argc, char **argv) delete = true; if (action == VIR_LEASE_ACTION_ADD || action == VIR_LEASE_ACTION_OLD) { - add = true; /* Create new lease */ if (!(lease_new = virJSONValueNewObject())) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -259,11 +272,13 @@ main(int argc, char **argv) goto cleanup; if (clientid && virJSONValueObjectAppendString(lease_new, "client-id", clientid) < 0) goto cleanup; + if (server_duid && virJSONValueObjectAppendString(lease_new, "server-duid", server_duid) < 0) + goto cleanup; if (expirytime && virJSONValueObjectAppendNumberLong(lease_new, "expiry-time", expirytime) < 0) goto cleanup; } } - } else { + } else if (action != VIR_LEASE_ACTION_INIT) { fprintf(stderr, _("Unsupported action: %s\n"), virLeaseActionTypeToString(action)); exit(EXIT_FAILURE); @@ -292,8 +307,6 @@ main(int argc, char **argv) i = 0; while (i < virJSONValueArraySize(leases_array)) { - const char *ip_tmp = NULL; - long long expirytime_tmp = -1; if (!(lease_tmp = virJSONValueArrayGet(leases_array, i))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -302,14 +315,13 @@ main(int argc, char **argv) } if (!(ip_tmp = virJSONValueObjectGetString(lease_tmp, "ip-address")) || - (virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &expirytime_tmp) < 0)) { + (virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &expirytime) < 0)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to parse json")); goto cleanup; } - /* Check whether lease has expired or not */ - if (expirytime_tmp < currtime) { + if (expirytime < currtime) { i++; continue; } @@ -320,6 +332,25 @@ main(int argc, char **argv) continue; } + if (strchr(ip_tmp, ':')) { + /* This is an ipv6 lease */ + if ((server_duid_tmp + = virJSONValueObjectGetString(lease_tmp, "server-duid"))) { + if (!server_duid) { + /* Control reaches here when the 'action' is not for an + * ipv6 lease or, for some weird reason the env var + * DNSMASQ_SERVER_DUID wasn't set*/ + server_duid = server_duid_tmp; + } + } else { + /* Inject server-duid into those ipv6 leases which + * didn't have it previously, for example, those + * created by leaseshelper from libvirt 1.2.6 */ + if (virJSONValueObjectAppendString(lease_tmp, "server-duid", server_duid) < 0) + goto cleanup; + } + } + /* Move old lease to new array */ if (virJSONValueArrayAppend(leases_array_new, lease_tmp) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -332,25 +363,80 @@ main(int argc, char **argv) } } - if (add) { + switch ((enum virLeaseActionFlags) action) { + case VIR_LEASE_ACTION_INIT: + /* Man page of dnsmasq says: the script (helper program, in our case) + * should write the saved state of the lease database, in dnsmasq + * leasefile format, to stdout and exit with zero exit code, when + * called with argument init. Format: + * $expirytime $mac $ip $hostname $clientid # For all ipv4 leases + * duid $server-duid # If DHCPv6 is present + * $expirytime $iaid $ip $hostname $clientduid # For all ipv6 leases */ + + /* Traversing the ipv4 leases */ + for (i = 0; i < virJSONValueArraySize(leases_array_new); i++) { + lease_tmp = virJSONValueArrayGet(leases_array_new, i); + if (!(ip_tmp = virJSONValueObjectGetString(lease_tmp, "ip-address"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to parse json")); + goto cleanup; + } + if (!strchr(ip_tmp, ':')) { + virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &expirytime); + printf("%lld %s %s %s %s\n", + expirytime, + virJSONValueObjectGetString(lease_tmp, "mac-address"), + virJSONValueObjectGetString(lease_tmp, "ip-address"), + EMPTY_STR(virJSONValueObjectGetString(lease_tmp, "hostname")), + EMPTY_STR(virJSONValueObjectGetString(lease_tmp, "client-id"))); + } + } + + /* Traversing the ipv6 leases */ + if (server_duid) { + printf("duid %s\n", server_duid); + for (i = 0; i < virJSONValueArraySize(leases_array_new); i++) { + lease_tmp = virJSONValueArrayGet(leases_array_new, i); + if (!(ip_tmp = virJSONValueObjectGetString(lease_tmp, "ip-address"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to parse json")); + goto cleanup; + } + if (strchr(ip_tmp, ':')) { + virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &expirytime); + printf("%lld %s %s %s %s\n", + expirytime, + virJSONValueObjectGetString(lease_tmp, "iaid"), + virJSONValueObjectGetString(lease_tmp, "ip-address"), + EMPTY_STR(virJSONValueObjectGetString(lease_tmp, "hostname")), + EMPTY_STR(virJSONValueObjectGetString(lease_tmp, "client-id"))); + } + } + } + + break; + + case VIR_LEASE_ACTION_OLD: + case VIR_LEASE_ACTION_ADD: if (virJSONValueArrayAppend(leases_array_new, lease_new) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create json")); goto cleanup; } lease_new = NULL; - } - if (!(leases_str = virJSONValueToString(leases_array_new, true))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("empty json array")); - goto cleanup; - } + default: + if (!(leases_str = virJSONValueToString(leases_array_new, true))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("empty json array")); + goto cleanup; + } - /* Write to file */ - if (virFileRewrite(custom_lease_file, 0644, - customLeaseRewriteFile, &leases_str) < 0) - goto cleanup; + /* Write to file */ + if (virFileRewrite(custom_lease_file, 0644, + customLeaseRewriteFile, &leases_str) < 0) + goto cleanup; + } rv = EXIT_SUCCESS; -- 1.9.3

On 11/18/14 18:16, Nehal J Wani wrote:
This patch enables the helper program to detect event(s) triggered when there is a change in lease length or expiry and client-id. This transfers complete control of leases database to libvirt and obsoletes use of the lease database file (<network-name>.leases). That file will not be created, read, or written. This is achieved by adding the option --leasefile-ro to dnsmasq and passing a custom env var to leaseshelper, which helps us map events related to leases with their corresponding network bridges, no matter what the event be.
Also, this requires the addition of a new non-lease entry in our custom lease database: "server-duid". It is required to identify a DHCPv6 server.
Now that dnsmasq doesn't maintain its own leases database, it relies on our helper program to tell it about previous leases and server duid. Thus, this patch makes our leases program honor an extra action: "init", in which it sends the known info in a particular format to dnsmasq by printing it to stdout.
---
This is compatible with libvirt 1.2.6 as only additions have been introduced, and the old leases file (*.status) will still be supported.
v4: * Removed extra data structures for segregating ipv4 and ipv6 leases.
v3: * Add server-duid as an entry in the lease object for every ipv6 lease. * Remove unnecessary variables and double copies. * Take value from DNSMASQ_OLD_HOSTNAME if hostname is not known. http://www.redhat.com/archives/libvir-list/2014-August/msg00028.html
v2: http://www.redhat.com/archives/libvir-list/2014-July/msg01109.html
v1: https://www.redhat.com/archives/libvir-list/2014-July/msg00568.html
--- src/network/bridge_driver.c | 3 + src/network/leaseshelper.c | 142 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 117 insertions(+), 28 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 6cb421c..6ecbc37 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1280,7 +1280,10 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps)); virCommandAddArgFormat(cmd, "--conf-file=%s", configfile); + /* Libvirt gains full control of leases database */ + virCommandAddArgFormat(cmd, "--leasefile-ro");
As we are now starting dnsmasq with the libvirt managed database, we should get rid of the lease file configuration option present in the config file.
virCommandAddArgFormat(cmd, "--dhcp-script=%s", leaseshelper_path); + virCommandAddEnvPair(cmd, "VIR_BRIDGE_NAME", network->def->bridge);
*cmdout = cmd; ret = 0; diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c index 5b3c9c3..fdd04a3 100644 --- a/src/network/leaseshelper.c +++ b/src/network/leaseshelper.c @@ -50,6 +50,12 @@ */ #define VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX (32 * 1024 * 1024)
+/* + * Use this when passing possibly-NULL strings to printf-a-likes. + * Required for unknown parameters during init call. + */ +#define EMPTY_STR(s) ((s) ? (s) : "*") + static const char *program_name;
/* Display version information. */ @@ -65,7 +71,7 @@ usage(int status) if (status) { fprintf(stderr, _("%s: try --help for more details\n"), program_name); } else { - printf(_("Usage: %s add|old|del mac|clientid ip [hostname]\n" + printf(_("Usage: %s add|old|del|init mac|clientid ip [hostname]\n" "Designed for use with 'dnsmasq --dhcp-script'\n" "Refer to man page of dnsmasq for more details'\n"), program_name); @@ -89,6 +95,7 @@ enum virLeaseActionFlags { VIR_LEASE_ACTION_ADD, /* Create new lease */ VIR_LEASE_ACTION_OLD, /* Lease already exists, renew it */ VIR_LEASE_ACTION_DEL, /* Delete the lease */ + VIR_LEASE_ACTION_INIT, /* Tell dnsmasq of existing leases on restart */
VIR_LEASE_ACTION_LAST }; @@ -96,7 +103,7 @@ enum virLeaseActionFlags { VIR_ENUM_DECL(virLeaseAction);
VIR_ENUM_IMPL(virLeaseAction, VIR_LEASE_ACTION_LAST, - "add", "old", "del"); + "add", "old", "del", "init");
int main(int argc, char **argv) @@ -107,12 +114,15 @@ main(int argc, char **argv) char *custom_lease_file = NULL; const char *ip = NULL; const char *mac = NULL; + const char *ip_tmp = NULL; + const char *leases_str = NULL; + const char *server_duid_tmp = NULL; const char *iaid = virGetEnvAllowSUID("DNSMASQ_IAID"); const char *clientid = virGetEnvAllowSUID("DNSMASQ_CLIENT_ID"); const char *interface = virGetEnvAllowSUID("DNSMASQ_INTERFACE"); const char *exptime_tmp = virGetEnvAllowSUID("DNSMASQ_LEASE_EXPIRES"); const char *hostname = virGetEnvAllowSUID("DNSMASQ_SUPPLIED_HOSTNAME"); - const char *leases_str = NULL; + const char *server_duid = virGetEnvAllowSUID("DNSMASQ_SERVER_DUID"); long long currtime = 0; long long expirytime = 0; size_t i = 0; @@ -120,7 +130,6 @@ main(int argc, char **argv) int pid_file_fd = -1; int rv = EXIT_FAILURE; int custom_lease_file_len = 0; - bool add = false; bool delete = false; virJSONValuePtr lease_new = NULL; virJSONValuePtr lease_tmp = NULL; @@ -156,16 +165,17 @@ main(int argc, char **argv) } }
- if (argc != 4 && argc != 5) { + if (argc != 4 && argc != 5 && argc != 2) { /* Refer man page of dnsmasq --dhcp-script for more details */ usage(EXIT_FAILURE); }
/* Make sure dnsmasq knows the interface. The interface name is not known - * when dnsmasq (re)starts and throws 'del' events for expired leases. - * So, if any old lease has expired, it will be automatically removed the - * next time this program is invoked */ - if (!interface) + * via env variable set by dnsmasq when dnsmasq (re)starts and throws 'del' + * events for expired leases. So, libvirtd sets another env var for this + * purpose */ + if (!interface && + !(interface = virGetEnvAllowSUID("VIR_BRIDGE_NAME"))) goto cleanup;
ip = argv[3]; @@ -176,6 +186,10 @@ main(int argc, char **argv) if (argc == 5) hostname = argv[4];
+ /* In case hostname is still unknown, use the last known one */ + if (!hostname) + hostname = virGetEnvAllowSUID("DNSMASQ_OLD_HOSTNAME"); + if (VIR_STRDUP(exptime, exptime_tmp) < 0) goto cleanup;
When dnsmasq is starting and invokes this helper with the "init" parameter it does not populate the DNSMASQ_LEASE_EXPIRES env variable. VIR_STRDUP then ignores that copy and ...
@@ -184,7 +198,7 @@ main(int argc, char **argv) exptime[strlen(exptime) - 1] = '\0';
The program crashes here at the strlen() call thus it never populates dnsmasq's internal lease database when started.
/* Check if it is an IPv6 lease */ - if (virGetEnvAllowSUID("DNSMASQ_IAID")) { + if (iaid) { mac = virGetEnvAllowSUID("DNSMASQ_MAC"); clientid = argv[2]; }
With the two things above fixed it looks good and seems to work correctly with my test setup. I'll be reposting this patch as I've already made the changes necessary to make this work while trying to figure out why it doesn't work. Peter

On 11/18/14 18:16, Nehal J Wani wrote:
This patch enables the helper program to detect event(s) triggered when there is a change in lease length or expiry and client-id. This transfers complete control of leases database to libvirt and obsoletes use of the lease database file (<network-name>.leases). That file will not be created, read, or written. This is achieved by adding the option --leasefile-ro to dnsmasq and passing a custom env var to leaseshelper, which helps us map events related to leases with their corresponding network bridges, no matter what the event be.
Also, this requires the addition of a new non-lease entry in our custom lease database: "server-duid". It is required to identify a DHCPv6 server.
Now that dnsmasq doesn't maintain its own leases database, it relies on our helper program to tell it about previous leases and server duid. Thus, this patch makes our leases program honor an extra action: "init", in which it sends the known info in a particular format to dnsmasq by printing it to stdout.
---
This is compatible with libvirt 1.2.6 as only additions have been introduced, and the old leases file (*.status) will still be supported.
v4: * Removed extra data structures for segregating ipv4 and ipv6 leases.
v3: * Add server-duid as an entry in the lease object for every ipv6 lease. * Remove unnecessary variables and double copies. * Take value from DNSMASQ_OLD_HOSTNAME if hostname is not known. http://www.redhat.com/archives/libvir-list/2014-August/msg00028.html
v2: http://www.redhat.com/archives/libvir-list/2014-July/msg01109.html
v1: https://www.redhat.com/archives/libvir-list/2014-July/msg00568.html
--- src/network/bridge_driver.c | 3 + src/network/leaseshelper.c | 142 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 117 insertions(+), 28 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 6cb421c..6ecbc37 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1280,7 +1280,10 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps)); virCommandAddArgFormat(cmd, "--conf-file=%s", configfile); + /* Libvirt gains full control of leases database */ + virCommandAddArgFormat(cmd, "--leasefile-ro");
One other thing that is worrying is that if you specify this option and the leaseshelper implements the init operation we'd no longer load a possibly pre-existing leases file that was present previous to the upgrade to this handling. This would cause the guests to be re-addressed from the moment of the upgrade. (exactly once). The question here is. Do we care about this slight breakage? I'm not entirely decided yet. I probably wouldn't care. A possible workaround will be to check whether the old leases file exists and refrain from starting with the --leasefile-ro option in that case.
virCommandAddArgFormat(cmd, "--dhcp-script=%s", leaseshelper_path); + virCommandAddEnvPair(cmd, "VIR_BRIDGE_NAME", network->def->bridge);
*cmdout = cmd; ret = 0;
Thanks for opinions. Peter

On Thu, Nov 20, 2014 at 10:56:53AM +0100, Peter Krempa wrote:
On 11/18/14 18:16, Nehal J Wani wrote:
This patch enables the helper program to detect event(s) triggered when there is a change in lease length or expiry and client-id. This transfers complete control of leases database to libvirt and obsoletes use of the lease database file (<network-name>.leases). That file will not be created, read, or written. This is achieved by adding the option --leasefile-ro to dnsmasq and passing a custom env var to leaseshelper, which helps us map events related to leases with their corresponding network bridges, no matter what the event be.
Also, this requires the addition of a new non-lease entry in our custom lease database: "server-duid". It is required to identify a DHCPv6 server.
Now that dnsmasq doesn't maintain its own leases database, it relies on our helper program to tell it about previous leases and server duid. Thus, this patch makes our leases program honor an extra action: "init", in which it sends the known info in a particular format to dnsmasq by printing it to stdout.
---
This is compatible with libvirt 1.2.6 as only additions have been introduced, and the old leases file (*.status) will still be supported.
v4: * Removed extra data structures for segregating ipv4 and ipv6 leases.
v3: * Add server-duid as an entry in the lease object for every ipv6 lease. * Remove unnecessary variables and double copies. * Take value from DNSMASQ_OLD_HOSTNAME if hostname is not known. http://www.redhat.com/archives/libvir-list/2014-August/msg00028.html
v2: http://www.redhat.com/archives/libvir-list/2014-July/msg01109.html
v1: https://www.redhat.com/archives/libvir-list/2014-July/msg00568.html
--- src/network/bridge_driver.c | 3 + src/network/leaseshelper.c | 142 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 117 insertions(+), 28 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 6cb421c..6ecbc37 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1280,7 +1280,10 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps)); virCommandAddArgFormat(cmd, "--conf-file=%s", configfile); + /* Libvirt gains full control of leases database */ + virCommandAddArgFormat(cmd, "--leasefile-ro");
One other thing that is worrying is that if you specify this option and the leaseshelper implements the init operation we'd no longer load a possibly pre-existing leases file that was present previous to the upgrade to this handling.
This would cause the guests to be re-addressed from the moment of the upgrade. (exactly once).
The question here is. Do we care about this slight breakage? I'm not entirely decided yet. I probably wouldn't care.
A possible workaround will be to check whether the old leases file exists and refrain from starting with the --leasefile-ro option in that case.
When libvirtd is upgraded, we don't restart dnsmasq so it will continue with its current config. Only once you shutdown the virtual network and restart it (eg most likely upon next reboot) would the config change loosing the leases. That probably isn't the end of the world because with DHCP there is never a strong guarantee of getting the same IP address unless fixed mappings are provided. If there's an easy way to notice the old file and convert it to the new file format we should do it, but if it is hard, then its not the end of the world. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 11/20/14 11:24, Daniel P. Berrange wrote:
On Thu, Nov 20, 2014 at 10:56:53AM +0100, Peter Krempa wrote:
On 11/18/14 18:16, Nehal J Wani wrote:
This patch enables the helper program to detect event(s) triggered when there is a change in lease length or expiry and client-id. This transfers complete control of leases database to libvirt and obsoletes use of the lease database file (<network-name>.leases). That file will not be created, read, or written. This is achieved by adding the option --leasefile-ro to dnsmasq and passing a custom env var to leaseshelper, which helps us map events related to leases with their corresponding network bridges, no matter what the event be.
Also, this requires the addition of a new non-lease entry in our custom lease database: "server-duid". It is required to identify a DHCPv6 server.
Now that dnsmasq doesn't maintain its own leases database, it relies on our helper program to tell it about previous leases and server duid. Thus, this patch makes our leases program honor an extra action: "init", in which it sends the known info in a particular format to dnsmasq by printing it to stdout.
---
This is compatible with libvirt 1.2.6 as only additions have been introduced, and the old leases file (*.status) will still be supported.
v4: * Removed extra data structures for segregating ipv4 and ipv6 leases.
v3: * Add server-duid as an entry in the lease object for every ipv6 lease. * Remove unnecessary variables and double copies. * Take value from DNSMASQ_OLD_HOSTNAME if hostname is not known. http://www.redhat.com/archives/libvir-list/2014-August/msg00028.html
v2: http://www.redhat.com/archives/libvir-list/2014-July/msg01109.html
v1: https://www.redhat.com/archives/libvir-list/2014-July/msg00568.html
--- src/network/bridge_driver.c | 3 + src/network/leaseshelper.c | 142 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 117 insertions(+), 28 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 6cb421c..6ecbc37 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1280,7 +1280,10 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps)); virCommandAddArgFormat(cmd, "--conf-file=%s", configfile); + /* Libvirt gains full control of leases database */ + virCommandAddArgFormat(cmd, "--leasefile-ro");
One other thing that is worrying is that if you specify this option and the leaseshelper implements the init operation we'd no longer load a possibly pre-existing leases file that was present previous to the upgrade to this handling.
This would cause the guests to be re-addressed from the moment of the upgrade. (exactly once).
The question here is. Do we care about this slight breakage? I'm not entirely decided yet. I probably wouldn't care.
A possible workaround will be to check whether the old leases file exists and refrain from starting with the --leasefile-ro option in that case.
When libvirtd is upgraded, we don't restart dnsmasq so it will continue with its current config. Only once you shutdown the virtual network and restart it (eg most likely upon next reboot) would the config change loosing the leases. That probably isn't the end of the world because with DHCP there is never a strong guarantee of getting the same IP address unless fixed mappings are provided.
Yep, and addresses that have to remain static can be configured explicitly.
If there's an easy way to notice the old file and convert it to the new file format we should do it, but if it is hard, then its not the end of the world.
AFAIK the leaseshelper was introduced so that we don't ever have to parse the dnsmasq lease file so having to parse it ourselves so parsing it wouldn't be viable. I was thinking of not using the new initial lease reloading in case an existing lease file is present if we would want to keep the mapping, but even that increases the complexity. Thus I'm glad we don't have to strictly keep the leases file and users will deal with this slight issue just once at upgrade.
Regards, Daniel
Peter
participants (3)
-
Daniel P. Berrange
-
Nehal J Wani
-
Peter Krempa