ISC DHCP  4.4.2b1
A reference DHCPv4 and DHCPv6 implementation
socket.c
Go to the documentation of this file.
1 /* socket.c
2 
3  BSD socket interface code... */
4 
5 /*
6  * Copyright (c) 2004-2019 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1995-2003 by Internet Software Consortium
8  *
9  * This Source Code Form is subject to the terms of the Mozilla Public
10  * License, v. 2.0. If a copy of the MPL was not distributed with this
11  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
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 /* SO_BINDTODEVICE support added by Elliot Poger (poger@leland.stanford.edu).
30  * This sockopt allows a socket to be bound to a particular interface,
31  * thus enabling the use of DHCPD on a multihomed host.
32  * If SO_BINDTODEVICE is defined in your system header files, the use of
33  * this sockopt will be automatically enabled.
34  * I have implemented it under Linux; other systems should be doable also.
35  */
36 
37 #include "dhcpd.h"
38 #include <isc/util.h>
39 #include <errno.h>
40 #include <sys/ioctl.h>
41 #include <sys/uio.h>
42 #include <sys/uio.h>
43 
44 #if defined(sun) && defined(USE_V4_PKTINFO)
45 #include <sys/sysmacros.h>
46 #include <net/if.h>
47 #include <sys/sockio.h>
48 #include <net/if_dl.h>
49 #include <sys/dlpi.h>
50 #endif
51 
52 #ifdef USE_SOCKET_FALLBACK
53 # if !defined (USE_SOCKET_SEND)
54 # define if_register_send if_register_fallback
55 # define send_packet send_fallback
56 # define if_reinitialize_send if_reinitialize_fallback
57 # endif
58 #endif
59 
60 #if defined(DHCPv6)
61 /*
62  * XXX: this is gross. we need to go back and overhaul the API for socket
63  * handling.
64  */
65 static int no_global_v6_socket = 0;
66 static unsigned int global_v6_socket_references = 0;
67 static int global_v6_socket = -1;
68 #if defined(RELAY_PORT)
69 static unsigned int relay_port_v6_socket_references = 0;
70 static int relay_port_v6_socket = -1;
71 #endif
72 
73 static void if_register_multicast(struct interface_info *info);
74 #endif
75 
76 /*
77  * We can use a single socket for AF_INET (similar to AF_INET6) on all
78  * interfaces configured for DHCP if the system has support for IP_PKTINFO
79  * and IP_RECVPKTINFO (for example Solaris 11).
80  */
81 #if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO)
82 static unsigned int global_v4_socket_references = 0;
83 static int global_v4_socket = -1;
84 #endif
85 
86 /*
87  * If we can't bind() to a specific interface, then we can only have
88  * a single socket. This variable insures that we don't try to listen
89  * on two sockets.
90  */
91 #if !defined(SO_BINDTODEVICE) && !defined(USE_FALLBACK)
92 static int once = 0;
93 #endif /* !defined(SO_BINDTODEVICE) && !defined(USE_FALLBACK) */
94 
95 /* Reinitializes the specified interface after an address change. This
96  is not required for packet-filter APIs. */
97 
98 #if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_FALLBACK)
99 void if_reinitialize_send (info)
100  struct interface_info *info;
101 {
102 #if 0
103 #ifndef USE_SOCKET_RECEIVE
104  once = 0;
105  close (info -> wfdesc);
106 #endif
107  if_register_send (info);
108 #endif
109 }
110 #endif
111 
112 #ifdef USE_SOCKET_RECEIVE
113 void if_reinitialize_receive (info)
114  struct interface_info *info;
115 {
116 #if 0
117  once = 0;
118  close (info -> rfdesc);
119  if_register_receive (info);
120 #endif
121 }
122 #endif
123 
124 #if defined (USE_SOCKET_SEND) || \
125  defined (USE_SOCKET_RECEIVE) || \
126  defined (USE_SOCKET_FALLBACK)
127 /* Generic interface registration routine... */
128 int
129 if_register_socket(struct interface_info *info, int family,
130  int *do_multicast, struct in6_addr *linklocal6)
131 {
132  struct sockaddr_storage name;
133  int name_len;
134  int sock;
135  int flag;
136  int domain;
137 #ifdef DHCPv6
138  struct sockaddr_in6 *addr6;
139 #endif
140  struct sockaddr_in *addr;
141 
142  /* INSIST((family == AF_INET) || (family == AF_INET6)); */
143 
144 #if !defined(SO_BINDTODEVICE) && !defined(USE_FALLBACK)
145  /* Make sure only one interface is registered. */
146  if (once) {
147  log_fatal ("The standard socket API can only support %s",
148  "hosts with a single network interface.");
149  }
150  once = 1;
151 #endif
152 
153  /*
154  * Set up the address we're going to bind to, depending on the
155  * address family.
156  */
157  memset(&name, 0, sizeof(name));
158  switch (family) {
159 #ifdef DHCPv6
160  case AF_INET6:
161  addr6 = (struct sockaddr_in6 *)&name;
162  addr6->sin6_family = AF_INET6;
163  addr6->sin6_port = local_port;
164 #if defined(RELAY_PORT)
165  if (relay_port &&
167  addr6->sin6_port = relay_port;
168 #endif
169  /* A server feature */
170  if (bind_local_address6) {
171  memcpy(&addr6->sin6_addr,
173  sizeof(addr6->sin6_addr));
174  }
175  /* A client feature */
176  if (linklocal6) {
177  memcpy(&addr6->sin6_addr,
178  linklocal6,
179  sizeof(addr6->sin6_addr));
180  }
181  if (IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr)) {
182  addr6->sin6_scope_id = if_nametoindex(info->name);
183  }
184 #ifdef HAVE_SA_LEN
185  addr6->sin6_len = sizeof(*addr6);
186 #endif
187  name_len = sizeof(*addr6);
188  domain = PF_INET6;
189  if ((info->flags & INTERFACE_STREAMS) == INTERFACE_UPSTREAM) {
190  *do_multicast = 0;
191  }
192  break;
193 #endif /* DHCPv6 */
194 
195  case AF_INET:
196  default:
197  addr = (struct sockaddr_in *)&name;
198  addr->sin_family = AF_INET;
199  addr->sin_port = relay_port ? relay_port : local_port;
200  memcpy(&addr->sin_addr,
201  &local_address,
202  sizeof(addr->sin_addr));
203 #ifdef HAVE_SA_LEN
204  addr->sin_len = sizeof(*addr);
205 #endif
206  name_len = sizeof(*addr);
207  domain = PF_INET;
208  break;
209  }
210 
211  /* Make a socket... */
212  sock = socket(domain, SOCK_DGRAM, IPPROTO_UDP);
213  if (sock < 0) {
214  log_fatal("Can't create dhcp socket: %m");
215  }
216 
217  /* Set the REUSEADDR option so that we don't fail to start if
218  we're being restarted. */
219  flag = 1;
220  if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
221  (char *)&flag, sizeof(flag)) < 0) {
222  log_fatal("Can't set SO_REUSEADDR option on dhcp socket: %m");
223  }
224 
225  /* Set the BROADCAST option so that we can broadcast DHCP responses.
226  We shouldn't do this for fallback devices, and we can detect that
227  a device is a fallback because it has no ifp structure. */
228  if (info->ifp &&
229  (setsockopt(sock, SOL_SOCKET, SO_BROADCAST,
230  (char *)&flag, sizeof(flag)) < 0)) {
231  log_fatal("Can't set SO_BROADCAST option on dhcp socket: %m");
232  }
233 
234 #if defined(DHCPv6) && defined(SO_REUSEPORT)
235  /*
236  * We only set SO_REUSEPORT on AF_INET6 sockets, so that multiple
237  * daemons can bind to their own sockets and get data for their
238  * respective interfaces. This does not (and should not) affect
239  * DHCPv4 sockets; we can't yet support BSD sockets well, much
240  * less multiple sockets. Make sense only with multicast.
241  * RedHat defines SO_REUSEPORT with a kernel which does not support
242  * it and returns ENOPROTOOPT so in this case ignore the error.
243  */
244  if ((local_family == AF_INET6) && *do_multicast) {
245  flag = 1;
246  if ((setsockopt(sock, SOL_SOCKET, SO_REUSEPORT,
247  (char *)&flag, sizeof(flag)) < 0) &&
248  (errno != ENOPROTOOPT)) {
249  log_fatal("Can't set SO_REUSEPORT option on dhcp "
250  "socket: %m");
251  }
252  }
253 #endif
254 
255  /* Bind the socket to this interface's IP address. */
256  if (bind(sock, (struct sockaddr *)&name, name_len) < 0) {
257  log_error("Can't bind to dhcp address: %m");
258  log_error("Please make sure there is no other dhcp server");
259  log_error("running and that there's no entry for dhcp or");
260  log_error("bootp in /etc/inetd.conf. Also make sure you");
261  log_error("are not running HP JetAdmin software, which");
262  log_fatal("includes a bootp server.");
263  }
264 
265 #if defined(SO_BINDTODEVICE)
266  /* Bind this socket to this interface. */
267  if ((local_family != AF_INET6) && (info->ifp != NULL) &&
268  setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE,
269  (char *)(info -> ifp), sizeof(*(info -> ifp))) < 0) {
270  log_fatal("setsockopt: SO_BINDTODEVICE: %m");
271  }
272 #endif
273 
274  /* IP_BROADCAST_IF instructs the kernel which interface to send
275  * IP packets whose destination address is 255.255.255.255. These
276  * will be treated as subnet broadcasts on the interface identified
277  * by ip address (info -> primary_address). This is only known to
278  * be defined in SCO system headers, and may not be defined in all
279  * releases.
280  */
281 #if defined(SCO) && defined(IP_BROADCAST_IF)
282  if (info->address_count &&
283  setsockopt(sock, IPPROTO_IP, IP_BROADCAST_IF, &info->addresses[0],
284  sizeof(info->addresses[0])) < 0)
285  log_fatal("Can't set IP_BROADCAST_IF on dhcp socket: %m");
286 #endif
287 
288 #if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO)
289  /*
290  * If we turn on IP_RECVPKTINFO we will be able to receive
291  * the interface index information of the received packet.
292  */
293  if (family == AF_INET) {
294  int on = 1;
295  if (setsockopt(sock, IPPROTO_IP, IP_RECVPKTINFO,
296  &on, sizeof(on)) != 0) {
297  log_fatal("setsockopt: IPV_RECVPKTINFO: %m");
298  }
299  }
300 #endif
301 
302 #ifdef DHCPv6
303  /*
304  * If we turn on IPV6_PKTINFO, we will be able to receive
305  * additional information, such as the destination IP address.
306  * We need this to spot unicast packets.
307  */
308  if (family == AF_INET6) {
309  int on = 1;
310 #ifdef IPV6_RECVPKTINFO
311  /* RFC3542 */
312  if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO,
313  &on, sizeof(on)) != 0) {
314  log_fatal("setsockopt: IPV6_RECVPKTINFO: %m");
315  }
316 #else
317  /* RFC2292 */
318  if (setsockopt(sock, IPPROTO_IPV6, IPV6_PKTINFO,
319  &on, sizeof(on)) != 0) {
320  log_fatal("setsockopt: IPV6_PKTINFO: %m");
321  }
322 #endif
323  }
324 
325 #endif /* DHCPv6 */
326 
327  return sock;
328 }
329 
330 #ifdef DHCPv6
331 void set_multicast_hop_limit(struct interface_info* info, int hop_limit) {
332  if (setsockopt(info->wfdesc, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
333  &hop_limit, sizeof(int)) < 0) {
334  log_fatal("setMulticaseHopLimit: IPV6_MULTICAST_HOPS: %m");
335  }
336 
337  log_debug("Setting hop count limit to %d for interface %s",
338  hop_limit, info->name);
339 
340 }
341 #endif /* DHCPv6 */
342 
343 #endif /* USE_SOCKET_SEND || USE_SOCKET_RECEIVE || USE_SOCKET_FALLBACK */
344 
345 #if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_FALLBACK)
346 void if_register_send (info)
347  struct interface_info *info;
348 {
349 #ifndef USE_SOCKET_RECEIVE
350  info->wfdesc = if_register_socket(info, AF_INET, 0, NULL);
351  /* If this is a normal IPv4 address, get the hardware address. */
352  if (strcmp(info->name, "fallback") != 0)
353  get_hw_addr(info);
354 #if defined (USE_SOCKET_FALLBACK)
355  /* Fallback only registers for send, but may need to receive as
356  well. */
357  info->rfdesc = info->wfdesc;
358 #endif
359 #else
360  info->wfdesc = info->rfdesc;
361 #endif
363  log_info ("Sending on Socket/%s%s%s",
364  info->name,
365  (info->shared_network ? "/" : ""),
366  (info->shared_network ?
367  info->shared_network->name : ""));
368 }
369 
370 #if defined (USE_SOCKET_SEND)
371 void if_deregister_send (info)
372  struct interface_info *info;
373 {
374 #ifndef USE_SOCKET_RECEIVE
375  close (info -> wfdesc);
376 #endif
377  info -> wfdesc = -1;
378 
380  log_info ("Disabling output on Socket/%s%s%s",
381  info -> name,
382  (info -> shared_network ? "/" : ""),
383  (info -> shared_network ?
384  info -> shared_network -> name : ""));
385 }
386 #endif /* USE_SOCKET_SEND */
387 #endif /* USE_SOCKET_SEND || USE_SOCKET_FALLBACK */
388 
389 #ifdef USE_SOCKET_RECEIVE
390 void if_register_receive (info)
391  struct interface_info *info;
392 {
393 
394 #if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO)
395  if (global_v4_socket_references == 0) {
396  global_v4_socket = if_register_socket(info, AF_INET, 0, NULL);
397  if (global_v4_socket < 0) {
398  /*
399  * if_register_socket() fatally logs if it fails to
400  * create a socket, this is just a sanity check.
401  */
402  log_fatal("Failed to create AF_INET socket %s:%d",
403  MDL);
404  }
405  }
406 
407  info->rfdesc = global_v4_socket;
408  global_v4_socket_references++;
409 #else
410  /* If we're using the socket API for sending and receiving,
411  we don't need to register this interface twice. */
412  info->rfdesc = if_register_socket(info, AF_INET, 0, NULL);
413 #endif /* IP_PKTINFO... */
414  /* If this is a normal IPv4 address, get the hardware address. */
415  if (strcmp(info->name, "fallback") != 0)
416  get_hw_addr(info);
417 
419  log_info ("Listening on Socket/%s%s%s",
420  info->name,
421  (info->shared_network ? "/" : ""),
422  (info->shared_network ?
423  info->shared_network->name : ""));
424 }
425 
426 void if_deregister_receive (info)
427  struct interface_info *info;
428 {
429 #if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO)
430  /* Dereference the global v4 socket. */
431  if ((info->rfdesc == global_v4_socket) &&
432  (global_v4_socket_references > 0)) {
433  global_v4_socket_references--;
434  info->rfdesc = -1;
435  } else {
436  log_fatal("Impossible condition at %s:%d", MDL);
437  }
438 
439  if (global_v4_socket_references == 0) {
440  close(global_v4_socket);
441  global_v4_socket = -1;
442  }
443 #else
444  close(info->rfdesc);
445  info->rfdesc = -1;
446 #endif /* IP_PKTINFO... */
448  log_info ("Disabling input on Socket/%s%s%s",
449  info -> name,
450  (info -> shared_network ? "/" : ""),
451  (info -> shared_network ?
452  info -> shared_network -> name : ""));
453 }
454 #endif /* USE_SOCKET_RECEIVE */
455 
456 
457 #ifdef DHCPv6
458 /*
459  * This function joins the interface to DHCPv6 multicast groups so we will
460  * receive multicast messages.
461  */
462 static void
463 if_register_multicast(struct interface_info *info) {
464  int sock = info->rfdesc;
465  struct ipv6_mreq mreq;
466 
467  if (inet_pton(AF_INET6, All_DHCP_Relay_Agents_and_Servers,
468  &mreq.ipv6mr_multiaddr) <= 0) {
469  log_fatal("inet_pton: unable to convert '%s'",
471  }
472  mreq.ipv6mr_interface = if_nametoindex(info->name);
473  if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
474  &mreq, sizeof(mreq)) < 0) {
475  log_fatal("setsockopt: IPV6_JOIN_GROUP: %m");
476  }
477 
478  /*
479  * The relay agent code sets the streams so you know which way
480  * is up and down. But a relay agent shouldn't join to the
481  * Server address, or else you get fun loops. So up or down
482  * doesn't matter, we're just using that config to sense this is
483  * a relay agent.
484  */
485  if ((info->flags & INTERFACE_STREAMS) == 0) {
486  if (inet_pton(AF_INET6, All_DHCP_Servers,
487  &mreq.ipv6mr_multiaddr) <= 0) {
488  log_fatal("inet_pton: unable to convert '%s'",
490  }
491  mreq.ipv6mr_interface = if_nametoindex(info->name);
492  if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
493  &mreq, sizeof(mreq)) < 0) {
494  log_fatal("setsockopt: IPV6_JOIN_GROUP: %m");
495  }
496  }
497 }
498 
499 void
500 if_register6(struct interface_info *info, int do_multicast) {
501  /* Bounce do_multicast to a stack variable because we may change it. */
502  int req_multi = do_multicast;
503 
504  if (no_global_v6_socket) {
505  log_fatal("Impossible condition at %s:%d", MDL);
506  }
507 
508 #if defined(RELAY_PORT)
509  if (!relay_port ||
511 #endif
512  if (global_v6_socket_references == 0) {
513  global_v6_socket = if_register_socket(info, AF_INET6,
514  &req_multi, NULL);
515  if (global_v6_socket < 0) {
516  /*
517  * if_register_socket() fatally logs if it fails to
518  * create a socket, this is just a sanity check.
519  */
520  log_fatal("Impossible condition at %s:%d", MDL);
521  } else if (bind_local_address6) {
522  char addr6_str[INET6_ADDRSTRLEN];
523 
524  if (inet_ntop(AF_INET6,
526  addr6_str,
527  sizeof(addr6_str)) == NULL) {
528  log_fatal("inet_ntop: unable to convert "
529  "local-address6");
530  }
531  log_info("Bound to [%s]:%d",
532  addr6_str,
533  (int) ntohs(local_port));
534  } else {
535  log_info("Bound to *:%d", (int) ntohs(local_port));
536  }
537  }
538 
539  info->rfdesc = global_v6_socket;
540  info->wfdesc = global_v6_socket;
541  global_v6_socket_references++;
542 
543 #if defined(RELAY_PORT)
544  } else {
545  /*
546  * If relay port is defined, we need to register one
547  * IPv6 UPD socket to handle upstream server or relay agent
548  * with a non-547 UDP local port.
549  */
550  if ((relay_port_v6_socket_references == 0) &&
551  ((info->flags & INTERFACE_STREAMS) == INTERFACE_UPSTREAM)) {
552  relay_port_v6_socket = if_register_socket(info, AF_INET6,
553  &req_multi, NULL);
554  if (relay_port_v6_socket < 0) {
555  log_fatal("Impossible condition at %s:%d", MDL);
556  } else {
557  log_info("Bound to relay port *:%d",
558  (int) ntohs(relay_port));
559  }
560  }
561  info->rfdesc = relay_port_v6_socket;
562  info->wfdesc = relay_port_v6_socket;
563  relay_port_v6_socket_references++;
564  }
565 #endif
566 
567  if (req_multi)
568  if_register_multicast(info);
569 
570  get_hw_addr(info);
571 
573  if (info->shared_network != NULL) {
574  log_info("Listening on Socket/%d/%s/%s",
575  global_v6_socket, info->name,
576  info->shared_network->name);
577  log_info("Sending on Socket/%d/%s/%s",
578  global_v6_socket, info->name,
579  info->shared_network->name);
580  } else {
581  log_info("Listening on Socket/%s", info->name);
582  log_info("Sending on Socket/%s", info->name);
583  }
584  }
585 }
586 
587 /*
588  * Register an IPv6 socket bound to the link-local address of
589  * the argument interface (used by clients on a multiple interface box,
590  * vs. a server or a relay using the global IPv6 socket and running
591  * *only* in a single instance).
592  */
593 void
595  int sock;
596  int count;
597  struct in6_addr *addr6 = NULL;
598  int req_multi = 0;
599 
600  if (global_v6_socket >= 0) {
601  log_fatal("Impossible condition at %s:%d", MDL);
602  }
603 
604  no_global_v6_socket = 1;
605 
606  /* get the (?) link-local address */
607  for (count = 0; count < info->v6address_count; count++) {
608  addr6 = &info->v6addresses[count];
609  if (IN6_IS_ADDR_LINKLOCAL(addr6))
610  break;
611  }
612 
613  if (!addr6) {
614  log_fatal("no link-local IPv6 address for %s", info->name);
615  }
616 
617  sock = if_register_socket(info, AF_INET6, &req_multi, addr6);
618 
619  if (sock < 0) {
620  log_fatal("if_register_socket for %s fails", info->name);
621  }
622 
623  info->rfdesc = sock;
624  info->wfdesc = sock;
625 
626  get_hw_addr(info);
627 
629  if (info->shared_network != NULL) {
630  log_info("Listening on Socket/%d/%s/%s",
631  global_v6_socket, info->name,
632  info->shared_network->name);
633  log_info("Sending on Socket/%d/%s/%s",
634  global_v6_socket, info->name,
635  info->shared_network->name);
636  } else {
637  log_info("Listening on Socket/%s", info->name);
638  log_info("Sending on Socket/%s", info->name);
639  }
640  }
641 }
642 
643 void
644 if_deregister6(struct interface_info *info) {
645  /* client case */
646  if (no_global_v6_socket) {
647  close(info->rfdesc);
648  info->rfdesc = -1;
649  info->wfdesc = -1;
650  } else if ((info->rfdesc == global_v6_socket) &&
651  (info->wfdesc == global_v6_socket) &&
652  (global_v6_socket_references > 0)) {
653  /* Dereference the global v6 socket. */
654  global_v6_socket_references--;
655  info->rfdesc = -1;
656  info->wfdesc = -1;
657 #if defined(RELAY_PORT)
658  } else if (relay_port &&
659  (info->rfdesc == relay_port_v6_socket) &&
660  (info->wfdesc == relay_port_v6_socket) &&
661  (relay_port_v6_socket_references > 0)) {
662  /* Dereference the relay port v6 socket. */
663  relay_port_v6_socket_references--;
664  info->rfdesc = -1;
665  info->wfdesc = -1;
666 #endif
667  } else {
668  log_fatal("Impossible condition at %s:%d", MDL);
669  }
670 
672  if (info->shared_network != NULL) {
673  log_info("Disabling input on Socket/%s/%s", info->name,
674  info->shared_network->name);
675  log_info("Disabling output on Socket/%s/%s", info->name,
676  info->shared_network->name);
677  } else {
678  log_info("Disabling input on Socket/%s", info->name);
679  log_info("Disabling output on Socket/%s", info->name);
680  }
681  }
682 
683  if (!no_global_v6_socket) {
684  if (global_v6_socket_references == 0) {
685  close(global_v6_socket);
686  global_v6_socket = -1;
687 
688  log_info("Unbound from *:%d",
689  (int) ntohs(local_port));
690  }
691 #if defined(RELAY_PORT)
692  if (relay_port && (relay_port_v6_socket_references == 0)) {
693  close(relay_port_v6_socket);
694  relay_port_v6_socket = -1;
695 
696  log_info("Unbound from relay port *:%d",
697  (int) ntohs(relay_port));
698  }
699 #endif
700  }
701 }
702 #endif /* DHCPv6 */
703 
704 #if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_FALLBACK)
705 ssize_t send_packet (interface, packet, raw, len, from, to, hto)
706  struct interface_info *interface;
707  struct packet *packet;
708  struct dhcp_packet *raw;
709  size_t len;
710  struct in_addr from;
711  struct sockaddr_in *to;
712  struct hardware *hto;
713 {
714  int result;
715 #ifdef IGNORE_HOSTUNREACH
716  int retry = 0;
717  do {
718 #endif
719 #if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO)
720  struct in_pktinfo pktinfo;
721 
722  if (interface->ifp != NULL) {
723  memset(&pktinfo, 0, sizeof (pktinfo));
724  pktinfo.ipi_ifindex = interface->ifp->ifr_index;
725  if (setsockopt(interface->wfdesc, IPPROTO_IP,
726  IP_PKTINFO, (char *)&pktinfo,
727  sizeof(pktinfo)) < 0)
728  log_fatal("setsockopt: IP_PKTINFO: %m");
729  }
730 #endif
731  result = sendto (interface -> wfdesc, (char *)raw, len, 0,
732  (struct sockaddr *)to, sizeof *to);
733 #ifdef IGNORE_HOSTUNREACH
734  } while (to -> sin_addr.s_addr == htonl (INADDR_BROADCAST) &&
735  result < 0 &&
736  (errno == EHOSTUNREACH ||
737  errno == ECONNREFUSED) &&
738  retry++ < 10);
739 #endif
740  if (result < 0) {
741  log_error ("send_packet: %m");
742  if (errno == ENETUNREACH)
743  log_error ("send_packet: please consult README file%s",
744  " regarding broadcast address.");
745  }
746  return result;
747 }
748 
749 #endif /* USE_SOCKET_SEND || USE_SOCKET_FALLBACK */
750 
751 #ifdef DHCPv6
752 /*
753  * Solaris 9 is missing the CMSG_LEN and CMSG_SPACE macros, so we will
754  * synthesize them (based on the BIND 9 technique).
755  */
756 
757 #ifndef CMSG_LEN
758 static size_t CMSG_LEN(size_t len) {
759  size_t hdrlen;
760  /*
761  * Cast NULL so that any pointer arithmetic performed by CMSG_DATA
762  * is correct.
763  */
764  hdrlen = (size_t)CMSG_DATA(((struct cmsghdr *)NULL));
765  return hdrlen + len;
766 }
767 #endif /* !CMSG_LEN */
768 
769 #ifndef CMSG_SPACE
770 static size_t CMSG_SPACE(size_t len) {
771  struct msghdr msg;
772  struct cmsghdr *cmsgp;
773 
774  /*
775  * XXX: The buffer length is an ad-hoc value, but should be enough
776  * in a practical sense.
777  */
778  union {
779  struct cmsghdr cmsg_sizer;
780  u_int8_t pktinfo_sizer[sizeof(struct cmsghdr) + 1024];
781  } dummybuf;
782 
783  memset(&msg, 0, sizeof(msg));
784  msg.msg_control = &dummybuf;
785  msg.msg_controllen = sizeof(dummybuf);
786 
787  cmsgp = (struct cmsghdr *)&dummybuf;
788  cmsgp->cmsg_len = CMSG_LEN(len);
789 
790  cmsgp = CMSG_NXTHDR(&msg, cmsgp);
791  if (cmsgp != NULL) {
792  return (char *)cmsgp - (char *)msg.msg_control;
793  } else {
794  return 0;
795  }
796 }
797 #endif /* !CMSG_SPACE */
798 
799 #endif /* DHCPv6 */
800 
801 #if defined(DHCPv6) || \
802  (defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && \
803  defined(USE_V4_PKTINFO))
804 /*
805  * For both send_packet6() and receive_packet6() we need to allocate
806  * space for the cmsg header information. We do this once and reuse
807  * the buffer. We also need the control buf for send_packet() and
808  * receive_packet() when we use a single socket and IP_PKTINFO to
809  * send the packet out the correct interface.
810  */
811 static void *control_buf = NULL;
812 static size_t control_buf_len = 0;
813 
814 static void
815 allocate_cmsg_cbuf(void) {
816  control_buf_len = CMSG_SPACE(sizeof(struct in6_pktinfo));
817  control_buf = dmalloc(control_buf_len, MDL);
818  return;
819 }
820 #endif /* DHCPv6, IP_PKTINFO ... */
821 
822 #ifdef DHCPv6
823 /*
824  * For both send_packet6() and receive_packet6() we need to use the
825  * sendmsg()/recvmsg() functions rather than the simpler send()/recv()
826  * functions.
827  *
828  * In the case of send_packet6(), we need to do this in order to insure
829  * that the reply packet leaves on the same interface that it arrived
830  * on.
831  *
832  * In the case of receive_packet6(), we need to do this in order to
833  * get the IP address the packet was sent to. This is used to identify
834  * whether a packet is multicast or unicast.
835  *
836  * Helpful man pages: recvmsg, readv (talks about the iovec stuff), cmsg.
837  *
838  * Also see the sections in RFC 3542 about IPV6_PKTINFO.
839  */
840 
841 /* Send an IPv6 packet */
842 ssize_t send_packet6(struct interface_info *interface,
843  const unsigned char *raw, size_t len,
844  struct sockaddr_in6 *to) {
845  struct msghdr m;
846  struct iovec v;
847  struct sockaddr_in6 dst;
848  int result;
849  struct in6_pktinfo *pktinfo;
850  struct cmsghdr *cmsg;
851  unsigned int ifindex;
852 
853  /*
854  * If necessary allocate space for the control message header.
855  * The space is common between send and receive.
856  */
857 
858  if (control_buf == NULL) {
859  allocate_cmsg_cbuf();
860  if (control_buf == NULL) {
861  log_error("send_packet6: unable to allocate cmsg header");
862  return(ENOMEM);
863  }
864  }
865  memset(control_buf, 0, control_buf_len);
866 
867  /*
868  * Initialize our message header structure.
869  */
870  memset(&m, 0, sizeof(m));
871 
872  /*
873  * Set the target address we're sending to.
874  * Enforce the scope ID for bogus BSDs.
875  */
876  memcpy(&dst, to, sizeof(dst));
877  m.msg_name = &dst;
878  m.msg_namelen = sizeof(dst);
879  ifindex = if_nametoindex(interface->name);
880 
881 // Per OpenBSD patch-common_socket_c,v 1.7 2018/03/06 08:37:39 sthen Exp
882 // always set the scope id. We'll leave the test for no global socket
883 // in place for all others.
884 #ifndef __OpenBSD__
885  if (no_global_v6_socket)
886 #endif
887  dst.sin6_scope_id = ifindex;
888 
889  /*
890  * Set the data buffer we're sending. (Using this wacky
891  * "scatter-gather" stuff... we only have a single chunk
892  * of data to send, so we declare a single vector entry.)
893  */
894  v.iov_base = (char *)raw;
895  v.iov_len = len;
896  m.msg_iov = &v;
897  m.msg_iovlen = 1;
898 
899  /*
900  * Setting the interface is a bit more involved.
901  *
902  * We have to create a "control message", and set that to
903  * define the IPv6 packet information. We could set the
904  * source address if we wanted, but we can safely let the
905  * kernel decide what that should be.
906  */
907  m.msg_control = control_buf;
908  m.msg_controllen = control_buf_len;
909  cmsg = CMSG_FIRSTHDR(&m);
910  INSIST(cmsg != NULL);
911  cmsg->cmsg_level = IPPROTO_IPV6;
912  cmsg->cmsg_type = IPV6_PKTINFO;
913  cmsg->cmsg_len = CMSG_LEN(sizeof(*pktinfo));
914  pktinfo = (struct in6_pktinfo *)CMSG_DATA(cmsg);
915  memset(pktinfo, 0, sizeof(*pktinfo));
916  pktinfo->ipi6_addr = local_address6;
917  pktinfo->ipi6_ifindex = ifindex;
918 
919  result = sendmsg(interface->wfdesc, &m, 0);
920  if (result < 0) {
921  log_error("send_packet6: %m");
922  }
923  return result;
924 }
925 #endif /* DHCPv6 */
926 
927 #ifdef USE_SOCKET_RECEIVE
928 ssize_t receive_packet (interface, buf, len, from, hfrom)
929  struct interface_info *interface;
930  unsigned char *buf;
931  size_t len;
932  struct sockaddr_in *from;
933  struct hardware *hfrom;
934 {
935 #if !(defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO))
936  SOCKLEN_T flen = sizeof *from;
937 #endif
938  int result;
939 
940  /*
941  * The normal Berkeley socket interface doesn't give us any way
942  * to know what hardware interface we received the message on,
943  * but we should at least make sure the structure is emptied.
944  */
945  memset(hfrom, 0, sizeof(*hfrom));
946 
947 #ifdef IGNORE_HOSTUNREACH
948  int retry = 0;
949  do {
950 #endif
951 
952 #if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO)
953  struct msghdr m;
954  struct iovec v;
955  struct cmsghdr *cmsg;
956  struct in_pktinfo *pktinfo;
957  unsigned int ifindex;
958 
959  /*
960  * If necessary allocate space for the control message header.
961  * The space is common between send and receive.
962  */
963  if (control_buf == NULL) {
964  allocate_cmsg_cbuf();
965  if (control_buf == NULL) {
966  log_error("receive_packet: unable to allocate cmsg "
967  "header");
968  return(ENOMEM);
969  }
970  }
971  memset(control_buf, 0, control_buf_len);
972 
973  /*
974  * Initialize our message header structure.
975  */
976  memset(&m, 0, sizeof(m));
977 
978  /*
979  * Point so we can get the from address.
980  */
981  m.msg_name = from;
982  m.msg_namelen = sizeof(*from);
983 
984  /*
985  * Set the data buffer we're receiving. (Using this wacky
986  * "scatter-gather" stuff... but we that doesn't really make
987  * sense for us, so we use a single vector entry.)
988  */
989  v.iov_base = buf;
990  v.iov_len = len;
991  m.msg_iov = &v;
992  m.msg_iovlen = 1;
993 
994  /*
995  * Getting the interface is a bit more involved.
996  *
997  * We set up some space for a "control message". We have
998  * previously asked the kernel to give us packet
999  * information (when we initialized the interface), so we
1000  * should get the interface index from that.
1001  */
1002  m.msg_control = control_buf;
1003  m.msg_controllen = control_buf_len;
1004 
1005  result = recvmsg(interface->rfdesc, &m, 0);
1006 
1007  if (result >= 0) {
1008  /*
1009  * If we did read successfully, then we need to loop
1010  * through the control messages we received and
1011  * find the one with our inteface index.
1012  */
1013  cmsg = CMSG_FIRSTHDR(&m);
1014  while (cmsg != NULL) {
1015  if ((cmsg->cmsg_level == IPPROTO_IP) &&
1016  (cmsg->cmsg_type == IP_PKTINFO)) {
1017  pktinfo = (struct in_pktinfo *)CMSG_DATA(cmsg);
1018  ifindex = pktinfo->ipi_ifindex;
1019  /*
1020  * We pass the ifindex back to the caller
1021  * using the unused hfrom parameter avoiding
1022  * interface changes between sockets and
1023  * the discover code.
1024  */
1025  memcpy(hfrom->hbuf, &ifindex, sizeof(ifindex));
1026  return (result);
1027  }
1028  cmsg = CMSG_NXTHDR(&m, cmsg);
1029  }
1030 
1031  /*
1032  * We didn't find the necessary control message
1033  * flag it as an error
1034  */
1035  result = -1;
1036  errno = EIO;
1037  }
1038 #else
1039  result = recvfrom(interface -> rfdesc, (char *)buf, len, 0,
1040  (struct sockaddr *)from, &flen);
1041 #endif /* IP_PKTINFO ... */
1042 #ifdef IGNORE_HOSTUNREACH
1043  } while (result < 0 &&
1044  (errno == EHOSTUNREACH ||
1045  errno == ECONNREFUSED) &&
1046  retry++ < 10);
1047 #endif
1048  return (result);
1049 }
1050 
1051 #endif /* USE_SOCKET_RECEIVE */
1052 
1053 #ifdef DHCPv6
1054 ssize_t
1055 receive_packet6(struct interface_info *interface,
1056  unsigned char *buf, size_t len,
1057  struct sockaddr_in6 *from, struct in6_addr *to_addr,
1058  unsigned int *if_idx)
1059 {
1060  struct msghdr m;
1061  struct iovec v;
1062  int result;
1063  struct cmsghdr *cmsg;
1064  struct in6_pktinfo *pktinfo;
1065 
1066  /*
1067  * If necessary allocate space for the control message header.
1068  * The space is common between send and receive.
1069  */
1070  if (control_buf == NULL) {
1071  allocate_cmsg_cbuf();
1072  if (control_buf == NULL) {
1073  log_error("receive_packet6: unable to allocate cmsg "
1074  "header");
1075  return(ENOMEM);
1076  }
1077  }
1078  memset(control_buf, 0, control_buf_len);
1079 
1080  /*
1081  * Initialize our message header structure.
1082  */
1083  memset(&m, 0, sizeof(m));
1084 
1085  /*
1086  * Point so we can get the from address.
1087  */
1088  m.msg_name = from;
1089  m.msg_namelen = sizeof(*from);
1090 
1091  /*
1092  * Set the data buffer we're receiving. (Using this wacky
1093  * "scatter-gather" stuff... but we that doesn't really make
1094  * sense for us, so we use a single vector entry.)
1095  */
1096  v.iov_base = buf;
1097  v.iov_len = len;
1098  m.msg_iov = &v;
1099  m.msg_iovlen = 1;
1100 
1101  /*
1102  * Getting the interface is a bit more involved.
1103  *
1104  * We set up some space for a "control message". We have
1105  * previously asked the kernel to give us packet
1106  * information (when we initialized the interface), so we
1107  * should get the destination address from that.
1108  */
1109  m.msg_control = control_buf;
1110  m.msg_controllen = control_buf_len;
1111 
1112  result = recvmsg(interface->rfdesc, &m, 0);
1113 
1114  if (result >= 0) {
1115  /*
1116  * If we did read successfully, then we need to loop
1117  * through the control messages we received and
1118  * find the one with our destination address.
1119  */
1120  cmsg = CMSG_FIRSTHDR(&m);
1121  while (cmsg != NULL) {
1122  if ((cmsg->cmsg_level == IPPROTO_IPV6) &&
1123  (cmsg->cmsg_type == IPV6_PKTINFO)) {
1124  pktinfo = (struct in6_pktinfo *)CMSG_DATA(cmsg);
1125  *to_addr = pktinfo->ipi6_addr;
1126  *if_idx = pktinfo->ipi6_ifindex;
1127 
1128  return (result);
1129  }
1130  cmsg = CMSG_NXTHDR(&m, cmsg);
1131  }
1132 
1133  /*
1134  * We didn't find the necessary control message
1135  * flag is as an error
1136  */
1137  result = -1;
1138  errno = EIO;
1139  }
1140 
1141  return (result);
1142 }
1143 #endif /* DHCPv6 */
1144 
1145 #if defined (USE_SOCKET_FALLBACK)
1146 /* This just reads in a packet and silently discards it. */
1147 
1148 isc_result_t fallback_discard (object)
1149  omapi_object_t *object;
1150 {
1151  char buf [1540];
1152  struct sockaddr_in from;
1153  SOCKLEN_T flen = sizeof from;
1154  int status;
1155  struct interface_info *interface;
1156 
1157  if (object -> type != dhcp_type_interface)
1158  return DHCP_R_INVALIDARG;
1159  interface = (struct interface_info *)object;
1160 
1161  status = recvfrom (interface -> wfdesc, buf, sizeof buf, 0,
1162  (struct sockaddr *)&from, &flen);
1163 #if defined (DEBUG)
1164  /* Only report fallback discard errors if we're debugging. */
1165  if (status < 0) {
1166  log_error ("fallback_discard: %m");
1167  return ISC_R_UNEXPECTED;
1168  }
1169 #else
1170  /* ignore the fact that status value is never used */
1171  IGNORE_UNUSED(status);
1172 #endif
1173  return ISC_R_SUCCESS;
1174 }
1175 #endif /* USE_SOCKET_FALLBACK */
1176 
1177 #if defined (USE_SOCKET_SEND)
1179  struct interface_info *ip;
1180 {
1181  return 0;
1182 }
1183 
1185  struct interface_info *ip;
1186 {
1187 #if defined (SOCKET_CAN_RECEIVE_UNICAST_UNCONFIGURED)
1188  return 1;
1189 #else
1190  return 0;
1191 #endif
1192 }
1193 
1195  struct interface_info *ip;
1196 {
1197 #if defined(SO_BINDTODEVICE) || \
1198  (defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && \
1199  defined(USE_V4_PKTINFO))
1200  return(1);
1201 #else
1202  return(0);
1203 #endif
1204 }
1205 
1206 /* If we have SO_BINDTODEVICE, set up a fallback interface; otherwise,
1207  do not. */
1208 
1209 void maybe_setup_fallback ()
1210 {
1211 #if defined (USE_SOCKET_FALLBACK)
1212  isc_result_t status;
1213  struct interface_info *fbi = (struct interface_info *)0;
1214  if (setup_fallback (&fbi, MDL)) {
1215  fbi -> wfdesc = if_register_socket (fbi, AF_INET, 0, NULL);
1216  fbi -> rfdesc = fbi -> wfdesc;
1217  log_info ("Sending on Socket/%s%s%s",
1218  fbi -> name,
1219  (fbi -> shared_network ? "/" : ""),
1220  (fbi -> shared_network ?
1221  fbi -> shared_network -> name : ""));
1222 
1223  status = omapi_register_io_object ((omapi_object_t *)fbi,
1224  if_readsocket, 0,
1225  fallback_discard, 0, 0);
1226  if (status != ISC_R_SUCCESS)
1227  log_fatal ("Can't register I/O handle for %s: %s",
1228  fbi -> name, isc_result_totext (status));
1229  interface_dereference (&fbi, MDL);
1230  }
1231 #endif
1232 }
1233 
1234 
1235 #if defined(sun) && defined(USE_V4_PKTINFO)
1236 /* This code assumes the existence of SIOCGLIFHWADDR */
1237 void
1238 get_hw_addr(const char *name, struct hardware *hw) {
1239  struct sockaddr_dl *dladdrp;
1240  int sock, i;
1241  struct lifreq lifr;
1242 
1243  memset(&lifr, 0, sizeof (lifr));
1244  (void) strlcpy(lifr.lifr_name, name, sizeof (lifr.lifr_name));
1245  /*
1246  * Check if the interface is a virtual or IPMP interface - in those
1247  * cases it has no hw address, so generate a random one.
1248  */
1249  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ||
1250  ioctl(sock, SIOCGLIFFLAGS, &lifr) < 0) {
1251  if (sock != -1)
1252  (void) close(sock);
1253 
1254 #ifdef DHCPv6
1255  /*
1256  * If approrpriate try this with an IPv6 socket
1257  */
1258  if ((sock = socket(AF_INET6, SOCK_DGRAM, 0)) >= 0 &&
1259  ioctl(sock, SIOCGLIFFLAGS, &lifr) >= 0) {
1260  goto flag_check;
1261  }
1262  if (sock != -1)
1263  (void) close(sock);
1264 #endif
1265  log_fatal("Couldn't get interface flags for %s: %m", name);
1266 
1267  }
1268 
1269  flag_check:
1270  if (lifr.lifr_flags & (IFF_VIRTUAL|IFF_IPMP)) {
1271  hw->hlen = sizeof (hw->hbuf);
1272  srandom((long)gethrtime());
1273 
1274  hw->hbuf[0] = HTYPE_IPMP;
1275  for (i = 1; i < hw->hlen; ++i) {
1276  hw->hbuf[i] = random() % 256;
1277  }
1278 
1279  if (sock != -1)
1280  (void) close(sock);
1281  return;
1282  }
1283 
1284  if (ioctl(sock, SIOCGLIFHWADDR, &lifr) < 0)
1285  log_fatal("Couldn't get interface hardware address for %s: %m",
1286  name);
1287  dladdrp = (struct sockaddr_dl *)&lifr.lifr_addr;
1288  hw->hlen = dladdrp->sdl_alen+1;
1289  switch (dladdrp->sdl_type) {
1290  case DL_CSMACD: /* IEEE 802.3 */
1291  case DL_ETHER:
1292  hw->hbuf[0] = HTYPE_ETHER;
1293  break;
1294  case DL_TPR:
1295  hw->hbuf[0] = HTYPE_IEEE802;
1296  break;
1297  case DL_FDDI:
1298  hw->hbuf[0] = HTYPE_FDDI;
1299  break;
1300  case DL_IB:
1301  hw->hbuf[0] = HTYPE_INFINIBAND;
1302  break;
1303  default:
1304  log_fatal("%s: unsupported DLPI MAC type %lu", name,
1305  (unsigned long)dladdrp->sdl_type);
1306  }
1307 
1308  memcpy(hw->hbuf+1, LLADDR(dladdrp), hw->hlen-1);
1309 
1310  if (sock != -1)
1311  (void) close(sock);
1312 }
1313 #endif /* defined(sun) */
1314 
1315 #endif /* USE_SOCKET_SEND */
#define IGNORE_UNUSED(x)
Definition: cdefs.h:67
u_int16_t local_port
Definition: dhclient.c:96
#define All_DHCP_Relay_Agents_and_Servers
Definition: dhcp6.h:189
#define All_DHCP_Servers
Definition: dhcp6.h:190
#define HTYPE_IPMP
Definition: dhcp.h:79
#define HTYPE_IEEE802
Definition: dhcp.h:76
#define HTYPE_FDDI
Definition: dhcp.h:77
#define HTYPE_ETHER
Definition: dhcp.h:75
#define HTYPE_INFINIBAND
Definition: dhcp.h:78
void if_reinitialize_receive(struct interface_info *)
void maybe_setup_fallback(void)
#define INTERFACE_UPSTREAM
Definition: dhcpd.h:1423
#define INTERFACE_DOWNSTREAM
Definition: dhcpd.h:1422
int supports_multiple_interfaces(struct interface_info *)
void if_deregister_send(struct interface_info *)
#define INTERFACE_STREAMS
Definition: dhcpd.h:1424
void if_reinitialize_send(struct interface_info *)
isc_result_t fallback_discard(omapi_object_t *)
ssize_t send_packet(struct interface_info *, struct packet *, struct dhcp_packet *, size_t, struct in_addr, struct sockaddr_in *, struct hardware *)
void if_register_linklocal6(struct interface_info *info)
void if_deregister6(struct interface_info *info)
int can_receive_unicast_unconfigured(struct interface_info *)
ssize_t receive_packet(struct interface_info *, unsigned char *, size_t, struct sockaddr_in *, struct hardware *)
void get_hw_addr(struct interface_info *info)
struct in6_addr local_address6
void if_register_receive(struct interface_info *)
void if_register6(struct interface_info *info, int do_multicast)
int bind_local_address6
int if_register_socket(struct interface_info *, int, int *, struct in6_addr *)
ssize_t send_packet6(struct interface_info *, const unsigned char *, size_t, struct sockaddr_in6 *)
void set_multicast_hop_limit(struct interface_info *info, int hop_limit)
int can_unicast_without_arp(struct interface_info *)
void if_deregister_receive(struct interface_info *)
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)
void if_register_send(struct interface_info *)
u_int16_t relay_port
Definition: discover.c:47
int local_family
Definition: discover.c:56
int setup_fallback(struct interface_info **fp, const char *file, int line)
Definition: discover.c:1056
int quiet_interface_discovery
Definition: discover.c:44
struct in_addr local_address
Definition: discover.c:57
#define SIOCGLIFFLAGS
Definition: discover.c:198
omapi_object_type_t * dhcp_type_interface
Definition: discover.c:80
int if_readsocket(omapi_object_t *h)
Definition: discover.c:1045
#define ISC_R_SUCCESS
#define MDL
Definition: omapip.h:567
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:198
void * dmalloc(size_t, const char *, int)
Definition: alloc.c:57
int log_error(const char *,...) __attribute__((__format__(__printf__
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int int log_info(const char *,...) __attribute__((__format__(__printf__
#define SOCKLEN_T
Definition: osdep.h:280
#define DHCP_R_INVALIDARG
Definition: result.h:49
u_int8_t hlen
Definition: dhcpd.h:492
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
Definition: dhcpd.h:493
char name[IFNAMSIZ]
Definition: dhcpd.h:1403
struct in6_addr * v6addresses
Definition: dhcpd.h:1388
struct ifreq * ifp
Definition: dhcpd.h:1414
int address_count
Definition: dhcpd.h:1386
struct shared_network * shared_network
Definition: dhcpd.h:1379
u_int32_t flags
Definition: dhcpd.h:1418
struct in_addr * addresses
Definition: dhcpd.h:1383
int v6address_count
Definition: dhcpd.h:1390
Definition: ip.h:47
Definition: dhcpd.h:405
char * name
Definition: dhcpd.h:1056