Re: [Dnsmasq-discuss] [PATCH] Change read_leases() to skip invalid entries

2019-01-17 Thread Simon Kelley
Patch applied. Thanks.

Simon.

On 17/01/2019 20:50, Brian Haley wrote:
> There's no reason to stop reading the existing lease file
> when dnsmasq is started and an invalid entry is found, it
> can just be ignored.  This was fallout from an Openstack
> bug where the file was being written incorrectly with []
> around IPv6 addresses.

___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


[Dnsmasq-discuss] [PATCH] Change read_leases() to skip invalid entries

2019-01-17 Thread Brian Haley

There's no reason to stop reading the existing lease file
when dnsmasq is started and an invalid entry is found, it
can just be ignored.  This was fallout from an Openstack
bug where the file was being written incorrectly with []
around IPv6 addresses.
---
 src/lease.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/lease.c b/src/lease.c
index 3514e44..a415513 100644
--- a/src/lease.c
+++ b/src/lease.c
@@ -60,7 +60,12 @@ static int read_leases(time_t now, FILE *leasestream)

if (fscanf(leasestream, " %64s %255s %764s",
   daemon->namebuff, daemon->dhcp_buff, daemon->packet) != 3)
- return 0;
+ {
+   my_syslog(MS_DHCP | LOG_WARNING, _("ignoring invalid line in lease 
database: %s %s %s %s ..."),
+ daemon->dhcp_buff3, daemon->dhcp_buff2,
+ daemon->namebuff, daemon->dhcp_buff);
+   continue;
+ }

if (inet_pton(AF_INET, daemon->namebuff, ))
  {
@@ -92,7 +97,12 @@ static int read_leases(time_t now, FILE *leasestream)
  }
 #endif
else
- return 0;
+ {
+   my_syslog(MS_DHCP | LOG_WARNING, _("ignoring invalid line in lease 
database, bad address: %s %s %s %s ..."),
+ daemon->dhcp_buff3, daemon->dhcp_buff2,
+ daemon->namebuff, daemon->dhcp_buff);
+   continue;
+ }
 
 	if (!lease)

  die (_("too many stored leases"), NULL, EC_MISC);
@@ -172,9 +182,7 @@ void lease_init(time_t now)
   if (leasestream)
 {
   if (!read_leases(now, leasestream))
-   my_syslog(MS_DHCP | LOG_ERR, _("failed to parse lease database, invalid 
line: %s %s %s %s ..."),
- daemon->dhcp_buff3, daemon->dhcp_buff2,
- daemon->namebuff, daemon->dhcp_buff);
+   my_syslog(MS_DHCP | LOG_ERR, _("failed to parse lease database 
cleanly"));
 
   if (ferror(leasestream))

die(_("failed to read lease file %s: %s"), daemon->lease_file, EC_FILE);
--
2.7.4


___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss