usbmodeswitch: Updated to v.1.2.6 from shibby's branch.
[tomato.git] / release / src / router / dnsmasq / src / dhcp-common.c
blob9321e924d33e2c571c1468b56804d177e95a5ac3
1 /* dnsmasq is Copyright (c) 2000-2013 Simon Kelley
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
5 the Free Software Foundation; version 2 dated June, 1991, or
6 (at your option) version 3 dated 29 June, 2007.
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.
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/>.
17 #include "dnsmasq.h"
19 #ifdef HAVE_DHCP
21 void dhcp_common_init(void)
23 /* These each hold a DHCP option max size 255
24 and get a terminating zero added */
25 daemon->dhcp_buff = safe_malloc(256);
26 daemon->dhcp_buff2 = safe_malloc(256);
27 daemon->dhcp_buff3 = safe_malloc(256);
29 /* dhcp_packet is used by v4 and v6, outpacket only by v6
30 sizeof(struct dhcp_packet) is as good an initial size as any,
31 even for v6 */
32 expand_buf(&daemon->dhcp_packet, sizeof(struct dhcp_packet));
33 #ifdef HAVE_DHCP6
34 if (daemon->dhcp6)
35 expand_buf(&daemon->outpacket, sizeof(struct dhcp_packet));
36 #endif
39 ssize_t recv_dhcp_packet(int fd, struct msghdr *msg)
41 ssize_t sz;
43 while (1)
45 msg->msg_flags = 0;
46 while ((sz = recvmsg(fd, msg, MSG_PEEK | MSG_TRUNC)) == -1 && errno == EINTR);
48 if (sz == -1)
49 return -1;
51 if (!(msg->msg_flags & MSG_TRUNC))
52 break;
54 /* Very new Linux kernels return the actual size needed,
55 older ones always return truncated size */
56 if ((size_t)sz == msg->msg_iov->iov_len)
58 if (!expand_buf(msg->msg_iov, sz + 100))
59 return -1;
61 else
63 expand_buf(msg->msg_iov, sz);
64 break;
68 while ((sz = recvmsg(fd, msg, 0)) == -1 && errno == EINTR);
70 return (msg->msg_flags & MSG_TRUNC) ? -1 : sz;
73 struct dhcp_netid *run_tag_if(struct dhcp_netid *tags)
75 struct tag_if *exprs;
76 struct dhcp_netid_list *list;
78 for (exprs = daemon->tag_if; exprs; exprs = exprs->next)
79 if (match_netid(exprs->tag, tags, 1))
80 for (list = exprs->set; list; list = list->next)
82 list->list->next = tags;
83 tags = list->list;
86 return tags;
90 struct dhcp_netid *option_filter(struct dhcp_netid *tags, struct dhcp_netid *context_tags, struct dhcp_opt *opts)
92 struct dhcp_netid *tagif = run_tag_if(tags);
93 struct dhcp_opt *opt;
94 struct dhcp_opt *tmp;
96 /* flag options which are valid with the current tag set (sans context tags) */
97 for (opt = opts; opt; opt = opt->next)
99 opt->flags &= ~DHOPT_TAGOK;
100 if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925)) &&
101 match_netid(opt->netid, tagif, 0))
102 opt->flags |= DHOPT_TAGOK;
105 /* now flag options which are valid, including the context tags,
106 otherwise valid options are inhibited if we found a higher priority one above */
107 if (context_tags)
109 struct dhcp_netid *last_tag;
111 for (last_tag = context_tags; last_tag->next; last_tag = last_tag->next);
112 last_tag->next = tags;
113 tagif = run_tag_if(context_tags);
115 /* reset stuff with tag:!<tag> which now matches. */
116 for (opt = opts; opt; opt = opt->next)
117 if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925)) &&
118 (opt->flags & DHOPT_TAGOK) &&
119 !match_netid(opt->netid, tagif, 0))
120 opt->flags &= ~DHOPT_TAGOK;
122 for (opt = opts; opt; opt = opt->next)
123 if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925 | DHOPT_TAGOK)) &&
124 match_netid(opt->netid, tagif, 0))
126 struct dhcp_opt *tmp;
127 for (tmp = opts; tmp; tmp = tmp->next)
128 if (tmp->opt == opt->opt && opt->netid && (tmp->flags & DHOPT_TAGOK))
129 break;
130 if (!tmp)
131 opt->flags |= DHOPT_TAGOK;
135 /* now flag untagged options which are not overridden by tagged ones */
136 for (opt = opts; opt; opt = opt->next)
137 if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925 | DHOPT_TAGOK)) && !opt->netid)
139 for (tmp = opts; tmp; tmp = tmp->next)
140 if (tmp->opt == opt->opt && (tmp->flags & DHOPT_TAGOK))
141 break;
142 if (!tmp)
143 opt->flags |= DHOPT_TAGOK;
144 else if (!tmp->netid)
145 my_syslog(MS_DHCP | LOG_WARNING, _("Ignoring duplicate dhcp-option %d"), tmp->opt);
148 /* Finally, eliminate duplicate options later in the chain, and therefore earlier in the config file. */
149 for (opt = opts; opt; opt = opt->next)
150 if (opt->flags & DHOPT_TAGOK)
151 for (tmp = opt->next; tmp; tmp = tmp->next)
152 if (tmp->opt == opt->opt)
153 tmp->flags &= ~DHOPT_TAGOK;
155 return tagif;
158 /* Is every member of check matched by a member of pool?
159 If tagnotneeded, untagged is OK */
160 int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int tagnotneeded)
162 struct dhcp_netid *tmp1;
164 if (!check && !tagnotneeded)
165 return 0;
167 for (; check; check = check->next)
169 /* '#' for not is for backwards compat. */
170 if (check->net[0] != '!' && check->net[0] != '#')
172 for (tmp1 = pool; tmp1; tmp1 = tmp1->next)
173 if (strcmp(check->net, tmp1->net) == 0)
174 break;
175 if (!tmp1)
176 return 0;
178 else
179 for (tmp1 = pool; tmp1; tmp1 = tmp1->next)
180 if (strcmp((check->net)+1, tmp1->net) == 0)
181 return 0;
183 return 1;
186 /* return domain or NULL if none. */
187 char *strip_hostname(char *hostname)
189 char *dot = strchr(hostname, '.');
191 if (!dot)
192 return NULL;
194 *dot = 0; /* truncate */
195 if (strlen(dot+1) != 0)
196 return dot+1;
198 return NULL;
201 void log_tags(struct dhcp_netid *netid, u32 xid)
203 if (netid && option_bool(OPT_LOG_OPTS))
205 char *s = daemon->namebuff;
206 for (*s = 0; netid; netid = netid->next)
208 /* kill dupes. */
209 struct dhcp_netid *n;
211 for (n = netid->next; n; n = n->next)
212 if (strcmp(netid->net, n->net) == 0)
213 break;
215 if (!n)
217 strncat (s, netid->net, (MAXDNAME-1) - strlen(s));
218 if (netid->next)
219 strncat (s, ", ", (MAXDNAME-1) - strlen(s));
222 my_syslog(MS_DHCP | LOG_INFO, _("%u tags: %s"), xid, s);
226 int match_bytes(struct dhcp_opt *o, unsigned char *p, int len)
228 int i;
230 if (o->len > len)
231 return 0;
233 if (o->len == 0)
234 return 1;
236 if (o->flags & DHOPT_HEX)
238 if (memcmp_masked(o->val, p, o->len, o->u.wildcard_mask))
239 return 1;
241 else
242 for (i = 0; i <= (len - o->len); )
244 if (memcmp(o->val, p + i, o->len) == 0)
245 return 1;
247 if (o->flags & DHOPT_STRING)
248 i++;
249 else
250 i += o->len;
253 return 0;
256 void dhcp_update_configs(struct dhcp_config *configs)
258 /* Some people like to keep all static IP addresses in /etc/hosts.
259 This goes through /etc/hosts and sets static addresses for any DHCP config
260 records which don't have an address and whose name matches.
261 We take care to maintain the invariant that any IP address can appear
262 in at most one dhcp-host. Since /etc/hosts can be re-read by SIGHUP,
263 restore the status-quo ante first. */
265 struct dhcp_config *config, *conf_tmp;
266 struct crec *crec;
267 int prot = AF_INET;
269 for (config = configs; config; config = config->next)
270 if (config->flags & CONFIG_ADDR_HOSTS)
271 config->flags &= ~(CONFIG_ADDR | CONFIG_ADDR6 | CONFIG_ADDR_HOSTS);
273 #ifdef HAVE_DHCP6
274 again:
275 #endif
277 if (daemon->port != 0)
278 for (config = configs; config; config = config->next)
280 int conflags = CONFIG_ADDR;
281 int cacheflags = F_IPV4;
283 #ifdef HAVE_DHCP6
284 if (prot == AF_INET6)
286 conflags = CONFIG_ADDR6;
287 cacheflags = F_IPV6;
289 #endif
290 if (!(config->flags & conflags) &&
291 (config->flags & CONFIG_NAME) &&
292 (crec = cache_find_by_name(NULL, config->hostname, 0, cacheflags)) &&
293 (crec->flags & F_HOSTS))
295 if (cache_find_by_name(crec, config->hostname, 0, cacheflags))
297 /* use primary (first) address */
298 while (crec && !(crec->flags & F_REVERSE))
299 crec = cache_find_by_name(crec, config->hostname, 0, cacheflags);
300 if (!crec)
301 continue; /* should be never */
302 inet_ntop(prot, &crec->addr.addr, daemon->addrbuff, ADDRSTRLEN);
303 my_syslog(MS_DHCP | LOG_WARNING, _("%s has more than one address in hostsfile, using %s for DHCP"),
304 config->hostname, daemon->addrbuff);
307 if (prot == AF_INET &&
308 (!(conf_tmp = config_find_by_address(configs, crec->addr.addr.addr.addr4)) || conf_tmp == config))
310 config->addr = crec->addr.addr.addr.addr4;
311 config->flags |= CONFIG_ADDR | CONFIG_ADDR_HOSTS;
312 continue;
315 #ifdef HAVE_DHCP6
316 if (prot == AF_INET6 &&
317 (!(conf_tmp = config_find_by_address6(configs, &crec->addr.addr.addr.addr6, 128, 0)) || conf_tmp == config))
319 memcpy(&config->addr6, &crec->addr.addr.addr.addr6, IN6ADDRSZ);
320 config->flags |= CONFIG_ADDR6 | CONFIG_ADDR_HOSTS;
321 continue;
323 #endif
325 inet_ntop(prot, &crec->addr.addr, daemon->addrbuff, ADDRSTRLEN);
326 my_syslog(MS_DHCP | LOG_WARNING, _("duplicate IP address %s (%s) in dhcp-config directive"),
327 daemon->addrbuff, config->hostname);
333 #ifdef HAVE_DHCP6
334 if (prot == AF_INET)
336 prot = AF_INET6;
337 goto again;
339 #endif
343 #ifdef HAVE_LINUX_NETWORK
344 void bindtodevice(int fd)
346 /* If we are doing DHCP on exactly one interface, and running linux, do SO_BINDTODEVICE
347 to that device. This is for the use case of (eg) OpenStack, which runs a new
348 dnsmasq instance for each VLAN interface it creates. Without the BINDTODEVICE,
349 individual processes don't always see the packets they should.
350 SO_BINDTODEVICE is only available Linux.
352 Note that if wildcards are used in --interface, or a configured interface doesn't
353 yet exist, then more interfaces may arrive later, so we can't safely assert there
354 is only one interface and proceed.
357 struct irec *iface, *found;
358 struct iname *if_tmp;
360 for (if_tmp = daemon->if_names; if_tmp; if_tmp = if_tmp->next)
361 if (if_tmp->name && (!if_tmp->used || strchr(if_tmp->name, '*')))
362 return;
364 for (found = NULL, iface = daemon->interfaces; iface; iface = iface->next)
365 if (iface->dhcp_ok)
367 if (!found)
368 found = iface;
369 else if (strcmp(found->name, iface->name) != 0)
370 return; /* more than one. */
373 if (found)
375 struct ifreq ifr;
376 strcpy(ifr.ifr_name, found->name);
377 /* only allowed by root. */
378 if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) == -1 &&
379 errno != EPERM)
380 die(_("failed to set SO_BINDTODEVICE on DHCP socket: %s"), NULL, EC_BADNET);
383 #endif
385 static const struct opttab_t {
386 char *name;
387 u16 val, size;
388 } opttab[] = {
389 { "netmask", 1, OT_ADDR_LIST },
390 { "time-offset", 2, 4 },
391 { "router", 3, OT_ADDR_LIST },
392 { "dns-server", 6, OT_ADDR_LIST },
393 { "log-server", 7, OT_ADDR_LIST },
394 { "lpr-server", 9, OT_ADDR_LIST },
395 { "hostname", 12, OT_INTERNAL | OT_NAME },
396 { "boot-file-size", 13, 2 | OT_DEC },
397 { "domain-name", 15, OT_NAME },
398 { "swap-server", 16, OT_ADDR_LIST },
399 { "root-path", 17, OT_NAME },
400 { "extension-path", 18, OT_NAME },
401 { "ip-forward-enable", 19, 1 },
402 { "non-local-source-routing", 20, 1 },
403 { "policy-filter", 21, OT_ADDR_LIST },
404 { "max-datagram-reassembly", 22, 2 | OT_DEC },
405 { "default-ttl", 23, 1 | OT_DEC },
406 { "mtu", 26, 2 | OT_DEC },
407 { "all-subnets-local", 27, 1 },
408 { "broadcast", 28, OT_INTERNAL | OT_ADDR_LIST },
409 { "router-discovery", 31, 1 },
410 { "router-solicitation", 32, OT_ADDR_LIST },
411 { "static-route", 33, OT_ADDR_LIST },
412 { "trailer-encapsulation", 34, 1 },
413 { "arp-timeout", 35, 4 | OT_DEC },
414 { "ethernet-encap", 36, 1 },
415 { "tcp-ttl", 37, 1 },
416 { "tcp-keepalive", 38, 4 | OT_DEC },
417 { "nis-domain", 40, OT_NAME },
418 { "nis-server", 41, OT_ADDR_LIST },
419 { "ntp-server", 42, OT_ADDR_LIST },
420 { "vendor-encap", 43, OT_INTERNAL },
421 { "netbios-ns", 44, OT_ADDR_LIST },
422 { "netbios-dd", 45, OT_ADDR_LIST },
423 { "netbios-nodetype", 46, 1 },
424 { "netbios-scope", 47, 0 },
425 { "x-windows-fs", 48, OT_ADDR_LIST },
426 { "x-windows-dm", 49, OT_ADDR_LIST },
427 { "requested-address", 50, OT_INTERNAL | OT_ADDR_LIST },
428 { "lease-time", 51, OT_INTERNAL | OT_TIME },
429 { "option-overload", 52, OT_INTERNAL },
430 { "message-type", 53, OT_INTERNAL | OT_DEC },
431 { "server-identifier", 54, OT_INTERNAL | OT_ADDR_LIST },
432 { "parameter-request", 55, OT_INTERNAL },
433 { "message", 56, OT_INTERNAL },
434 { "max-message-size", 57, OT_INTERNAL },
435 { "T1", 58, OT_INTERNAL | OT_TIME},
436 { "T2", 59, OT_INTERNAL | OT_TIME},
437 { "vendor-class", 60, 0 },
438 { "client-id", 61, OT_INTERNAL },
439 { "nis+-domain", 64, OT_NAME },
440 { "nis+-server", 65, OT_ADDR_LIST },
441 { "tftp-server", 66, OT_NAME },
442 { "bootfile-name", 67, OT_NAME },
443 { "mobile-ip-home", 68, OT_ADDR_LIST },
444 { "smtp-server", 69, OT_ADDR_LIST },
445 { "pop3-server", 70, OT_ADDR_LIST },
446 { "nntp-server", 71, OT_ADDR_LIST },
447 { "irc-server", 74, OT_ADDR_LIST },
448 { "user-class", 77, 0 },
449 { "FQDN", 81, OT_INTERNAL },
450 { "agent-id", 82, OT_INTERNAL },
451 { "client-arch", 93, 2 | OT_DEC },
452 { "client-interface-id", 94, 0 },
453 { "client-machine-id", 97, 0 },
454 { "subnet-select", 118, OT_INTERNAL },
455 { "domain-search", 119, OT_RFC1035_NAME },
456 { "sip-server", 120, 0 },
457 { "classless-static-route", 121, 0 },
458 { "vendor-id-encap", 125, 0 },
459 { "server-ip-address", 255, OT_ADDR_LIST }, /* special, internal only, sets siaddr */
460 { NULL, 0, 0 }
463 #ifdef HAVE_DHCP6
464 static const struct opttab_t opttab6[] = {
465 { "client-id", 1, OT_INTERNAL },
466 { "server-id", 2, OT_INTERNAL },
467 { "ia-na", 3, OT_INTERNAL },
468 { "ia-ta", 4, OT_INTERNAL },
469 { "iaaddr", 5, OT_INTERNAL },
470 { "oro", 6, OT_INTERNAL },
471 { "preference", 7, OT_INTERNAL | OT_DEC },
472 { "unicast", 12, OT_INTERNAL },
473 { "status", 13, OT_INTERNAL },
474 { "rapid-commit", 14, OT_INTERNAL },
475 { "user-class", 15, OT_INTERNAL | OT_CSTRING },
476 { "vendor-class", 16, OT_INTERNAL | OT_CSTRING },
477 { "vendor-opts", 17, OT_INTERNAL },
478 { "sip-server-domain", 21, OT_RFC1035_NAME },
479 { "sip-server", 22, OT_ADDR_LIST },
480 { "dns-server", 23, OT_ADDR_LIST },
481 { "domain-search", 24, OT_RFC1035_NAME },
482 { "nis-server", 27, OT_ADDR_LIST },
483 { "nis+-server", 28, OT_ADDR_LIST },
484 { "nis-domain", 29, OT_RFC1035_NAME },
485 { "nis+-domain", 30, OT_RFC1035_NAME },
486 { "sntp-server", 31, OT_ADDR_LIST },
487 { "information-refresh-time", 32, OT_TIME },
488 { "FQDN", 39, OT_INTERNAL | OT_RFC1035_NAME },
489 { "ntp-server", 56, OT_ADDR_LIST },
490 { "bootfile-url", 59, OT_NAME },
491 { "bootfile-param", 60, OT_CSTRING },
492 { NULL, 0, 0 }
494 #endif
498 void display_opts(void)
500 int i;
502 printf(_("Known DHCP options:\n"));
504 for (i = 0; opttab[i].name; i++)
505 if (!(opttab[i].size & OT_INTERNAL))
506 printf("%3d %s\n", opttab[i].val, opttab[i].name);
509 #ifdef HAVE_DHCP6
510 void display_opts6(void)
512 int i;
513 printf(_("Known DHCPv6 options:\n"));
515 for (i = 0; opttab6[i].name; i++)
516 if (!(opttab6[i].size & OT_INTERNAL))
517 printf("%3d %s\n", opttab6[i].val, opttab6[i].name);
519 #endif
521 int lookup_dhcp_opt(int prot, char *name)
523 const struct opttab_t *t;
524 int i;
526 #ifdef HAVE_DHCP6
527 if (prot == AF_INET6)
528 t = opttab6;
529 else
530 #endif
531 t = opttab;
533 for (i = 0; t[i].name; i++)
534 if (strcasecmp(t[i].name, name) == 0)
535 return t[i].val;
537 return -1;
540 int lookup_dhcp_len(int prot, int val)
542 const struct opttab_t *t;
543 int i;
545 #ifdef HAVE_DHCP6
546 if (prot == AF_INET6)
547 t = opttab6;
548 else
549 #endif
550 t = opttab;
552 for (i = 0; t[i].name; i++)
553 if (val == t[i].val)
554 return t[i].size & ~OT_DEC;
556 return 0;
559 char *option_string(int prot, unsigned int opt, unsigned char *val, int opt_len, char *buf, int buf_len)
561 int o, i, j, nodecode = 0;
562 const struct opttab_t *ot = opttab;
564 #ifdef HAVE_DHCP6
565 if (prot == AF_INET6)
566 ot = opttab6;
567 #endif
569 for (o = 0; ot[o].name; o++)
570 if (ot[o].val == opt)
572 if (buf)
574 memset(buf, 0, buf_len);
576 if (ot[o].size & OT_ADDR_LIST)
578 struct all_addr addr;
579 int addr_len = INADDRSZ;
581 #ifdef HAVE_DHCP6
582 if (prot == AF_INET6)
583 addr_len = IN6ADDRSZ;
584 #endif
585 for (buf[0]= 0, i = 0; i <= opt_len - addr_len; i += addr_len)
587 if (i != 0)
588 strncat(buf, ", ", buf_len - strlen(buf));
589 /* align */
590 memcpy(&addr, &val[i], addr_len);
591 inet_ntop(prot, &val[i], daemon->addrbuff, ADDRSTRLEN);
592 strncat(buf, daemon->addrbuff, buf_len - strlen(buf));
595 else if (ot[o].size & OT_NAME)
596 for (i = 0, j = 0; i < opt_len && j < buf_len ; i++)
598 char c = val[i];
599 if (isprint((int)c))
600 buf[j++] = c;
602 #ifdef HAVE_DHCP6
603 /* We don't handle compressed rfc1035 names, so no good in IPv4 land */
604 else if ((ot[o].size & OT_RFC1035_NAME) && prot == AF_INET6)
606 i = 0, j = 0;
607 while (i < opt_len && val[i] != 0)
609 int k, l = i + val[i] + 1;
610 for (k = i + 1; k < opt_len && k < l && j < buf_len ; k++)
612 char c = val[k];
613 if (isprint((int)c))
614 buf[j++] = c;
616 i = l;
617 if (val[i] != 0 && j < buf_len)
618 buf[j++] = '.';
621 else if ((ot[o].size & OT_CSTRING))
623 int k, len;
624 unsigned char *p;
626 i = 0, j = 0;
627 while (1)
629 p = &val[i];
630 GETSHORT(len, p);
631 for (k = 0; k < len && j < buf_len; k++)
633 char c = *p++;
634 if (isprint((int)c))
635 buf[j++] = c;
637 i += len +2;
638 if (i >= opt_len)
639 break;
641 if (j < buf_len)
642 buf[j++] = ',';
645 #endif
646 else if ((ot[o].size & (OT_DEC | OT_TIME)) && opt_len != 0)
648 unsigned int dec = 0;
650 for (i = 0; i < opt_len; i++)
651 dec = (dec << 8) | val[i];
653 if (ot[o].size & OT_TIME)
654 prettyprint_time(buf, dec);
655 else
656 sprintf(buf, "%u", dec);
658 else
659 nodecode = 1;
661 break;
664 if (opt_len != 0 && buf && (!ot[o].name || nodecode))
666 int trunc = 0;
667 if (opt_len > 14)
669 trunc = 1;
670 opt_len = 14;
672 print_mac(buf, val, opt_len);
673 if (trunc)
674 strncat(buf, "...", buf_len - strlen(buf));
679 return ot[o].name ? ot[o].name : "";
683 void log_context(int family, struct dhcp_context *context)
685 /* Cannot use dhcp_buff* for RA contexts */
687 void *start = &context->start;
688 void *end = &context->end;
689 char *template = "", *p = daemon->namebuff;
691 *p = 0;
693 #ifdef HAVE_DHCP6
694 if (family == AF_INET6)
696 struct in6_addr subnet = context->start6;
697 if (!(context->flags & CONTEXT_TEMPLATE))
698 setaddr6part(&subnet, 0);
699 inet_ntop(AF_INET6, &subnet, daemon->addrbuff, ADDRSTRLEN);
700 start = &context->start6;
701 end = &context->end6;
703 #endif
705 if (family != AF_INET && (context->flags & CONTEXT_DEPRECATE))
706 strcpy(daemon->namebuff, _(", prefix deprecated"));
707 else
709 p += sprintf(p, _(", lease time "));
710 prettyprint_time(p, context->lease_time);
711 p += strlen(p);
714 #ifdef HAVE_DHCP6
715 if (context->flags & CONTEXT_CONSTRUCTED)
717 char ifrn_name[IFNAMSIZ];
719 template = p;
720 p += sprintf(p, ", ");
722 if (indextoname(daemon->doing_dhcp6 ? daemon->dhcp6fd : daemon->icmp6fd, context->if_index, ifrn_name))
723 sprintf(p, "constructed for %s", ifrn_name);
725 else if (context->flags & CONTEXT_TEMPLATE)
727 template = p;
728 p += sprintf(p, ", ");
730 sprintf(p, "template for %s", context->template_interface);
732 #endif
734 if ((context->flags & CONTEXT_DHCP) || family == AF_INET)
736 inet_ntop(family, start, daemon->dhcp_buff, 256);
737 inet_ntop(family, end, daemon->dhcp_buff3, 256);
738 my_syslog(MS_DHCP | LOG_INFO,
739 (context->flags & CONTEXT_RA_STATELESS) ?
740 _("%s stateless on %s%.0s%.0s%s") :
741 (context->flags & CONTEXT_STATIC) ?
742 _("%s, static leases only on %.0s%s%s%.0s") :
743 (context->flags & CONTEXT_PROXY) ?
744 _("%s, proxy on subnet %.0s%s%.0s%.0s") :
745 _("%s, IP range %s -- %s%s%.0s"),
746 (family != AF_INET) ? "DHCPv6" : "DHCP",
747 daemon->dhcp_buff, daemon->dhcp_buff3, daemon->namebuff, template);
750 #ifdef HAVE_DHCP6
751 if (context->flags & CONTEXT_RA_NAME)
752 my_syslog(MS_DHCP | LOG_INFO, _("DHCPv4-derived IPv6 names on %s%s"), daemon->addrbuff, template);
754 if ((context->flags & CONTEXT_RA) || (option_bool(OPT_RA) && (context->flags & CONTEXT_DHCP) && family == AF_INET6))
755 my_syslog(MS_DHCP | LOG_INFO, _("router advertisement on %s%s"), daemon->addrbuff, template);
756 #endif
761 #endif