ISC DHCP  4.3.6
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) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1995-2003 by Internet Software Consortium
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  *
21  * Internet Systems Consortium, Inc.
22  * 950 Charter Street
23  * Redwood City, CA 94063
24  * <info@isc.org>
25  * https://www.isc.org/
26  *
27  */
28 
29 #include "dhcpd.h"
30 
31 /* length of line we can read from the IF file, 256 is too small in some cases */
32 #define IF_LINE_LENGTH 1024
33 
34 #define BSD_COMP /* needed on Solaris for SIOCGLIFNUM */
35 #include <sys/ioctl.h>
36 #include <errno.h>
37 
38 #ifdef HAVE_NET_IF6_H
39 # include <net/if6.h>
40 #endif
41 
45 u_int16_t local_port;
46 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 
82 
83 isc_result_t interface_setup ()
84 {
85  isc_result_t status;
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  memset(info, 0, sizeof(struct iface_info));
336  strncpy(info->name, p->lifr_name, sizeof(info->name) - 1);
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  strncpy(tmp.lifr_name, info->name, sizeof(tmp.lifr_name) - 1);
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/Linux support
380  * -----------
381  *
382  * FreeBSD, NetBSD, OpenBSD, OS X/macOS 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  memset(info, 0, sizeof(struct iface_info));
443  strncpy(info->name, ifaces->next->ifa_name, sizeof(info->name) - 1);
444  memset(&info->addr, 0 , sizeof(info->addr));
445  /*
446  * getifaddrs() can on Linux with some interfaces like PPP or TEQL
447  * result in a record with no address (ifa_addr).
448  */
449  if (ifaces->next->ifa_addr != NULL) {
450 /* Linux lacks the sa_len member in struct sockaddr. */
451 #if defined(__linux)
452  if (ifaces->next->ifa_addr->sa_family == AF_INET)
453  sa_len = sizeof(struct sockaddr_in);
454  else if (ifaces->next->ifa_addr->sa_family == AF_INET6)
455  sa_len = sizeof(struct sockaddr_in6);
456 #else
457  sa_len = ifaces->next->ifa_addr->sa_len;
458 #endif
459  memcpy(&info->addr, ifaces->next->ifa_addr, sa_len);
460  }
461  info->flags = ifaces->next->ifa_flags;
462  ifaces->next = ifaces->next->ifa_next;
463  *err = 0;
464  return 1;
465 }
466 
467 /*
468  * End scan of interfaces.
469  */
470 void
471 end_iface_scan(struct iface_conf_list *ifaces) {
472  freeifaddrs(ifaces->head);
473  ifaces->head = NULL;
474  ifaces->next = NULL;
475 }
476 #endif
477 
478 /* XXX: perhaps create drealloc() rather than do it manually */
479 void
481  const struct in_addr *addr) {
482  /*
483  * We don't expect a lot of addresses per IPv4 interface, so
484  * we use 4, as our "chunk size" for collecting addresses.
485  */
486  if (iface->addresses == NULL) {
487  iface->addresses = dmalloc(4 * sizeof(struct in_addr), MDL);
488  if (iface->addresses == NULL) {
489  log_fatal("Out of memory saving IPv4 address "
490  "on interface.");
491  }
492  iface->address_count = 0;
493  iface->address_max = 4;
494  } else if (iface->address_count >= iface->address_max) {
495  struct in_addr *tmp;
496  int new_max;
497 
498  new_max = iface->address_max + 4;
499  tmp = dmalloc(new_max * sizeof(struct in_addr), MDL);
500  if (tmp == NULL) {
501  log_fatal("Out of memory saving IPv4 address "
502  "on interface.");
503  }
504  memcpy(tmp,
505  iface->addresses,
506  iface->address_max * sizeof(struct in_addr));
507  dfree(iface->addresses, MDL);
508  iface->addresses = tmp;
509  iface->address_max = new_max;
510  }
511  iface->addresses[iface->address_count++] = *addr;
512 }
513 
514 #ifdef DHCPv6
515 /* XXX: perhaps create drealloc() rather than do it manually */
516 void
517 add_ipv6_addr_to_interface(struct interface_info *iface,
518  const struct in6_addr *addr) {
519  /*
520  * Each IPv6 interface will have at least two IPv6 addresses,
521  * and likely quite a few more. So we use 8, as our "chunk size" for
522  * collecting addresses.
523  */
524  if (iface->v6addresses == NULL) {
525  iface->v6addresses = dmalloc(8 * sizeof(struct in6_addr), MDL);
526  if (iface->v6addresses == NULL) {
527  log_fatal("Out of memory saving IPv6 address "
528  "on interface.");
529  }
530  iface->v6address_count = 0;
531  iface->v6address_max = 8;
532  } else if (iface->v6address_count >= iface->v6address_max) {
533  struct in6_addr *tmp;
534  int new_max;
535 
536  new_max = iface->v6address_max + 8;
537  tmp = dmalloc(new_max * sizeof(struct in6_addr), MDL);
538  if (tmp == NULL) {
539  log_fatal("Out of memory saving IPv6 address "
540  "on interface.");
541  }
542  memcpy(tmp,
543  iface->v6addresses,
544  iface->v6address_max * sizeof(struct in6_addr));
545  dfree(iface->v6addresses, MDL);
546  iface->v6addresses = tmp;
547  iface->v6address_max = new_max;
548  }
549  iface->v6addresses[iface->v6address_count++] = *addr;
550 }
551 #endif /* DHCPv6 */
552 
553 /* Use the SIOCGIFCONF ioctl to get a list of all the attached interfaces.
554  For each interface that's of type INET and not the loopback interface,
555  register that interface with the network I/O software, figure out what
556  subnet it's on, and add it to the list of interfaces. */
557 
558 void
560  struct iface_conf_list ifaces;
561  struct iface_info info;
562  int err;
563 
564  struct interface_info *tmp;
565  struct interface_info *last, *next;
566 
567 #ifdef DHCPv6
568  char abuf[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
569 #endif /* DHCPv6 */
570 
571 
572  struct subnet *subnet;
573  int ir;
574  isc_result_t status;
575  int wifcount = 0;
576 
577  static int setup_fallback = 0;
578 
579  if (!begin_iface_scan(&ifaces)) {
580  log_fatal("Can't get list of interfaces.");
581  }
582 
583  /* If we already have a list of interfaces, and we're running as
584  a DHCP server, the interfaces were requested. */
585  if (interfaces && (state == DISCOVER_SERVER ||
586  state == DISCOVER_RELAY ||
587  state == DISCOVER_REQUESTED))
588  ir = 0;
589  else if (state == DISCOVER_UNCONFIGURED)
591  else {
592  ir = INTERFACE_REQUESTED;
593  if (state == DISCOVER_RELAY && local_family == AF_INET) {
594  /* We're a v4 relay without specifically requested
595  * interfaces, so mark them all as bidirectional. */
596  ir |= INTERFACE_STREAMS;
597  }
598  }
599 
600  /* Cycle through the list of interfaces looking for IP addresses. */
601  while (next_iface(&info, &err, &ifaces)) {
602 
603  /* See if we've seen an interface that matches this one. */
604  for (tmp = interfaces; tmp; tmp = tmp->next) {
605  if (!strcmp(tmp->name, info.name))
606  break;
607  }
608 
609  /* Skip non broadcast interfaces (plus loopback and
610  point-to-point in case an OS incorrectly marks them
611  as broadcast). Also skip down interfaces unless we're
612  trying to get a list of configurable interfaces. */
613  if ((((local_family == AF_INET &&
614  !(info.flags & IFF_BROADCAST)) ||
615 #ifdef DHCPv6
616  (local_family == AF_INET6 &&
617  !(info.flags & IFF_MULTICAST)) ||
618 #endif
619  info.flags & IFF_LOOPBACK ||
620  info.flags & IFF_POINTOPOINT) && !tmp) ||
621  (!(info.flags & IFF_UP) &&
622  state != DISCOVER_UNCONFIGURED))
623  continue;
624 
625  /* If there isn't already an interface by this name,
626  allocate one. */
627  if (tmp == NULL) {
628  status = interface_allocate(&tmp, MDL);
629  if (status != ISC_R_SUCCESS) {
630  log_fatal("Error allocating interface %s: %s",
631  info.name, isc_result_totext(status));
632  }
633  strncpy(tmp->name, info.name, sizeof(tmp->name) - 1);
634  interface_snorf(tmp, ir);
635  interface_dereference(&tmp, MDL);
636  tmp = interfaces; /* XXX */
637  }
638  if (tmp != NULL)
639  try_hw_addr(tmp);
640 
642  (*dhcp_interface_discovery_hook)(tmp);
643  }
644 
645  if ((info.addr.ss_family == AF_INET) &&
646  (local_family == AF_INET)) {
647  struct sockaddr_in *a = (struct sockaddr_in*)&info.addr;
648  struct iaddr addr;
649 
650  /* We don't want the loopback interface. */
651  if (a->sin_addr.s_addr == htonl(INADDR_LOOPBACK) &&
652  ((tmp->flags & INTERFACE_AUTOMATIC) &&
653  ((state == DISCOVER_SERVER) ||
654  (state == DISCOVER_SERVER46))))
655  continue;
656 
657  /* If the only address we have is 0.0.0.0, we
658  shouldn't consider the interface configured. */
659  if (a->sin_addr.s_addr != htonl(INADDR_ANY))
660  tmp->configured = 1;
661 
662  add_ipv4_addr_to_interface(tmp, &a->sin_addr);
663 
664  /* invoke the setup hook */
665  addr.len = 4;
666  memcpy(addr.iabuf, &a->sin_addr.s_addr, addr.len);
668  (*dhcp_interface_setup_hook)(tmp, &addr);
669  }
670  }
671 #ifdef DHCPv6
672  else if ((info.addr.ss_family == AF_INET6) &&
673  (local_family == AF_INET6)) {
674  struct sockaddr_in6 *a =
675  (struct sockaddr_in6*)&info.addr;
676  struct iaddr addr;
677 
678  /* We don't want the loopback interface. */
679  if (IN6_IS_ADDR_LOOPBACK(&a->sin6_addr) &&
680  ((tmp->flags & INTERFACE_AUTOMATIC) &&
681  ((state == DISCOVER_SERVER) ||
682  (state == DISCOVER_SERVER46))))
683  continue;
684 
685  /* If the only address we have is 0.0.0.0, we
686  shouldn't consider the interface configured. */
687  if (IN6_IS_ADDR_UNSPECIFIED(&a->sin6_addr))
688  tmp->configured = 1;
689 
690  add_ipv6_addr_to_interface(tmp, &a->sin6_addr);
691 
692  /* invoke the setup hook */
693  addr.len = 16;
694  memcpy(addr.iabuf, &a->sin6_addr, addr.len);
696  (*dhcp_interface_setup_hook)(tmp, &addr);
697  }
698  }
699 #endif /* DHCPv6 */
700  }
701 
702  if (err) {
703  log_fatal("Error getting interface information.");
704  }
705 
706  end_iface_scan(&ifaces);
707 
708 
709  /* Mock-up an 'ifp' structure which is no longer used in the
710  * new interface-sensing code, but is used in higher layers
711  * (for example to sense fallback interfaces).
712  */
713  for (tmp = interfaces ; tmp != NULL ; tmp = tmp->next) {
714  if (tmp->ifp == NULL) {
715  struct ifreq *tif;
716 
717  tif = (struct ifreq *)dmalloc(sizeof(struct ifreq),
718  MDL);
719  if (tif == NULL)
720  log_fatal("no space for ifp mockup.");
721  strcpy(tif->ifr_name, tmp->name);
722  tmp->ifp = tif;
723  }
724  }
725 
726 
727  /* If we're just trying to get a list of interfaces that we might
728  be able to configure, we can quit now. */
729  if (state == DISCOVER_UNCONFIGURED) {
730  return;
731  }
732 
733  /* Weed out the interfaces that did not have IP addresses. */
734  tmp = last = next = NULL;
735  if (interfaces)
736  interface_reference (&tmp, interfaces, MDL);
737  while (tmp) {
738  if (next)
739  interface_dereference (&next, MDL);
740  if (tmp -> next)
741  interface_reference (&next, tmp -> next, MDL);
742  /* skip interfaces that are running already */
743  if (tmp -> flags & INTERFACE_RUNNING) {
744  interface_dereference(&tmp, MDL);
745  if(next)
746  interface_reference(&tmp, next, MDL);
747  continue;
748  }
749  if ((tmp -> flags & INTERFACE_AUTOMATIC) &&
750  state == DISCOVER_REQUESTED)
751  tmp -> flags &= ~(INTERFACE_AUTOMATIC |
753 
754 #ifdef DHCPv6
755  if (!(tmp->flags & INTERFACE_REQUESTED)) {
756 #else
757  if (!tmp -> ifp || !(tmp -> flags & INTERFACE_REQUESTED)) {
758 #endif /* DHCPv6 */
759  if ((tmp -> flags & INTERFACE_REQUESTED) != ir)
760  log_fatal ("%s: not found", tmp -> name);
761  if (!last) {
762  if (interfaces)
763  interface_dereference (&interfaces,
764  MDL);
765  if (next)
766  interface_reference (&interfaces, next, MDL);
767  } else {
768  interface_dereference (&last -> next, MDL);
769  if (next)
770  interface_reference (&last -> next,
771  next, MDL);
772  }
773  if (tmp -> next)
774  interface_dereference (&tmp -> next, MDL);
775 
776  /* Remember the interface in case we need to know
777  about it later. */
778  if (dummy_interfaces) {
779  interface_reference (&tmp -> next,
781  interface_dereference (&dummy_interfaces, MDL);
782  }
783  interface_reference (&dummy_interfaces, tmp, MDL);
784  interface_dereference (&tmp, MDL);
785  if (next)
786  interface_reference (&tmp, next, MDL);
787  continue;
788  }
789  last = tmp;
790 
791  /* We must have a subnet declaration for each interface. */
792  if (!tmp->shared_network && (state == DISCOVER_SERVER)) {
793  log_info("%s", "");
794  if (local_family == AF_INET) {
795  log_info("No subnet declaration for %s (%s).",
796  tmp->name,
797  (tmp->addresses == NULL) ?
798  "no IPv4 addresses" :
799  inet_ntoa(tmp->addresses[0]));
800 #ifdef DHCPv6
801  } else {
802  if (tmp->v6addresses != NULL) {
803  inet_ntop(AF_INET6,
804  &tmp->v6addresses[0],
805  abuf,
806  sizeof(abuf));
807  } else {
808  strcpy(abuf, "no IPv6 addresses");
809  }
810  log_info("No subnet6 declaration for %s (%s).",
811  tmp->name,
812  abuf);
813 #endif /* DHCPv6 */
814  }
815  if (supports_multiple_interfaces(tmp)) {
816  log_info ("** Ignoring requests on %s. %s",
817  tmp -> name, "If this is not what");
818  log_info (" you want, please write %s",
819 #ifdef DHCPv6
820  (local_family != AF_INET) ?
821  "a subnet6 declaration" :
822 #endif
823  "a subnet declaration");
824  log_info (" in your dhcpd.conf file %s",
825  "for the network segment");
826  log_info (" to %s %s %s",
827  "which interface",
828  tmp -> name, "is attached. **");
829  log_info ("%s", "");
830  goto next;
831  } else {
832  log_error ("You must write a %s",
833 #ifdef DHCPv6
834  (local_family != AF_INET) ?
835  "subnet6 declaration for this" :
836 #endif
837  "subnet declaration for this");
838  log_error ("subnet. You cannot prevent %s",
839  "the DHCP server");
840  log_error ("from listening on this subnet %s",
841  "because your");
842  log_fatal ("operating system does not %s.",
843  "support this capability");
844  }
845  }
846 
847  /* Find subnets that don't have valid interface
848  addresses... */
849  for (subnet = (tmp -> shared_network
850  ? tmp -> shared_network -> subnets
851  : (struct subnet *)0);
852  subnet; subnet = subnet -> next_sibling) {
853  /* Set the interface address for this subnet
854  to the first address we found. */
855  if (subnet->interface_address.len == 0) {
856  if (tmp->address_count > 0) {
859  &tmp->addresses[0].s_addr, 4);
860  } else if (tmp->v6address_count > 0) {
863  &tmp->v6addresses[0].s6_addr,
864  16);
865  } else {
866  /* XXX: should be one */
867  log_error("%s missing an interface "
868  "address", tmp->name);
869  continue;
870  }
871  }
872  }
873 
874  /* Flag the index as not having been set, so that the
875  interface registerer can set it or not as it chooses. */
876  tmp -> index = -1;
877 
878  /* Register the interface... */
879  switch (local_family) {
880  case AF_INET:
881  if (!dhcpv4_over_dhcpv6) {
882  if_register_receive(tmp);
883  if_register_send(tmp);
884  } else {
885  /* get_hw_addr() was called by register. */
886  get_hw_addr(tmp);
887  }
888  break;
889 #ifdef DHCPv6
890  case AF_INET6:
891  if ((state == DISCOVER_SERVER) ||
892  (state == DISCOVER_RELAY)) {
893  if_register6(tmp, 1);
894  } else if (state == DISCOVER_SERVER46) {
895  /* get_hw_addr() was called by if_register*6
896  so now we have to call it explicitly
897  to not leave the hardware address unknown
898  (some code expects it cannot be. */
899  get_hw_addr(tmp);
900  } else {
902  }
903  break;
904 #endif /* DHCPv6 */
905  }
906 
907  interface_stash (tmp);
908  wifcount++;
909 #if defined (F_SETFD)
910  /* if_register*() are no longer always called so
911  descriptors must be checked. */
912  if ((tmp -> rfdesc >= 0) &&
913  (fcntl (tmp -> rfdesc, F_SETFD, 1) < 0))
914  log_error ("Can't set close-on-exec on %s: %m",
915  tmp -> name);
916  if ((tmp -> wfdesc != tmp -> rfdesc) &&
917  (tmp -> wfdesc >= 0) &&
918  (fcntl (tmp -> wfdesc, F_SETFD, 1) < 0))
919  log_error ("Can't set close-on-exec on %s: %m",
920  tmp -> name);
921 #endif
922  next:
923  interface_dereference (&tmp, MDL);
924  if (next)
925  interface_reference (&tmp, next, MDL);
926  }
927 
928  /*
929  * Now register all the remaining interfaces as protocols.
930  * We register with omapi to allow for control of the interface,
931  * we've already registered the fd or socket with the socket
932  * manager as part of if_register_receive().
933  */
934  for (tmp = interfaces; tmp; tmp = tmp -> next) {
935  /* not if it's been registered before */
936  if (tmp -> flags & INTERFACE_RUNNING)
937  continue;
938  if (tmp -> rfdesc == -1)
939  continue;
940  switch (local_family) {
941 #ifdef DHCPv6
942  case AF_INET6:
944  if_readsocket,
945  0, got_one_v6, 0, 0);
946  break;
947 #endif /* DHCPv6 */
948  case AF_INET:
949  default:
951  if_readsocket,
952  0, got_one, 0, 0);
953  break;
954  }
955 
956  if (status != ISC_R_SUCCESS)
957  log_fatal ("Can't register I/O handle for %s: %s",
958  tmp -> name, isc_result_totext (status));
959 
960 #if defined(DHCPv6)
961  /* Only register the first interface for V6, since
962  * servers and relays all use the same socket.
963  * XXX: This has some messy side effects if we start
964  * dynamically adding and removing interfaces, but
965  * we're well beyond that point in terms of mess.
966  */
967  if (((state == DISCOVER_SERVER) || (state == DISCOVER_RELAY)) &&
968  (local_family == AF_INET6))
969  break;
970 #endif
971  } /* for (tmp = interfaces; ... */
972 
973  if (state == DISCOVER_SERVER && wifcount == 0) {
974  log_info ("%s", "");
975  log_fatal ("Not configured to listen on any interfaces!");
976  }
977 
978  if ((local_family == AF_INET) &&
980  setup_fallback = 1;
982  }
983 
984 #if defined (F_SETFD)
985  if (fallback_interface) {
986  if (fcntl (fallback_interface -> rfdesc, F_SETFD, 1) < 0)
987  log_error ("Can't set close-on-exec on fallback: %m");
988  if (fallback_interface -> rfdesc != fallback_interface -> wfdesc) {
989  if (fcntl (fallback_interface -> wfdesc, F_SETFD, 1) < 0)
990  log_error ("Can't set close-on-exec on fallback: %m");
991  }
992  }
993 #endif /* F_SETFD */
994 }
995 
997  omapi_object_t *h;
998 {
999  struct interface_info *ip;
1000 
1001  if (h -> type != dhcp_type_interface)
1002  return -1;
1003  ip = (struct interface_info *)h;
1004  return ip -> rfdesc;
1005 }
1006 
1007 int setup_fallback (struct interface_info **fp, const char *file, int line)
1008 {
1009  isc_result_t status;
1010 
1011  status = interface_allocate (&fallback_interface, file, line);
1012  if (status != ISC_R_SUCCESS)
1013  log_fatal ("Error allocating fallback interface: %s",
1014  isc_result_totext (status));
1015  strcpy (fallback_interface -> name, "fallback");
1017  (*dhcp_interface_setup_hook) (fallback_interface,
1018  (struct iaddr *)0);
1019  status = interface_reference (fp, fallback_interface, file, line);
1020 
1021  fallback_interface -> index = -1;
1023  return status == ISC_R_SUCCESS;
1024 }
1025 
1027 {
1028  struct interface_info *ip;
1029 
1030  for (ip = interfaces; ip; ip = ip -> next) {
1033  }
1034 
1035  if (fallback_interface)
1037 
1039 }
1040 
1041 isc_result_t got_one (h)
1042  omapi_object_t *h;
1043 {
1044  struct sockaddr_in from;
1045  struct hardware hfrom;
1046  struct iaddr ifrom;
1047  int result;
1048  union {
1049  unsigned char packbuf [4095]; /* Packet input buffer.
1050  Must be as large as largest
1051  possible MTU. */
1052  struct dhcp_packet packet;
1053  } u;
1054  struct interface_info *ip;
1055 
1056  if (h -> type != dhcp_type_interface)
1057  return DHCP_R_INVALIDARG;
1058  ip = (struct interface_info *)h;
1059 
1060  again:
1061  if ((result =
1062  receive_packet (ip, u.packbuf, sizeof u, &from, &hfrom)) < 0) {
1063  log_error ("receive_packet failed on %s: %m", ip -> name);
1064  return ISC_R_UNEXPECTED;
1065  }
1066  if (result == 0)
1067  return ISC_R_UNEXPECTED;
1068 
1069  /*
1070  * If we didn't at least get the fixed portion of the BOOTP
1071  * packet, drop the packet.
1072  * Previously we allowed packets with no sname or filename
1073  * as we were aware of at least one client that did. But
1074  * a bug caused short packets to not work and nobody has
1075  * complained, it seems rational to tighten up that
1076  * restriction.
1077  */
1078  if (result < DHCP_FIXED_NON_UDP)
1079  return ISC_R_UNEXPECTED;
1080 
1081 #if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO)
1082  {
1083  /* We retrieve the ifindex from the unused hfrom variable */
1084  unsigned int ifindex;
1085 
1086  memcpy(&ifindex, hfrom.hbuf, sizeof (ifindex));
1087 
1088  /*
1089  * Seek forward from the first interface to find the matching
1090  * source interface by interface index.
1091  */
1092  ip = interfaces;
1093  while ((ip != NULL) && (if_nametoindex(ip->name) != ifindex))
1094  ip = ip->next;
1095  if (ip == NULL)
1096  return ISC_R_NOTFOUND;
1097  }
1098 #endif
1099 
1100  if (bootp_packet_handler) {
1101  ifrom.len = 4;
1102  memcpy (ifrom.iabuf, &from.sin_addr, ifrom.len);
1103 
1104  (*bootp_packet_handler) (ip, &u.packet, (unsigned)result,
1105  from.sin_port, ifrom, &hfrom);
1106  }
1107 
1108  /* If there is buffered data, read again. This is for, e.g.,
1109  bpf, which may return two packets at once. */
1110  if (ip -> rbuf_offset != ip -> rbuf_len)
1111  goto again;
1112  return ISC_R_SUCCESS;
1113 }
1114 
1115 #ifdef DHCPv6
1116 isc_result_t
1118  struct sockaddr_in6 from;
1119  struct in6_addr to;
1120  struct iaddr ifrom;
1121  int result;
1122  char buf[65536]; /* maximum size for a UDP packet is 65536 */
1123  struct interface_info *ip;
1124  int is_unicast;
1125  unsigned int if_idx = 0;
1126 
1127  if (h->type != dhcp_type_interface) {
1128  return DHCP_R_INVALIDARG;
1129  }
1130  ip = (struct interface_info *)h;
1131 
1132  result = receive_packet6(ip, (unsigned char *)buf, sizeof(buf),
1133  &from, &to, &if_idx);
1134  if (result < 0) {
1135  log_error("receive_packet6() failed on %s: %m", ip->name);
1136  return ISC_R_UNEXPECTED;
1137  }
1138 
1139  /* 0 is 'any' interface. */
1140  if (if_idx == 0)
1141  return ISC_R_NOTFOUND;
1142 
1143  if (dhcpv6_packet_handler != NULL) {
1144  /*
1145  * If a packet is not multicast, we assume it is unicast.
1146  */
1147  if (IN6_IS_ADDR_MULTICAST(&to)) {
1148  is_unicast = ISC_FALSE;
1149  } else {
1150  is_unicast = ISC_TRUE;
1151  }
1152 
1153  ifrom.len = 16;
1154  memcpy(ifrom.iabuf, &from.sin6_addr, ifrom.len);
1155 
1156  /* Seek forward to find the matching source interface. */
1157  ip = interfaces;
1158  while ((ip != NULL) && (if_nametoindex(ip->name) != if_idx))
1159  ip = ip->next;
1160 
1161  if (ip == NULL)
1162  return ISC_R_NOTFOUND;
1163 
1164  (*dhcpv6_packet_handler)(ip, buf,
1165  result, from.sin6_port,
1166  &ifrom, is_unicast);
1167  }
1168 
1169  return ISC_R_SUCCESS;
1170 }
1171 #endif /* DHCPv6 */
1172 
1174  omapi_object_t *id,
1176  omapi_typed_data_t *value)
1177 {
1178  struct interface_info *interface;
1179  isc_result_t status;
1180 
1181  if (h -> type != dhcp_type_interface)
1182  return DHCP_R_INVALIDARG;
1183  interface = (struct interface_info *)h;
1184 
1185  if (!omapi_ds_strcmp (name, "name")) {
1186  if ((value -> type == omapi_datatype_data ||
1187  value -> type == omapi_datatype_string) &&
1188  value -> u.buffer.len < sizeof interface -> name) {
1189  memcpy (interface -> name,
1190  value -> u.buffer.value,
1191  value -> u.buffer.len);
1192  interface -> name [value -> u.buffer.len] = 0;
1193  } else
1194  return DHCP_R_INVALIDARG;
1195  return ISC_R_SUCCESS;
1196  }
1197 
1198  /* Try to find some inner object that can take the value. */
1199  if (h -> inner && h -> inner -> type -> set_value) {
1200  status = ((*(h -> inner -> type -> set_value))
1201  (h -> inner, id, name, value));
1202  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
1203  return status;
1204  }
1205 
1206  return ISC_R_NOTFOUND;
1207 }
1208 
1209 
1211  omapi_object_t *id,
1212  omapi_data_string_t *name,
1213  omapi_value_t **value)
1214 {
1215  return ISC_R_NOTIMPLEMENTED;
1216 }
1217 
1219  const char *file, int line)
1220 {
1221  struct interface_info *interface;
1222 
1223  if (h -> type != dhcp_type_interface)
1224  return DHCP_R_INVALIDARG;
1225  interface = (struct interface_info *)h;
1226 
1227  if (interface -> ifp) {
1228  dfree (interface -> ifp, file, line);
1229  interface -> ifp = 0;
1230  }
1231  if (interface -> next)
1232  interface_dereference (&interface -> next, file, line);
1233  if (interface -> rbuf) {
1234  dfree (interface -> rbuf, file, line);
1235  interface -> rbuf = (unsigned char *)0;
1236  }
1237  if (interface -> client)
1238  interface -> client = (struct client_state *)0;
1239 
1240  if (interface -> shared_network)
1243 
1244  return ISC_R_SUCCESS;
1245 }
1246 
1248  const char *name, va_list ap)
1249 {
1250  struct interface_info *ip, *interface;
1251  isc_result_t status;
1252 
1253  if (h -> type != dhcp_type_interface)
1254  return DHCP_R_INVALIDARG;
1255  interface = (struct interface_info *)h;
1256 
1257  /* If it's an update signal, see if the interface is dead right
1258  now, or isn't known at all, and if that's the case, revive it. */
1259  if (!strcmp (name, "update")) {
1260  for (ip = dummy_interfaces; ip; ip = ip -> next)
1261  if (ip == interface)
1262  break;
1264  return (*dhcp_interface_startup_hook) (ip);
1265 
1266  for (ip = interfaces; ip; ip = ip -> next)
1267  if (ip == interface)
1268  break;
1270  return (*dhcp_interface_startup_hook) (ip);
1271  }
1272 
1273  /* Try to find some inner object that can take the value. */
1274  if (h -> inner && h -> inner -> type -> signal_handler) {
1275  status = ((*(h -> inner -> type -> signal_handler))
1276  (h -> inner, name, ap));
1277  if (status == ISC_R_SUCCESS)
1278  return status;
1279  }
1280  return ISC_R_NOTFOUND;
1281 }
1282 
1284  omapi_object_t *id,
1285  omapi_object_t *h)
1286 {
1287  struct interface_info *interface;
1288  isc_result_t status;
1289 
1290  if (h -> type != dhcp_type_interface)
1291  return DHCP_R_INVALIDARG;
1292  interface = (struct interface_info *)h;
1293 
1294  /* Write out all the values. */
1295 
1296  status = omapi_connection_put_name (c, "state");
1297  if (status != ISC_R_SUCCESS)
1298  return status;
1299  if ((interface->flags & INTERFACE_REQUESTED) != 0)
1300  status = omapi_connection_put_string (c, "up");
1301  else
1302  status = omapi_connection_put_string (c, "down");
1303  if (status != ISC_R_SUCCESS)
1304  return status;
1305 
1306  /* Write out the inner object, if any. */
1307  if (h -> inner && h -> inner -> type -> stuff_values) {
1308  status = ((*(h -> inner -> type -> stuff_values))
1309  (c, id, h -> inner));
1310  if (status == ISC_R_SUCCESS)
1311  return status;
1312  }
1313 
1314  return ISC_R_SUCCESS;
1315 }
1316 
1318  omapi_object_t *id,
1319  omapi_object_t *ref)
1320 {
1321  omapi_value_t *tv = (omapi_value_t *)0;
1322  isc_result_t status;
1323  struct interface_info *interface;
1324 
1325  if (!ref)
1326  return DHCP_R_NOKEYS;
1327 
1328  /* First see if we were sent a handle. */
1329  status = omapi_get_value_str (ref, id, "handle", &tv);
1330  if (status == ISC_R_SUCCESS) {
1331  status = omapi_handle_td_lookup (ip, tv -> value);
1332 
1334  if (status != ISC_R_SUCCESS)
1335  return status;
1336 
1337  /* Don't return the object if the type is wrong. */
1338  if ((*ip) -> type != dhcp_type_interface) {
1340  return DHCP_R_INVALIDARG;
1341  }
1342  }
1343 
1344  /* Now look for an interface name. */
1345  status = omapi_get_value_str (ref, id, "name", &tv);
1346  if (status == ISC_R_SUCCESS) {
1347  char *s;
1348  unsigned len;
1349  for (interface = interfaces; interface;
1350  interface = interface -> next) {
1351  s = memchr (interface -> name, 0, IFNAMSIZ);
1352  if (s)
1353  len = s - &interface -> name [0];
1354  else
1355  len = IFNAMSIZ;
1356  if ((tv -> value -> u.buffer.len == len &&
1357  !memcmp (interface -> name,
1358  (char *)tv -> value -> u.buffer.value,
1359  len)))
1360  break;
1361  }
1362  if (!interface) {
1363  for (interface = dummy_interfaces;
1364  interface; interface = interface -> next) {
1365  s = memchr (interface -> name, 0, IFNAMSIZ);
1366  if (s)
1367  len = s - &interface -> name [0];
1368  else
1369  len = IFNAMSIZ;
1370  if ((tv -> value -> u.buffer.len == len &&
1371  !memcmp (interface -> name,
1372  (char *)
1373  tv -> value -> u.buffer.value,
1374  len)))
1375  break;
1376  }
1377  }
1378 
1380  if (*ip && *ip != (omapi_object_t *)interface) {
1382  return DHCP_R_KEYCONFLICT;
1383  } else if (!interface) {
1384  if (*ip)
1386  return ISC_R_NOTFOUND;
1387  } else if (!*ip)
1389  (omapi_object_t *)interface,
1390  MDL);
1391  }
1392 
1393  /* If we get to here without finding an interface, no valid key was
1394  specified. */
1395  if (!*ip)
1396  return DHCP_R_NOKEYS;
1397  return ISC_R_SUCCESS;
1398 }
1399 
1400 /* actually just go discover the interface */
1402  omapi_object_t *id)
1403 {
1404  struct interface_info *hp;
1405  isc_result_t status;
1406 
1407  hp = (struct interface_info *)0;
1408  status = interface_allocate (&hp, MDL);
1409  if (status != ISC_R_SUCCESS)
1410  return status;
1411  hp -> flags = INTERFACE_REQUESTED;
1412  status = interface_reference ((struct interface_info **)lp, hp, MDL);
1413  interface_dereference (&hp, MDL);
1414  return status;
1415 }
1416 
1418  omapi_object_t *id)
1419 {
1420  struct interface_info *interface, *ip, *last;
1421 
1422  interface = (struct interface_info *)lp;
1423 
1424  /* remove from interfaces */
1425  last = 0;
1426  for (ip = interfaces; ip; ip = ip -> next) {
1427  if (ip == interface) {
1428  if (last) {
1429  interface_dereference (&last -> next, MDL);
1430  if (ip -> next)
1431  interface_reference (&last -> next,
1432  ip -> next, MDL);
1433  } else {
1434  interface_dereference (&interfaces, MDL);
1435  if (ip -> next)
1436  interface_reference (&interfaces,
1437  ip -> next, MDL);
1438  }
1439  if (ip -> next)
1440  interface_dereference (&ip -> next, MDL);
1441  break;
1442  }
1443  last = ip;
1444  }
1445  if (!ip)
1446  return ISC_R_NOTFOUND;
1447 
1448  /* add the interface to the dummy_interface list */
1449  if (dummy_interfaces) {
1450  interface_reference (&interface -> next,
1452  interface_dereference (&dummy_interfaces, MDL);
1453  }
1454  interface_reference (&dummy_interfaces, interface, MDL);
1455 
1456  /* do a DHCPRELEASE */
1458  (*dhcp_interface_shutdown_hook) (interface);
1459 
1460  /* remove the io object */
1462 
1463  switch(local_family) {
1464 #ifdef DHCPv6
1465  case AF_INET6:
1466  if_deregister6(interface);
1467  break;
1468 #endif /* DHCPv6 */
1469  case AF_INET:
1470  default:
1471  if_deregister_send(interface);
1472  if_deregister_receive(interface);
1473  break;
1474  }
1475 
1476  return ISC_R_SUCCESS;
1477 }
1478 
1479 void interface_stash (struct interface_info *tptr)
1480 {
1481  struct interface_info **vec;
1482  int delta;
1483 
1484  /* If the registerer didn't assign an index, assign one now. */
1485  if (tptr -> index == -1) {
1486  tptr -> index = interface_count++;
1487  while (tptr -> index < interface_max &&
1488  interface_vector [tptr -> index])
1489  tptr -> index = interface_count++;
1490  }
1491 
1492  if (interface_max <= tptr -> index) {
1493  delta = tptr -> index - interface_max + 10;
1494  vec = dmalloc ((interface_max + delta) *
1495  sizeof (struct interface_info *), MDL);
1496  if (!vec) {
1497  log_error ("interface_stash: allocation failed ");
1498  return;
1499  }
1500 
1501  memset (&vec [interface_max], 0,
1502  (sizeof (struct interface_info *)) * delta);
1503  interface_max += delta;
1504  if (interface_vector) {
1505  memcpy (vec, interface_vector,
1506  (interface_count *
1507  sizeof (struct interface_info *)));
1509  }
1510 
1511  interface_vector = vec;
1512  }
1513 
1514  interface_reference (&interface_vector [tptr -> index], tptr, MDL);
1515  if (tptr -> index >= interface_count)
1516  interface_count = tptr -> index + 1;
1517 #if defined (TRACING)
1519 #endif
1520 }
1521 
1522 void interface_snorf (struct interface_info *tmp, int ir)
1523 {
1524  tmp -> circuit_id = (u_int8_t *)tmp -> name;
1525  tmp -> circuit_id_len = strlen (tmp -> name);
1526  tmp -> remote_id = 0;
1527  tmp -> remote_id_len = 0;
1528  tmp -> flags = ir;
1529  if (interfaces) {
1530  interface_reference (&tmp -> next,
1531  interfaces, MDL);
1532  interface_dereference (&interfaces, MDL);
1533  }
1534  interface_reference (&interfaces, tmp, MDL);
1535 }
#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:45
const char int line
Definition: dhcpd.h:3726
void try_hw_addr(struct interface_info *info)
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:571
struct shared_network * shared_network
Definition: dhcpd.h:1351
isc_result_t dhcp_interface_destroy(omapi_object_t *h, const char *file, int line)
Definition: discover.c:1218
int if_readsocket(omapi_object_t *h)
Definition: discover.c:996
char name[IFNAMSIZ]
Definition: dhcpd.h:1375
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
Definition: dhcpd.h:1044
u_int16_t remote_port
Definition: discover.c:46
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:1283
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:697
void reinitialize_interfaces()
Definition: discover.c:1026
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:1417
struct in_addr * addresses
Definition: dhcpd.h:1355
int dhcpv4_over_dhcpv6
Definition: discover.c:47
int setup_fallback(struct interface_info **fp, const char *file, int line)
Definition: discover.c:1007
#define INTERFACE_RUNNING
Definition: dhcpd.h:1392
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:480
struct subnet * subnets
Definition: mdb.c:32
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 get_hw_addr(struct interface_info *info)
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:1383
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:1210
#define DISCOVER_RELAY
Definition: dhcpd.h:695
#define INTERFACE_AUTOMATIC
Definition: dhcpd.h:1391
void interface_trace_setup(void)
struct omapi_typed_data_t::@3::@4 buffer
size_t rbuf_offset
Definition: dhcpd.h:1382
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:1268
struct interface_info * fallback_interface
Definition: discover.c:42
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:693
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:1050
isc_result_t dhcp_interface_create(omapi_object_t **lp, omapi_object_t *id)
Definition: discover.c:1401
void trace_inpacket_input(trace_type_t *, unsigned, char *)
trace_type_t * trace_type_register(const char *, void *, void(*)(trace_type_t *, unsigned, char *), void(*)(trace_type_t *), const char *, int)
unsigned circuit_id_len
Definition: dhcpd.h:1369
trace_type_t * inpacket_trace
Definition: dhcpd.h:405
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
Definition: alloc.c:593
Definition: ip.h:47
isc_result_t got_one_v6(omapi_object_t *)
void dfree(void *, const char *, int)
Definition: alloc.c:145
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__
void * dmalloc(size_t, const char *, int)
Definition: alloc.c:57
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:1173
struct interface_info * interfaces
Definition: discover.c:42
u_int32_t flags
Definition: dhcpd.h:1389
isc_result_t omapi_connection_put_string(omapi_object_t *, const char *)
Definition: buffer.c:690
int interfaces_invalidated
Definition: discover.c:43
void interface_snorf(struct interface_info *tmp, int ir)
Definition: discover.c:1522
int v6address_count
Definition: dhcpd.h:1362
int address_max
Definition: dhcpd.h:1359
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:1060
u_int8_t * circuit_id
Definition: dhcpd.h:1367
void if_register6(struct interface_info *info, int do_multicast)
int local_family
Definition: discover.c:55
int quiet_interface_discovery
Definition: discover.c:44
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)
Definition: support.c:194
isc_result_t(* dhcp_interface_startup_hook)(struct interface_info *)
Definition: discover.c:50
#define DISCOVER_UNCONFIGURED
Definition: dhcpd.h:694
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:1247
struct interface_info * next
Definition: dhcpd.h:1350
isc_uint64_t flags
Definition: discover.c:230
const char int
Definition: omapip.h:443
struct interface_info * dummy_interfaces
Definition: discover.c:42
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:1041
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
Definition: tree.h:61
#define DISCOVER_SERVER46
Definition: dhcpd.h:696
int supports_multiple_interfaces(struct interface_info *)
u_int8_t * remote_id
Definition: dhcpd.h:1371
isc_result_t interface_setup()
Definition: discover.c:83
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
Definition: dhcpd.h:490
int address_count
Definition: dhcpd.h:1358
unsigned remote_id_len
Definition: dhcpd.h:1373
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:3726
isc_result_t omapi_connection_put_name(omapi_object_t *, const char *)
Definition: buffer.c:679
int configured
Definition: dhcpd.h:1386
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:1479
struct interface_info * interface
Definition: dhcpd.h:1267
trace_type_t * outpacket_trace
#define DHCPv6
Definition: config.h:24
#define LIFREQ
Definition: discover.c:190
int v6address_max
Definition: dhcpd.h:1364
#define INTERFACE_STREAMS
Definition: dhcpd.h:1395
struct ifreq * ifp
Definition: dhcpd.h:1385
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:559
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:1317
#define INTERFACE_REQUESTED
Definition: dhcpd.h:1390
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:1360