]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/netinet6/nd6_prproxy.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / netinet6 / nd6_prproxy.c
index a3006a929d6acc6081c30ce1d87809c7b56234f4..733fc9081a70ef393cd26804f5ffd13fce881886 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2016 Apple Inc. All rights reserved.
+ * Copyright (c) 2011-2020 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  *
@@ -141,7 +141,7 @@ SLIST_HEAD(nd6_prproxy_prelist_head, nd6_prproxy_prelist);
 
 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 *);
@@ -177,23 +177,14 @@ RB_PROTOTYPE_SC_PREV(__private_extern__, prproxy_sols_tree, nd6_prproxy_soltgt,
 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,
@@ -218,55 +209,10 @@ SYSCTL_UINT(_net_inet6_icmp6, OID_AUTO, prproxy_cnt,
     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
@@ -279,7 +225,7 @@ nd6_ndprl_free(struct nd6_prproxy_prelist *ndprl)
  * 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,
@@ -405,7 +351,7 @@ 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)
@@ -417,7 +363,7 @@ 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;
        }
@@ -457,11 +403,11 @@ nd6_if_prproxy(struct ifnet *ifp, boolean_t enable)
                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);
@@ -472,7 +418,7 @@ nd6_if_prproxy(struct ifnet *ifp, boolean_t enable)
                        break;
                }
 
-               up = nd6_ndprl_alloc(M_WAITOK);
+               up = nd6_ndprl_alloc(Z_WAITOK);
                if (up == NULL) {
                        NDPR_REMREF(pr);
                        continue;
@@ -511,7 +457,7 @@ nd6_if_prproxy(struct ifnet *ifp, boolean_t enable)
                        }
                        NDPR_UNLOCK(fwd);
 
-                       down = nd6_ndprl_alloc(M_WAITOK);
+                       down = nd6_ndprl_alloc(Z_WAITOK);
                        if (down == NULL) {
                                continue;
                        }
@@ -619,10 +565,10 @@ nd6_proxy_find_fwdroute(struct ifnet *ifp, struct route_in6 *ro6)
        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 {
@@ -701,9 +647,9 @@ nd6_proxy_find_fwdroute(struct ifnet *ifp, struct route_in6 *ro6)
                        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);
@@ -723,9 +669,9 @@ nd6_proxy_find_fwdroute(struct ifnet *ifp, struct route_in6 *ro6)
                        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 */
                }
@@ -733,9 +679,9 @@ nd6_proxy_find_fwdroute(struct ifnet *ifp, struct route_in6 *ro6)
        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);
 }
@@ -810,7 +756,7 @@ nd6_prproxy_prelist_update(struct nd_prefix *pr_cur, struct nd_prefix *pr_up)
        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;
@@ -837,7 +783,7 @@ nd6_prproxy_prelist_update(struct nd_prefix *pr_cur, struct nd_prefix *pr_up)
                }
                NDPR_UNLOCK(pr);
 
-               down = nd6_ndprl_alloc(M_WAITOK);
+               down = nd6_ndprl_alloc(Z_WAITOK);
                if (down == NULL) {
                        continue;
                }
@@ -929,12 +875,12 @@ nd6_prproxy_ns_output(struct ifnet *ifp, struct ifnet *exclifp,
        }
 
        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);
@@ -970,7 +916,7 @@ nd6_prproxy_ns_output(struct ifnet *ifp, struct ifnet *exclifp,
                        fwd_ifp = fwd->ndpr_ifp;
                        NDPR_UNLOCK(fwd);
 
-                       ndprl = nd6_ndprl_alloc(M_WAITOK);
+                       ndprl = nd6_ndprl_alloc(Z_WAITOK);
                        if (ndprl == NULL) {
                                continue;
                        }
@@ -1001,10 +947,10 @@ nd6_prproxy_ns_output(struct ifnet *ifp, struct ifnet *exclifp,
                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 {
@@ -1086,7 +1032,7 @@ nd6_prproxy_ns_input(struct ifnet *ifp, struct in6_addr *saddr,
                        fwd_ifp = fwd->ndpr_ifp;
                        NDPR_UNLOCK(fwd);
 
-                       ndprl = nd6_ndprl_alloc(M_WAITOK);
+                       ndprl = nd6_ndprl_alloc(Z_WAITOK);
                        if (ndprl == NULL) {
                                continue;
                        }
@@ -1133,12 +1079,12 @@ nd6_prproxy_ns_input(struct ifnet *ifp, struct in6_addr *saddr,
                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);
@@ -1202,7 +1148,7 @@ nd6_prproxy_na_input(struct ifnet *ifp, struct in6_addr *saddr,
                        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 */
                        }
@@ -1237,7 +1183,7 @@ nd6_prproxy_na_input(struct ifnet *ifp, struct in6_addr *saddr,
                                fwd_ifp = fwd->ndpr_ifp;
                                NDPR_UNLOCK(fwd);
 
-                               ndprl = nd6_ndprl_alloc(M_WAITOK);
+                               ndprl = nd6_ndprl_alloc(Z_WAITOK);
                                if (ndprl == NULL) {
                                        continue;
                                }
@@ -1278,20 +1224,20 @@ nd6_prproxy_na_input(struct ifnet *ifp, struct in6_addr *saddr,
 
                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);
@@ -1309,15 +1255,7 @@ nd6_prproxy_na_input(struct ifnet *ifp, struct in6_addr *saddr,
 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
@@ -1496,10 +1434,8 @@ nd6_soltgt_alloc(int how)
 {
        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;