- static size_t if_indexlim = 8;
- struct in6_ifaddr *ia;
- struct in6_addr in6;
- int error;
-
- lck_rw_lock_exclusive(&in6_ifs_rwlock);
- /*
- * We have some arrays that should be indexed by if_index.
- * since if_index will grow dynamically, they should grow too.
- * struct in6_ifstat **in6_ifstat
- * struct icmp6_ifstat **icmp6_ifstat
- */
- if (in6_ifstat == NULL || icmp6_ifstat == NULL ||
- if_index >= if_indexlim) {
- while (if_index >= if_indexlim)
- if_indexlim <<= 1;
- }
-
- /* grow in6_ifstat */
- if (in6_ifstatmax < if_indexlim) {
- size_t n;
- caddr_t q;
-
- n = if_indexlim * sizeof(struct in6_ifstat *);
- q = (caddr_t)_MALLOC(n, M_IFADDR, M_WAITOK);
- if (q == NULL) {
- lck_rw_done(&in6_ifs_rwlock);
- return ENOBUFS;
- }
- bzero(q, n);
- if (in6_ifstat) {
- bcopy((caddr_t)in6_ifstat, q,
- in6_ifstatmax * sizeof(struct in6_ifstat *));
- FREE((caddr_t)in6_ifstat, M_IFADDR);
- }
- in6_ifstat = (struct in6_ifstat **)q;
- in6_ifstatmax = if_indexlim;
- }
-
- if (in6_ifstat[ifp->if_index] == NULL) {
- in6_ifstat[ifp->if_index] = (struct in6_ifstat *)
- _MALLOC(sizeof(struct in6_ifstat), M_IFADDR, M_WAITOK);
- if (in6_ifstat[ifp->if_index] == NULL) {
- lck_rw_done(&in6_ifs_rwlock);
- return ENOBUFS;
- }
- bzero(in6_ifstat[ifp->if_index], sizeof(struct in6_ifstat));
- }
- lck_rw_done(&in6_ifs_rwlock);
-
- lck_rw_lock_exclusive(&icmp6_ifs_rwlock);
- if (icmp6_ifstatmax < if_indexlim) {
- size_t n;
- caddr_t q;
-
- n = if_indexlim * sizeof(struct icmp6_ifstat *);
- q = (caddr_t)_MALLOC(n, M_IFADDR, M_WAITOK);
- if (q == NULL) {
- lck_rw_done(&icmp6_ifs_rwlock);
- return ENOBUFS;
- }
- bzero(q, n);
- if (icmp6_ifstat) {
- bcopy((caddr_t)icmp6_ifstat, q,
- icmp6_ifstatmax * sizeof(struct icmp6_ifstat *));
- FREE((caddr_t)icmp6_ifstat, M_IFADDR);
- }
- icmp6_ifstat = (struct icmp6_ifstat **)q;
- icmp6_ifstatmax = if_indexlim;
- }
-
- if (icmp6_ifstat[ifp->if_index] == NULL) {
- icmp6_ifstat[ifp->if_index] = (struct icmp6_ifstat *)
- _MALLOC(sizeof(struct icmp6_ifstat), M_IFADDR, M_WAITOK);
- if (icmp6_ifstat[ifp->if_index] == NULL) {
- lck_rw_done(&icmp6_ifs_rwlock);
- return ENOBUFS;
- }
- bzero(icmp6_ifstat[ifp->if_index], sizeof(struct icmp6_ifstat));
- }
- lck_rw_done(&icmp6_ifs_rwlock);
-
- /* initialize NDP variables */
- if ((error = nd6_ifattach(ifp)) != 0)
- return error;