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