32 #define IF_LINE_LENGTH 1024 35 #include <sys/ioctl.h> 99 if (status != ISC_R_SUCCESS)
100 log_fatal (
"Can't register interface object type: %s",
101 isc_result_totext (status));
106 #if defined (TRACING) 126 return ISC_R_SUCCESS;
150 #if defined(SIOCGLIFCONF) && defined(SIOCGLIFNUM) && defined(SIOCGLIFFLAGS) 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 161 # define ISC_HAVE_LIFC_FAMILY 1 162 # define ISC_HAVE_LIFC_FLAGS 1 163 # define LIFCONF lifconf 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 175 # define LIFREQ lifreq 179 # if defined(LIFNAMSIZ) 180 # define IF_NAMESIZE LIFNAMSIZ 181 # elif defined(IFNAMSIZ) 182 # define IF_NAMESIZE IFNAMSIZ 184 # define IF_NAMESIZE 16 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 199 # define ss_family __ss_family 203 #if defined(SIOCGLIFCONF) && defined(SIOCGLIFFLAGS) 240 #ifdef ISC_PLATFORM_HAVELIFNUM 241 struct lifnum lifnum;
247 if (ifaces->
sock < 0) {
248 log_error(
"Error creating socket to list interfaces; %m");
252 memset(&lifnum, 0,
sizeof(lifnum));
253 #ifdef ISC_PLATFORM_HAVELIFNUM 254 lifnum.lifn_family = AF_UNSPEC;
257 if (ioctl(ifaces->
sock, SIOCGLIFNUM, &lifnum) < 0) {
258 log_error(
"Error finding total number of interfaces; %m");
264 #ifdef ISC_PLATFORM_HAVELIFNUM 265 ifaces->
num = lifnum.lifn_count;
267 ifaces->
num = lifnum;
273 memset(&ifaces->
conf, 0,
sizeof(ifaces->
conf));
274 #ifdef ISC_HAVE_LIFC_FAMILY 275 ifaces->
conf.lifc_family = AF_UNSPEC;
279 if (ifaces->
conf.lifc_buf == NULL) {
280 log_fatal(
"Out of memory getting interface list.");
284 log_error(
"Error getting interfaces configuration list; %m");
306 isc_boolean_t foundif;
307 #if defined(sun) || defined(__linux) 315 if (ifaces->
next >= ifaces->
num) {
320 p = ifaces->
conf.lifc_req;
323 if (strlen(p->lifr_name) >=
sizeof(info->
name)) {
325 log_error(
"Interface name '%s' too long", p->lifr_name);
336 strncpy(info->
name, p->lifr_name,
sizeof(info->
name) - 1);
337 memcpy(&info->
addr, &p->lifr_addr,
sizeof(p->lifr_addr));
339 #if defined(sun) || defined(__linux) 341 s = strchr(info->
name,
':');
348 }
while ((foundif == ISC_FALSE) ||
349 (strncmp(info->
name,
"dummy", 5) == 0));
351 memset(&tmp, 0,
sizeof(tmp));
352 strncpy(tmp.lifr_name, info->
name,
sizeof(tmp.lifr_name) - 1);
354 log_error(
"Error getting interface flags for '%s'; %m",
359 info->
flags = tmp.lifr_flags;
394 struct ifaddrs *head;
395 struct ifaddrs *
next;
403 struct sockaddr_storage
addr;
414 if (getifaddrs(&ifaces->head) != 0) {
415 log_error(
"Error getting interfaces; %m");
418 ifaces->
next = ifaces->head;
432 if (ifaces->
next == NULL) {
436 if (strlen(ifaces->
next->ifa_name) >=
sizeof(info->
name)) {
437 log_error(
"Interface name '%s' too long",
438 ifaces->
next->ifa_name);
443 strncpy(info->
name, ifaces->
next->ifa_name,
sizeof(info->
name) - 1);
444 memset(&info->
addr, 0 ,
sizeof(info->
addr));
449 if (ifaces->
next->ifa_addr != NULL) {
452 if (ifaces->
next->ifa_addr->sa_family == AF_INET)
453 sa_len =
sizeof(
struct sockaddr_in);
454 else if (ifaces->
next->ifa_addr->sa_family == AF_INET6)
455 sa_len =
sizeof(
struct sockaddr_in6);
457 sa_len = ifaces->
next->ifa_addr->sa_len;
459 memcpy(&info->
addr, ifaces->
next->ifa_addr, sa_len);
462 ifaces->
next = ifaces->
next->ifa_next;
472 freeifaddrs(ifaces->head);
481 const struct in_addr *addr) {
489 log_fatal(
"Out of memory saving IPv4 address " 499 tmp =
dmalloc(new_max *
sizeof(
struct in_addr),
MDL);
501 log_fatal(
"Out of memory saving IPv4 address " 518 const struct in6_addr *addr) {
527 log_fatal(
"Out of memory saving IPv6 address " 533 struct in6_addr *tmp;
537 tmp =
dmalloc(new_max *
sizeof(
struct in6_addr),
MDL);
539 log_fatal(
"Out of memory saving IPv6 address " 568 char abuf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
580 log_fatal(
"Can't get list of interfaces.");
614 !(info.
flags & IFF_BROADCAST)) ||
617 !(info.
flags & IFF_MULTICAST)) ||
619 info.
flags & IFF_LOOPBACK ||
620 info.
flags & IFF_POINTOPOINT) && !tmp) ||
621 (!(info.
flags & IFF_UP) &&
628 status = interface_allocate(&tmp,
MDL);
629 if (status != ISC_R_SUCCESS) {
630 log_fatal(
"Error allocating interface %s: %s",
631 info.
name, isc_result_totext(status));
635 interface_dereference(&tmp,
MDL);
640 (*dhcp_interface_discovery_hook)(tmp);
643 if ((info.
addr.ss_family == AF_INET) &&
645 struct sockaddr_in *a = (
struct sockaddr_in*)&info.
addr;
649 if (a->sin_addr.s_addr == htonl(INADDR_LOOPBACK) &&
657 if (a->sin_addr.s_addr != htonl(INADDR_ANY))
664 memcpy(addr.iabuf, &a->sin_addr.s_addr, addr.len);
666 (*dhcp_interface_setup_hook)(tmp, &addr);
670 else if ((info.
addr.ss_family == AF_INET6) &&
672 struct sockaddr_in6 *a =
673 (
struct sockaddr_in6*)&info.
addr;
677 if (IN6_IS_ADDR_LOOPBACK(&a->sin6_addr) &&
685 if (IN6_IS_ADDR_UNSPECIFIED(&a->sin6_addr))
688 add_ipv6_addr_to_interface(tmp, &a->sin6_addr);
692 memcpy(addr.iabuf, &a->sin6_addr, addr.len);
694 (*dhcp_interface_setup_hook)(tmp, &addr);
701 log_fatal(
"Error getting interface information.");
712 if (tmp->
ifp == NULL) {
715 tif = (
struct ifreq *)
dmalloc(
sizeof(
struct ifreq),
719 strcpy(tif->ifr_name, tmp->
name);
732 tmp = last = next = NULL;
737 interface_dereference (&next,
MDL);
739 interface_reference (&next, tmp -> next,
MDL);
742 interface_dereference(&tmp,
MDL);
744 interface_reference(&tmp, next,
MDL);
758 log_fatal (
"%s: not found", tmp -> name);
766 interface_dereference (&last -> next,
MDL);
768 interface_reference (&last -> next,
772 interface_dereference (&tmp -> next,
MDL);
777 interface_reference (&tmp -> next,
782 interface_dereference (&tmp,
MDL);
784 interface_reference (&tmp, next,
MDL);
793 log_info(
"No subnet declaration for %s (%s).",
796 "no IPv4 addresses" :
806 strcpy(abuf,
"no IPv6 addresses");
808 log_info(
"No subnet6 declaration for %s (%s).",
814 log_info (
"** Ignoring requests on %s. %s",
815 tmp -> name,
"If this is not what");
816 log_info (
" you want, please write %s",
819 "a subnet6 declaration" :
821 "a subnet declaration");
822 log_info (
" in your dhcpd.conf file %s",
823 "for the network segment");
826 tmp -> name,
"is attached. **");
833 "subnet6 declaration for this" :
835 "subnet declaration for this");
836 log_error (
"subnet. You cannot prevent %s",
838 log_error (
"from listening on this subnet %s",
840 log_fatal (
"operating system does not %s.",
841 "support this capability");
866 "address", tmp->
name);
907 #if defined (F_SETFD) 910 if ((tmp -> rfdesc >= 0) &&
911 (fcntl (tmp -> rfdesc, F_SETFD, 1) < 0))
912 log_error (
"Can't set close-on-exec on %s: %m",
914 if ((tmp -> wfdesc != tmp -> rfdesc) &&
915 (tmp -> wfdesc >= 0) &&
916 (fcntl (tmp -> wfdesc, F_SETFD, 1) < 0))
917 log_error (
"Can't set close-on-exec on %s: %m",
921 interface_dereference (&tmp,
MDL);
923 interface_reference (&tmp, next,
MDL);
932 for (tmp =
interfaces; tmp; tmp = tmp -> next) {
936 if (tmp -> rfdesc == -1)
954 if (status != ISC_R_SUCCESS)
955 log_fatal (
"Can't register I/O handle for %s: %s",
956 tmp -> name, isc_result_totext (status));
973 log_fatal (
"Not configured to listen on any interfaces!");
982 #if defined (F_SETFD) 985 log_error (
"Can't set close-on-exec on fallback: %m");
988 log_error (
"Can't set close-on-exec on fallback: %m");
1007 isc_result_t status;
1010 if (status != ISC_R_SUCCESS)
1011 log_fatal (
"Error allocating fallback interface: %s",
1012 isc_result_totext (status));
1021 return status == ISC_R_SUCCESS;
1042 struct sockaddr_in from;
1047 unsigned char packbuf [4095];
1062 return ISC_R_UNEXPECTED;
1065 return ISC_R_UNEXPECTED;
1077 return ISC_R_UNEXPECTED;
1079 #if defined(IP_PKTINFO) && defined(IP_RECVPKTINFO) && defined(USE_V4_PKTINFO) 1082 unsigned int ifindex;
1084 memcpy(&ifindex, hfrom.
hbuf, sizeof (ifindex));
1091 while ((
ip != NULL) && (if_nametoindex(
ip->name) != ifindex))
1094 return ISC_R_NOTFOUND;
1100 memcpy (ifrom.
iabuf, &from.sin_addr, ifrom.
len);
1102 (*bootp_packet_handler) (
ip, &u.packet, (unsigned)result,
1103 from.sin_port, ifrom, &hfrom);
1110 return ISC_R_SUCCESS;
1116 struct sockaddr_in6 from;
1123 unsigned int if_idx = 0;
1131 &from, &to, &if_idx);
1133 log_error(
"receive_packet6() failed on %s: %m",
ip->name);
1134 return ISC_R_UNEXPECTED;
1139 return ISC_R_NOTFOUND;
1145 if (IN6_IS_ADDR_MULTICAST(&to)) {
1146 is_unicast = ISC_FALSE;
1148 is_unicast = ISC_TRUE;
1152 memcpy(ifrom.iabuf, &from.sin6_addr, ifrom.len);
1156 while ((
ip != NULL) && (if_nametoindex(
ip->name) != if_idx))
1160 return ISC_R_NOTFOUND;
1162 (*dhcpv6_packet_handler)(
ip, buf,
1163 result, from.sin6_port,
1164 &ifrom, is_unicast);
1167 return ISC_R_SUCCESS;
1177 isc_result_t status;
1186 value -> u.
buffer.len <
sizeof interface -> name) {
1187 memcpy (interface -> name,
1190 interface -> name [value -> u.
buffer.len] = 0;
1193 return ISC_R_SUCCESS;
1197 if (h -> inner && h -> inner -> type -> set_value) {
1198 status = ((*(h -> inner -> type -> set_value))
1199 (h -> inner, id, name, value));
1204 return ISC_R_NOTFOUND;
1213 return ISC_R_NOTIMPLEMENTED;
1225 if (interface -> ifp) {
1227 interface -> ifp = 0;
1229 if (interface -> next)
1230 interface_dereference (&interface -> next,
file,
line);
1231 if (interface -> rbuf) {
1233 interface -> rbuf = (
unsigned char *)0;
1235 if (interface -> client)
1242 return ISC_R_SUCCESS;
1246 const char *
name, va_list ap)
1249 isc_result_t status;
1257 if (!strcmp (name,
"update")) {
1259 if (
ip == interface)
1265 if (
ip == interface)
1272 if (h -> inner && h -> inner -> type -> signal_handler) {
1273 status = ((*(h -> inner -> type -> signal_handler))
1274 (h -> inner, name, ap));
1275 if (status == ISC_R_SUCCESS)
1278 return ISC_R_NOTFOUND;
1286 isc_result_t status;
1295 if (status != ISC_R_SUCCESS)
1301 if (status != ISC_R_SUCCESS)
1305 if (h -> inner && h -> inner -> type -> stuff_values) {
1306 status = ((*(h -> inner -> type -> stuff_values))
1307 (c, id, h -> inner));
1308 if (status == ISC_R_SUCCESS)
1312 return ISC_R_SUCCESS;
1320 isc_result_t status;
1328 if (status == ISC_R_SUCCESS) {
1332 if (status != ISC_R_SUCCESS)
1344 if (status == ISC_R_SUCCESS) {
1348 interface = interface -> next) {
1349 s = memchr (interface -> name, 0, IFNAMSIZ);
1351 len = s - &
interface -> name [0];
1354 if ((tv -> value -> u.buffer.len == len &&
1355 !memcmp (interface -> name,
1356 (
char *)tv -> value -> u.buffer.
value,
1362 interface;
interface = interface -> next) {
1363 s = memchr (interface -> name, 0, IFNAMSIZ);
1365 len = s - &
interface -> name [0];
1368 if ((tv -> value -> u.buffer.len == len &&
1369 !memcmp (interface -> name,
1371 tv -> value -> u.buffer.
value,
1381 }
else if (!interface) {
1384 return ISC_R_NOTFOUND;
1395 return ISC_R_SUCCESS;
1403 isc_result_t status;
1406 status = interface_allocate (&hp,
MDL);
1407 if (status != ISC_R_SUCCESS)
1411 interface_dereference (&hp,
MDL);
1425 if (
ip == interface) {
1427 interface_dereference (&last -> next,
MDL);
1429 interface_reference (&last -> next,
1438 interface_dereference (&
ip -> next,
MDL);
1444 return ISC_R_NOTFOUND;
1448 interface_reference (&interface -> next,
1456 (*dhcp_interface_shutdown_hook) (interface);
1474 return ISC_R_SUCCESS;
1483 if (tptr ->
index == -1) {
1490 if (interface_max <= tptr ->
index) {
1495 log_error (
"interface_stash: allocation failed ");
1515 #if defined (TRACING) 1528 interface_reference (&tmp ->
next,
void if_register_send(struct interface_info *)
#define DHCP_FIXED_NON_UDP
void(* dhcpv6_packet_handler)(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
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 *))
void end_iface_scan(struct iface_conf_list *ifaces)
isc_result_t omapi_object_reference(omapi_object_t **, omapi_object_t *, const char *, int)
struct shared_network * shared_network
isc_result_t dhcp_interface_destroy(omapi_object_t *h, const char *file, int line)
int if_readsocket(omapi_object_t *h)
void if_reinitialize_send(struct interface_info *)
void(* bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, unsigned, unsigned int, struct iaddr, struct hardware *)
void trace_interface_register(trace_type_t *, struct interface_info *)
trace_type_t * interface_trace
isc_result_t dhcp_interface_stuff_values(omapi_object_t *c, omapi_object_t *id, omapi_object_t *h)
#define DHCP_R_INVALIDARG
omapi_typed_data_t * value
#define DISCOVER_REQUESTED
void reinitialize_interfaces()
void trace_outpacket_input(trace_type_t *, unsigned, char *)
isc_result_t dhcp_interface_remove(omapi_object_t *lp, omapi_object_t *id)
struct in_addr * addresses
int setup_fallback(struct interface_info **fp, const char *file, int line)
#define INTERFACE_RUNNING
int log_error(const char *,...) __attribute__((__format__(__printf__
void add_ipv4_addr_to_interface(struct interface_info *iface, const struct in_addr *addr)
#define OMAPI_OBJECT_ALLOC(name, stype, type)
void if_deregister_receive(struct interface_info *)
#define DHCP_R_KEYCONFLICT
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__
isc_result_t dhcp_interface_get_value(omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value)
#define INTERFACE_AUTOMATIC
void interface_trace_setup(void)
struct omapi_typed_data_t::@3::@4 buffer
void if_deregister6(struct interface_info *info)
struct interface_info * fallback_interface
void trace_outpacket_stop(trace_type_t *)
void trace_inpacket_stop(trace_type_t *)
void if_register_linklocal6(struct interface_info *info)
isc_result_t omapi_get_value_str(omapi_object_t *, omapi_object_t *, const char *, omapi_value_t **)
struct iaddr interface_address
isc_result_t dhcp_interface_create(omapi_object_t **lp, omapi_object_t *id)
void trace_inpacket_input(trace_type_t *, unsigned, char *)
trace_type_t * trace_type_register(const char *, void *, void(*)(trace_type_t *, unsigned, char *), void(*)(trace_type_t *), const char *, int)
trace_type_t * inpacket_trace
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
isc_result_t got_one_v6(omapi_object_t *)
void dfree(void *, const char *, int)
omapi_object_type_t * dhcp_type_interface
isc_result_t omapi_handle_td_lookup(omapi_object_t **, omapi_typed_data_t *)
int begin_iface_scan(struct iface_conf_list *ifaces)
struct in_addr limited_broadcast
int int log_info(const char *,...) __attribute__((__format__(__printf__
void * dmalloc(size_t, const char *, int)
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 * interfaces
isc_result_t omapi_connection_put_string(omapi_object_t *, const char *)
int interfaces_invalidated
void interface_snorf(struct interface_info *tmp, int ir)
int(* dhcp_interface_setup_hook)(struct interface_info *, struct iaddr *)
isc_result_t omapi_value_dereference(omapi_value_t **, const char *, int)
void if_register6(struct interface_info *info, int do_multicast)
int quiet_interface_discovery
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(* dhcp_interface_startup_hook)(struct interface_info *)
#define DISCOVER_UNCONFIGURED
struct sockaddr_storage addr
isc_result_t dhcp_interface_signal_handler(omapi_object_t *h, const char *name, va_list ap)
struct interface_info * next
struct interface_info * dummy_interfaces
int omapi_ds_strcmp(omapi_data_string_t *, const char *)
isc_result_t got_one(omapi_object_t *h)
isc_result_t omapi_unregister_io_object(omapi_object_t *)
isc_result_t interface_initialize(omapi_object_t *ipo, const char *file, int line)
#define DISCOVER_SERVER46
int supports_multiple_interfaces(struct interface_info *)
isc_result_t interface_setup()
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
struct in_addr local_address
int(* dhcp_interface_discovery_hook)(struct interface_info *)
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 *)
isc_result_t omapi_connection_put_name(omapi_object_t *, const char *)
void if_reinitialize_receive(struct interface_info *)
void if_register_receive(struct interface_info *)
struct interface_info ** interface_vector
void interface_stash(struct interface_info *tptr)
struct interface_info * interface
trace_type_t * outpacket_trace
#define INTERFACE_STREAMS
void trace_interface_stop(trace_type_t *)
int(* dhcp_interface_shutdown_hook)(struct interface_info *)
void discover_interfaces(int state)
int next_iface(struct iface_info *info, int *err, struct iface_conf_list *ifaces)
isc_result_t dhcp_interface_lookup(omapi_object_t **ip, omapi_object_t *id, omapi_object_t *ref)
#define INTERFACE_REQUESTED
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