dnsmasq: latest pre-2.81 patches
[openwrt/openwrt.git] / package / network / services / dnsmasq / patches / 0032-Change-read_leases-to-skip-invalid-entries.patch
1 From 28cfe36e1eee9d2c234e0256ad459956b415a3bb Mon Sep 17 00:00:00 2001
2 From: Brian Haley <haleyb.dev@gmail.com>
3 Date: Thu, 17 Jan 2019 23:21:23 +0000
4 Subject: [PATCH 32/32] Change read_leases() to skip invalid entries.
5
6 There's no reason to stop reading the existing lease file
7 when dnsmasq is started and an invalid entry is found, it
8 can just be ignored. This was fallout from an Openstack
9 bug where the file was being written incorrectly with []
10 around IPv6 addresses.
11
12 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
13 ---
14 src/lease.c | 22 +++++++++++++++-------
15 1 file changed, 15 insertions(+), 7 deletions(-)
16
17 --- a/src/lease.c
18 +++ b/src/lease.c
19 @@ -60,8 +60,13 @@ static int read_leases(time_t now, FILE
20
21 if (fscanf(leasestream, " %64s %255s %764s",
22 daemon->namebuff, daemon->dhcp_buff, daemon->packet) != 3)
23 - return 0;
24 -
25 + {
26 + my_syslog(MS_DHCP | LOG_WARNING, _("ignoring invalid line in lease database: %s %s %s %s ..."),
27 + daemon->dhcp_buff3, daemon->dhcp_buff2,
28 + daemon->namebuff, daemon->dhcp_buff);
29 + continue;
30 + }
31 +
32 if (inet_pton(AF_INET, daemon->namebuff, &addr.addr4))
33 {
34 if ((lease = lease4_allocate(addr.addr4)))
35 @@ -92,7 +97,12 @@ static int read_leases(time_t now, FILE
36 }
37 #endif
38 else
39 - return 0;
40 + {
41 + my_syslog(MS_DHCP | LOG_WARNING, _("ignoring invalid line in lease database, bad address: %s"),
42 + daemon->namebuff);
43 + continue;
44 + }
45 +
46
47 if (!lease)
48 die (_("too many stored leases"), NULL, EC_MISC);
49 @@ -172,10 +182,8 @@ void lease_init(time_t now)
50 if (leasestream)
51 {
52 if (!read_leases(now, leasestream))
53 - my_syslog(MS_DHCP | LOG_ERR, _("failed to parse lease database, invalid line: %s %s %s %s ..."),
54 - daemon->dhcp_buff3, daemon->dhcp_buff2,
55 - daemon->namebuff, daemon->dhcp_buff);
56 -
57 + my_syslog(MS_DHCP | LOG_ERR, _("failed to parse lease database cleanly"));
58 +
59 if (ferror(leasestream))
60 die(_("failed to read lease file %s: %s"), daemon->lease_file, EC_FILE);
61 }