Simon Kelley | c47e3ba | 2014-01-08 17:07:54 +0000 | [diff] [blame] | 1 | /* dnsmasq is Copyright (c) 2000-2014 Simon Kelley |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License as published by |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5 | the Free Software Foundation; version 2 dated June, 1991, or |
| 6 | (at your option) version 3 dated 29 June, 2007. |
| 7 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 12 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 17 | #include "dnsmasq.h" |
| 18 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 19 | #ifdef HAVE_DHCP |
| 20 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 21 | static struct dhcp_lease *leases = NULL, *old_leases = NULL; |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 22 | static int dns_dirty, file_dirty, leases_left; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 23 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 24 | void lease_init(time_t now) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 25 | { |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 26 | unsigned long ei; |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 27 | struct all_addr addr; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 28 | struct dhcp_lease *lease; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 29 | int clid_len, hw_len, hw_type; |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 30 | FILE *leasestream; |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 31 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 32 | leases_left = daemon->dhcp_max; |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 33 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 34 | if (option_bool(OPT_LEASE_RO)) |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 35 | { |
| 36 | /* run "<lease_change_script> init" once to get the |
| 37 | initial state of the database. If leasefile-ro is |
| 38 | set without a script, we just do without any |
| 39 | lease database. */ |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 40 | #ifdef HAVE_SCRIPT |
| 41 | if (daemon->lease_change_command) |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 42 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 43 | strcpy(daemon->dhcp_buff, daemon->lease_change_command); |
| 44 | strcat(daemon->dhcp_buff, " init"); |
| 45 | leasestream = popen(daemon->dhcp_buff, "r"); |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 46 | } |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 47 | else |
| 48 | #endif |
| 49 | { |
| 50 | file_dirty = dns_dirty = 0; |
| 51 | return; |
| 52 | } |
| 53 | |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 54 | } |
| 55 | else |
| 56 | { |
| 57 | /* NOTE: need a+ mode to create file if it doesn't exist */ |
| 58 | leasestream = daemon->lease_stream = fopen(daemon->lease_file, "a+"); |
| 59 | |
| 60 | if (!leasestream) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 61 | die(_("cannot open or create lease file %s: %s"), daemon->lease_file, EC_FILE); |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 62 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 63 | /* a+ mode leaves pointer at end. */ |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 64 | rewind(leasestream); |
| 65 | } |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 66 | |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 67 | /* client-id max length is 255 which is 255*2 digits + 254 colons |
| 68 | borrow DNS packet buffer which is always larger than 1000 bytes */ |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 69 | if (leasestream) |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 70 | while (fscanf(leasestream, "%255s %255s", daemon->dhcp_buff3, daemon->dhcp_buff2) == 2) |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 71 | { |
Simon Kelley | 3d7b550 | 2012-02-10 17:35:37 +0000 | [diff] [blame] | 72 | #ifdef HAVE_DHCP6 |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 73 | if (strcmp(daemon->dhcp_buff3, "duid") == 0) |
| 74 | { |
| 75 | daemon->duid_len = parse_hex(daemon->dhcp_buff2, (unsigned char *)daemon->dhcp_buff2, 130, NULL, NULL); |
| 76 | daemon->duid = safe_malloc(daemon->duid_len); |
| 77 | memcpy(daemon->duid, daemon->dhcp_buff2, daemon->duid_len); |
| 78 | continue; |
| 79 | } |
Simon Kelley | 3d7b550 | 2012-02-10 17:35:37 +0000 | [diff] [blame] | 80 | #endif |
| 81 | |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 82 | ei = atol(daemon->dhcp_buff3); |
| 83 | |
| 84 | if (fscanf(leasestream, " %64s %255s %764s", |
| 85 | daemon->namebuff, daemon->dhcp_buff, daemon->packet) != 3) |
| 86 | break; |
| 87 | |
| 88 | clid_len = 0; |
| 89 | if (strcmp(daemon->packet, "*") != 0) |
| 90 | clid_len = parse_hex(daemon->packet, (unsigned char *)daemon->packet, 255, NULL, NULL); |
| 91 | |
| 92 | if (inet_pton(AF_INET, daemon->namebuff, &addr.addr.addr4) && |
| 93 | (lease = lease4_allocate(addr.addr.addr4))) |
| 94 | { |
| 95 | hw_len = parse_hex(daemon->dhcp_buff2, (unsigned char *)daemon->dhcp_buff2, DHCP_CHADDR_MAX, NULL, &hw_type); |
| 96 | /* For backwards compatibility, no explict MAC address type means ether. */ |
| 97 | if (hw_type == 0 && hw_len != 0) |
| 98 | hw_type = ARPHRD_ETHER; |
| 99 | |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 100 | lease_set_hwaddr(lease, (unsigned char *)daemon->dhcp_buff2, (unsigned char *)daemon->packet, |
Simon Kelley | a9ab732 | 2012-04-28 11:29:37 +0100 | [diff] [blame] | 101 | hw_len, hw_type, clid_len, now, 0); |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 102 | |
| 103 | if (strcmp(daemon->dhcp_buff, "*") != 0) |
| 104 | lease_set_hostname(lease, daemon->dhcp_buff, 0, get_domain(lease->addr), NULL); |
| 105 | } |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 106 | #ifdef HAVE_DHCP6 |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 107 | else if (inet_pton(AF_INET6, daemon->namebuff, &addr.addr.addr6)) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 108 | { |
| 109 | char *s = daemon->dhcp_buff2; |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 110 | int lease_type = LEASE_NA; |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 111 | int iaid; |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 112 | |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 113 | if (s[0] == 'T') |
| 114 | { |
| 115 | lease_type = LEASE_TA; |
| 116 | s++; |
| 117 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 118 | |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 119 | iaid = strtoul(s, NULL, 10); |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 120 | |
| 121 | if ((lease = lease6_allocate(&addr.addr.addr6, lease_type))) |
| 122 | { |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 123 | lease_set_hwaddr(lease, NULL, (unsigned char *)daemon->packet, 0, 0, clid_len, now, 0); |
| 124 | lease_set_iaid(lease, iaid); |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 125 | if (strcmp(daemon->dhcp_buff, "*") != 0) |
| 126 | lease_set_hostname(lease, daemon->dhcp_buff, 0, get_domain6((struct in6_addr *)lease->hwaddr), NULL); |
| 127 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 128 | } |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 129 | #endif |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 130 | else |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 131 | break; |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 132 | |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 133 | if (!lease) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 134 | die (_("too many stored leases"), NULL, EC_MISC); |
| 135 | |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 136 | #ifdef HAVE_BROKEN_RTC |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 137 | if (ei != 0) |
| 138 | lease->expires = (time_t)ei + now; |
| 139 | else |
| 140 | lease->expires = (time_t)0; |
| 141 | lease->length = ei; |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 142 | #else |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 143 | /* strictly time_t is opaque, but this hack should work on all sane systems, |
| 144 | even when sizeof(time_t) == 8 */ |
| 145 | lease->expires = (time_t)ei; |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 146 | #endif |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 147 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 148 | /* set these correctly: the "old" events are generated later from |
| 149 | the startup synthesised SIGHUP. */ |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 150 | lease->flags &= ~(LEASE_NEW | LEASE_CHANGED); |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 153 | #ifdef HAVE_SCRIPT |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 154 | if (!daemon->lease_stream) |
| 155 | { |
| 156 | int rc = 0; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 157 | |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 158 | /* shell returns 127 for "command not found", 126 for bad permissions. */ |
| 159 | if (!leasestream || (rc = pclose(leasestream)) == -1 || WEXITSTATUS(rc) == 127 || WEXITSTATUS(rc) == 126) |
| 160 | { |
| 161 | if (WEXITSTATUS(rc) == 127) |
| 162 | errno = ENOENT; |
| 163 | else if (WEXITSTATUS(rc) == 126) |
| 164 | errno = EACCES; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 165 | die(_("cannot run lease-init script %s: %s"), daemon->lease_change_command, EC_FILE); |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | if (WEXITSTATUS(rc) != 0) |
| 169 | { |
| 170 | sprintf(daemon->dhcp_buff, "%d", WEXITSTATUS(rc)); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 171 | die(_("lease-init script returned exit code %s"), daemon->dhcp_buff, WEXITSTATUS(rc) + EC_INIT_OFFSET); |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 172 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 173 | } |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 174 | #endif |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 175 | |
| 176 | /* Some leases may have expired */ |
| 177 | file_dirty = 0; |
| 178 | lease_prune(NULL, now); |
| 179 | dns_dirty = 1; |
Simon Kelley | 44a2a31 | 2004-03-10 20:04:35 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 182 | void lease_update_from_configs(void) |
Simon Kelley | 44a2a31 | 2004-03-10 20:04:35 +0000 | [diff] [blame] | 183 | { |
| 184 | /* changes to the config may change current leases. */ |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 185 | |
Simon Kelley | 44a2a31 | 2004-03-10 20:04:35 +0000 | [diff] [blame] | 186 | struct dhcp_lease *lease; |
| 187 | struct dhcp_config *config; |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 188 | char *name; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 189 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 190 | for (lease = leases; lease; lease = lease->next) |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 191 | if (lease->flags & (LEASE_TA | LEASE_NA)) |
| 192 | continue; |
| 193 | else if ((config = find_config(daemon->dhcp_conf, NULL, lease->clid, lease->clid_len, |
| 194 | lease->hwaddr, lease->hwaddr_len, lease->hwaddr_type, NULL)) && |
| 195 | (config->flags & CONFIG_NAME) && |
| 196 | (!(config->flags & CONFIG_ADDR) || config->addr.s_addr == lease->addr.s_addr)) |
Simon Kelley | 70c5e3e | 2012-02-06 22:05:15 +0000 | [diff] [blame] | 197 | lease_set_hostname(lease, config->hostname, 1, get_domain(lease->addr), NULL); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 198 | else if ((name = host_from_dns(lease->addr))) |
Simon Kelley | 70c5e3e | 2012-02-06 22:05:15 +0000 | [diff] [blame] | 199 | lease_set_hostname(lease, name, 1, get_domain(lease->addr), NULL); /* updates auth flag only */ |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 200 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 201 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 202 | static void ourprintf(int *errp, char *format, ...) |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 203 | { |
| 204 | va_list ap; |
| 205 | |
| 206 | va_start(ap, format); |
| 207 | if (!(*errp) && vfprintf(daemon->lease_stream, format, ap) < 0) |
| 208 | *errp = errno; |
| 209 | va_end(ap); |
| 210 | } |
| 211 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 212 | void lease_update_file(time_t now) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 213 | { |
| 214 | struct dhcp_lease *lease; |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 215 | time_t next_event; |
| 216 | int i, err = 0; |
| 217 | |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 218 | if (file_dirty != 0 && daemon->lease_stream) |
Simon Kelley | 44a2a31 | 2004-03-10 20:04:35 +0000 | [diff] [blame] | 219 | { |
Simon Kelley | cdeda28 | 2006-03-16 20:16:06 +0000 | [diff] [blame] | 220 | errno = 0; |
| 221 | rewind(daemon->lease_stream); |
| 222 | if (errno != 0 || ftruncate(fileno(daemon->lease_stream), 0) != 0) |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 223 | err = errno; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 224 | |
| 225 | for (lease = leases; lease; lease = lease->next) |
| 226 | { |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 227 | |
| 228 | #ifdef HAVE_DHCP6 |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 229 | if (lease->flags & (LEASE_TA | LEASE_NA)) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 230 | continue; |
| 231 | #endif |
| 232 | |
Simon Kelley | 44a2a31 | 2004-03-10 20:04:35 +0000 | [diff] [blame] | 233 | #ifdef HAVE_BROKEN_RTC |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 234 | ourprintf(&err, "%u ", lease->length); |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 235 | #else |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 236 | ourprintf(&err, "%lu ", (unsigned long)lease->expires); |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 237 | #endif |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 238 | |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 239 | if (lease->hwaddr_type != ARPHRD_ETHER || lease->hwaddr_len == 0) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 240 | ourprintf(&err, "%.2x-", lease->hwaddr_type); |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 241 | for (i = 0; i < lease->hwaddr_len; i++) |
| 242 | { |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 243 | ourprintf(&err, "%.2x", lease->hwaddr[i]); |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 244 | if (i != lease->hwaddr_len - 1) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 245 | ourprintf(&err, ":"); |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 246 | } |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 247 | |
| 248 | inet_ntop(AF_INET, &lease->addr, daemon->addrbuff, ADDRSTRLEN); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 249 | |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 250 | ourprintf(&err, " %s ", daemon->addrbuff); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 251 | ourprintf(&err, "%s ", lease->hostname ? lease->hostname : "*"); |
| 252 | |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 253 | if (lease->clid && lease->clid_len != 0) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 254 | { |
| 255 | for (i = 0; i < lease->clid_len - 1; i++) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 256 | ourprintf(&err, "%.2x:", lease->clid[i]); |
| 257 | ourprintf(&err, "%.2x\n", lease->clid[i]); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 258 | } |
| 259 | else |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 260 | ourprintf(&err, "*\n"); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 261 | } |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 262 | |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 263 | #ifdef HAVE_DHCP6 |
| 264 | if (daemon->duid) |
| 265 | { |
| 266 | ourprintf(&err, "duid "); |
| 267 | for (i = 0; i < daemon->duid_len - 1; i++) |
| 268 | ourprintf(&err, "%.2x:", daemon->duid[i]); |
| 269 | ourprintf(&err, "%.2x\n", daemon->duid[i]); |
| 270 | |
| 271 | for (lease = leases; lease; lease = lease->next) |
| 272 | { |
| 273 | |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 274 | if (!(lease->flags & (LEASE_TA | LEASE_NA))) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 275 | continue; |
| 276 | |
| 277 | #ifdef HAVE_BROKEN_RTC |
| 278 | ourprintf(&err, "%u ", lease->length); |
| 279 | #else |
| 280 | ourprintf(&err, "%lu ", (unsigned long)lease->expires); |
| 281 | #endif |
| 282 | |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 283 | inet_ntop(AF_INET6, &lease->addr6, daemon->addrbuff, ADDRSTRLEN); |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 284 | |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 285 | ourprintf(&err, "%s%u %s ", (lease->flags & LEASE_TA) ? "T" : "", |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 286 | lease->iaid, daemon->addrbuff); |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 287 | ourprintf(&err, "%s ", lease->hostname ? lease->hostname : "*"); |
| 288 | |
| 289 | if (lease->clid && lease->clid_len != 0) |
| 290 | { |
| 291 | for (i = 0; i < lease->clid_len - 1; i++) |
| 292 | ourprintf(&err, "%.2x:", lease->clid[i]); |
| 293 | ourprintf(&err, "%.2x\n", lease->clid[i]); |
| 294 | } |
| 295 | else |
| 296 | ourprintf(&err, "*\n"); |
| 297 | } |
| 298 | } |
| 299 | #endif |
| 300 | |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 301 | if (fflush(daemon->lease_stream) != 0 || |
| 302 | fsync(fileno(daemon->lease_stream)) < 0) |
| 303 | err = errno; |
| 304 | |
| 305 | if (!err) |
| 306 | file_dirty = 0; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 307 | } |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 308 | |
Simon Kelley | dd0e0a3 | 2014-01-22 11:16:59 +0000 | [diff] [blame] | 309 | /* Set alarm for when the first lease expires. */ |
Simon Kelley | c5ad4e7 | 2012-02-24 16:06:20 +0000 | [diff] [blame] | 310 | next_event = 0; |
| 311 | |
| 312 | #ifdef HAVE_DHCP6 |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 313 | /* do timed RAs and determine when the next is, also pings to potential SLAAC addresses */ |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 314 | if (daemon->doing_ra) |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 315 | { |
Simon Kelley | 919dd7c | 2012-05-12 15:23:09 +0100 | [diff] [blame] | 316 | time_t event; |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 317 | |
Simon Kelley | 919dd7c | 2012-05-12 15:23:09 +0100 | [diff] [blame] | 318 | if ((event = periodic_slaac(now, leases)) != 0) |
| 319 | { |
| 320 | if (next_event == 0 || difftime(next_event, event) > 0.0) |
| 321 | next_event = event; |
| 322 | } |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 323 | |
Simon Kelley | 919dd7c | 2012-05-12 15:23:09 +0100 | [diff] [blame] | 324 | if ((event = periodic_ra(now)) != 0) |
| 325 | { |
| 326 | if (next_event == 0 || difftime(next_event, event) > 0.0) |
| 327 | next_event = event; |
| 328 | } |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 329 | } |
Simon Kelley | c5ad4e7 | 2012-02-24 16:06:20 +0000 | [diff] [blame] | 330 | #endif |
| 331 | |
| 332 | for (lease = leases; lease; lease = lease->next) |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 333 | if (lease->expires != 0 && |
Simon Kelley | dd0e0a3 | 2014-01-22 11:16:59 +0000 | [diff] [blame] | 334 | (next_event == 0 || difftime(next_event, lease->expires) > 0.0)) |
| 335 | next_event = lease->expires; |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 336 | |
| 337 | if (err) |
| 338 | { |
| 339 | if (next_event == 0 || difftime(next_event, LEASE_RETRY + now) > 0.0) |
| 340 | next_event = LEASE_RETRY + now; |
| 341 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 342 | my_syslog(MS_DHCP | LOG_ERR, _("failed to write %s: %s (retry in %us)"), |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 343 | daemon->lease_file, strerror(err), |
| 344 | (unsigned int)difftime(next_event, now)); |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 345 | } |
| 346 | |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 347 | send_alarm(next_event, now); |
Simon Kelley | 44a2a31 | 2004-03-10 20:04:35 +0000 | [diff] [blame] | 348 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 349 | |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 350 | |
Simon Kelley | 3f2873d | 2013-05-14 11:28:47 +0100 | [diff] [blame] | 351 | static int find_interface_v4(struct in_addr local, int if_index, char *label, |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 352 | struct in_addr netmask, struct in_addr broadcast, void *vparam) |
Simon Kelley | 44a2a31 | 2004-03-10 20:04:35 +0000 | [diff] [blame] | 353 | { |
| 354 | struct dhcp_lease *lease; |
| 355 | |
Simon Kelley | 3f2873d | 2013-05-14 11:28:47 +0100 | [diff] [blame] | 356 | (void) label; |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 357 | (void) broadcast; |
| 358 | (void) vparam; |
| 359 | |
| 360 | for (lease = leases; lease; lease = lease->next) |
| 361 | if (!(lease->flags & (LEASE_TA | LEASE_NA))) |
| 362 | if (is_same_net(local, lease->addr, netmask)) |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 363 | lease_set_interface(lease, if_index, *((time_t *)vparam)); |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 364 | |
| 365 | return 1; |
| 366 | } |
| 367 | |
| 368 | #ifdef HAVE_DHCP6 |
| 369 | static int find_interface_v6(struct in6_addr *local, int prefix, |
Simon Kelley | bad7b87 | 2012-12-20 22:00:39 +0000 | [diff] [blame] | 370 | int scope, int if_index, int flags, |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 371 | int preferred, int valid, void *vparam) |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 372 | { |
| 373 | struct dhcp_lease *lease; |
| 374 | |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 375 | (void)scope; |
Simon Kelley | bad7b87 | 2012-12-20 22:00:39 +0000 | [diff] [blame] | 376 | (void)flags; |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 377 | (void)preferred; |
| 378 | (void)valid; |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 379 | |
| 380 | for (lease = leases; lease; lease = lease->next) |
| 381 | if ((lease->flags & (LEASE_TA | LEASE_NA))) |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 382 | if (is_same_net6(local, &lease->addr6, prefix)) |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 383 | lease_set_interface(lease, if_index, *((time_t *)vparam)); |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 384 | |
| 385 | return 1; |
| 386 | } |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 387 | |
| 388 | void lease_ping_reply(struct in6_addr *sender, unsigned char *packet, char *interface) |
| 389 | { |
Simon Kelley | 5ef3327 | 2012-03-30 15:10:28 +0100 | [diff] [blame] | 390 | /* We may be doing RA but not DHCPv4, in which case the lease |
| 391 | database may not exist and we have nothing to do anyway */ |
| 392 | if (daemon->dhcp) |
| 393 | slaac_ping_reply(sender, packet, interface, leases); |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Simon Kelley | 0c05024 | 2012-12-22 22:13:19 +0000 | [diff] [blame] | 396 | void lease_update_slaac(time_t now) |
| 397 | { |
| 398 | /* Called when we contruct a new RA-names context, to add putative |
| 399 | new SLAAC addresses to existing leases. */ |
| 400 | |
| 401 | struct dhcp_lease *lease; |
| 402 | |
| 403 | if (daemon->dhcp) |
| 404 | for (lease = leases; lease; lease = lease->next) |
| 405 | slaac_add_addrs(lease, now, 0); |
| 406 | } |
| 407 | |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 408 | #endif |
| 409 | |
| 410 | |
| 411 | /* Find interfaces associated with leases at start-up. This gets updated as |
| 412 | we do DHCP transactions, but information about directly-connected subnets |
| 413 | is useful from scrips and necessary for determining SLAAC addresses from |
| 414 | start-time. */ |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 415 | void lease_find_interfaces(time_t now) |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 416 | { |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 417 | iface_enumerate(AF_INET, &now, find_interface_v4); |
| 418 | #ifdef HAVE_DHCP6 |
| 419 | iface_enumerate(AF_INET6, &now, find_interface_v6); |
Simon Kelley | 3511a92 | 2013-11-07 10:28:11 +0000 | [diff] [blame] | 420 | #endif |
| 421 | } |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 422 | |
Simon Kelley | 3511a92 | 2013-11-07 10:28:11 +0000 | [diff] [blame] | 423 | #ifdef HAVE_DHCP6 |
| 424 | void lease_make_duid(time_t now) |
| 425 | { |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 426 | /* If we're not doing DHCPv6, and there are not v6 leases, don't add the DUID to the database */ |
Simon Kelley | 3511a92 | 2013-11-07 10:28:11 +0000 | [diff] [blame] | 427 | if (!daemon->duid && daemon->doing_dhcp6) |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 428 | { |
| 429 | file_dirty = 1; |
| 430 | make_duid(now); |
| 431 | } |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 432 | } |
Simon Kelley | 3511a92 | 2013-11-07 10:28:11 +0000 | [diff] [blame] | 433 | #endif |
| 434 | |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 435 | |
| 436 | |
| 437 | |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 438 | void lease_update_dns(int force) |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 439 | { |
| 440 | struct dhcp_lease *lease; |
| 441 | |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 442 | if (daemon->port != 0 && (dns_dirty || force)) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 443 | { |
Simon Kelley | 8ff5567 | 2012-12-09 21:09:01 +0000 | [diff] [blame] | 444 | #ifndef HAVE_BROKEN_RTC |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 445 | /* force transfer to authoritative secondaries */ |
| 446 | daemon->soa_sn++; |
Simon Kelley | 8ff5567 | 2012-12-09 21:09:01 +0000 | [diff] [blame] | 447 | #endif |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 448 | |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 449 | cache_unhash_dhcp(); |
| 450 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 451 | for (lease = leases; lease; lease = lease->next) |
| 452 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 453 | int prot = AF_INET; |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 454 | |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 455 | #ifdef HAVE_DHCP6 |
| 456 | if (lease->flags & (LEASE_TA | LEASE_NA)) |
| 457 | prot = AF_INET6; |
Simon Kelley | f444cdd | 2012-03-07 10:15:57 +0000 | [diff] [blame] | 458 | else if (lease->hostname || lease->fqdn) |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 459 | { |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 460 | struct slaac_address *slaac; |
| 461 | |
| 462 | for (slaac = lease->slaac_address; slaac; slaac = slaac->next) |
| 463 | if (slaac->backoff == 0) |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 464 | { |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 465 | if (lease->fqdn) |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 466 | cache_add_dhcp_entry(lease->fqdn, AF_INET6, (struct all_addr *)&slaac->addr, lease->expires); |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 467 | if (!option_bool(OPT_DHCP_FQDN) && lease->hostname) |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 468 | cache_add_dhcp_entry(lease->hostname, AF_INET6, (struct all_addr *)&slaac->addr, lease->expires); |
Simon Kelley | 801ca9a | 2012-03-06 19:30:17 +0000 | [diff] [blame] | 469 | } |
| 470 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 471 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 472 | if (lease->fqdn) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 473 | cache_add_dhcp_entry(lease->fqdn, prot, |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 474 | prot == AF_INET ? (struct all_addr *)&lease->addr : (struct all_addr *)&lease->addr6, |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 475 | lease->expires); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 476 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 477 | if (!option_bool(OPT_DHCP_FQDN) && lease->hostname) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 478 | cache_add_dhcp_entry(lease->hostname, prot, |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 479 | prot == AF_INET ? (struct all_addr *)&lease->addr : (struct all_addr *)&lease->addr6, |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 480 | lease->expires); |
Simon Kelley | 91543f4 | 2013-09-23 12:41:20 +0100 | [diff] [blame] | 481 | |
| 482 | #else |
| 483 | if (lease->fqdn) |
| 484 | cache_add_dhcp_entry(lease->fqdn, prot, (struct all_addr *)&lease->addr, lease->expires); |
| 485 | |
| 486 | if (!option_bool(OPT_DHCP_FQDN) && lease->hostname) |
| 487 | cache_add_dhcp_entry(lease->hostname, prot, (struct all_addr *)&lease->addr, lease->expires); |
| 488 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | dns_dirty = 0; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | void lease_prune(struct dhcp_lease *target, time_t now) |
| 496 | { |
| 497 | struct dhcp_lease *lease, *tmp, **up; |
| 498 | |
| 499 | for (lease = leases, up = &leases; lease; lease = tmp) |
| 500 | { |
| 501 | tmp = lease->next; |
| 502 | if ((lease->expires != 0 && difftime(now, lease->expires) > 0) || lease == target) |
| 503 | { |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 504 | file_dirty = 1; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 505 | if (lease->hostname) |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 506 | dns_dirty = 1; |
| 507 | |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 508 | *up = lease->next; /* unlink */ |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 509 | |
| 510 | /* Put on old_leases list 'till we |
| 511 | can run the script */ |
| 512 | lease->next = old_leases; |
| 513 | old_leases = lease; |
| 514 | |
Simon Kelley | 44a2a31 | 2004-03-10 20:04:35 +0000 | [diff] [blame] | 515 | leases_left++; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 516 | } |
| 517 | else |
| 518 | up = &lease->next; |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | |
Simon Kelley | cdeda28 | 2006-03-16 20:16:06 +0000 | [diff] [blame] | 523 | struct dhcp_lease *lease_find_by_client(unsigned char *hwaddr, int hw_len, int hw_type, |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 524 | unsigned char *clid, int clid_len) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 525 | { |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 526 | struct dhcp_lease *lease; |
| 527 | |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 528 | if (clid) |
| 529 | for (lease = leases; lease; lease = lease->next) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 530 | { |
| 531 | #ifdef HAVE_DHCP6 |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 532 | if (lease->flags & (LEASE_TA | LEASE_NA)) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 533 | continue; |
| 534 | #endif |
| 535 | if (lease->clid && clid_len == lease->clid_len && |
| 536 | memcmp(clid, lease->clid, clid_len) == 0) |
| 537 | return lease; |
| 538 | } |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 539 | |
| 540 | for (lease = leases; lease; lease = lease->next) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 541 | { |
| 542 | #ifdef HAVE_DHCP6 |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 543 | if (lease->flags & (LEASE_TA | LEASE_NA)) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 544 | continue; |
| 545 | #endif |
| 546 | if ((!lease->clid || !clid) && |
| 547 | hw_len != 0 && |
| 548 | lease->hwaddr_len == hw_len && |
| 549 | lease->hwaddr_type == hw_type && |
| 550 | memcmp(hwaddr, lease->hwaddr, hw_len) == 0) |
| 551 | return lease; |
| 552 | } |
| 553 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 554 | return NULL; |
| 555 | } |
| 556 | |
| 557 | struct dhcp_lease *lease_find_by_addr(struct in_addr addr) |
| 558 | { |
| 559 | struct dhcp_lease *lease; |
| 560 | |
| 561 | for (lease = leases; lease; lease = lease->next) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 562 | { |
| 563 | #ifdef HAVE_DHCP6 |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 564 | if (lease->flags & (LEASE_TA | LEASE_NA)) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 565 | continue; |
| 566 | #endif |
| 567 | if (lease->addr.s_addr == addr.s_addr) |
| 568 | return lease; |
| 569 | } |
| 570 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 571 | return NULL; |
| 572 | } |
| 573 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 574 | #ifdef HAVE_DHCP6 |
Simon Kelley | a6ebfac | 2013-03-06 20:52:35 +0000 | [diff] [blame] | 575 | /* find address for {CLID, IAID, address} */ |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 576 | struct dhcp_lease *lease6_find(unsigned char *clid, int clid_len, |
| 577 | int lease_type, int iaid, struct in6_addr *addr) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 578 | { |
| 579 | struct dhcp_lease *lease; |
| 580 | |
| 581 | for (lease = leases; lease; lease = lease->next) |
| 582 | { |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 583 | if (!(lease->flags & lease_type) || lease->iaid != iaid) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 584 | continue; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 585 | |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 586 | if (!IN6_ARE_ADDR_EQUAL(&lease->addr6, addr)) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 587 | continue; |
| 588 | |
Simon Kelley | a6ebfac | 2013-03-06 20:52:35 +0000 | [diff] [blame] | 589 | if ((clid_len != lease->clid_len || |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 590 | memcmp(clid, lease->clid, clid_len) != 0)) |
| 591 | continue; |
| 592 | |
Simon Kelley | 8b46061 | 2012-09-08 21:47:28 +0100 | [diff] [blame] | 593 | return lease; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | return NULL; |
| 597 | } |
| 598 | |
Simon Kelley | a6ebfac | 2013-03-06 20:52:35 +0000 | [diff] [blame] | 599 | /* reset "USED flags */ |
| 600 | void lease6_reset(void) |
Simon Kelley | 8b46061 | 2012-09-08 21:47:28 +0100 | [diff] [blame] | 601 | { |
| 602 | struct dhcp_lease *lease; |
| 603 | |
| 604 | for (lease = leases; lease; lease = lease->next) |
Simon Kelley | a6ebfac | 2013-03-06 20:52:35 +0000 | [diff] [blame] | 605 | lease->flags &= ~LEASE_USED; |
| 606 | } |
| 607 | |
| 608 | /* enumerate all leases belonging to {CLID, IAID} */ |
| 609 | struct dhcp_lease *lease6_find_by_client(struct dhcp_lease *first, int lease_type, unsigned char *clid, int clid_len, int iaid) |
| 610 | { |
| 611 | struct dhcp_lease *lease; |
| 612 | |
| 613 | if (!first) |
| 614 | first = leases; |
Simon Kelley | 27cb314 | 2013-04-02 20:06:39 +0100 | [diff] [blame] | 615 | else |
| 616 | first = first->next; |
Simon Kelley | a6ebfac | 2013-03-06 20:52:35 +0000 | [diff] [blame] | 617 | |
| 618 | for (lease = first; lease; lease = lease->next) |
Simon Kelley | 8b46061 | 2012-09-08 21:47:28 +0100 | [diff] [blame] | 619 | { |
Simon Kelley | a6ebfac | 2013-03-06 20:52:35 +0000 | [diff] [blame] | 620 | if (lease->flags & LEASE_USED) |
| 621 | continue; |
| 622 | |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 623 | if (!(lease->flags & lease_type) || lease->iaid != iaid) |
Simon Kelley | 8b46061 | 2012-09-08 21:47:28 +0100 | [diff] [blame] | 624 | continue; |
Simon Kelley | a6ebfac | 2013-03-06 20:52:35 +0000 | [diff] [blame] | 625 | |
| 626 | if ((clid_len != lease->clid_len || |
| 627 | memcmp(clid, lease->clid, clid_len) != 0)) |
| 628 | continue; |
| 629 | |
| 630 | return lease; |
Simon Kelley | 8b46061 | 2012-09-08 21:47:28 +0100 | [diff] [blame] | 631 | } |
Simon Kelley | a6ebfac | 2013-03-06 20:52:35 +0000 | [diff] [blame] | 632 | |
| 633 | return NULL; |
Simon Kelley | 8b46061 | 2012-09-08 21:47:28 +0100 | [diff] [blame] | 634 | } |
| 635 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 636 | struct dhcp_lease *lease6_find_by_addr(struct in6_addr *net, int prefix, u64 addr) |
| 637 | { |
| 638 | struct dhcp_lease *lease; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 639 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 640 | for (lease = leases; lease; lease = lease->next) |
| 641 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 642 | if (!(lease->flags & (LEASE_TA | LEASE_NA))) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 643 | continue; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 644 | |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 645 | if (is_same_net6(&lease->addr6, net, prefix) && |
| 646 | (prefix == 128 || addr6part(&lease->addr6) == addr)) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 647 | return lease; |
| 648 | } |
| 649 | |
| 650 | return NULL; |
Simon Kelley | 0793380 | 2012-02-14 20:55:25 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /* Find largest assigned address in context */ |
| 654 | u64 lease_find_max_addr6(struct dhcp_context *context) |
| 655 | { |
| 656 | struct dhcp_lease *lease; |
| 657 | u64 addr = addr6part(&context->start6); |
| 658 | |
| 659 | if (!(context->flags & (CONTEXT_STATIC | CONTEXT_PROXY))) |
| 660 | for (lease = leases; lease; lease = lease->next) |
| 661 | { |
Simon Kelley | 0793380 | 2012-02-14 20:55:25 +0000 | [diff] [blame] | 662 | if (!(lease->flags & (LEASE_TA | LEASE_NA))) |
| 663 | continue; |
Simon Kelley | 6caacac | 2012-02-15 21:58:33 +0000 | [diff] [blame] | 664 | |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 665 | if (is_same_net6(&lease->addr6, &context->start6, 64) && |
| 666 | addr6part(&lease->addr6) > addr6part(&context->start6) && |
| 667 | addr6part(&lease->addr6) <= addr6part(&context->end6) && |
| 668 | addr6part(&lease->addr6) > addr) |
| 669 | addr = addr6part(&lease->addr6); |
Simon Kelley | 0793380 | 2012-02-14 20:55:25 +0000 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | return addr; |
| 673 | } |
| 674 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 675 | #endif |
| 676 | |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 677 | /* Find largest assigned address in context */ |
| 678 | struct in_addr lease_find_max_addr(struct dhcp_context *context) |
| 679 | { |
| 680 | struct dhcp_lease *lease; |
| 681 | struct in_addr addr = context->start; |
| 682 | |
| 683 | if (!(context->flags & (CONTEXT_STATIC | CONTEXT_PROXY))) |
| 684 | for (lease = leases; lease; lease = lease->next) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 685 | { |
| 686 | #ifdef HAVE_DHCP6 |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 687 | if (lease->flags & (LEASE_TA | LEASE_NA)) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 688 | continue; |
| 689 | #endif |
| 690 | if (((unsigned)ntohl(lease->addr.s_addr)) > ((unsigned)ntohl(context->start.s_addr)) && |
| 691 | ((unsigned)ntohl(lease->addr.s_addr)) <= ((unsigned)ntohl(context->end.s_addr)) && |
| 692 | ((unsigned)ntohl(lease->addr.s_addr)) > ((unsigned)ntohl(addr.s_addr))) |
| 693 | addr = lease->addr; |
| 694 | } |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 695 | |
| 696 | return addr; |
| 697 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 698 | |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 699 | static struct dhcp_lease *lease_allocate(void) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 700 | { |
| 701 | struct dhcp_lease *lease; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 702 | if (!leases_left || !(lease = whine_malloc(sizeof(struct dhcp_lease)))) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 703 | return NULL; |
| 704 | |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 705 | memset(lease, 0, sizeof(struct dhcp_lease)); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 706 | lease->flags = LEASE_NEW; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 707 | lease->expires = 1; |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 708 | #ifdef HAVE_BROKEN_RTC |
| 709 | lease->length = 0xffffffff; /* illegal value */ |
| 710 | #endif |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 711 | lease->hwaddr_len = 256; /* illegal value */ |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 712 | lease->next = leases; |
| 713 | leases = lease; |
| 714 | |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 715 | file_dirty = 1; |
Simon Kelley | 44a2a31 | 2004-03-10 20:04:35 +0000 | [diff] [blame] | 716 | leases_left--; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 717 | |
| 718 | return lease; |
| 719 | } |
| 720 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 721 | struct dhcp_lease *lease4_allocate(struct in_addr addr) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 722 | { |
| 723 | struct dhcp_lease *lease = lease_allocate(); |
Simon Kelley | 0b0a73c | 2013-04-11 14:07:02 +0100 | [diff] [blame] | 724 | if (lease) |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 725 | lease->addr = addr; |
| 726 | |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 727 | return lease; |
| 728 | } |
| 729 | |
| 730 | #ifdef HAVE_DHCP6 |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 731 | struct dhcp_lease *lease6_allocate(struct in6_addr *addrp, int lease_type) |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 732 | { |
| 733 | struct dhcp_lease *lease = lease_allocate(); |
Simon Kelley | 0b0a73c | 2013-04-11 14:07:02 +0100 | [diff] [blame] | 734 | |
| 735 | if (lease) |
| 736 | { |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 737 | lease->addr6 = *addrp; |
Simon Kelley | 0b0a73c | 2013-04-11 14:07:02 +0100 | [diff] [blame] | 738 | lease->flags |= lease_type; |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 739 | lease->iaid = 0; |
Simon Kelley | 0b0a73c | 2013-04-11 14:07:02 +0100 | [diff] [blame] | 740 | } |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 741 | |
| 742 | return lease; |
| 743 | } |
| 744 | #endif |
| 745 | |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 746 | void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 747 | { |
Simon Kelley | dd0e0a3 | 2014-01-22 11:16:59 +0000 | [diff] [blame] | 748 | time_t exp; |
| 749 | |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 750 | if (len == 0xffffffff) |
| 751 | { |
| 752 | exp = 0; |
| 753 | len = 0; |
| 754 | } |
Simon Kelley | dd0e0a3 | 2014-01-22 11:16:59 +0000 | [diff] [blame] | 755 | else |
| 756 | { |
| 757 | exp = now + (time_t)len; |
| 758 | /* Check for 2038 overflow. Make the lease |
| 759 | inifinite in that case, as the least disruptive |
| 760 | thing we can do. */ |
| 761 | if (difftime(exp, now) <= 0.0) |
| 762 | exp = 0; |
| 763 | } |
| 764 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 765 | if (exp != lease->expires) |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 766 | { |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 767 | dns_dirty = 1; |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 768 | lease->expires = exp; |
| 769 | #ifndef HAVE_BROKEN_RTC |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 770 | lease->flags |= LEASE_AUX_CHANGED; |
| 771 | file_dirty = 1; |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 772 | #endif |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 773 | } |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 774 | |
| 775 | #ifdef HAVE_BROKEN_RTC |
| 776 | if (len != lease->length) |
| 777 | { |
| 778 | lease->length = len; |
Simon Kelley | b7f4020 | 2012-02-29 21:43:37 +0000 | [diff] [blame] | 779 | lease->flags |= LEASE_AUX_CHANGED; |
| 780 | file_dirty = 1; |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 781 | } |
| 782 | #endif |
| 783 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 784 | |
Simon Kelley | 89500e3 | 2013-09-20 16:29:20 +0100 | [diff] [blame] | 785 | #ifdef HAVE_DHCP6 |
| 786 | void lease_set_iaid(struct dhcp_lease *lease, int iaid) |
| 787 | { |
| 788 | if (lease->iaid != iaid) |
| 789 | { |
| 790 | lease->iaid = iaid; |
| 791 | lease->flags |= LEASE_CHANGED; |
| 792 | } |
| 793 | } |
| 794 | #endif |
| 795 | |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 796 | void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr, |
Simon Kelley | a9ab732 | 2012-04-28 11:29:37 +0100 | [diff] [blame] | 797 | unsigned char *clid, int hw_len, int hw_type, int clid_len, |
| 798 | time_t now, int force) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 799 | { |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 800 | #ifdef HAVE_DHCP6 |
Simon Kelley | a9ab732 | 2012-04-28 11:29:37 +0100 | [diff] [blame] | 801 | int change = force; |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 802 | lease->flags |= LEASE_HAVE_HWADDR; |
| 803 | #endif |
| 804 | |
Simon Kelley | a9ab732 | 2012-04-28 11:29:37 +0100 | [diff] [blame] | 805 | (void)force; |
Vladislav Grishenko | 408c368 | 2013-09-24 16:18:49 +0100 | [diff] [blame] | 806 | (void)now; |
Simon Kelley | a9ab732 | 2012-04-28 11:29:37 +0100 | [diff] [blame] | 807 | |
Simon Kelley | cdeda28 | 2006-03-16 20:16:06 +0000 | [diff] [blame] | 808 | if (hw_len != lease->hwaddr_len || |
| 809 | hw_type != lease->hwaddr_type || |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 810 | (hw_len != 0 && memcmp(lease->hwaddr, hwaddr, hw_len) != 0)) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 811 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 812 | if (hw_len != 0) |
| 813 | memcpy(lease->hwaddr, hwaddr, hw_len); |
Simon Kelley | cdeda28 | 2006-03-16 20:16:06 +0000 | [diff] [blame] | 814 | lease->hwaddr_len = hw_len; |
| 815 | lease->hwaddr_type = hw_type; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 816 | lease->flags |= LEASE_CHANGED; |
| 817 | file_dirty = 1; /* run script on change */ |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 818 | } |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 819 | |
| 820 | /* only update clid when one is available, stops packets |
| 821 | without a clid removing the record. Lease init uses |
| 822 | clid_len == 0 for no clid. */ |
| 823 | if (clid_len != 0 && clid) |
| 824 | { |
| 825 | if (!lease->clid) |
| 826 | lease->clid_len = 0; |
| 827 | |
| 828 | if (lease->clid_len != clid_len) |
| 829 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 830 | lease->flags |= LEASE_AUX_CHANGED; |
| 831 | file_dirty = 1; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 832 | free(lease->clid); |
| 833 | if (!(lease->clid = whine_malloc(clid_len))) |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 834 | return; |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 835 | #ifdef HAVE_DHCP6 |
| 836 | change = 1; |
| 837 | #endif |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 838 | } |
| 839 | else if (memcmp(lease->clid, clid, clid_len) != 0) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 840 | { |
| 841 | lease->flags |= LEASE_AUX_CHANGED; |
| 842 | file_dirty = 1; |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 843 | #ifdef HAVE_DHCP6 |
| 844 | change = 1; |
| 845 | #endif |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 846 | } |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 847 | |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 848 | lease->clid_len = clid_len; |
| 849 | memcpy(lease->clid, clid, clid_len); |
| 850 | } |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 851 | |
| 852 | #ifdef HAVE_DHCP6 |
| 853 | if (change) |
Simon Kelley | a9ab732 | 2012-04-28 11:29:37 +0100 | [diff] [blame] | 854 | slaac_add_addrs(lease, now, force); |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 855 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 858 | static void kill_name(struct dhcp_lease *lease) |
| 859 | { |
| 860 | /* run script to say we lost our old name */ |
| 861 | |
| 862 | /* this shouldn't happen unless updates are very quick and the |
| 863 | script very slow, we just avoid a memory leak if it does. */ |
| 864 | free(lease->old_hostname); |
| 865 | |
| 866 | /* If we know the fqdn, pass that. The helper will derive the |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 867 | unqualified name from it, free the unqualified name here. */ |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 868 | |
| 869 | if (lease->fqdn) |
| 870 | { |
| 871 | lease->old_hostname = lease->fqdn; |
| 872 | free(lease->hostname); |
| 873 | } |
| 874 | else |
| 875 | lease->old_hostname = lease->hostname; |
| 876 | |
| 877 | lease->hostname = lease->fqdn = NULL; |
| 878 | } |
| 879 | |
Simon Kelley | 70c5e3e | 2012-02-06 22:05:15 +0000 | [diff] [blame] | 880 | void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth, char *domain, char *config_domain) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 881 | { |
| 882 | struct dhcp_lease *lease_tmp; |
| 883 | char *new_name = NULL, *new_fqdn = NULL; |
Simon Kelley | 70c5e3e | 2012-02-06 22:05:15 +0000 | [diff] [blame] | 884 | |
| 885 | if (config_domain && (!domain || !hostname_isequal(domain, config_domain))) |
| 886 | my_syslog(MS_DHCP | LOG_WARNING, _("Ignoring domain %s for DHCP host name %s"), config_domain, name); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 887 | |
Simon Kelley | a222641 | 2004-05-13 20:27:08 +0100 | [diff] [blame] | 888 | if (lease->hostname && name && hostname_isequal(lease->hostname, name)) |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 889 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 890 | if (auth) |
| 891 | lease->flags |= LEASE_AUTH_NAME; |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 892 | return; |
| 893 | } |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 894 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 895 | if (!name && !lease->hostname) |
| 896 | return; |
| 897 | |
| 898 | /* If a machine turns up on a new net without dropping the old lease, |
| 899 | or two machines claim the same name, then we end up with two interfaces with |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 900 | the same name. Check for that here and remove the name from the old lease. |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 901 | Note that IPv6 leases are different. All the leases to the same DUID are |
| 902 | allowed the same name. |
| 903 | |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 904 | Don't allow a name from the client to override a name from dnsmasq config. */ |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 905 | |
| 906 | if (name) |
| 907 | { |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 908 | if ((new_name = whine_malloc(strlen(name) + 1))) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 909 | { |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 910 | strcpy(new_name, name); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 911 | if (domain && (new_fqdn = whine_malloc(strlen(new_name) + strlen(domain) + 2))) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 912 | { |
| 913 | strcpy(new_fqdn, name); |
| 914 | strcat(new_fqdn, "."); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 915 | strcat(new_fqdn, domain); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
| 919 | /* Depending on mode, we check either unqualified name or FQDN. */ |
| 920 | for (lease_tmp = leases; lease_tmp; lease_tmp = lease_tmp->next) |
| 921 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 922 | if (option_bool(OPT_DHCP_FQDN)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 923 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 924 | if (!new_fqdn || !lease_tmp->fqdn || !hostname_isequal(lease_tmp->fqdn, new_fqdn)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 925 | continue; |
| 926 | } |
| 927 | else |
| 928 | { |
| 929 | if (!new_name || !lease_tmp->hostname || !hostname_isequal(lease_tmp->hostname, new_name) ) |
| 930 | continue; |
| 931 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 932 | |
| 933 | if (lease->flags & (LEASE_TA | LEASE_NA)) |
| 934 | { |
| 935 | if (!(lease_tmp->flags & (LEASE_TA | LEASE_NA))) |
| 936 | continue; |
| 937 | |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 938 | /* another lease for the same DUID is OK for IPv6 */ |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 939 | if (lease->clid_len == lease_tmp->clid_len && |
| 940 | lease->clid && lease_tmp->clid && |
| 941 | memcmp(lease->clid, lease_tmp->clid, lease->clid_len) == 0) |
| 942 | continue; |
| 943 | } |
| 944 | else if (lease_tmp->flags & (LEASE_TA | LEASE_NA)) |
| 945 | continue; |
| 946 | |
| 947 | if ((lease_tmp->flags & LEASE_AUTH_NAME) && !auth) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 948 | { |
| 949 | free(new_name); |
| 950 | free(new_fqdn); |
| 951 | return; |
| 952 | } |
| 953 | |
| 954 | kill_name(lease_tmp); |
| 955 | break; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | |
| 959 | if (lease->hostname) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 960 | kill_name(lease); |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 961 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 962 | lease->hostname = new_name; |
| 963 | lease->fqdn = new_fqdn; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 964 | |
| 965 | if (auth) |
| 966 | lease->flags |= LEASE_AUTH_NAME; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 967 | |
Simon Kelley | 5e9e0ef | 2006-04-17 14:24:29 +0100 | [diff] [blame] | 968 | file_dirty = 1; |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 969 | dns_dirty = 1; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 970 | lease->flags |= LEASE_CHANGED; /* run script on change */ |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 971 | } |
| 972 | |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 973 | void lease_set_interface(struct dhcp_lease *lease, int interface, time_t now) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 974 | { |
Vladislav Grishenko | 408c368 | 2013-09-24 16:18:49 +0100 | [diff] [blame] | 975 | (void)now; |
| 976 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 977 | if (lease->last_interface == interface) |
| 978 | return; |
| 979 | |
| 980 | lease->last_interface = interface; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 981 | lease->flags |= LEASE_CHANGED; |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 982 | |
| 983 | #ifdef HAVE_DHCP6 |
Simon Kelley | a9ab732 | 2012-04-28 11:29:37 +0100 | [diff] [blame] | 984 | slaac_add_addrs(lease, now, 0); |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 985 | #endif |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 986 | } |
| 987 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 988 | void rerun_scripts(void) |
| 989 | { |
| 990 | struct dhcp_lease *lease; |
| 991 | |
| 992 | for (lease = leases; lease; lease = lease->next) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 993 | lease->flags |= LEASE_CHANGED; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 994 | } |
| 995 | |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 996 | /* deleted leases get transferred to the old_leases list. |
| 997 | remove them here, after calling the lease change |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 998 | script. Also run the lease change script on new/modified leases. |
| 999 | |
| 1000 | Return zero if nothing to do. */ |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1001 | int do_script_run(time_t now) |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 1002 | { |
| 1003 | struct dhcp_lease *lease; |
| 1004 | |
Vladislav Grishenko | 408c368 | 2013-09-24 16:18:49 +0100 | [diff] [blame] | 1005 | (void)now; |
| 1006 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1007 | #ifdef HAVE_DBUS |
| 1008 | /* If we're going to be sending DBus signals, but the connection is not yet up, |
| 1009 | delay everything until it is. */ |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1010 | if (option_bool(OPT_DBUS) && !daemon->dbus) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1011 | return 0; |
| 1012 | #endif |
| 1013 | |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 1014 | if (old_leases) |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 1015 | { |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 1016 | lease = old_leases; |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 1017 | |
| 1018 | /* If the lease still has an old_hostname, do the "old" action on that first */ |
| 1019 | if (lease->old_hostname) |
| 1020 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1021 | #ifdef HAVE_SCRIPT |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1022 | queue_script(ACTION_OLD_HOSTNAME, lease, lease->old_hostname, now); |
| 1023 | #endif |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 1024 | free(lease->old_hostname); |
| 1025 | lease->old_hostname = NULL; |
| 1026 | return 1; |
| 1027 | } |
| 1028 | else |
| 1029 | { |
Simon Kelley | 353ae4d | 2012-03-19 20:07:51 +0000 | [diff] [blame] | 1030 | #ifdef HAVE_DHCP6 |
| 1031 | struct slaac_address *slaac, *tmp; |
| 1032 | for (slaac = lease->slaac_address; slaac; slaac = tmp) |
| 1033 | { |
| 1034 | tmp = slaac->next; |
| 1035 | free(slaac); |
| 1036 | } |
| 1037 | #endif |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1038 | kill_name(lease); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1039 | #ifdef HAVE_SCRIPT |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1040 | queue_script(ACTION_DEL, lease, lease->old_hostname, now); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1041 | #endif |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1042 | #ifdef HAVE_DBUS |
| 1043 | emit_dbus_signal(ACTION_DEL, lease, lease->old_hostname); |
| 1044 | #endif |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 1045 | old_leases = lease->next; |
| 1046 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1047 | free(lease->old_hostname); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1048 | free(lease->clid); |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1049 | free(lease->extradata); |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 1050 | free(lease); |
| 1051 | |
| 1052 | return 1; |
| 1053 | } |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 1054 | } |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 1055 | |
| 1056 | /* make sure we announce the loss of a hostname before its new location. */ |
| 1057 | for (lease = leases; lease; lease = lease->next) |
| 1058 | if (lease->old_hostname) |
| 1059 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1060 | #ifdef HAVE_SCRIPT |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1061 | queue_script(ACTION_OLD_HOSTNAME, lease, lease->old_hostname, now); |
| 1062 | #endif |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 1063 | free(lease->old_hostname); |
| 1064 | lease->old_hostname = NULL; |
| 1065 | return 1; |
| 1066 | } |
| 1067 | |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 1068 | for (lease = leases; lease; lease = lease->next) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1069 | if ((lease->flags & (LEASE_NEW | LEASE_CHANGED)) || |
| 1070 | ((lease->flags & LEASE_AUX_CHANGED) && option_bool(OPT_LEASE_RO))) |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 1071 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1072 | #ifdef HAVE_SCRIPT |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1073 | queue_script((lease->flags & LEASE_NEW) ? ACTION_ADD : ACTION_OLD, lease, |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1074 | lease->fqdn ? lease->fqdn : lease->hostname, now); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1075 | #endif |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1076 | #ifdef HAVE_DBUS |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1077 | emit_dbus_signal((lease->flags & LEASE_NEW) ? ACTION_ADD : ACTION_OLD, lease, |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1078 | lease->fqdn ? lease->fqdn : lease->hostname); |
| 1079 | #endif |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1080 | lease->flags &= ~(LEASE_NEW | LEASE_CHANGED | LEASE_AUX_CHANGED); |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 1081 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1082 | /* this is used for the "add" call, then junked, since they're not in the database */ |
| 1083 | free(lease->extradata); |
| 1084 | lease->extradata = NULL; |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 1085 | |
| 1086 | return 1; |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 1087 | } |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 1088 | |
| 1089 | return 0; /* nothing to do */ |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 1090 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1091 | |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 1092 | #ifdef HAVE_SCRIPT |
| 1093 | void lease_add_extradata(struct dhcp_lease *lease, unsigned char *data, unsigned int len, int delim) |
| 1094 | { |
| 1095 | unsigned int i; |
| 1096 | |
| 1097 | /* check for embeded NULLs */ |
| 1098 | for (i = 0; i < len; i++) |
| 1099 | if (data[i] == 0) |
| 1100 | { |
| 1101 | len = i; |
| 1102 | break; |
| 1103 | } |
| 1104 | |
| 1105 | if ((lease->extradata_size - lease->extradata_len) < (len + 1)) |
| 1106 | { |
| 1107 | size_t newsz = lease->extradata_len + len + 100; |
| 1108 | unsigned char *new = whine_malloc(newsz); |
| 1109 | |
| 1110 | if (!new) |
| 1111 | return; |
| 1112 | |
| 1113 | if (lease->extradata) |
| 1114 | { |
| 1115 | memcpy(new, lease->extradata, lease->extradata_len); |
| 1116 | free(lease->extradata); |
| 1117 | } |
| 1118 | |
| 1119 | lease->extradata = new; |
| 1120 | lease->extradata_size = newsz; |
| 1121 | } |
| 1122 | |
| 1123 | if (len != 0) |
| 1124 | memcpy(lease->extradata + lease->extradata_len, data, len); |
| 1125 | lease->extradata[lease->extradata_len + len] = delim; |
| 1126 | lease->extradata_len += len + 1; |
| 1127 | } |
| 1128 | #endif |
| 1129 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1130 | #endif |
Simon Kelley | 7cebd20 | 2006-05-06 14:13:33 +0100 | [diff] [blame] | 1131 | |
| 1132 | |
| 1133 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 1134 | |