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 
640  (*dhcp_interface_discovery_hook)(tmp);
641  }
642 
643  if ((info.addr.ss_family == AF_INET) &&
644  (local_family == AF_INET)) {
645  struct sockaddr_in *a = (struct sockaddr_in*)&info.addr;
646  struct iaddr addr;
647 
648  /* We don't want the loopback interface. */
649  if (a->sin_addr.s_addr == htonl(INADDR_LOOPBACK) &&
650  ((tmp->flags & INTERFACE_AUTOMATIC) &&
651  ((state == DISCOVER_SERVER) ||
652  (state == DISCOVER_SERVER46))))
653  continue;
654 
655  /* If the only address we have is 0.0.0.0, we
656  shouldn't consider the interface configured. */
657  if (a->sin_addr.s_addr != htonl(INADDR_ANY))
658  tmp->configured = 1;
659 
660  add_ipv4_addr_to_interface(tmp, &a->sin_addr);
661 
662  /* invoke the setup hook */
663  addr.len = 4;
664  memcpy(addr.iabuf, &a->sin_addr.s_addr, addr.len);
666  (*dhcp_interface_setup_hook)(tmp, &addr);
667  }
668  }
669 #ifdef DHCPv6
670  else if ((info.addr.ss_family == AF_INET6) &&
671  (local_family == AF_INET6)) {
672  struct sockaddr_in6 *a =
673  (struct sockaddr_in6*)&info.addr;
674  struct iaddr addr;
675 
676  /* We don't want the loopback interface. */
677  if (IN6_IS_ADDR_LOOPBACK(&a->sin6_addr) &&
678  ((tmp->flags & INTERFACE_AUTOMATIC) &&
679  ((state == DISCOVER_SERVER) ||
680  (state == DISCOVER_SERVER46))))
681  continue;
682 
683  /* If the only address we have is 0.0.0.0, we
684  shouldn't consider the interface configured. */
685  if (IN6_IS_ADDR_UNSPECIFIED(&a->sin6_addr))
686  tmp->configured = 1;
687 
688  add_ipv6_addr_to_interface(tmp, &a->sin6_addr);
689 
690  /* invoke the setup hook */
691  addr.len = 16;
692  memcpy(addr.iabuf, &a->sin6_addr, addr.len);
694  (*dhcp_interface_setup_hook)(tmp, &addr);
695  }
696  }
697 #endif /* DHCPv6 */
698  }
699 
700  if (err) {
701  log_fatal("Error getting interface information.");
702  }
703 
704  end_iface_scan(&ifaces);
705 
706 
707  /* Mock-up an 'ifp' structure which is no longer used in the
708  * new interface-sensing code, but is used in higher layers
709  * (for example to sense fallback interfaces).
710  */
711  for (tmp = interfaces ; tmp != NULL ; tmp = tmp->next) {
712  if (tmp->ifp == NULL) {
713  struct ifreq *tif;
714 
715  tif = (struct ifreq *)dmalloc(sizeof(struct ifreq),
716  MDL);
717  if (tif == NULL)
718  log_fatal("no space for ifp mockup.");
719  strcpy(tif->ifr_name, tmp->name);
720  tmp->ifp = tif;
721  }
722  }
723 
724 
725  /* If we're just trying to get a list of interfaces that we might
726  be able to configure, we can quit now. */
727  if (state == DISCOVER_UNCONFIGURED) {
728  return;
729  }
730 
731  /* Weed out the interfaces that did not have IP addresses. */
732  tmp = last = next = NULL;
733  if (interfaces)
734  interface_reference (&tmp, interfaces, MDL);
735  while (tmp) {
736  if (next)
737  interface_dereference (&next, MDL);
738  if (tmp -> next)
739  interface_reference (&next, tmp -> next, MDL);
740  /* skip interfaces that are running already */
741  if (tmp -> flags & INTERFACE_RUNNING) {
742  interface_dereference(&tmp, MDL);
743  if(next)
744  interface_reference(&tmp, next, MDL);
745  continue;
746  }
747  if ((tmp -> flags & INTERFACE_AUTOMATIC) &&
748  state == DISCOVER_REQUESTED)
749  tmp -> flags &= ~(INTERFACE_AUTOMATIC |
751 
752 #ifdef DHCPv6
753  if (!(tmp->flags & INTERFACE_REQUESTED)) {
754 #else
755  if (!tmp -> ifp || !(tmp -> flags & INTERFACE_REQUESTED)) {
756 #endif /* DHCPv6 */
757  if ((tmp -> flags & INTERFACE_REQUESTED) != ir)
758  log_fatal ("%s: not found", tmp -> name);
759  if (!last) {
760  if (interfaces)
761  interface_dereference (&interfaces,
762  MDL);
763  if (next)
764  interface_reference (&interfaces, next, MDL);
765  } else {
766  interface_dereference (&last -> next, MDL);
767  if (next)
768  interface_reference (&last -> next,
769  next, MDL);
770  }
771  if (tmp -> next)
772  interface_dereference (&tmp -> next, MDL);
773 
774  /* Remember the interface in case we need to know
775  about it later. */
776  if (dummy_interfaces) {
777  interface_reference (&tmp -> next,
779  interface_dereference (&dummy_interfaces, MDL);
780  }
781  interface_reference (&dummy_interfaces, tmp, MDL);
782  interface_dereference (&tmp, MDL);
783  if (next)
784  interface_reference (&tmp, next, MDL);
785  continue;
786  }
787  last = tmp;
788 
789  /* We must have a subnet declaration for each interface. */
790  if (!tmp->shared_network && (state == DISCOVER_SERVER)) {
791  log_info("%s", "");
792  if (local_family == AF_INET) {
793  log_info("No subnet declaration for %s (%s).",
794  tmp->name,
795  (tmp->addresses == NULL) ?
796  "no IPv4 addresses" :
797  inet_ntoa(tmp->addresses[0]));
798 #ifdef DHCPv6
799  } else {
800  if (tmp->v6addresses != NULL) {
801  inet_ntop(AF_INET6,
802  &tmp->v6addresses[0],
803  abuf,
804  sizeof(abuf));
805  } else {
806  strcpy(abuf, "no IPv6 addresses");
807  }
808  log_info("No subnet6 declaration for %s (%s).",
809  tmp->name,
810  abuf);
811 #endif /* DHCPv6 */
812  }
813  if (supports_multiple_interfaces(tmp)) {
814  log_info ("** Ignoring requests on %s. %s",
815  tmp -> name, "If this is not what");
816  log_info (" you want, please write %s",
817 #ifdef DHCPv6
818  (local_family != AF_INET) ?
819  "a subnet6 declaration" :
820 #endif
821  "a subnet declaration");
822  log_info (" in your dhcpd.conf file %s",
823  "for the network segment");
824  log_info (" to %s %s %s",
825  "which interface",
826  tmp -> name, "is attached. **");
827  log_info ("%s", "");
828  goto next;
829  } else {
830  log_error ("You must write a %s",
831 #ifdef DHCPv6
832  (local_family != AF_INET) ?
833  "subnet6 declaration for this" :
834 #endif
835  "subnet declaration for this");
836  log_error ("subnet. You cannot prevent %s",
837  "the DHCP server");
838  log_error ("from listening on this subnet %s",
839  "because your");
840  log_fatal ("operating system does not %s.",
841  "support this capability");
842  }
843  }
844 
845  /* Find subnets that don't have valid interface
846  addresses... */
847  for (subnet = (tmp -> shared_network
848  ? tmp -> shared_network -> subnets
849  : (struct subnet *)0);
850  subnet; subnet = subnet -> next_sibling) {
851  /* Set the interface address for this subnet
852  to the first address we found. */
853  if (subnet->interface_address.len == 0) {
854  if (tmp->address_count > 0) {
857  &tmp->addresses[0].s_addr, 4);
858  } else if (tmp->v6address_count > 0) {
861  &tmp->v6addresses[0].s6_addr,
862  16);
863  } else {
864  /* XXX: should be one */
865  log_error("%s missing an interface "
866  "address", tmp->name);
867  continue;
868  }
869  }
870  }
871 
872  /* Flag the index as not having been set, so that the
873  interface registerer can set it or not as it chooses. */
874  tmp -> index = -1;
875 
876  /* Register the interface... */
877  switch (local_family) {
878  case AF_INET:
879  if (!dhcpv4_over_dhcpv6) {
880  if_register_receive(tmp);
881  if_register_send(tmp);
882  } else {
883  /* get_hw_addr() was called by register. */
884  get_hw_addr(tmp);
885  }
886  break;
887 #ifdef DHCPv6
888  case AF_INET6:
889  if ((state == DISCOVER_SERVER) ||
890  (state == DISCOVER_RELAY)) {
891  if_register6(tmp, 1);
892  } else if (state == DISCOVER_SERVER46) {
893  /* get_hw_addr() was called by if_register*6
894  so now we have to call it explicitly
895  to not leave the hardware address unknown
896  (some code expects it cannot be. */
897  get_hw_addr(tmp);
898  } else {
900  }
901  break;
902 #endif /* DHCPv6 */
903  }
904 
905  interface_stash (tmp);
906  wifcount++;
907 #if defined (F_SETFD)
908  /* if_register*() are no longer always called so
909  descriptors must be checked. */
910  if ((tmp -> rfdesc >= 0) &&
911  (fcntl (tmp -> rfdesc, F_SETFD, 1) < 0))
912  log_error ("Can't set close-on-exec on %s: %m",
913  tmp -> name);
914  if ((tmp -> wfdesc != tmp -> rfdesc) &&
915  (tmp -> wfdesc >= 0) &&
916  (fcntl (tmp -> wfdesc, F_SETFD, 1) < 0))
917  log_error ("Can't set close-on-exec on %s: %m",
918  tmp -> name);
919 #endif
920  next:
921  interface_dereference (&tmp, MDL);
922  if (next)
923  interface_reference (&tmp, next, MDL);
924  }
925 
926  /*
927  * Now register all the remaining interfaces as protocols.
928  * We register with omapi to allow for control of the interface,
929  * we've already registered the fd or socket with the socket
930  * manager as part of if_register_receive().
931  */
932  for (tmp = interfaces; tmp; tmp = tmp -> next) {
933  /* not if it's been registered before */
934  if (tmp -> flags & INTERFACE_RUNNING)
935  continue;
936  if (tmp -> rfdesc == -1)
937  continue;
938  switch (local_family) {
939 #ifdef DHCPv6
940  case AF_INET6:
942  if_readsocket,
943  0, got_one_v6, 0, 0);
944  break;
945 #endif /* DHCPv6 */
946  case AF_INET:
947  default:
949  if_readsocket,
950  0, got_one, 0, 0);
951  break;
952  }
953 
954  if (status != ISC_R_SUCCESS)
955  log_fatal ("Can't register I/O handle for %s: %s",
956  tmp -> name, isc_result_totext (status));
957 
958 #if defined(DHCPv6)
959  /* Only register the first interface for V6, since
960  * servers and relays all use the same socket.
961  * XXX: This has some messy side effects if we start
962  * dynamically adding and removing interfaces, but
963  * we're well beyond that point in terms of mess.
964  */
965  if (((state == DISCOVER_SERVER) || (state == DISCOVER_RELAY)) &&
966  (local_family == AF_INET6))
967  break;
968 #endif
969  } /* for (tmp = interfaces; ... */
970 
971  if (state == DISCOVER_SERVER && wifcount == 0) {
972  log_info ("%s", "");
973  log_fatal ("Not configured to listen on any interfaces!");
974  }
975 
976  if ((local_family == AF_INET) &&
978  setup_fallback = 1;
980  }
981 
982 #if defined (F_SETFD)
983  if (fallback_interface) {
984  if (fcntl (fallback_interface -> rfdesc, F_SETFD, 1) < 0)
985  log_error ("Can't set close-on-exec on fallback: %m");
986  if (fallback_interface -> rfdesc != fallback_interface -> wfdesc) {
987  if (fcntl (fallback_interface -> wfdesc, F_SETFD, 1) < 0)
988  log_error ("Can't set close-on-exec on fallback: %m");
989  }
990  }
991 #endif /* F_SETFD */
992 }
993 
995  omapi_object_t *h;
996 {
997  struct interface_info *ip;
998 
999  if (h -> type != dhcp_type_interface)
1000  return -1;
1001  ip = (struct interface_info *)h;
1002  return ip -> rfdesc;
1003 }
1004 
1005 int setup_fallback (struct interface_info **fp, const char *file, int line)
1006 {
1007  isc_result_t status;
1008 
1009  status = interface_allocate (&fallback_interface, file, line);
1010  if (status != ISC_R_SUCCESS)
1011  log_fatal ("Error allocating fallback interface: %s",
1012  isc_result_totext (status));
1013  strcpy (fallback_interface -> name, "fallback");
1015  (*dhcp_interface_setup_hook) (fallback_interface,
1016  (struct iaddr *)0);
1017  status = interface_reference (fp, fallback_interface, file, line);
1018 
1019  fallback_interface -> index = -1;
1021  return status == ISC_R_SUCCESS;
1022 }
1023 
1025 {
1026  struct interface_info *ip;
1027 
1028  for (ip = interfaces; ip; ip = ip -> next) {
1031  }
1032 
1033  if (fallback_interface)
1035 
1037 }
1038 
1039 isc_result_t got_one (h)
1040  omapi_object_t *h;
1041 {
1042  struct sockaddr_in from;
1043  struct hardware hfrom;
1044  struct iaddr ifrom;
1045  int result;
1046  union {
1047  unsigned char packbuf [4095]; /* Packet input buffer.
1048  Must be as large as largest
1049  possible MTU. */
1050  struct dhcp_packet packet;
1051  } u;
1052  struct interface_info *ip;
1053 
1054  if (h -> type != dhcp_type_interface)
1055  return DHCP_R_INVALIDARG;
1056  ip = (struct interface_info *)h;
1057 
1058  again:
1059  if ((result =
1060  receive_packet (ip, u.packbuf, sizeof u, &from, &hfrom)) < 0) {
1061  log_error ("receive_packet failed on %s: %m", ip -> name);
1062  return ISC_R_UNEXPECTED;
1063  }
1064  if (result == 0)
1065  return ISC_R_UNEXPECTED;
1066 
1067  /*
1068  * If we didn't at least get the fixed portion of the BOOTP
1069  * packet, drop the packet.
1070  * Previously we allowed packets with no sname or filename
1071  * as we were aware of at least one client that did. But
1072  * a bug caused short packets to not work and nobody has
1073  * complained, it seems rational to tighten up that
1074  * restriction.
1075  */
1076  if (result < DHCP_FIXED_NON_UDP)
1077  return ISC_R_UNEXPECTED;
1078 
1079 #if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO)
1080  {
1081  /* We retrieve the ifindex from the unused hfrom variable */
1082  unsigned int ifindex;
1083 
1084  memcpy(&ifindex, hfrom.hbuf, sizeof (ifindex));
1085 
1086  /*
1087  * Seek forward from the first interface to find the matching
1088  * source interface by interface index.
1089  */
1090  ip = interfaces;
1091  while ((ip != NULL) && (if_nametoindex(ip->name) != ifindex))
1092  ip = ip->next;
1093  if (ip == NULL)
1094  return ISC_R_NOTFOUND;
1095  }
1096 #endif
1097 
1098  if (bootp_packet_handler) {
1099  ifrom.len = 4;
1100  memcpy (ifrom.iabuf, &from.sin_addr, ifrom.len);
1101 
1102  (*bootp_packet_handler) (ip, &u.packet, (unsigned)result,
1103  from.sin_port, ifrom, &hfrom);
1104  }
1105 
1106  /* If there is buffered data, read again. This is for, e.g.,
1107  bpf, which may return two packets at once. */
1108  if (ip -> rbuf_offset != ip -> rbuf_len)
1109  goto again;
1110  return ISC_R_SUCCESS;
1111 }
1112 
1113 #ifdef DHCPv6
1114 isc_result_t
1116  struct sockaddr_in6 from;
1117  struct in6_addr to;
1118  struct iaddr ifrom;
1119  int result;
1120  char buf[65536]; /* maximum size for a UDP packet is 65536 */
1121  struct interface_info *ip;
1122  int is_unicast;
1123  unsigned int if_idx = 0;
1124 
1125  if (h->type != dhcp_type_interface) {
1126  return DHCP_R_INVALIDARG;
1127  }
1128  ip = (struct interface_info *)h;
1129 
1130  result = receive_packet6(ip, (unsigned char *)buf, sizeof(buf),
1131  &from, &to, &if_idx);
1132  if (result < 0) {
1133  log_error("receive_packet6() failed on %s: %m", ip->name);
1134  return ISC_R_UNEXPECTED;
1135  }
1136 
1137  /* 0 is 'any' interface. */
1138  if (if_idx == 0)
1139  return ISC_R_NOTFOUND;
1140 
1141  if (dhcpv6_packet_handler != NULL) {
1142  /*
1143  * If a packet is not multicast, we assume it is unicast.
1144  */
1145  if (IN6_IS_ADDR_MULTICAST(&to)) {
1146  is_unicast = ISC_FALSE;
1147  } else {
1148  is_unicast = ISC_TRUE;
1149  }
1150 
1151  ifrom.len = 16;
1152  memcpy(ifrom.iabuf, &from.sin6_addr, ifrom.len);
1153 
1154  /* Seek forward to find the matching source interface. */
1155  ip = interfaces;
1156  while ((ip != NULL) && (if_nametoindex(ip->name) != if_idx))
1157  ip = ip->next;
1158 
1159  if (ip == NULL)
1160  return ISC_R_NOTFOUND;
1161 
1162  (*dhcpv6_packet_handler)(ip, buf,
1163  result, from.sin6_port,
1164  &ifrom, is_unicast);
1165  }
1166 
1167  return ISC_R_SUCCESS;
1168 }
1169 #endif /* DHCPv6 */
1170 
1172  omapi_object_t *id,
1174  omapi_typed_data_t *value)
1175 {
1176  struct interface_info *interface;
1177  isc_result_t status;
1178 
1179  if (h -> type != dhcp_type_interface)
1180  return DHCP_R_INVALIDARG;
1181  interface = (struct interface_info *)h;
1182 
1183  if (!omapi_ds_strcmp (name, "name")) {
1184  if ((value -> type == omapi_datatype_data ||
1185  value -> type == omapi_datatype_string) &&
1186  value -> u.buffer.len < sizeof interface -> name) {
1187  memcpy (interface -> name,
1188  value -> u.buffer.value,
1189  value -> u.buffer.len);
1190  interface -> name [value -> u.buffer.len] = 0;
1191  } else
1192  return DHCP_R_INVALIDARG;
1193  return ISC_R_SUCCESS;
1194  }
1195 
1196  /* Try to find some inner object that can take the value. */
1197  if (h -> inner && h -> inner -> type -> set_value) {
1198  status = ((*(h -> inner -> type -> set_value))
1199  (h -> inner, id, name, value));
1200  if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
1201  return status;
1202  }
1203 
1204  return ISC_R_NOTFOUND;
1205 }
1206 
1207 
1209  omapi_object_t *id,
1210  omapi_data_string_t *name,
1211  omapi_value_t **value)
1212 {
1213  return ISC_R_NOTIMPLEMENTED;
1214 }
1215 
1217  const char *file, int line)
1218 {
1219  struct interface_info *interface;
1220 
1221  if (h -> type != dhcp_type_interface)
1222  return DHCP_R_INVALIDARG;
1223  interface = (struct interface_info *)h;
1224 
1225  if (interface -> ifp) {
1226  dfree (interface -> ifp, file, line);
1227  interface -> ifp = 0;
1228  }
1229  if (interface -> next)
1230  interface_dereference (&interface -> next, file, line);
1231  if (interface -> rbuf) {
1232  dfree (interface -> rbuf, file, line);
1233  interface -> rbuf = (unsigned char *)0;
1234  }
1235  if (interface -> client)
1236  interface -> client = (struct client_state *)0;
1237 
1238  if (interface -> shared_network)
1241 
1242  return ISC_R_SUCCESS;
1243 }
1244 
1246  const char *name, va_list ap)
1247 {
1248  struct interface_info *ip, *interface;
1249  isc_result_t status;
1250 
1251  if (h -> type != dhcp_type_interface)
1252  return DHCP_R_INVALIDARG;
1253  interface = (struct interface_info *)h;
1254 
1255  /* If it's an update signal, see if the interface is dead right
1256  now, or isn't known at all, and if that's the case, revive it. */
1257  if (!strcmp (name, "update")) {
1258  for (ip = dummy_interfaces; ip; ip = ip -> next)
1259  if (ip == interface)
1260  break;
1262  return (*dhcp_interface_startup_hook) (ip);
1263 
1264  for (ip = interfaces; ip; ip = ip -> next)
1265  if (ip == interface)
1266  break;
1268  return (*dhcp_interface_startup_hook) (ip);
1269  }
1270 
1271  /* Try to find some inner object that can take the value. */
1272  if (h -> inner && h -> inner -> type -> signal_handler) {
1273  status = ((*(h -> inner -> type -> signal_handler))
1274  (h -> inner, name, ap));
1275  if (status == ISC_R_SUCCESS)
1276  return status;
1277  }
1278  return ISC_R_NOTFOUND;
1279 }
1280 
1282  omapi_object_t *id,
1283  omapi_object_t *h)
1284 {
1285  struct interface_info *interface;
1286  isc_result_t status;
1287 
1288  if (h -> type != dhcp_type_interface)
1289  return DHCP_R_INVALIDARG;
1290  interface = (struct interface_info *)h;
1291 
1292  /* Write out all the values. */
1293 
1294  status = omapi_connection_put_name (c, "state");
1295  if (status != ISC_R_SUCCESS)
1296  return status;
1297  if ((interface->flags & INTERFACE_REQUESTED) != 0)
1298  status = omapi_connection_put_string (c, "up");
1299  else
1300  status = omapi_connection_put_string (c, "down");
1301  if (status != ISC_R_SUCCESS)
1302  return status;
1303 
1304  /* Write out the inner object, if any. */
1305  if (h -> inner && h -> inner -> type -> stuff_values) {
1306  status = ((*(h -> inner -> type -> stuff_values))
1307  (c, id, h -> inner));
1308  if (status == ISC_R_SUCCESS)
1309  return status;
1310  }
1311 
1312  return ISC_R_SUCCESS;
1313 }
1314 
1316  omapi_object_t *id,
1317  omapi_object_t *ref)
1318 {
1319  omapi_value_t *tv = (omapi_value_t *)0;
1320  isc_result_t status;
1321  struct interface_info *interface;
1322 
1323  if (!ref)
1324  return DHCP_R_NOKEYS;
1325 
1326  /* First see if we were sent a handle. */
1327  status = omapi_get_value_str (ref, id, "handle", &tv);
1328  if (status == ISC_R_SUCCESS) {
1329  status = omapi_handle_td_lookup (ip, tv -> value);
1330 
1332  if (status != ISC_R_SUCCESS)
1333  return status;
1334 
1335  /* Don't return the object if the type is wrong. */
1336  if ((*ip) -> type != dhcp_type_interface) {
1338  return DHCP_R_INVALIDARG;
1339  }
1340  }
1341 
1342  /* Now look for an interface name. */
1343  status = omapi_get_value_str (ref, id, "name", &tv);
1344  if (status == ISC_R_SUCCESS) {
1345  char *s;
1346  unsigned len;
1347  for (interface = interfaces; interface;
1348  interface = interface -> next) {
1349  s = memchr (interface -> name, 0, IFNAMSIZ);
1350  if (s)
1351  len = s - &interface -> name [0];
1352  else
1353  len = IFNAMSIZ;
1354  if ((tv -> value -> u.buffer.len == len &&
1355  !memcmp (interface -> name,
1356  (char *)tv -> value -> u.buffer.value,
1357  len)))
1358  break;
1359  }
1360  if (!interface) {
1361  for (interface = dummy_interfaces;
1362  interface; interface = interface -> next) {
1363  s = memchr (interface -> name, 0, IFNAMSIZ);
1364  if (s)
1365  len = s - &interface -> name [0];
1366  else
1367  len = IFNAMSIZ;
1368  if ((tv -> value -> u.buffer.len == len &&
1369  !memcmp (interface -> name,
1370  (char *)
1371  tv -> value -> u.buffer.value,
1372  len)))
1373  break;
1374  }
1375  }
1376 
1378  if (*ip && *ip != (omapi_object_t *)interface) {
1380  return DHCP_R_KEYCONFLICT;
1381  } else if (!interface) {
1382  if (*ip)
1384  return ISC_R_NOTFOUND;
1385  } else if (!*ip)
1387  (omapi_object_t *)interface,
1388  MDL);
1389  }
1390 
1391  /* If we get to here without finding an interface, no valid key was
1392  specified. */
1393  if (!*ip)
1394  return DHCP_R_NOKEYS;
1395  return ISC_R_SUCCESS;
1396 }
1397 
1398 /* actually just go discover the interface */
1400  omapi_object_t *id)
1401 {
1402  struct interface_info *hp;
1403  isc_result_t status;
1404 
1405  hp = (struct interface_info *)0;
1406  status = interface_allocate (&hp, MDL);
1407  if (status != ISC_R_SUCCESS)
1408  return status;
1409  hp -> flags = INTERFACE_REQUESTED;
1410  status = interface_reference ((struct interface_info **)lp, hp, MDL);
1411  interface_dereference (&hp, MDL);
1412  return status;
1413 }
1414 
1416  omapi_object_t *id)
1417 {
1418  struct interface_info *interface, *ip, *last;
1419 
1420  interface = (struct interface_info *)lp;
1421 
1422  /* remove from interfaces */
1423  last = 0;
1424  for (ip = interfaces; ip; ip = ip -> next) {
1425  if (ip == interface) {
1426  if (last) {
1427  interface_dereference (&last -> next, MDL);
1428  if (ip -> next)
1429  interface_reference (&last -> next,
1430  ip -> next, MDL);
1431  } else {
1432  interface_dereference (&interfaces, MDL);
1433  if (ip -> next)
1434  interface_reference (&interfaces,
1435  ip -> next, MDL);
1436  }
1437  if (ip -> next)
1438  interface_dereference (&ip -> next, MDL);
1439  break;
1440  }
1441  last = ip;
1442  }
1443  if (!ip)
1444  return ISC_R_NOTFOUND;
1445 
1446  /* add the interface to the dummy_interface list */
1447  if (dummy_interfaces) {
1448  interface_reference (&interface -> next,
1450  interface_dereference (&dummy_interfaces, MDL);
1451  }
1452  interface_reference (&dummy_interfaces, interface, MDL);
1453 
1454  /* do a DHCPRELEASE */
1456  (*dhcp_interface_shutdown_hook) (interface);
1457 
1458  /* remove the io object */
1460 
1461  switch(local_family) {
1462 #ifdef DHCPv6
1463  case AF_INET6:
1464  if_deregister6(interface);
1465  break;
1466 #endif /* DHCPv6 */
1467  case AF_INET:
1468  default:
1469  if_deregister_send(interface);
1470  if_deregister_receive(interface);
1471  break;
1472  }
1473 
1474  return ISC_R_SUCCESS;
1475 }
1476 
1477 void interface_stash (struct interface_info *tptr)
1478 {
1479  struct interface_info **vec;
1480  int delta;
1481 
1482  /* If the registerer didn't assign an index, assign one now. */
1483  if (tptr -> index == -1) {
1484  tptr -> index = interface_count++;
1485  while (tptr -> index < interface_max &&
1486  interface_vector [tptr -> index])
1487  tptr -> index = interface_count++;
1488  }
1489 
1490  if (interface_max <= tptr -> index) {
1491  delta = tptr -> index - interface_max + 10;
1492  vec = dmalloc ((interface_max + delta) *
1493  sizeof (struct interface_info *), MDL);
1494  if (!vec) {
1495  log_error ("interface_stash: allocation failed ");
1496  return;
1497  }
1498 
1499  memset (&vec [interface_max], 0,
1500  (sizeof (struct interface_info *)) * delta);
1501  interface_max += delta;
1502  if (interface_vector) {
1503  memcpy (vec, interface_vector,
1504  (interface_count *
1505  sizeof (struct interface_info *)));
1507  }
1508 
1509  interface_vector = vec;
1510  }
1511 
1512  interface_reference (&interface_vector [tptr -> index], tptr, MDL);
1513  if (tptr -> index >= interface_count)
1514  interface_count = tptr -> index + 1;
1515 #if defined (TRACING)
1517 #endif
1518 }
1519 
1520 void interface_snorf (struct interface_info *tmp, int ir)
1521 {
1522  tmp -> circuit_id = (u_int8_t *)tmp -> name;
1523  tmp -> circuit_id_len = strlen (tmp -> name);
1524  tmp -> remote_id = 0;
1525  tmp -> remote_id_len = 0;
1526  tmp -> flags = ir;
1527  if (interfaces) {
1528  interface_reference (&tmp -> next,
1529  interfaces, MDL);
1530  interface_dereference (&interfaces, MDL);
1531  }
1532  interface_reference (&interfaces, tmp, MDL);
1533 }
#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:3724
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:1216
int if_readsocket(omapi_object_t *h)
Definition: discover.c:994
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:1281
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:1024
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:1415
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:1005
#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:1208
#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:1399
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:1171
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:1520
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:1245
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:1039
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:3724
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:1477
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:1315
#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