ISC DHCP  4.3.2
A reference DHCPv4 and DHCPv6 implementation
discover.c
Go to the documentation of this file.
1 /* discover.c
2 
3  Find and identify the network interfaces. */
4 
5 /*
6  * Copyright (c) 2013-2014 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 2004-2009,2011 by Internet Systems Consortium, Inc. ("ISC")
8  * Copyright (c) 1995-2003 by Internet Software Consortium
9  *
10  * Permission to use, copy, modify, and distribute this software for any
11  * purpose with or without fee is hereby granted, provided that the above
12  * copyright notice and this permission notice appear in all copies.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
15  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
17  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
20  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  *
22  * Internet Systems Consortium, Inc.
23  * 950 Charter Street
24  * Redwood City, CA 94063
25  * <info@isc.org>
26  * https://www.isc.org/
27  *
28  */
29 
30 #include "dhcpd.h"
31 
32 /* length of line we can read from the IF file, 256 is too small in some cases */
33 #define IF_LINE_LENGTH 1024
34 
35 #define BSD_COMP /* needed on Solaris for SIOCGLIFNUM */
36 #include <sys/ioctl.h>
37 #include <errno.h>
38 
39 #ifdef HAVE_NET_IF6_H
40 # include <net/if6.h>
41 #endif
42 
46 u_int16_t local_port;
47 u_int16_t remote_port;
50 isc_result_t (*dhcp_interface_startup_hook) (struct interface_info *);
52 
53 struct in_addr limited_broadcast;
54 
55 int local_family = AF_INET;
56 struct in_addr local_address;
57 
59  struct dhcp_packet *, unsigned,
60  unsigned int,
61  struct iaddr, struct hardware *);
62 
63 #ifdef DHCPv6
64 void (*dhcpv6_packet_handler)(struct interface_info *,
65  const char *, int,
66  int, const struct iaddr *,
67  isc_boolean_t);
68 #endif /* DHCPv6 */
69 
70 
72 #if defined (TRACING)
76 #endif
80 
81 OMAPI_OBJECT_ALLOC (interface, struct interface_info, dhcp_type_interface)
82 
83 isc_result_t interface_setup ()
84 {
85  isc_result_t status;
86  status = omapi_object_type_register (&dhcp_type_interface,
87  "interface",
96  0, 0, 0,
97  sizeof (struct interface_info),
99  if (status != ISC_R_SUCCESS)
100  log_fatal ("Can't register interface object type: %s",
101  isc_result_totext (status));
102 
103  return status;
104 }
105 
106 #if defined (TRACING)
107 void interface_trace_setup ()
108 {
109  interface_trace = trace_type_register ("interface", (void *)0,
112  inpacket_trace = trace_type_register ("inpacket", (void *)0,
115  outpacket_trace = trace_type_register ("outpacket", (void *)0,
118 }
119 #endif
120 
122  const char *file, int line)
123 {
124  struct interface_info *ip = (struct interface_info *)ipo;
125  ip -> rfdesc = ip -> wfdesc = -1;
126  return ISC_R_SUCCESS;
127 }
128 
129 
130 /*
131  * Scanning for Interfaces
132  * -----------------------
133  *
134  * To find interfaces, we create an iterator that abstracts out most
135  * of the platform specifics. Use is fairly straightforward:
136  *
137  * - begin_iface_scan() starts the process.
138  * - Use next_iface() until it returns 0.
139  * - end_iface_scan() performs any necessary cleanup.
140  *
141  * We check for errors on each call to next_iface(), which returns a
142  * description of the error as a string if any occurs.
143  *
144  * We currently have code for Solaris and Linux. Other systems need
145  * to have code written.
146  *
147  * NOTE: the long-term goal is to use the interface code from BIND 9.
148  */
149 
150 #if defined(SIOCGLIFCONF) && defined(SIOCGLIFNUM) && defined(SIOCGLIFFLAGS)
151 
152 /* HP/UX doesn't define struct lifconf, instead they define struct
153  * if_laddrconf. Similarly, 'struct lifreq' and 'struct lifaddrreq'.
154  */
155 #ifdef ISC_PLATFORM_HAVEIF_LADDRCONF
156 # define lifc_len iflc_len
157 # define lifc_buf iflc_buf
158 # define lifc_req iflc_req
159 # define LIFCONF if_laddrconf
160 #else
161 # define ISC_HAVE_LIFC_FAMILY 1
162 # define ISC_HAVE_LIFC_FLAGS 1
163 # define LIFCONF lifconf
164 #endif
165 
166 #ifdef ISC_PLATFORM_HAVEIF_LADDRREQ
167 # define lifr_addr iflr_addr
168 # define lifr_name iflr_name
169 # define lifr_dstaddr iflr_dstaddr
170 # define lifr_flags iflr_flags
171 # define sockaddr_storage sockaddr_ext
172 # define ss_family sa_family
173 # define LIFREQ if_laddrreq
174 #else
175 # define LIFREQ lifreq
176 #endif
177 
178 #ifndef IF_NAMESIZE
179 # if defined(LIFNAMSIZ)
180 # define IF_NAMESIZE LIFNAMSIZ
181 # elif defined(IFNAMSIZ)
182 # define IF_NAMESIZE IFNAMSIZ
183 # else
184 # define IF_NAMESIZE 16
185 # endif
186 #endif
187 #elif !defined(__linux) && !defined(HAVE_IFADDRS_H)
188 # define SIOCGLIFCONF SIOCGIFCONF
189 # define SIOCGLIFFLAGS SIOCGIFFLAGS
190 # define LIFREQ ifreq
191 # define LIFCONF ifconf
192 # define lifr_name ifr_name
193 # define lifr_addr ifr_addr
194 # define lifr_flags ifr_flags
195 # define lifc_len ifc_len
196 # define lifc_buf ifc_buf
197 # define lifc_req ifc_req
198 #ifdef _AIX
199 # define ss_family __ss_family
200 #endif
201 #endif
202 
203 #if defined(SIOCGLIFCONF) && defined(SIOCGLIFFLAGS)
204 /*
205  * Solaris support
206  * ---------------
207  *
208  * The SIOCGLIFCONF ioctl() are the extension that you need to use
209  * on Solaris to get information about IPv6 addresses.
210  *
211  * Solaris' extended interface is documented in the if_tcp man page.
212  */
213 
214 /*
215  * Structure holding state about the scan.
216  */
218  int sock; /* file descriptor used to get information */
219  int num; /* total number of interfaces */
220  struct LIFCONF conf; /* structure used to get information */
221  int next; /* next interface to retrieve when iterating */
222 };
223 
224 /*
225  * Structure used to return information about a specific interface.
226  */
227 struct iface_info {
228  char name[IF_NAMESIZE+1]; /* name of the interface, e.g. "bge0" */
229  struct sockaddr_storage addr; /* address information */
230  isc_uint64_t flags; /* interface flags, e.g. IFF_LOOPBACK */
231 };
232 
233 /*
234  * Start a scan of interfaces.
235  *
236  * The iface_conf_list structure maintains state for this process.
237  */
238 int
240 #ifdef ISC_PLATFORM_HAVELIFNUM
241  struct lifnum lifnum;
242 #else
243  int lifnum;
244 #endif
245 
246  ifaces->sock = socket(local_family, SOCK_DGRAM, IPPROTO_UDP);
247  if (ifaces->sock < 0) {
248  log_error("Error creating socket to list interfaces; %m");
249  return 0;
250  }
251 
252  memset(&lifnum, 0, sizeof(lifnum));
253 #ifdef ISC_PLATFORM_HAVELIFNUM
254  lifnum.lifn_family = AF_UNSPEC;
255 #endif
256 #ifdef SIOCGLIFNUM
257  if (ioctl(ifaces->sock, SIOCGLIFNUM, &lifnum) < 0) {
258  log_error("Error finding total number of interfaces; %m");
259  close(ifaces->sock);
260  ifaces->sock = -1;
261  return 0;
262  }
263 
264 #ifdef ISC_PLATFORM_HAVELIFNUM
265  ifaces->num = lifnum.lifn_count;
266 #else
267  ifaces->num = lifnum;
268 #endif
269 #else
270  ifaces->num = 64;
271 #endif /* SIOCGLIFNUM */
272 
273  memset(&ifaces->conf, 0, sizeof(ifaces->conf));
274 #ifdef ISC_HAVE_LIFC_FAMILY
275  ifaces->conf.lifc_family = AF_UNSPEC;
276 #endif
277  ifaces->conf.lifc_len = ifaces->num * sizeof(struct LIFREQ);
278  ifaces->conf.lifc_buf = dmalloc(ifaces->conf.lifc_len, MDL);
279  if (ifaces->conf.lifc_buf == NULL) {
280  log_fatal("Out of memory getting interface list.");
281  }
282 
283  if (ioctl(ifaces->sock, SIOCGLIFCONF, &ifaces->conf) < 0) {
284  log_error("Error getting interfaces configuration list; %m");
285  dfree(ifaces->conf.lifc_buf, MDL);
286  close(ifaces->sock);
287  ifaces->sock = -1;
288  return 0;
289  }
290 
291  ifaces->next = 0;
292 
293  return 1;
294 }
295 
296 /*
297  * Retrieve the next interface.
298  *
299  * Returns information in the info structure.
300  * Sets err to 1 if there is an error, otherwise 0.
301  */
302 int
303 next_iface(struct iface_info *info, int *err, struct iface_conf_list *ifaces) {
304  struct LIFREQ *p;
305  struct LIFREQ tmp;
306  isc_boolean_t foundif;
307 #if defined(sun) || defined(__linux)
308  /* Pointer used to remove interface aliases. */
309  char *s;
310 #endif
311 
312  do {
313  foundif = ISC_FALSE;
314 
315  if (ifaces->next >= ifaces->num) {
316  *err = 0;
317  return 0;
318  }
319 
320  p = ifaces->conf.lifc_req;
321  p += ifaces->next;
322 
323  if (strlen(p->lifr_name) >= sizeof(info->name)) {
324  *err = 1;
325  log_error("Interface name '%s' too long", p->lifr_name);
326  return 0;
327  }
328 
329  /* Reject if interface address family does not match */
330  if (p->lifr_addr.ss_family != local_family) {
331  ifaces->next++;
332  continue;
333  }
334 
335  strcpy(info->name, p->lifr_name);
336  memset(&info->addr, 0, sizeof(info->addr));
337  memcpy(&info->addr, &p->lifr_addr, sizeof(p->lifr_addr));
338 
339 #if defined(sun) || defined(__linux)
340  /* interface aliases look like "eth0:1" or "wlan1:3" */
341  s = strchr(info->name, ':');
342  if (s != NULL) {
343  *s = '\0';
344  }
345 #endif /* defined(sun) || defined(__linux) */
346 
347  foundif = ISC_TRUE;
348  } while ((foundif == ISC_FALSE) ||
349  (strncmp(info->name, "dummy", 5) == 0));
350 
351  memset(&tmp, 0, sizeof(tmp));
352  strcpy(tmp.lifr_name, info->name);
353  if (ioctl(ifaces->sock, SIOCGLIFFLAGS, &tmp) < 0) {
354  log_error("Error getting interface flags for '%s'; %m",
355  p->lifr_name);
356  *err = 1;
357  return 0;
358  }
359  info->flags = tmp.lifr_flags;
360 
361  ifaces->next++;
362  *err = 0;
363  return 1;
364 }
365 
366 /*
367  * End scan of interfaces.
368  */
369 void
371  dfree(ifaces->conf.lifc_buf, MDL);
372  close(ifaces->sock);
373  ifaces->sock = -1;
374 }
375 
376 #else
377 
378 /*
379  * BSD support
380  * -----------
381  *
382  * FreeBSD, NetBSD, OpenBSD, OS X and Linux all have the getifaddrs()
383  * function.
384  *
385  * The getifaddrs() man page describes the use.
386  */
387 
388 #include <ifaddrs.h>
389 
390 /*
391  * Structure holding state about the scan.
392  */
393 struct iface_conf_list {
394  struct ifaddrs *head; /* beginning of the list */
395  struct ifaddrs *next; /* current position in the list */
396 };
397 
398 /*
399  * Structure used to return information about a specific interface.
400  */
401 struct iface_info {
402  char name[IFNAMSIZ]; /* name of the interface, e.g. "bge0" */
403  struct sockaddr_storage addr; /* address information */
404  isc_uint64_t flags; /* interface flags, e.g. IFF_LOOPBACK */
405 };
406 
407 /*
408  * Start a scan of interfaces.
409  *
410  * The iface_conf_list structure maintains state for this process.
411  */
412 int
413 begin_iface_scan(struct iface_conf_list *ifaces) {
414  if (getifaddrs(&ifaces->head) != 0) {
415  log_error("Error getting interfaces; %m");
416  return 0;
417  }
418  ifaces->next = ifaces->head;
419  return 1;
420 }
421 
422 /*
423  * Retrieve the next interface.
424  *
425  * Returns information in the info structure.
426  * Sets err to 1 if there is an error, otherwise 0.
427  */
428 int
429 next_iface(struct iface_info *info, int *err, struct iface_conf_list *ifaces) {
430  size_t sa_len = 0;
431 
432  if (ifaces->next == NULL) {
433  *err = 0;
434  return 0;
435  }
436  if (strlen(ifaces->next->ifa_name) >= sizeof(info->name)) {
437  log_error("Interface name '%s' too long",
438  ifaces->next->ifa_name);
439  *err = 1;
440  return 0;
441  }
442  strcpy(info->name, ifaces->next->ifa_name);
443 
444  memset(&info->addr, 0 , sizeof(info->addr));
445 
446  if (ifaces->next->ifa_addr != NULL) {
447 #ifdef HAVE_SA_LEN
448  sa_len = ifaces->next->ifa_addr->sa_len;
449 #else
450  if (ifaces->next->ifa_addr->sa_family == AF_INET)
451  sa_len = sizeof(struct sockaddr_in);
452  else if (ifaces->next->ifa_addr->sa_family == AF_INET6)
453  sa_len = sizeof(struct sockaddr_in6);
454 #endif
455  memcpy(&info->addr, ifaces->next->ifa_addr, sa_len);
456  }
457  info->flags = ifaces->next->ifa_flags;
458  ifaces->next = ifaces->next->ifa_next;
459  *err = 0;
460  return 1;
461 }
462 
463 /*
464  * End scan of interfaces.
465  */
466 void
467 end_iface_scan(struct iface_conf_list *ifaces) {
468  freeifaddrs(ifaces->head);
469  ifaces->head = NULL;
470  ifaces->next = NULL;
471 }
472 #endif
473 
474 /* XXX: perhaps create drealloc() rather than do it manually */
475 void
477  const struct in_addr *addr) {
478  /*
479  * We don't expect a lot of addresses per IPv4 interface, so
480  * we use 4, as our "chunk size" for collecting addresses.
481  */
482  if (iface->addresses == NULL) {
483  iface->addresses = dmalloc(4 * sizeof(struct in_addr), MDL);
484  if (iface->addresses == NULL) {
485  log_fatal("Out of memory saving IPv4 address "
486  "on interface.");
487  }
488  iface->address_count = 0;
489  iface->address_max = 4;
490  } else if (iface->address_count >= iface->address_max) {
491  struct in_addr *tmp;
492  int new_max;
493 
494  new_max = iface->address_max + 4;
495  tmp = dmalloc(new_max * sizeof(struct in_addr), MDL);
496  if (tmp == NULL) {
497  log_fatal("Out of memory saving IPv4 address "
498  "on interface.");
499  }
500  memcpy(tmp,
501  iface->addresses,
502  iface->address_max * sizeof(struct in_addr));
503  dfree(iface->addresses, MDL);
504  iface->addresses = tmp;
505  iface->address_max = new_max;
506  }
507  iface->addresses[iface->address_count++] = *addr;
508 }
509 
510 #ifdef DHCPv6
511 /* XXX: perhaps create drealloc() rather than do it manually */
512 void
513 add_ipv6_addr_to_interface(struct interface_info *iface,
514  const struct in6_addr *addr) {
515  /*
516  * Each IPv6 interface will have at least two IPv6 addresses,
517  * and likely quite a few more. So we use 8, as our "chunk size" for
518  * collecting addresses.
519  */
520  if (iface->v6addresses == NULL) {
521  iface->v6addresses = dmalloc(8 * sizeof(struct in6_addr), MDL);
522  if (iface->v6addresses == NULL) {
523  log_fatal("Out of memory saving IPv6 address "
524  "on interface.");
525  }
526  iface->v6address_count = 0;
527  iface->v6address_max = 8;
528  } else if (iface->v6address_count >= iface->v6address_max) {
529  struct in6_addr *tmp;
530  int new_max;
531 
532  new_max = iface->v6address_max + 8;
533  tmp = dmalloc(new_max * sizeof(struct in6_addr), MDL);
534  if (tmp == NULL) {
535  log_fatal("Out of memory saving IPv6 address "
536  "on interface.");
537  }
538  memcpy(tmp,
539  iface->v6addresses,
540  iface->v6address_max * sizeof(struct in6_addr));
541  dfree(iface->v6addresses, MDL);
542  iface->v6addresses = tmp;
543  iface->v6address_max = new_max;
544  }
545  iface->v6addresses[iface->v6address_count++] = *addr;
546 }
547 #endif /* DHCPv6 */
548 
549 /* Use the SIOCGIFCONF ioctl to get a list of all the attached interfaces.
550  For each interface that's of type INET and not the loopback interface,
551  register that interface with the network I/O software, figure out what
552  subnet it's on, and add it to the list of interfaces. */
553 
554 void
556  struct iface_conf_list ifaces;
557  struct iface_info info;
558  int err;
559 
560  struct interface_info *tmp;
561  struct interface_info *last, *next;
562 
563 #ifdef DHCPv6
564  char abuf[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
565 #endif /* DHCPv6 */
566 
567 
568  struct subnet *subnet;
569  int ir;
570  isc_result_t status;
571  int wifcount = 0;
572 
573  static int setup_fallback = 0;
574 
575  if (!begin_iface_scan(&ifaces)) {
576  log_fatal("Can't get list of interfaces.");
577  }
578 
579  /* If we already have a list of interfaces, and we're running as
580  a DHCP server, the interfaces were requested. */
581  if (interfaces && (state == DISCOVER_SERVER ||
582  state == DISCOVER_RELAY ||
583  state == DISCOVER_REQUESTED))
584  ir = 0;
585  else if (state == DISCOVER_UNCONFIGURED)
587  else
588  ir = INTERFACE_REQUESTED;
589 
590  /* Cycle through the list of interfaces looking for IP addresses. */
591  while (next_iface(&info, &err, &ifaces)) {
592 
593  /* See if we've seen an interface that matches this one. */
594  for (tmp = interfaces; tmp; tmp = tmp->next) {
595  if (!strcmp(tmp->name, info.name))
596  break;
597  }
598 
599  /* Skip non broadcast interfaces (plus loopback and
600  point-to-point in case an OS incorrectly marks them
601  as broadcast). Also skip down interfaces unless we're
602  trying to get a list of configurable interfaces. */
603  if ((((local_family == AF_INET &&
604  !(info.flags & IFF_BROADCAST)) ||
605 #ifdef DHCPv6
606  (local_family == AF_INET6 &&
607  !(info.flags & IFF_MULTICAST)) ||
608 #endif
609  info.flags & IFF_LOOPBACK ||
610  info.flags & IFF_POINTOPOINT) && !tmp) ||
611  (!(info.flags & IFF_UP) &&
612  state != DISCOVER_UNCONFIGURED))
613  continue;
614 
615  /* If there isn't already an interface by this name,
616  allocate one. */
617  if (tmp == NULL) {
618  status = interface_allocate(&tmp, MDL);
619  if (status != ISC_R_SUCCESS) {
620  log_fatal("Error allocating interface %s: %s",
621  info.name, isc_result_totext(status));
622  }
623  strcpy(tmp->name, info.name);
624  interface_snorf(tmp, ir);
625  interface_dereference(&tmp, MDL);
626  tmp = interfaces; /* XXX */
627  }
628 
630  (*dhcp_interface_discovery_hook)(tmp);
631  }
632 
633  if ((info.addr.ss_family == AF_INET) &&
634  (local_family == AF_INET)) {
635  struct sockaddr_in *a = (struct sockaddr_in*)&info.addr;
636  struct iaddr addr;
637 
638  /* We don't want the loopback interface. */
639  if (a->sin_addr.s_addr == htonl(INADDR_LOOPBACK) &&
640  ((tmp->flags & INTERFACE_AUTOMATIC) &&
641  state == DISCOVER_SERVER))
642  continue;
643 
644  /* If the only address we have is 0.0.0.0, we
645  shouldn't consider the interface configured. */
646  if (a->sin_addr.s_addr != htonl(INADDR_ANY))
647  tmp->configured = 1;
648 
649  add_ipv4_addr_to_interface(tmp, &a->sin_addr);
650 
651  /* invoke the setup hook */
652  addr.len = 4;
653  memcpy(addr.iabuf, &a->sin_addr.s_addr, addr.len);
655  (*dhcp_interface_setup_hook)(tmp, &addr);
656  }
657  }
658 #ifdef DHCPv6
659  else if ((info.addr.ss_family == AF_INET6) &&
660  (local_family == AF_INET6)) {
661  struct sockaddr_in6 *a =
662  (struct sockaddr_in6*)&info.addr;
663  struct iaddr addr;
664 
665  /* We don't want the loopback interface. */
666  if (IN6_IS_ADDR_LOOPBACK(&a->sin6_addr) &&
667  ((tmp->flags & INTERFACE_AUTOMATIC) &&
668  state == DISCOVER_SERVER))
669  continue;
670 
671  /* If the only address we have is 0.0.0.0, we
672  shouldn't consider the interface configured. */
673  if (IN6_IS_ADDR_UNSPECIFIED(&a->sin6_addr))
674  tmp->configured = 1;
675 
676  add_ipv6_addr_to_interface(tmp, &a->sin6_addr);
677 
678  /* invoke the setup hook */
679  addr.len = 16;
680  memcpy(addr.iabuf, &a->sin6_addr, addr.len);
682  (*dhcp_interface_setup_hook)(tmp, &addr);
683  }
684  }
685 #endif /* DHCPv6 */
686  }
687 
688  if (err) {
689  log_fatal("Error getting interface information.");
690  }
691 
692  end_iface_scan(&ifaces);
693 
694 
695  /* Mock-up an 'ifp' structure which is no longer used in the
696  * new interface-sensing code, but is used in higher layers
697  * (for example to sense fallback interfaces).
698  */
699  for (tmp = interfaces ; tmp != NULL ; tmp = tmp->next) {
700  if (tmp->ifp == NULL) {
701  struct ifreq *tif;
702 
703  tif = (struct ifreq *)dmalloc(sizeof(struct ifreq),
704  MDL);
705  if (tif == NULL)
706  log_fatal("no space for ifp mockup.");
707  strcpy(tif->ifr_name, tmp->name);
708  tmp->ifp = tif;
709  }
710  }
711 
712 
713  /* If we're just trying to get a list of interfaces that we might
714  be able to configure, we can quit now. */
715  if (state == DISCOVER_UNCONFIGURED) {
716  return;
717  }
718 
719  /* Weed out the interfaces that did not have IP addresses. */
720  tmp = last = next = NULL;
721  if (interfaces)
722  interface_reference (&tmp, interfaces, MDL);
723  while (tmp) {
724  if (next)
725  interface_dereference (&next, MDL);
726  if (tmp -> next)
727  interface_reference (&next, tmp -> next, MDL);
728  /* skip interfaces that are running already */
729  if (tmp -> flags & INTERFACE_RUNNING) {
730  interface_dereference(&tmp, MDL);
731  if(next)
732  interface_reference(&tmp, next, MDL);
733  continue;
734  }
735  if ((tmp -> flags & INTERFACE_AUTOMATIC) &&
736  state == DISCOVER_REQUESTED)
737  tmp -> flags &= ~(INTERFACE_AUTOMATIC |
739 
740 #ifdef DHCPv6
741  if (!(tmp->flags & INTERFACE_REQUESTED)) {
742 #else
743  if (!tmp -> ifp || !(tmp -> flags & INTERFACE_REQUESTED)) {
744 #endif /* DHCPv6 */
745  if ((tmp -> flags & INTERFACE_REQUESTED) != ir)
746  log_fatal ("%s: not found", tmp -> name);
747  if (!last) {
748  if (interfaces)
749  interface_dereference (&interfaces,
750  MDL);
751  if (next)
752  interface_reference (&interfaces, next, MDL);
753  } else {
754  interface_dereference (&last -> next, MDL);
755  if (next)
756  interface_reference (&last -> next,
757  next, MDL);
758  }
759  if (tmp -> next)
760  interface_dereference (&tmp -> next, MDL);
761 
762  /* Remember the interface in case we need to know
763  about it later. */
764  if (dummy_interfaces) {
765  interface_reference (&tmp -> next,
766  dummy_interfaces, MDL);
767  interface_dereference (&dummy_interfaces, MDL);
768  }
769  interface_reference (&dummy_interfaces, tmp, MDL);
770  interface_dereference (&tmp, MDL);
771  if (next)
772  interface_reference (&tmp, next, MDL);
773  continue;
774  }
775  last = tmp;
776 
777  /* We must have a subnet declaration for each interface. */
778  if (!tmp->shared_network && (state == DISCOVER_SERVER)) {
779  log_info("%s", "");
780  if (local_family == AF_INET) {
781  log_info("No subnet declaration for %s (%s).",
782  tmp->name,
783  (tmp->addresses == NULL) ?
784  "no IPv4 addresses" :
785  inet_ntoa(tmp->addresses[0]));
786 #ifdef DHCPv6
787  } else {
788  if (tmp->v6addresses != NULL) {
789  inet_ntop(AF_INET6,
790  &tmp->v6addresses[0],
791  abuf,
792  sizeof(abuf));
793  } else {
794  strcpy(abuf, "no IPv6 addresses");
795  }
796  log_info("No subnet6 declaration for %s (%s).",
797  tmp->name,
798  abuf);
799 #endif /* DHCPv6 */
800  }
801  if (supports_multiple_interfaces(tmp)) {
802  log_info ("** Ignoring requests on %s. %s",
803  tmp -> name, "If this is not what");
804  log_info (" you want, please write %s",
805 #ifdef DHCPv6
806  (local_family != AF_INET) ?
807  "a subnet6 declaration" :
808 #endif
809  "a subnet declaration");
810  log_info (" in your dhcpd.conf file %s",
811  "for the network segment");
812  log_info (" to %s %s %s",
813  "which interface",
814  tmp -> name, "is attached. **");
815  log_info ("%s", "");
816  goto next;
817  } else {
818  log_error ("You must write a %s",
819 #ifdef DHCPv6
820  (local_family != AF_INET) ?
821  "subnet6 declaration for this" :
822 #endif
823  "subnet declaration for this");
824  log_error ("subnet. You cannot prevent %s",
825  "the DHCP server");
826  log_error ("from listening on this subnet %s",
827  "because your");
828  log_fatal ("operating system does not %s.",
829  "support this capability");
830  }
831  }
832 
833  /* Find subnets that don't have valid interface
834  addresses... */
835  for (subnet = (tmp -> shared_network
836  ? tmp -> shared_network -> subnets
837  : (struct subnet *)0);
838  subnet; subnet = subnet -> next_sibling) {
839  /* Set the interface address for this subnet
840  to the first address we found. */
841  if (subnet->interface_address.len == 0) {
842  if (tmp->address_count > 0) {
843  subnet->interface_address.len = 4;
844  memcpy(subnet->interface_address.iabuf,
845  &tmp->addresses[0].s_addr, 4);
846  } else if (tmp->v6address_count > 0) {
847  subnet->interface_address.len = 16;
848  memcpy(subnet->interface_address.iabuf,
849  &tmp->v6addresses[0].s6_addr,
850  16);
851  } else {
852  /* XXX: should be one */
853  log_error("%s missing an interface "
854  "address", tmp->name);
855  continue;
856  }
857  }
858  }
859 
860  /* Flag the index as not having been set, so that the
861  interface registerer can set it or not as it chooses. */
862  tmp -> index = -1;
863 
864  /* Register the interface... */
865  if (local_family == AF_INET) {
866  if_register_receive(tmp);
867  if_register_send(tmp);
868 #ifdef DHCPv6
869  } else {
870  if ((state == DISCOVER_SERVER) ||
871  (state == DISCOVER_RELAY)) {
872  if_register6(tmp, 1);
873  } else {
875  }
876 #endif /* DHCPv6 */
877  }
878 
879  interface_stash (tmp);
880  wifcount++;
881 #if defined (F_SETFD)
882  if (fcntl (tmp -> rfdesc, F_SETFD, 1) < 0)
883  log_error ("Can't set close-on-exec on %s: %m",
884  tmp -> name);
885  if (tmp -> rfdesc != tmp -> wfdesc) {
886  if (fcntl (tmp -> wfdesc, F_SETFD, 1) < 0)
887  log_error ("Can't set close-on-exec on %s: %m",
888  tmp -> name);
889  }
890 #endif
891  next:
892  interface_dereference (&tmp, MDL);
893  if (next)
894  interface_reference (&tmp, next, MDL);
895  }
896 
897  /*
898  * Now register all the remaining interfaces as protocols.
899  * We register with omapi to allow for control of the interface,
900  * we've already registered the fd or socket with the socket
901  * manager as part of if_register_receive().
902  */
903  for (tmp = interfaces; tmp; tmp = tmp -> next) {
904  /* not if it's been registered before */
905  if (tmp -> flags & INTERFACE_RUNNING)
906  continue;
907  if (tmp -> rfdesc == -1)
908  continue;
909  switch (local_family) {
910 #ifdef DHCPv6
911  case AF_INET6:
913  if_readsocket,
914  0, got_one_v6, 0, 0);
915  break;
916 #endif /* DHCPv6 */
917  case AF_INET:
918  default:
920  if_readsocket,
921  0, got_one, 0, 0);
922  break;
923  }
924 
925  if (status != ISC_R_SUCCESS)
926  log_fatal ("Can't register I/O handle for %s: %s",
927  tmp -> name, isc_result_totext (status));
928 
929 #if defined(DHCPv6)
930  /* Only register the first interface for V6, since
931  * servers and relays all use the same socket.
932  * XXX: This has some messy side effects if we start
933  * dynamically adding and removing interfaces, but
934  * we're well beyond that point in terms of mess.
935  */
936  if (((state == DISCOVER_SERVER) || (state == DISCOVER_RELAY)) &&
937  (local_family == AF_INET6))
938  break;
939 #endif
940  } /* for (tmp = interfaces; ... */
941 
942  if (state == DISCOVER_SERVER && wifcount == 0) {
943  log_info ("%s", "");
944  log_fatal ("Not configured to listen on any interfaces!");
945  }
946 
947  if ((local_family == AF_INET) && !setup_fallback) {
948  setup_fallback = 1;
950  }
951 
952 #if defined (F_SETFD)
953  if (fallback_interface) {
954  if (fcntl (fallback_interface -> rfdesc, F_SETFD, 1) < 0)
955  log_error ("Can't set close-on-exec on fallback: %m");
956  if (fallback_interface -> rfdesc != fallback_interface -> wfdesc) {
957  if (fcntl (fallback_interface -> wfdesc, F_SETFD, 1) < 0)
958  log_error ("Can't set close-on-exec on fallback: %m");
959  }
960  }
961 #endif /* F_SETFD */
962 }
963 
965  omapi_object_t *h;
966 {
967  struct interface_info *ip;
968 
969  if (h -> type != dhcp_type_interface)
970  return -1;
971  ip = (struct interface_info *)h;
972  return ip -> rfdesc;
973 }
974 
975 int setup_fallback (struct interface_info **fp, const char *file, int line)
976 {
977  isc_result_t status;
978 
979  status = interface_allocate (&fallback_interface, file, line);
980  if (status != ISC_R_SUCCESS)
981  log_fatal ("Error allocating fallback interface: %s",
982  isc_result_totext (status));
983  strcpy (fallback_interface -> name, "fallback");
985  (*dhcp_interface_setup_hook) (fallback_interface,
986  (struct iaddr *)0);
987  status = interface_reference (fp, fallback_interface, file, line);
988 
989  fallback_interface -> index = -1;
990  interface_stash (fallback_interface);
991  return status == ISC_R_SUCCESS;
992 }
993 
995 {
996  struct interface_info *ip;
997 
998  for (ip = interfaces; ip; ip = ip -> next) {
1000  if_reinitialize_send (ip);
1001  }
1002 
1003  if (fallback_interface)
1004  if_reinitialize_send (fallback_interface);
1005 
1007 }
1008 
1009 isc_result_t got_one (h)
1010  omapi_object_t *h;
1011 {
1012  struct sockaddr_in from;
1013  struct hardware hfrom;
1014  struct iaddr ifrom;
1015  int result;
1016  union {
1017  unsigned char packbuf [4095]; /* Packet input buffer.
1018  Must be as large as largest
1019  possible MTU. */
1020  struct dhcp_packet packet;
1021  } u;
1022  struct interface_info *ip;
1023 
1024  if (h -> type != dhcp_type_interface)
1025  return DHCP_R_INVALIDARG;
1026  ip = (struct interface_info *)h;
1027 
1028  again:
1029  if ((result =
1030  receive_packet (ip, u.packbuf, sizeof u, &from, &hfrom)) < 0) {
1031  log_error ("receive_packet failed on %s: %m", ip -> name);
1032  return ISC_R_UNEXPECTED;
1033  }
1034  if (result == 0)
1035  return ISC_R_UNEXPECTED;
1036 
1037  /*
1038  * If we didn't at least get the fixed portion of the BOOTP
1039  * packet, drop the packet.
1040  * Previously we allowed packets with no sname or filename
1041  * as we were aware of at least one client that did. But
1042  * a bug caused short packets to not work and nobody has
1043  * complained, it seems rational to tighten up that
1044  * restriction.
1045  */
1046  if (result < DHCP_FIXED_NON_UDP)
1047  return ISC_R_UNEXPECTED;
1048 
1049 #if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO)
1050  {
1051  /* We retrieve the ifindex from the unused hfrom variable */
1052  unsigned int ifindex;
1053 
1054  memcpy(&ifindex, hfrom.hbuf, sizeof (ifindex));
1055 
1056  /*
1057  * Seek forward from the first interface to find the matching
1058  * source interface by interface index.
1059  */
1060  ip = interfaces;
1061  while ((ip != NULL) && (if_nametoindex(ip->name) != ifindex))
1062  ip = ip->next;
1063  if (ip == NULL)
1064  return ISC_R_NOTFOUND;
1065  }
1066 #endif
1067 
1068  if (bootp_packet_handler) {
1069  ifrom.len = 4;
1070  memcpy (ifrom.iabuf, &from.sin_addr, ifrom.len);
1071 
1072  (*bootp_packet_handler) (ip, &u.packet, (unsigned)result,
1073  from.sin_port, ifrom, &hfrom);
1074  }
1075 
1076  /* If there is buffered data, read again. This is for, e.g.,
1077  bpf, which may return two packets at once. */
1078  if (ip -> rbuf_offset != ip -> rbuf_len)
1079  goto again;
1080  return ISC_R_SUCCESS;
1081 }
1082 
1083 #ifdef DHCPv6
1084 isc_result_t
1086  struct sockaddr_in6 from;
1087  struct in6_addr to;
1088  struct iaddr ifrom;
1089  int result;
1090  char buf[65536]; /* maximum size for a UDP packet is 65536 */
1091  struct interface_info *ip;
1092  int is_unicast;
1093  unsigned int if_idx = 0;
1094 
1095  if (h->type != dhcp_type_interface) {
1096  return DHCP_R_INVALIDARG;
1097  }
1098  ip = (struct interface_info *)h;
1099 
1100  result = receive_packet6(ip, (unsigned char *)buf, sizeof(buf),
1101  &from, &to, &if_idx);
1102  if (result < 0) {
1103  log_error("receive_packet6() failed on %s: %m", ip->name);
1104  return ISC_R_UNEXPECTED;
1105  }
1106 
1107  /* 0 is 'any' interface. */
1108  if (if_idx == 0)
1109  return ISC_R_NOTFOUND;
1110 
1111  if (dhcpv6_packet_handler != NULL) {
1112  /*
1113  * If a packet is not multicast, we assume it is unicast.
1114  */
1115  if (IN6_IS_ADDR_MULTICAST(&to)) {
1116  is_unicast = ISC_FALSE;
1117  } else {
1118  is_unicast = ISC_TRUE;
1119  }
1120 
1121  ifrom.len = 16;
1122  memcpy(ifrom.iabuf, &from.sin6_addr, ifrom.len);
1123 
1124  /* Seek forward to find the matching source interface. */
1125  ip = interfaces;
1126  while ((ip != NULL) && (if_nametoindex(ip->name) != if_idx))
1127  ip = ip->next;
1128 
1129  if (ip == NULL)
1130  return ISC_R_NOTFOUND;
1131 
1132  (*dhcpv6_packet_handler)(ip, buf,
1133  result, from.sin6_port,
1134  &ifrom, is_unicast);
1135  }
1136 
1137  return ISC_R_SUCCESS;
1138 }
1139 #endif /* DHCPv6 */
1140 
1142  omapi_object_t *id,
1144  omapi_typed_data_t *value)
1145 {
1146  struct interface_info *interface;
1147  isc_result_t status;
1148 
1149  if (h -> type != dhcp_type_interface)
1150  return DHCP_R_INVALIDARG;
1151  interface = (struct interface_info *)h;
1152 
1153  if (!omapi_ds_strcmp (name, "name")) {
1154  if ((value -> type == omapi_datatype_data ||
1155  value -> type == omapi_datatype_string) &&
1156  value -> u.buffer.len < sizeof interface -> name) {
1157  memcpy (interface -> name,
1158  value -> u.buffer.value,
1159  value -> u.buffer.len);
1160  interface -> name [value -> u.buffer.len] = 0;
1161  } else
1162  return DHCP_R_INVALIDARG;
1163  return ISC_R_SUCCESS;
1164  }
1165 
1166  /* Try to find some inner object that can take the value. */
1167  if (h -> inner && h -> inner -> type -> set_value) {
1168  status = ((*(h -> inner -> type -> set_value))
1169  (h -> inner, id, name, value));
1170  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
1171  return status;
1172  }
1173 
1174  return ISC_R_NOTFOUND;
1175 }
1176 
1177 
1179  omapi_object_t *id,
1180  omapi_data_string_t *name,
1181  omapi_value_t **value)
1182 {
1183  return ISC_R_NOTIMPLEMENTED;
1184 }
1185 
1187  const char *file, int line)
1188 {
1189  struct interface_info *interface;
1190 
1191  if (h -> type != dhcp_type_interface)
1192  return DHCP_R_INVALIDARG;
1193  interface = (struct interface_info *)h;
1194 
1195  if (interface -> ifp) {
1196  dfree (interface -> ifp, file, line);
1197  interface -> ifp = 0;
1198  }
1199  if (interface -> next)
1200  interface_dereference (&interface -> next, file, line);
1201  if (interface -> rbuf) {
1202  dfree (interface -> rbuf, file, line);
1203  interface -> rbuf = (unsigned char *)0;
1204  }
1205  if (interface -> client)
1206  interface -> client = (struct client_state *)0;
1207 
1208  if (interface -> shared_network)
1210  &interface -> shared_network, MDL);
1211 
1212  return ISC_R_SUCCESS;
1213 }
1214 
1216  const char *name, va_list ap)
1217 {
1218  struct interface_info *ip, *interface;
1219  isc_result_t status;
1220 
1221  if (h -> type != dhcp_type_interface)
1222  return DHCP_R_INVALIDARG;
1223  interface = (struct interface_info *)h;
1224 
1225  /* If it's an update signal, see if the interface is dead right
1226  now, or isn't known at all, and if that's the case, revive it. */
1227  if (!strcmp (name, "update")) {
1228  for (ip = dummy_interfaces; ip; ip = ip -> next)
1229  if (ip == interface)
1230  break;
1231  if (ip && dhcp_interface_startup_hook)
1232  return (*dhcp_interface_startup_hook) (ip);
1233 
1234  for (ip = interfaces; ip; ip = ip -> next)
1235  if (ip == interface)
1236  break;
1237  if (!ip && dhcp_interface_startup_hook)
1238  return (*dhcp_interface_startup_hook) (ip);
1239  }
1240 
1241  /* Try to find some inner object that can take the value. */
1242  if (h -> inner && h -> inner -> type -> signal_handler) {
1243  status = ((*(h -> inner -> type -> signal_handler))
1244  (h -> inner, name, ap));
1245  if (status == ISC_R_SUCCESS)
1246  return status;
1247  }
1248  return ISC_R_NOTFOUND;
1249 }
1250 
1252  omapi_object_t *id,
1253  omapi_object_t *h)
1254 {
1255  struct interface_info *interface;
1256  isc_result_t status;
1257 
1258  if (h -> type != dhcp_type_interface)
1259  return DHCP_R_INVALIDARG;
1260  interface = (struct interface_info *)h;
1261 
1262  /* Write out all the values. */
1263 
1264  status = omapi_connection_put_name (c, "state");
1265  if (status != ISC_R_SUCCESS)
1266  return status;
1267  if ((interface->flags & INTERFACE_REQUESTED) != 0)
1268  status = omapi_connection_put_string (c, "up");
1269  else
1270  status = omapi_connection_put_string (c, "down");
1271  if (status != ISC_R_SUCCESS)
1272  return status;
1273 
1274  /* Write out the inner object, if any. */
1275  if (h -> inner && h -> inner -> type -> stuff_values) {
1276  status = ((*(h -> inner -> type -> stuff_values))
1277  (c, id, h -> inner));
1278  if (status == ISC_R_SUCCESS)
1279  return status;
1280  }
1281 
1282  return ISC_R_SUCCESS;
1283 }
1284 
1286  omapi_object_t *id,
1287  omapi_object_t *ref)
1288 {
1289  omapi_value_t *tv = (omapi_value_t *)0;
1290  isc_result_t status;
1291  struct interface_info *interface;
1292 
1293  if (!ref)
1294  return DHCP_R_NOKEYS;
1295 
1296  /* First see if we were sent a handle. */
1297  status = omapi_get_value_str (ref, id, "handle", &tv);
1298  if (status == ISC_R_SUCCESS) {
1299  status = omapi_handle_td_lookup (ip, tv -> value);
1300 
1302  if (status != ISC_R_SUCCESS)
1303  return status;
1304 
1305  /* Don't return the object if the type is wrong. */
1306  if ((*ip) -> type != dhcp_type_interface) {
1308  return DHCP_R_INVALIDARG;
1309  }
1310  }
1311 
1312  /* Now look for an interface name. */
1313  status = omapi_get_value_str (ref, id, "name", &tv);
1314  if (status == ISC_R_SUCCESS) {
1315  char *s;
1316  unsigned len;
1317  for (interface = interfaces; interface;
1318  interface = interface -> next) {
1319  s = memchr (interface -> name, 0, IFNAMSIZ);
1320  if (s)
1321  len = s - &interface -> name [0];
1322  else
1323  len = IFNAMSIZ;
1324  if ((tv -> value -> u.buffer.len == len &&
1325  !memcmp (interface -> name,
1326  (char *)tv -> value -> u.buffer.value,
1327  len)))
1328  break;
1329  }
1330  if (!interface) {
1331  for (interface = dummy_interfaces;
1332  interface; interface = interface -> next) {
1333  s = memchr (interface -> name, 0, IFNAMSIZ);
1334  if (s)
1335  len = s - &interface -> name [0];
1336  else
1337  len = IFNAMSIZ;
1338  if ((tv -> value -> u.buffer.len == len &&
1339  !memcmp (interface -> name,
1340  (char *)
1341  tv -> value -> u.buffer.value,
1342  len)))
1343  break;
1344  }
1345  }
1346 
1348  if (*ip && *ip != (omapi_object_t *)interface) {
1350  return DHCP_R_KEYCONFLICT;
1351  } else if (!interface) {
1352  if (*ip)
1354  return ISC_R_NOTFOUND;
1355  } else if (!*ip)
1357  (omapi_object_t *)interface,
1358  MDL);
1359  }
1360 
1361  /* If we get to here without finding an interface, no valid key was
1362  specified. */
1363  if (!*ip)
1364  return DHCP_R_NOKEYS;
1365  return ISC_R_SUCCESS;
1366 }
1367 
1368 /* actually just go discover the interface */
1370  omapi_object_t *id)
1371 {
1372  struct interface_info *hp;
1373  isc_result_t status;
1374 
1375  hp = (struct interface_info *)0;
1376  status = interface_allocate (&hp, MDL);
1377  if (status != ISC_R_SUCCESS)
1378  return status;
1379  hp -> flags = INTERFACE_REQUESTED;
1380  status = interface_reference ((struct interface_info **)lp, hp, MDL);
1381  interface_dereference (&hp, MDL);
1382  return status;
1383 }
1384 
1386  omapi_object_t *id)
1387 {
1388  struct interface_info *interface, *ip, *last;
1389 
1390  interface = (struct interface_info *)lp;
1391 
1392  /* remove from interfaces */
1393  last = 0;
1394  for (ip = interfaces; ip; ip = ip -> next) {
1395  if (ip == interface) {
1396  if (last) {
1397  interface_dereference (&last -> next, MDL);
1398  if (ip -> next)
1399  interface_reference (&last -> next,
1400  ip -> next, MDL);
1401  } else {
1402  interface_dereference (&interfaces, MDL);
1403  if (ip -> next)
1404  interface_reference (&interfaces,
1405  ip -> next, MDL);
1406  }
1407  if (ip -> next)
1408  interface_dereference (&ip -> next, MDL);
1409  break;
1410  }
1411  last = ip;
1412  }
1413  if (!ip)
1414  return ISC_R_NOTFOUND;
1415 
1416  /* add the interface to the dummy_interface list */
1417  if (dummy_interfaces) {
1418  interface_reference (&interface -> next,
1419  dummy_interfaces, MDL);
1420  interface_dereference (&dummy_interfaces, MDL);
1421  }
1422  interface_reference (&dummy_interfaces, interface, MDL);
1423 
1424  /* do a DHCPRELEASE */
1426  (*dhcp_interface_shutdown_hook) (interface);
1427 
1428  /* remove the io object */
1430 
1431  switch(local_family) {
1432 #ifdef DHCPv6
1433  case AF_INET6:
1434  if_deregister6(interface);
1435  break;
1436 #endif /* DHCPv6 */
1437  case AF_INET:
1438  default:
1439  if_deregister_send(interface);
1440  if_deregister_receive(interface);
1441  break;
1442  }
1443 
1444  return ISC_R_SUCCESS;
1445 }
1446 
1447 void interface_stash (struct interface_info *tptr)
1448 {
1449  struct interface_info **vec;
1450  int delta;
1451 
1452  /* If the registerer didn't assign an index, assign one now. */
1453  if (tptr -> index == -1) {
1454  tptr -> index = interface_count++;
1455  while (tptr -> index < interface_max &&
1456  interface_vector [tptr -> index])
1457  tptr -> index = interface_count++;
1458  }
1459 
1460  if (interface_max <= tptr -> index) {
1461  delta = tptr -> index - interface_max + 10;
1462  vec = dmalloc ((interface_max + delta) *
1463  sizeof (struct interface_info *), MDL);
1464  if (!vec)
1465  return;
1466  memset (&vec [interface_max], 0,
1467  (sizeof (struct interface_info *)) * delta);
1468  interface_max += delta;
1469  if (interface_vector) {
1470  memcpy (vec, interface_vector,
1471  (interface_count *
1472  sizeof (struct interface_info *)));
1473  dfree (interface_vector, MDL);
1474  }
1475  interface_vector = vec;
1476  }
1477  interface_reference (&interface_vector [tptr -> index], tptr, MDL);
1478  if (tptr -> index >= interface_count)
1479  interface_count = tptr -> index + 1;
1480 #if defined (TRACING)
1481  trace_interface_register (interface_trace, tptr);
1482 #endif
1483 }
1484 
1485 void interface_snorf (struct interface_info *tmp, int ir)
1486 {
1487  tmp -> circuit_id = (u_int8_t *)tmp -> name;
1488  tmp -> circuit_id_len = strlen (tmp -> name);
1489  tmp -> remote_id = 0;
1490  tmp -> remote_id_len = 0;
1491  tmp -> flags = ir;
1492  if (interfaces) {
1493  interface_reference (&tmp -> next,
1494  interfaces, MDL);
1495  interface_dereference (&interfaces, MDL);
1496  }
1497  interface_reference (&interfaces, tmp, MDL);
1498 }
#define LIFCONF
Definition: discover.c:191
void if_register_send(struct interface_info *)
#define DHCP_FIXED_NON_UDP
Definition: dhcp.h:37
void(* dhcpv6_packet_handler)(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
u_int16_t local_port
Definition: discover.c:46
const char int line
Definition: dhcpd.h:3615
char name[IF_NAMESIZE+1]
Definition: discover.c:228
isc_result_t omapi_register_io_object(omapi_object_t *, int(*)(omapi_object_t *), int(*)(omapi_object_t *), isc_result_t(*)(omapi_object_t *), isc_result_t(*)(omapi_object_t *), isc_result_t(*)(omapi_object_t *))
Definition: dispatch.c:199
#define SIOCGLIFFLAGS
Definition: discover.c:189
void end_iface_scan(struct iface_conf_list *ifaces)
Definition: discover.c:370
isc_result_t omapi_object_reference(omapi_object_t **, omapi_object_t *, const char *, int)
Definition: alloc.c:557
struct shared_network * shared_network
Definition: dhcpd.h:1281
isc_result_t dhcp_interface_destroy(omapi_object_t *h, const char *file, int line)
Definition: discover.c:1186
int if_readsocket(omapi_object_t *h)
Definition: discover.c:964
char name[IFNAMSIZ]
Definition: dhcpd.h:1305
void if_reinitialize_send(struct interface_info *)
void(* bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, unsigned, unsigned int, struct iaddr, struct hardware *)
Definition: discover.c:58
void * dmalloc(unsigned, const char *, int)
Definition: alloc.c:56
Definition: dhcpd.h:985
u_int16_t remote_port
Definition: discover.c:47
void trace_interface_register(trace_type_t *, struct interface_info *)
trace_type_t * interface_trace
#define MDL
Definition: omapip.h:568
isc_result_t dhcp_interface_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
Definition: discover.c:1251
unsigned char iabuf[16]
Definition: inet.h:33
#define DHCP_R_INVALIDARG
Definition: result.h:48
omapi_typed_data_t * value
Definition: omapip.h:91
#define DISCOVER_REQUESTED
Definition: dhcpd.h:654
void reinitialize_interfaces()
Definition: discover.c:994
void trace_outpacket_input(trace_type_t *, unsigned, char *)
isc_result_t dhcp_interface_remove(omapi_object_t *lp, omapi_object_t *id)
Definition: discover.c:1385
struct in_addr * addresses
Definition: dhcpd.h:1285
int setup_fallback(struct interface_info **fp, const char *file, int line)
Definition: discover.c:975
#define INTERFACE_RUNNING
Definition: dhcpd.h:1322
int log_error(const char *,...) __attribute__((__format__(__printf__
void add_ipv4_addr_to_interface(struct interface_info *iface, const struct in_addr *addr)
Definition: discover.c:476
struct subnet * subnets
Definition: mdb.c:33
unsigned len
Definition: inet.h:32
#define OMAPI_OBJECT_ALLOC(name, stype, type)
Definition: omapip.h:161
int interface_max
Definition: discover.c:79
void if_deregister_receive(struct interface_info *)
#define DHCP_R_KEYCONFLICT
Definition: result.h:52
void maybe_setup_fallback(void)
void if_deregister_send(struct interface_info *)
void log_fatal(const char *,...) __attribute__((__format__(__printf__
size_t rbuf_len
Definition: dhcpd.h:1313
isc_result_t dhcp_interface_get_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value)
Definition: discover.c:1178
#define DISCOVER_RELAY
Definition: dhcpd.h:653
#define INTERFACE_AUTOMATIC
Definition: dhcpd.h:1321
void interface_trace_setup(void)
struct omapi_typed_data_t::@3::@4 buffer
size_t rbuf_offset
Definition: dhcpd.h:1312
int interface_count
Definition: discover.c:78
struct LIFCONF conf
Definition: discover.c:220
#define SIOCGLIFCONF
Definition: discover.c:188
void if_deregister6(struct interface_info *info)
char * name
Definition: dhcpd.h:1199
struct interface_info * fallback_interface
Definition: discover.c:43
void trace_outpacket_stop(trace_type_t *)
void trace_inpacket_stop(trace_type_t *)
void if_register_linklocal6(struct interface_info *info)
#define DISCOVER_SERVER
Definition: dhcpd.h:651
isc_result_t omapi_get_value_str(omapi_object_t *, omapi_object_t *, const char *, omapi_value_t **)
Definition: support.c:483
struct iaddr interface_address
Definition: dhcpd.h:991
isc_result_t dhcp_interface_create(omapi_object_t **lp, omapi_object_t *id)
Definition: discover.c:1369
void trace_inpacket_input(trace_type_t *, unsigned, char *)
unsigned circuit_id_len
Definition: dhcpd.h:1299
trace_type_t * inpacket_trace
trace_type_t * trace_type_register(const char *, void *, void(*)(trace_type_t *, unsigned, char *), void(*)(trace_type_t *), const char *, int)
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
Definition: alloc.c:579
Definition: ip.h:47
isc_result_t got_one_v6(omapi_object_t *)
void dfree(void *, const char *, int)
Definition: alloc.c:131
omapi_object_type_t * dhcp_type_interface
Definition: discover.c:71
isc_result_t omapi_handle_td_lookup(omapi_object_t **, omapi_typed_data_t *)
Definition: handle.c:283
int begin_iface_scan(struct iface_conf_list *ifaces)
Definition: discover.c:239
struct in_addr limited_broadcast
Definition: discover.c:53
int int log_info(const char *,...) __attribute__((__format__(__printf__
isc_result_t dhcp_interface_set_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_typed_data_t *value)
Definition: discover.c:1141
struct interface_info * interfaces
Definition: discover.c:43
u_int32_t flags
Definition: dhcpd.h:1319
isc_result_t omapi_connection_put_string(omapi_object_t *, const char *)
Definition: buffer.c:681
int interfaces_invalidated
Definition: discover.c:44
void interface_snorf(struct interface_info *tmp, int ir)
Definition: discover.c:1485
int v6address_count
Definition: dhcpd.h:1292
int address_max
Definition: dhcpd.h:1289
int(* dhcp_interface_setup_hook)(struct interface_info *, struct iaddr *)
Definition: discover.c:48
Definition: inet.h:31
isc_result_t omapi_value_dereference(omapi_value_t **, const char *, int)
Definition: alloc.c:1046
u_int8_t * circuit_id
Definition: dhcpd.h:1297
void if_register6(struct interface_info *info, int do_multicast)
int local_family
Definition: discover.c:55
int quiet_interface_discovery
Definition: discover.c:45
isc_result_t(* dhcp_interface_startup_hook)(struct interface_info *)
Definition: discover.c:50
#define DISCOVER_UNCONFIGURED
Definition: dhcpd.h:652
struct sockaddr_storage addr
Definition: discover.c:229
#define DHCP_R_NOKEYS
Definition: result.h:54
#define DHCP_R_UNCHANGED
Definition: result.h:50
isc_result_t dhcp_interface_signal_handler(omapi_object_t *h, const char *name, va_list ap)
Definition: discover.c:1215
struct interface_info * next
Definition: dhcpd.h:1280
isc_uint64_t flags
Definition: discover.c:230
isc_result_t omapi_object_type_register(omapi_object_type_t **, const char *, isc_result_t(*)(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_typed_data_t *), isc_result_t(*)(omapi_object_t *, omapi_object_t *, omapi_data_string_t *, omapi_value_t **), isc_result_t(*)(omapi_object_t *, const char *, int), isc_result_t(*)(omapi_object_t *, const char *, va_list), isc_result_t(*)(omapi_object_t *, omapi_object_t *, omapi_object_t *), isc_result_t(*)(omapi_object_t **, omapi_object_t *, omapi_object_t *), isc_result_t(*)(omapi_object_t **, omapi_object_t *), isc_result_t(*)(omapi_object_t *, omapi_object_t *), isc_result_t(*)(omapi_object_t *, const char *, int), isc_result_t(*)(omapi_object_t **, const char *, int), isc_result_t(*)(size_t), size_t, isc_result_t(*)(omapi_object_t *, const char *, int), int)
const char int
Definition: omapip.h:443
struct interface_info * dummy_interfaces
Definition: discover.c:43
int omapi_ds_strcmp(omapi_data_string_t *, const char *)
Definition: support.c:582
isc_result_t got_one(omapi_object_t *h)
Definition: discover.c:1009
isc_result_t omapi_unregister_io_object(omapi_object_t *)
Definition: dispatch.c:356
isc_result_t interface_initialize(omapi_object_t *ipo, const char *file, int line)
Definition: discover.c:121
int supports_multiple_interfaces(struct interface_info *)
u_int8_t * remote_id
Definition: dhcpd.h:1301
isc_result_t interface_setup()
Definition: discover.c:83
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
Definition: dhcpd.h:455
int address_count
Definition: dhcpd.h:1288
unsigned remote_id_len
Definition: dhcpd.h:1303
struct in_addr local_address
Definition: discover.c:56
int(* dhcp_interface_discovery_hook)(struct interface_info *)
Definition: discover.c:49
ssize_t receive_packet(struct interface_info *, unsigned char *, size_t, struct sockaddr_in *, struct hardware *)
void trace_interface_input(trace_type_t *, unsigned, char *)
const char * file
Definition: dhcpd.h:3615
isc_result_t omapi_connection_put_name(omapi_object_t *, const char *)
Definition: buffer.c:670
int configured
Definition: dhcpd.h:1316
void if_reinitialize_receive(struct interface_info *)
void if_register_receive(struct interface_info *)
struct interface_info ** interface_vector
Definition: discover.c:77
void interface_stash(struct interface_info *tptr)
Definition: discover.c:1447
trace_type_t * outpacket_trace
#define DHCPv6
Definition: config.h:18
#define LIFREQ
Definition: discover.c:190
int v6address_max
Definition: dhcpd.h:1294
struct ifreq * ifp
Definition: dhcpd.h:1315
void trace_interface_stop(trace_type_t *)
#define RC_MISC
Definition: alloc.h:56
int(* dhcp_interface_shutdown_hook)(struct interface_info *)
Definition: discover.c:51
void discover_interfaces(int state)
Definition: discover.c:555
int next_iface(struct iface_info *info, int *err, struct iface_conf_list *ifaces)
Definition: discover.c:303
isc_result_t dhcp_interface_lookup(omapi_object_t **ip, omapi_object_t *id, omapi_object_t *ref)
Definition: discover.c:1285
#define INTERFACE_REQUESTED
Definition: dhcpd.h:1320
ssize_t receive_packet6(struct interface_info *interface, unsigned char *buf, size_t len, struct sockaddr_in6 *from, struct in6_addr *to_addr, unsigned int *if_index)
struct in6_addr * v6addresses
Definition: dhcpd.h:1290