/*
- * Copyright (c) 2011-2016 Apple Inc. All rights reserved.
+ * Copyright (c) 2011-2020 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
static void nd6_prproxy_prelist_setroute(boolean_t enable,
struct nd6_prproxy_prelist_head *, struct nd6_prproxy_prelist_head *);
-static struct nd6_prproxy_prelist *nd6_ndprl_alloc(int);
+static struct nd6_prproxy_prelist *nd6_ndprl_alloc(zalloc_flags_t);
static void nd6_ndprl_free(struct nd6_prproxy_prelist *);
static struct nd6_prproxy_solsrc *nd6_solsrc_alloc(int);
static void nd6_solsrc_free(struct nd6_prproxy_solsrc *);
static u_int32_t nd6_max_tgt_sols = ND6_MAX_TGT_SOLS_DEFAULT;
static u_int32_t nd6_max_src_sols = ND6_MAX_SRC_SOLS_DEFAULT;
-static unsigned int ndprl_size; /* size of zone element */
-static struct zone *ndprl_zone; /* nd6_prproxy_prelist zone */
+static ZONE_DECLARE(ndprl_zone, "nd6_prproxy_prelist",
+ sizeof(struct nd6_prproxy_prelist), ZC_ZFREE_CLEARMEM); /* nd6_prproxy_prelist zone */
-#define NDPRL_ZONE_MAX 256 /* maximum elements in zone */
-#define NDPRL_ZONE_NAME "nd6_prproxy_prelist" /* name for zone */
+static ZONE_DECLARE(solsrc_zone, "nd6_prproxy_solsrc",
+ sizeof(struct nd6_prproxy_solsrc), ZC_ZFREE_CLEARMEM); /* nd6_prproxy_solsrc zone */
-static unsigned int solsrc_size; /* size of zone element */
-static struct zone *solsrc_zone; /* nd6_prproxy_solsrc zone */
-
-#define SOLSRC_ZONE_MAX 256 /* maximum elements in zone */
-#define SOLSRC_ZONE_NAME "nd6_prproxy_solsrc" /* name for zone */
-
-static unsigned int soltgt_size; /* size of zone element */
-static struct zone *soltgt_zone; /* nd6_prproxy_soltgt zone */
-
-#define SOLTGT_ZONE_MAX 256 /* maximum elements in zone */
-#define SOLTGT_ZONE_NAME "nd6_prproxy_soltgt" /* name for zone */
+static ZONE_DECLARE(soltgt_zone, "nd6_prproxy_soltgt",
+ sizeof(struct nd6_prproxy_soltgt), ZC_ZFREE_CLEARMEM); /* nd6_prproxy_soltgt zone */
/* The following is protected by ndpr_lock */
RB_GENERATE_PREV(prproxy_sols_tree, nd6_prproxy_soltgt,
CTLFLAG_RD | CTLFLAG_LOCKED, &nd6_prproxy, 0,
"total number of proxied prefixes");
-/*
- * Called by nd6_init() during initialization time.
- */
-void
-nd6_prproxy_init(void)
-{
- ndprl_size = sizeof(struct nd6_prproxy_prelist);
- ndprl_zone = zinit(ndprl_size, NDPRL_ZONE_MAX * ndprl_size, 0,
- NDPRL_ZONE_NAME);
- if (ndprl_zone == NULL) {
- panic("%s: failed allocating ndprl_zone", __func__);
- }
-
- zone_change(ndprl_zone, Z_EXPAND, TRUE);
- zone_change(ndprl_zone, Z_CALLERACCT, FALSE);
-
- solsrc_size = sizeof(struct nd6_prproxy_solsrc);
- solsrc_zone = zinit(solsrc_size, SOLSRC_ZONE_MAX * solsrc_size, 0,
- SOLSRC_ZONE_NAME);
- if (solsrc_zone == NULL) {
- panic("%s: failed allocating solsrc_zone", __func__);
- }
-
- zone_change(solsrc_zone, Z_EXPAND, TRUE);
- zone_change(solsrc_zone, Z_CALLERACCT, FALSE);
-
- soltgt_size = sizeof(struct nd6_prproxy_soltgt);
- soltgt_zone = zinit(soltgt_size, SOLTGT_ZONE_MAX * soltgt_size, 0,
- SOLTGT_ZONE_NAME);
- if (soltgt_zone == NULL) {
- panic("%s: failed allocating soltgt_zone", __func__);
- }
-
- zone_change(soltgt_zone, Z_EXPAND, TRUE);
- zone_change(soltgt_zone, Z_CALLERACCT, FALSE);
-}
-
static struct nd6_prproxy_prelist *
-nd6_ndprl_alloc(int how)
+nd6_ndprl_alloc(zalloc_flags_t how)
{
- struct nd6_prproxy_prelist *ndprl;
-
- ndprl = (how == M_WAITOK) ? zalloc(ndprl_zone) :
- zalloc_noblock(ndprl_zone);
- if (ndprl != NULL) {
- bzero(ndprl, ndprl_size);
- }
-
- return ndprl;
+ return zalloc_flags(ndprl_zone, how | Z_ZERO);
}
static void
* Apply routing function on the affected upstream and downstream prefixes,
* i.e. either set or clear RTF_PROXY on the cloning prefix route; all route
* entries that were cloned off these prefixes will be blown away. Caller
- * must have acquried proxy6_lock and must not be holding nd6_mutex.
+ * must have acquired proxy6_lock and must not be holding nd6_mutex.
*/
static void
nd6_prproxy_prelist_setroute(boolean_t enable,
/*
* Enable/disable prefix proxying on an interface; typically called
- * as part of handling SIOCSIFINFO_FLAGS[IFEF_IPV6_ROUTER].
+ * as part of handling SIOCSIFINFO_FLAGS[SETROUTERMODE_IN6]
*/
int
nd6_if_prproxy(struct ifnet *ifp, boolean_t enable)
/* Can't be enabled if we are an advertising router on the interface */
ifnet_lock_shared(ifp);
- if (enable && (ifp->if_eflags & IFEF_IPV6_ROUTER)) {
+ if (enable && (ifp->if_ipv6_router_mode == IPV6_ROUTER_MODE_EXCLUSIVE)) {
ifnet_lock_done(ifp);
return EBUSY;
}
if (enable && (pr->ndpr_stateflags & NDPRF_ONLINK) &&
nd6_need_cache(ifp)) {
pr->ndpr_stateflags |= NDPRF_PRPROXY;
- NDPR_ADDREF_LOCKED(pr);
+ NDPR_ADDREF(pr);
NDPR_UNLOCK(pr);
} else if (!enable) {
pr->ndpr_stateflags &= ~NDPRF_PRPROXY;
- NDPR_ADDREF_LOCKED(pr);
+ NDPR_ADDREF(pr);
NDPR_UNLOCK(pr);
} else {
NDPR_UNLOCK(pr);
break;
}
- up = nd6_ndprl_alloc(M_WAITOK);
+ up = nd6_ndprl_alloc(Z_WAITOK);
if (up == NULL) {
NDPR_REMREF(pr);
continue;
}
NDPR_UNLOCK(fwd);
- down = nd6_ndprl_alloc(M_WAITOK);
+ down = nd6_ndprl_alloc(Z_WAITOK);
if (down == NULL) {
continue;
}
if ((rt = ro6->ro_rt) != NULL) {
RT_LOCK(rt);
if (!(rt->rt_flags & RTF_PROXY) || rt->rt_ifp == ifp) {
- nd6log2((LOG_DEBUG, "%s: found incorrect prefix "
+ nd6log2(debug, "%s: found incorrect prefix "
"proxy route for dst %s on %s\n", if_name(ifp),
ip6_sprintf(dst6),
- if_name(rt->rt_ifp)));
+ if_name(rt->rt_ifp));
RT_UNLOCK(rt);
/* look it up below */
} else {
rtfree_locked(rt);
rt = NULL;
} else {
- nd6log2((LOG_DEBUG, "%s: found prefix proxy route "
+ nd6log2(debug, "%s: found prefix proxy route "
"for dst %s\n", if_name(rt->rt_ifp),
- ip6_sprintf(dst6)));
+ ip6_sprintf(dst6));
RT_UNLOCK(rt);
ro6->ro_rt = rt; /* refcnt held by rtalloc1 */
lck_mtx_unlock(rnh_lock);
rtfree_locked(rt);
rt = NULL;
} else {
- nd6log2((LOG_DEBUG, "%s: allocated prefix proxy "
+ nd6log2(debug, "%s: allocated prefix proxy "
"route for dst %s\n", if_name(rt->rt_ifp),
- ip6_sprintf(dst6)));
+ ip6_sprintf(dst6));
RT_UNLOCK(rt);
ro6->ro_rt = rt; /* refcnt held by rtalloc1 */
}
VERIFY(rt != NULL || ro6->ro_rt == NULL);
if (fwd_ifp == NULL || rt == NULL) {
- nd6log2((LOG_ERR, "%s: failed to find forwarding prefix "
+ nd6log2(error, "%s: failed to find forwarding prefix "
"proxy entry for dst %s\n", if_name(ifp),
- ip6_sprintf(dst6)));
+ ip6_sprintf(dst6));
}
lck_mtx_unlock(rnh_lock);
}
enable = (pr_up->ndpr_stateflags & NDPRF_PRPROXY);
NDPR_UNLOCK(pr_up);
- up = nd6_ndprl_alloc(M_WAITOK);
+ up = nd6_ndprl_alloc(Z_WAITOK);
if (up == NULL) {
lck_mtx_unlock(nd6_mutex);
goto done;
}
NDPR_UNLOCK(pr);
- down = nd6_ndprl_alloc(M_WAITOK);
+ down = nd6_ndprl_alloc(Z_WAITOK);
if (down == NULL) {
continue;
}
}
if (exclifp == NULL) {
- nd6log2((LOG_DEBUG, "%s: sending NS who has %s on ALL\n",
- if_name(ifp), ip6_sprintf(taddr)));
+ nd6log2(debug, "%s: sending NS who has %s on ALL\n",
+ if_name(ifp), ip6_sprintf(taddr));
} else {
- nd6log2((LOG_DEBUG, "%s: sending NS who has %s on ALL "
+ nd6log2(debug, "%s: sending NS who has %s on ALL "
"(except %s)\n", if_name(ifp),
- ip6_sprintf(taddr), if_name(exclifp)));
+ ip6_sprintf(taddr), if_name(exclifp));
}
SLIST_INIT(&ndprl_head);
fwd_ifp = fwd->ndpr_ifp;
NDPR_UNLOCK(fwd);
- ndprl = nd6_ndprl_alloc(M_WAITOK);
+ ndprl = nd6_ndprl_alloc(Z_WAITOK);
if (ndprl == NULL) {
continue;
}
NDPR_LOCK(pr);
if (pr->ndpr_stateflags & NDPRF_ONLINK) {
NDPR_UNLOCK(pr);
- nd6log2((LOG_DEBUG,
+ nd6log2(debug,
"%s: Sending cloned NS who has %s, originally "
"on %s\n", if_name(fwd_ifp),
- ip6_sprintf(taddr), if_name(ifp)));
+ ip6_sprintf(taddr), if_name(ifp));
nd6_ns_output(fwd_ifp, daddr, taddr, NULL, NULL);
} else {
fwd_ifp = fwd->ndpr_ifp;
NDPR_UNLOCK(fwd);
- ndprl = nd6_ndprl_alloc(M_WAITOK);
+ ndprl = nd6_ndprl_alloc(Z_WAITOK);
if (ndprl == NULL) {
continue;
}
NDPR_LOCK(pr);
if (pr->ndpr_stateflags & NDPRF_ONLINK) {
NDPR_UNLOCK(pr);
- nd6log2((LOG_DEBUG,
+ nd6log2(debug,
"%s: Forwarding NS (%s) from %s to %s who "
"has %s, originally on %s\n", if_name(fwd_ifp),
ndprl->ndprl_sol ? "NUD/AR" :
"DAD", ip6_sprintf(saddr), ip6_sprintf(daddr),
- ip6_sprintf(taddr), if_name(ifp)));
+ ip6_sprintf(taddr), if_name(ifp));
nd6_ns_output(fwd_ifp, ndprl->ndprl_sol ? taddr : NULL,
taddr, NULL, nonce);
VERIFY(!IN6_IS_ADDR_UNSPECIFIED(&daddr) && fwd_ifp);
NDPR_UNLOCK(pr);
- ndprl = nd6_ndprl_alloc(M_WAITOK);
+ ndprl = nd6_ndprl_alloc(Z_WAITOK);
if (ndprl == NULL) {
break; /* bail out */
}
fwd_ifp = fwd->ndpr_ifp;
NDPR_UNLOCK(fwd);
- ndprl = nd6_ndprl_alloc(M_WAITOK);
+ ndprl = nd6_ndprl_alloc(Z_WAITOK);
if (ndprl == NULL) {
continue;
}
if (send_na) {
if (!ndprl->ndprl_sol) {
- nd6log2((LOG_DEBUG,
+ nd6log2(debug,
"%s: Forwarding NA (DAD) from %s to %s "
"tgt is %s, originally on %s\n",
if_name(fwd_ifp),
ip6_sprintf(saddr), ip6_sprintf(&daddr),
- ip6_sprintf(taddr), if_name(ifp)));
+ ip6_sprintf(taddr), if_name(ifp));
} else {
- nd6log2((LOG_DEBUG,
+ nd6log2(debug,
"%s: Forwarding NA (NUD/AR) from %s to "
"%s (was %s) tgt is %s, originally on "
"%s\n", if_name(fwd_ifp),
ip6_sprintf(saddr),
ip6_sprintf(&daddr), ip6_sprintf(daddr0),
- ip6_sprintf(taddr), if_name(ifp)));
+ ip6_sprintf(taddr), if_name(ifp));
}
nd6_na_output(fwd_ifp, &daddr, taddr, flags, 1, NULL);
static struct nd6_prproxy_solsrc *
nd6_solsrc_alloc(int how)
{
- struct nd6_prproxy_solsrc *ssrc;
-
- ssrc = (how == M_WAITOK) ? zalloc(solsrc_zone) :
- zalloc_noblock(solsrc_zone);
- if (ssrc != NULL) {
- bzero(ssrc, solsrc_size);
- }
-
- return ssrc;
+ return zalloc_flags(solsrc_zone, how | Z_ZERO);
}
static void
{
struct nd6_prproxy_soltgt *soltgt;
- soltgt = (how == M_WAITOK) ? zalloc(soltgt_zone) :
- zalloc_noblock(soltgt_zone);
+ soltgt = zalloc_flags(soltgt_zone, how | Z_ZERO);
if (soltgt != NULL) {
- bzero(soltgt, soltgt_size);
TAILQ_INIT(&soltgt->soltgt_q);
}
return soltgt;