Lines Matching refs:iter

104 getbuf4(isc_interfaceiter_t *iter) {
107 iter->bufsize = IFCONF_BUFSIZE_INITIAL;
110 iter->buf = isc_mem_get(iter->mctx, iter->bufsize);
111 if (iter->buf == NULL)
114 memset(&iter->ifc.ifc_len, 0, sizeof(iter->ifc.ifc_len));
115 iter->ifc.ifc_len = iter->bufsize;
116 iter->ifc.ifc_buf = iter->buf;
122 if (ioctl(iter->socket, SIOCGIFCONF, (char *)&iter->ifc)
148 if (iter->ifc.ifc_len + 2 * sizeof(struct ifreq)
149 < iter->bufsize)
152 if (iter->bufsize >= IFCONF_BUFSIZE_MAX) {
163 isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
165 iter->bufsize *= 2;
170 isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
171 iter->buf = NULL;
177 getbuf6(isc_interfaceiter_t *iter) {
181 iter->bufsize6 = IFCONF_BUFSIZE_INITIAL;
184 iter->buf6 = isc_mem_get(iter->mctx, iter->bufsize6);
185 if (iter->buf6 == NULL)
188 memset(&iter->lifc, 0, sizeof(iter->lifc));
190 iter->lifc.lifc_family = AF_INET6;
193 iter->lifc.lifc_flags = 0;
195 iter->lifc.lifc_len = iter->bufsize6;
196 iter->lifc.lifc_buf = iter->buf6;
202 if (ioctl(iter->socket6, SIOCGLIFCONF, (char *)&iter->lifc)
249 if (iter->lifc.lifc_len + 2 * sizeof(struct LIFREQ)
250 < iter->bufsize6)
253 if (iter->bufsize6 >= IFCONF_BUFSIZE_MAX) {
265 isc_mem_put(iter->mctx, iter->buf6, iter->bufsize6);
267 iter->bufsize6 *= 2;
270 if (iter->lifc.lifc_len != 0)
271 iter->mode = 6;
275 isc_mem_put(iter->mctx, iter->buf6, iter->bufsize6);
276 iter->buf6 = NULL;
283 isc_interfaceiter_t *iter;
291 iter = isc_mem_get(mctx, sizeof(*iter));
292 if (iter == NULL)
295 iter->mctx = mctx;
296 iter->mode = 4;
297 iter->buf = NULL;
298 iter->pos = (unsigned int) -1;
300 iter->buf6 = NULL;
301 iter->pos6 = (unsigned int) -1;
302 iter->result6 = ISC_R_NOMORE;
303 iter->socket6 = -1;
304 iter->first6 = ISC_FALSE;
320 if ((iter->socket6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
332 result = iter->result6 = getbuf6(iter);
337 if ((iter->socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
349 result = getbuf4(iter);
358 iter->clua_context = -1;
359 iter->clua_done = ISC_TRUE;
362 iter->proc = fopen("/proc/net/if_inet6", "r");
363 iter->valid = ISC_R_FAILURE;
365 iter->result = ISC_R_FAILURE;
367 iter->magic = IFITER_MAGIC;
368 *iterp = iter;
372 if (iter->buf != NULL)
373 isc_mem_put(mctx, iter->buf, iter->bufsize);
374 (void) close(iter->socket);
378 if (iter->buf6 != NULL)
379 isc_mem_put(mctx, iter->buf6, iter->bufsize6);
381 if (iter->socket6 != -1)
382 (void) close(iter->socket6);
386 isc_mem_put(mctx, iter, sizeof(*iter));
398 internal_current_clusteralias(isc_interfaceiter_t *iter) {
400 if (clua_getaliasinfo(&iter->clua_sa, &ci) != CLUA_SUCCESS)
402 memset(&iter->current, 0, sizeof(iter->current));
403 iter->current.af = iter->clua_sa.sa_family;
404 memset(iter->current.name, 0, sizeof(iter->current.name));
405 snprintf(iter->current.name, sizeof(iter->current.name),
407 iter->current.flags = INTERFACE_F_UP;
408 get_inaddr(&iter->current.address, &ci.addr);
409 get_inaddr(&iter->current.netmask, &ci.netmask);
415 * Get information about the current interface to iter->current.
423 internal_current4(isc_interfaceiter_t *iter) {
435 REQUIRE(VALID_IFITER(iter));
437 if (iter->ifc.ifc_len == 0 ||
438 iter->pos == (unsigned int)iter->ifc.ifc_len) {
440 return (linux_if_inet6_current(iter));
446 INSIST( iter->pos < (unsigned int) iter->ifc.ifc_len);
448 ifrp = (struct ifreq *)((char *) iter->ifc.ifc_req + iter->pos);
461 memset(&iter->current, 0, sizeof(iter->current));
462 iter->current.af = family;
464 INSIST(sizeof(ifreq.ifr_name) <= sizeof(iter->current.name));
465 memset(iter->current.name, 0, sizeof(iter->current.name));
466 memmove(iter->current.name, ifreq.ifr_name, sizeof(ifreq.ifr_name));
468 get_addr(family, &iter->current.address,
476 if (iter->current.address.type.in.s_addr == htonl(INADDR_ANY))
480 if (memcmp(&iter->current.address.type.in6, &in6addr_any,
490 iter->current.flags = 0;
497 if (ioctl(iter->socket, SIOCGIFFLAGS, (char *) &ifreq) < 0) {
506 iter->current.flags |= INTERFACE_F_UP;
510 iter->current.flags |= INTERFACE_F_POINTTOPOINT;
514 iter->current.flags |= INTERFACE_F_LOOPBACK;
521 memmove(lifreq.lifr_name, iter->current.name, sizeof(lifreq.lifr_name));
522 memmove(&lifreq.lifr_addr, &iter->current.address.type.in6,
523 sizeof(iter->current.address.type.in6));
525 if (ioctl(iter->socket, SIOCGLIFADDR, &lifreq) < 0) {
534 isc_netaddr_format(&iter->current.address, sabuf, sizeof(sabuf));
549 iter->current.netmask.family = family;
558 iter->current.netmask.type.in6.s6_addr[i] = (~0 << bits) & 0xff;
569 if ((iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) {
575 if (ioctl(iter->socket, SIOCGIFDSTADDR, (char *)&ifreq)
587 get_addr(family, &iter->current.dstaddress,
602 if (ioctl(iter->socket, SIOCGIFNETMASK, (char *)&ifreq) < 0) {
612 get_addr(family, &iter->current.netmask,
619 internal_current6(isc_interfaceiter_t *iter) {
626 REQUIRE(VALID_IFITER(iter));
627 if (iter->result6 != ISC_R_SUCCESS)
628 return (iter->result6);
629 REQUIRE(iter->pos6 < (unsigned int) iter->lifc.lifc_len);
631 ifrp = (struct LIFREQ *)((char *) iter->lifc.lifc_req + iter->pos6);
644 memset(&iter->current, 0, sizeof(iter->current));
645 iter->current.af = family;
647 INSIST(sizeof(lifreq.lifr_name) <= sizeof(iter->current.name));
648 memset(iter->current.name, 0, sizeof(iter->current.name));
649 memmove(iter->current.name, lifreq.lifr_name, sizeof(lifreq.lifr_name));
651 get_addr(family, &iter->current.address,
659 if (iter->current.address.type.in.s_addr == htonl(INADDR_ANY))
663 if (memcmp(&iter->current.address.type.in6, &in6addr_any,
673 iter->current.flags = 0;
676 fd = iter->socket6;
678 fd = iter->socket;
694 iter->current.flags |= INTERFACE_F_UP;
698 iter->current.flags |= INTERFACE_F_POINTTOPOINT;
702 iter->current.flags |= INTERFACE_F_LOOPBACK;
708 if ((iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) {
726 get_addr(family, &iter->current.dstaddress,
747 iter->current.netmask.family = family;
751 iter->current.netmask.type.in6.s6_addr[i / 8] =
774 get_addr(family, &iter->current.netmask,
782 internal_current(isc_interfaceiter_t *iter) {
784 if (iter->mode == 6) {
785 iter->result6 = internal_current6(iter);
786 if (iter->result6 != ISC_R_NOMORE)
787 return (iter->result6);
791 if (!iter->clua_done)
792 return(internal_current_clusteralias(iter));
794 return (internal_current4(iter));
805 internal_next4(isc_interfaceiter_t *iter) {
810 if (iter->pos < (unsigned int) iter->ifc.ifc_len) {
812 ifrp = (struct ifreq *)((char *) iter->ifc.ifc_req + iter->pos);
815 iter->pos += sizeof(ifrp->ifr_name) +
819 iter->pos += sizeof(struct ifreq);
822 INSIST(iter->pos == (unsigned int) iter->ifc.ifc_len);
824 return (linux_if_inet6_next(iter));
834 internal_next6(isc_interfaceiter_t *iter) {
839 if (iter->result6 != ISC_R_SUCCESS && iter->result6 != ISC_R_IGNORE)
840 return (iter->result6);
842 REQUIRE(iter->pos6 < (unsigned int) iter->lifc.lifc_len);
845 ifrp = (struct LIFREQ *)((char *) iter->lifc.lifc_req + iter->pos6);
848 iter->pos6 += sizeof(ifrp->lifr_name) + ifrp->lifr_addr.sa_len;
851 iter->pos6 += sizeof(struct LIFREQ);
853 if (iter->pos6 >= (unsigned int) iter->lifc.lifc_len)
861 internal_next(isc_interfaceiter_t *iter) {
866 if (iter->mode == 6) {
867 iter->result6 = internal_next6(iter);
868 if (iter->result6 != ISC_R_NOMORE)
869 return (iter->result6);
870 if (iter->first6) {
871 iter->first6 = ISC_FALSE;
877 if (!iter->clua_done) {
878 clua_result = clua_getaliasaddress(&iter->clua_sa,
879 &iter->clua_context);
881 iter->clua_done = ISC_TRUE;
885 return (internal_next4(iter));
889 internal_destroy(isc_interfaceiter_t *iter) {
890 (void) close(iter->socket);
892 if (iter->socket6 != -1)
893 (void) close(iter->socket6);
894 if (iter->buf6 != NULL) {
895 isc_mem_put(iter->mctx, iter->buf6, iter->bufsize6);
899 if (iter->proc != NULL)
900 fclose(iter->proc);
905 void internal_first(isc_interfaceiter_t *iter) {
909 iter->pos = 0;
911 iter->pos6 = 0;
912 if (iter->result6 == ISC_R_NOMORE)
913 iter->result6 = ISC_R_SUCCESS;
914 iter->first6 = ISC_TRUE;
917 iter->clua_context = 0;
918 clua_result = clua_getaliasaddress(&iter->clua_sa,
919 &iter->clua_context);
920 iter->clua_done = ISC_TF(clua_result != CLUA_SUCCESS);
923 linux_if_inet6_first(iter);