32#define IF_LINE_LENGTH 1024
112 log_fatal (
"Can't register interface object type: %s",
113 isc_result_totext (status));
162#if defined(SIOCGLIFCONF) && defined(SIOCGLIFNUM) && defined(SIOCGLIFFLAGS)
167#ifdef ISC_PLATFORM_HAVEIF_LADDRCONF
168# define lifc_len iflc_len
169# define lifc_buf iflc_buf
170# define lifc_req iflc_req
171# define LIFCONF if_laddrconf
173# define ISC_HAVE_LIFC_FAMILY 1
174# define ISC_HAVE_LIFC_FLAGS 1
175# define LIFCONF lifconf
178#ifdef ISC_PLATFORM_HAVEIF_LADDRREQ
179# define lifr_addr iflr_addr
180# define lifr_name iflr_name
181# define lifr_dstaddr iflr_dstaddr
182# define lifr_flags iflr_flags
183# define sockaddr_storage sockaddr_ext
184# define ss_family sa_family
185# define LIFREQ if_laddrreq
187# define LIFREQ lifreq
191# if defined(LIFNAMSIZ)
192# define IF_NAMESIZE LIFNAMSIZ
193# elif defined(IFNAMSIZ)
194# define IF_NAMESIZE IFNAMSIZ
196# define IF_NAMESIZE 16
199#elif !defined(__linux) && !defined(HAVE_IFADDRS_H)
200# define SIOCGLIFCONF SIOCGIFCONF
201# define SIOCGLIFFLAGS SIOCGIFFLAGS
203# define LIFCONF ifconf
204# define lifr_name ifr_name
205# define lifr_addr ifr_addr
206# define lifr_flags ifr_flags
207# define lifc_len ifc_len
208# define lifc_buf ifc_buf
209# define lifc_req ifc_req
211# define ss_family __ss_family
215#if defined(SIOCGLIFCONF) && defined(SIOCGLIFFLAGS)
252#ifdef ISC_PLATFORM_HAVELIFNUM
253 struct lifnum lifnum;
259 if (ifaces->
sock < 0) {
260 log_error(
"Error creating socket to list interfaces; %m");
264 memset(&lifnum, 0,
sizeof(lifnum));
265#ifdef ISC_PLATFORM_HAVELIFNUM
266 lifnum.lifn_family = AF_UNSPEC;
269 if (ioctl(ifaces->
sock, SIOCGLIFNUM, &lifnum) < 0) {
270 log_error(
"Error finding total number of interfaces; %m");
276#ifdef ISC_PLATFORM_HAVELIFNUM
277 ifaces->
num = lifnum.lifn_count;
279 ifaces->
num = lifnum;
285 memset(&ifaces->
conf, 0,
sizeof(ifaces->
conf));
286#ifdef ISC_HAVE_LIFC_FAMILY
287 ifaces->
conf.lifc_family = AF_UNSPEC;
291 if (ifaces->
conf.lifc_buf == NULL) {
292 log_fatal(
"Out of memory getting interface list.");
296 log_error(
"Error getting interfaces configuration list; %m");
319#if defined(sun) || defined(__linux)
327 if (ifaces->
next >= ifaces->
num) {
332 p = ifaces->
conf.lifc_req;
335 if (strlen(p->lifr_name) >=
sizeof(info->
name)) {
337 log_error(
"Interface name '%s' too long", p->lifr_name);
348 strncpy(info->
name, p->lifr_name,
sizeof(info->
name) - 1);
349 memcpy(&info->
addr, &p->lifr_addr,
sizeof(p->lifr_addr));
351#if defined(sun) || defined(__linux)
353 s = strchr(info->
name,
':');
361 (strncmp(info->
name,
"dummy", 5) == 0));
363 memset(&tmp, 0,
sizeof(tmp));
364 strncpy(tmp.lifr_name, info->
name,
sizeof(tmp.lifr_name) - 1);
366 log_error(
"Error getting interface flags for '%s'; %m",
371 info->
flags = tmp.lifr_flags;
406 struct ifaddrs *head;
407 struct ifaddrs *
next;
415 struct sockaddr_storage
addr;
426 if (getifaddrs(&ifaces->head) != 0) {
427 log_error(
"Error getting interfaces; %m");
430 ifaces->
next = ifaces->head;
444 if (ifaces->
next == NULL) {
448 if (strlen(ifaces->
next->ifa_name) >=
sizeof(info->
name)) {
449 log_error(
"Interface name '%s' too long",
450 ifaces->
next->ifa_name);
455 strncpy(info->
name, ifaces->
next->ifa_name,
sizeof(info->
name) - 1);
456 memset(&info->
addr, 0 ,
sizeof(info->
addr));
461 if (ifaces->
next->ifa_addr != NULL) {
464 if (ifaces->
next->ifa_addr->sa_family == AF_INET)
465 sa_len =
sizeof(
struct sockaddr_in);
466 else if (ifaces->
next->ifa_addr->sa_family == AF_INET6)
467 sa_len =
sizeof(
struct sockaddr_in6);
469 sa_len = ifaces->
next->ifa_addr->sa_len;
471 memcpy(&info->
addr, ifaces->
next->ifa_addr, sa_len);
474 ifaces->
next = ifaces->
next->ifa_next;
484 freeifaddrs(ifaces->head);
493 const struct in_addr *addr) {
501 log_fatal(
"Out of memory saving IPv4 address "
511 tmp =
dmalloc(new_max *
sizeof(
struct in_addr),
MDL);
513 log_fatal(
"Out of memory saving IPv4 address "
530 const struct in6_addr *addr) {
539 log_fatal(
"Out of memory saving IPv6 address "
545 struct in6_addr *tmp;
549 tmp =
dmalloc(new_max *
sizeof(
struct in6_addr),
MDL);
551 log_fatal(
"Out of memory saving IPv6 address "
580 char abuf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
596 log_fatal(
"Can't get list of interfaces.");
630 !(info.
flags & IFF_BROADCAST)) ||
633 !(info.
flags & IFF_MULTICAST)) ||
635 info.
flags & IFF_LOOPBACK ||
636 info.
flags & IFF_POINTOPOINT) && !tmp) ||
637 (!(info.
flags & IFF_UP) &&
644 status = interface_allocate(&tmp,
MDL);
646 log_fatal(
"Error allocating interface %s: %s",
647 info.
name, isc_result_totext(status));
653 interface_dereference(&tmp,
MDL);
660 (*dhcp_interface_discovery_hook)(tmp);
663 if ((info.
addr.ss_family == AF_INET) &&
665 struct sockaddr_in *a = (
struct sockaddr_in*)&info.
addr;
669 if (a->sin_addr.s_addr == htonl(INADDR_LOOPBACK) &&
677 if (a->sin_addr.s_addr != htonl(INADDR_ANY))
684 memcpy(addr.
iabuf, &a->sin_addr.s_addr, addr.
len);
686 (*dhcp_interface_setup_hook)(tmp, &addr);
690 else if ((info.
addr.ss_family == AF_INET6) &&
692 struct sockaddr_in6 *a =
693 (
struct sockaddr_in6*)&info.
addr;
697 if (IN6_IS_ADDR_LOOPBACK(&a->sin6_addr) &&
705 if (IN6_IS_ADDR_UNSPECIFIED(&a->sin6_addr))
708 add_ipv6_addr_to_interface(tmp, &a->sin6_addr);
712 memcpy(addr.
iabuf, &a->sin6_addr, addr.
len);
714 (*dhcp_interface_setup_hook)(tmp, &addr);
721 log_fatal(
"Error getting interface information.");
732 if (tmp->
ifp == NULL) {
735 tif = (
struct ifreq *)
dmalloc(
sizeof(
struct ifreq),
739 strcpy(tif->ifr_name, tmp->
name);
752 tmp = last = next = NULL;
757 interface_dereference (&next,
MDL);
759 interface_reference (&next, tmp -> next,
MDL);
762 interface_dereference(&tmp,
MDL);
764 interface_reference(&tmp, next,
MDL);
778 log_fatal (
"%s: not found", tmp -> name);
786 interface_dereference (&last -> next,
MDL);
788 interface_reference (&last -> next,
792 interface_dereference (&tmp -> next,
MDL);
797 interface_reference (&tmp -> next,
802 interface_dereference (&tmp,
MDL);
804 interface_reference (&tmp, next,
MDL);
813 log_info(
"No subnet declaration for %s (%s).",
816 "no IPv4 addresses" :
826 strcpy(abuf,
"no IPv6 addresses");
828 log_info(
"No subnet6 declaration for %s (%s).",
834 log_info (
"** Ignoring requests on %s. %s",
835 tmp -> name,
"If this is not what");
836 log_info (
" you want, please write %s",
839 "a subnet6 declaration" :
841 "a subnet declaration");
842 log_info (
" in your dhcpd.conf file %s",
843 "for the network segment");
846 tmp -> name,
"is attached. **");
853 "subnet6 declaration for this" :
855 "subnet declaration for this");
856 log_error (
"subnet. You cannot prevent %s",
858 log_error (
"from listening on this subnet %s",
860 log_fatal (
"operating system does not %s.",
861 "support this capability");
886 "address", tmp->
name);
930 if ((tmp -> rfdesc >= 0) &&
931 (fcntl (tmp -> rfdesc, F_SETFD, 1) < 0))
932 log_error (
"Can't set close-on-exec on %s: %m",
934 if ((tmp -> wfdesc != tmp -> rfdesc) &&
935 (tmp -> wfdesc >= 0) &&
936 (fcntl (tmp -> wfdesc, F_SETFD, 1) < 0))
937 log_error (
"Can't set close-on-exec on %s: %m",
941 interface_dereference (&tmp,
MDL);
943 interface_reference (&tmp, next,
MDL);
952 for (tmp =
interfaces; tmp; tmp = tmp -> next) {
956 if (tmp -> rfdesc == -1)
962#define UPSTREAM(ifp) \
963 ((ifp->flags & INTERFACE_STREAMS) == INTERFACE_UPSTREAM)
964#define DOWNSTREAM(ifp) \
965 ((ifp->flags & INTERFACE_STREAMS) == INTERFACE_DOWNSTREAM)
979 if (updone && UPSTREAM(tmp))
981 if (downdone && DOWNSTREAM(tmp))
1005 log_fatal (
"Can't register I/O handle for %s: %s",
1006 tmp -> name, isc_result_totext (status));
1017#
if defined(RELAY_PORT)
1018 && ((
relay_port == 0) || (updone && downdone))
1027 log_fatal (
"Not configured to listen on any interfaces!");
1036#if defined (F_SETFD)
1039 log_error (
"Can't set close-on-exec on fallback: %m");
1042 log_error (
"Can't set close-on-exec on fallback: %m");
1061 isc_result_t status;
1065 log_fatal (
"Error allocating fallback interface: %s",
1066 isc_result_totext (status));
1096 struct sockaddr_in from;
1101 unsigned char packbuf [4095];
1116 return ISC_R_UNEXPECTED;
1119 return ISC_R_UNEXPECTED;
1131 return ISC_R_UNEXPECTED;
1133#if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO)
1136 unsigned int ifindex;
1138 memcpy(&ifindex, hfrom.
hbuf, sizeof (ifindex));
1145 while ((
ip != NULL) && (if_nametoindex(
ip->name) != ifindex))
1148 return ISC_R_NOTFOUND;
1154 memcpy (ifrom.
iabuf, &from.sin_addr, ifrom.
len);
1156 (*bootp_packet_handler) (
ip, &u.packet, (unsigned)result,
1157 from.sin_port, ifrom, &hfrom);
1170 struct sockaddr_in6 from;
1177 unsigned int if_idx = 0;
1185 &from, &to, &if_idx);
1187 log_error(
"receive_packet6() failed on %s: %m",
ip->name);
1188 return ISC_R_UNEXPECTED;
1193 return ISC_R_NOTFOUND;
1199 if (IN6_IS_ADDR_MULTICAST(&to)) {
1206 memcpy(ifrom.iabuf, &from.sin6_addr, ifrom.len);
1210 while ((
ip != NULL) && (if_nametoindex(
ip->name) != if_idx))
1214 return ISC_R_NOTFOUND;
1216 (*dhcpv6_packet_handler)(
ip, buf,
1217 result, from.sin6_port,
1218 &ifrom, is_unicast);
1231 isc_result_t status;
1240 value -> u.buffer.len <
sizeof interface -> name) {
1241 memcpy (interface -> name,
1242 value -> u.buffer.value,
1243 value -> u.buffer.len);
1251 if (h -> inner && h -> inner -> type -> set_value) {
1252 status = ((*(h -> inner -> type -> set_value))
1253 (h -> inner, id, name,
value));
1258 return ISC_R_NOTFOUND;
1279 if (interface -> ifp) {
1281 interface -> ifp = 0;
1283 if (interface -> next)
1284 interface_dereference (&interface -> next,
file,
line);
1285 if (interface -> rbuf) {
1287 interface -> rbuf = (
unsigned char *)0;
1289 if (interface -> client)
1300 const char *
name, va_list ap)
1303 isc_result_t status;
1311 if (!strcmp (name,
"update")) {
1313 if (
ip == interface)
1319 if (
ip == interface)
1326 if (h -> inner && h -> inner -> type -> signal_handler) {
1327 status = ((*(h -> inner -> type -> signal_handler))
1328 (h -> inner, name, ap));
1332 return ISC_R_NOTFOUND;
1340 isc_result_t status;
1359 if (h -> inner && h -> inner -> type -> stuff_values) {
1360 status = ((*(h -> inner -> type -> stuff_values))
1361 (c, id, h -> inner));
1374 isc_result_t status;
1402 interface = interface -> next) {
1403 s = memchr (interface -> name, 0, IFNAMSIZ);
1405 len = s - &
interface -> name [0];
1408 if ((tv ->
value -> u.buffer.len == len &&
1409 !memcmp (interface -> name,
1410 (
char *)tv ->
value -> u.buffer.value,
1416 interface;
interface = interface -> next) {
1417 s = memchr (interface -> name, 0, IFNAMSIZ);
1419 len = s - &
interface -> name [0];
1422 if ((tv ->
value -> u.buffer.len == len &&
1423 !memcmp (interface -> name,
1425 tv ->
value -> u.buffer.value,
1435 }
else if (!interface) {
1438 return ISC_R_NOTFOUND;
1457 isc_result_t status;
1460 status = interface_allocate (&hp,
MDL);
1465 interface_dereference (&hp,
MDL);
1479 if (
ip == interface) {
1481 interface_dereference (&last -> next,
MDL);
1483 interface_reference (&last -> next,
1492 interface_dereference (&
ip -> next,
MDL);
1498 return ISC_R_NOTFOUND;
1502 interface_reference (&interface -> next,
1510 (*dhcp_interface_shutdown_hook) (interface);
1537 if (tptr ->
index == -1) {
1549 log_error (
"interface_stash: allocation failed ");
1569#if defined (TRACING)
1582 interface_reference (&tmp ->
next,
void trace_interface_input(trace_type_t *, unsigned, char *)
void trace_interface_register(trace_type_t *, struct interface_info *)
void trace_outpacket_input(trace_type_t *, unsigned, char *)
void trace_inpacket_input(trace_type_t *, unsigned, char *)
void trace_interface_stop(trace_type_t *)
void trace_outpacket_stop(trace_type_t *)
void trace_inpacket_stop(trace_type_t *)
#define DHCP_FIXED_NON_UDP
void if_reinitialize_receive(struct interface_info *)
void maybe_setup_fallback(void)
#define INTERFACE_RUNNING
#define DISCOVER_REQUESTED
trace_type_t * inpacket_trace
#define INTERFACE_REQUESTED
void interface_trace_setup(void)
int supports_multiple_interfaces(struct interface_info *)
void if_deregister_send(struct interface_info *)
trace_type_t * outpacket_trace
#define DISCOVER_SERVER46
#define INTERFACE_STREAMS
void try_hw_addr(struct interface_info *info)
void if_reinitialize_send(struct interface_info *)
void if_register_linklocal6(struct interface_info *info)
void if_deregister6(struct interface_info *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)
void(* dhcpv6_packet_handler)(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
struct in6_addr local_address6
void if_register_receive(struct interface_info *)
void if_register6(struct interface_info *info, int do_multicast)
#define INTERFACE_AUTOMATIC
#define DISCOVER_UNCONFIGURED
void if_deregister_receive(struct interface_info *)
trace_type_t * interface_trace
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 *)
isc_result_t got_one_v6(omapi_object_t *)
isc_result_t dhcp_interface_get_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value)
void end_iface_scan(struct iface_conf_list *ifaces)
struct interface_info * interfaces
isc_result_t dhcp_interface_create(omapi_object_t **lp, omapi_object_t *id)
isc_result_t interface_initialize(omapi_object_t *ipo, const char *file, int line)
struct interface_info * fallback_interface
int setup_fallback(struct interface_info **fp, const char *file, int line)
struct in_addr limited_broadcast
void discover_interfaces(int state)
void add_ipv4_addr_to_interface(struct interface_info *iface, const struct in_addr *addr)
int begin_iface_scan(struct iface_conf_list *ifaces)
isc_result_t dhcp_interface_destroy(omapi_object_t *h, const char *file, int line)
int(* dhcp_interface_discovery_hook)(struct interface_info *)
int quiet_interface_discovery
int(* dhcp_interface_setup_hook)(struct interface_info *, struct iaddr *)
isc_result_t interface_setup()
void reinitialize_interfaces()
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)
struct interface_info ** interface_vector
isc_result_t dhcp_interface_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
isc_result_t dhcp_interface_lookup(omapi_object_t **ip, omapi_object_t *id, omapi_object_t *ref)
void(* bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, unsigned, unsigned int, struct iaddr, struct hardware *)
void interface_stash(struct interface_info *tptr)
struct in_addr local_address
int(* dhcp_interface_shutdown_hook)(struct interface_info *)
struct interface_info * dummy_interfaces
void interface_snorf(struct interface_info *tmp, int ir)
int interfaces_invalidated
omapi_object_type_t * dhcp_type_interface
isc_result_t got_one(omapi_object_t *h)
int if_readsocket(omapi_object_t *h)
int next_iface(struct iface_info *info, int *err, struct iface_conf_list *ifaces)
isc_result_t dhcp_interface_signal_handler(omapi_object_t *h, const char *name, va_list ap)
isc_result_t dhcp_interface_remove(omapi_object_t *lp, omapi_object_t *id)
isc_result_t(* dhcp_interface_startup_hook)(struct interface_info *)
#define ISC_R_NOTIMPLEMENTED
isc_result_t omapi_value_dereference(omapi_value_t **, const char *, int)
isc_result_t omapi_connection_put_string(omapi_object_t *, const char *)
struct __omapi_object_type_t omapi_object_type_t
#define OMAPI_OBJECT_ALLOC(name, stype, type)
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 *))
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
isc_result_t omapi_unregister_io_object(omapi_object_t *)
struct __omapi_object omapi_object_t
isc_result_t omapi_handle_td_lookup(omapi_object_t **, omapi_typed_data_t *)
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)
isc_result_t omapi_object_reference(omapi_object_t **, omapi_object_t *, const char *, int)
int omapi_ds_strcmp(omapi_data_string_t *, const char *)
void * dmalloc(size_t, const char *, int)
void dfree(void *, const char *, int)
isc_result_t omapi_get_value_str(omapi_object_t *, omapi_object_t *, const char *, omapi_value_t **)
isc_result_t omapi_connection_put_name(omapi_object_t *, const char *)
int log_error(const char *,...) __attribute__((__format__(__printf__
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int int log_info(const char *,...) __attribute__((__format__(__printf__
#define DHCP_R_INVALIDARG
#define DHCP_R_KEYCONFLICT
struct interface_info * interface
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
struct sockaddr_storage addr
struct interface_info * next
struct in6_addr * v6addresses
struct shared_network * shared_network
struct in_addr * addresses
struct iaddr interface_address
trace_type_t * trace_type_register(const char *, void *, void(*)(trace_type_t *, unsigned, char *), void(*)(trace_type_t *), const char *, int)
struct trace_type trace_type_t