/*
- * Copyright (c) 2010-2012 Apple Inc. All rights reserved.
+ * Copyright (c) 2010-2016 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
static struct in6_msource *in6ms_alloc(int);
static void in6ms_free(struct in6_msource *);
-#define IM6O_CAST_TO_NONCONST(x) ((struct ip6_moptions *)(void *)(uintptr_t)x)
-#define IN6M_CAST_TO_NONCONST(x) ((struct in6_multi *)(void *)(uintptr_t)x)
-
/*
* IPv6 source tree comparison function.
*
int idx;
int nmships;
- IM6O_LOCK_ASSERT_HELD(IM6O_CAST_TO_NONCONST(imo));
+ IM6O_LOCK_ASSERT_HELD(__DECONST(struct ip6_moptions *, imo));
gsin6 = (struct sockaddr_in6 *)(uintptr_t)(size_t)group;
struct ip6_msource *ims;
const sockunion_t *psa;
- IM6O_LOCK_ASSERT_HELD(IM6O_CAST_TO_NONCONST(imo));
+ IM6O_LOCK_ASSERT_HELD(__DECONST(struct ip6_moptions *, imo));
VERIFY(src->sa_family == AF_INET6);
VERIFY(gidx != (size_t)-1 && gidx < imo->im6o_num_memberships);
struct in6_msource *ims;
int mode;
- IM6O_LOCK_ASSERT_HELD(IM6O_CAST_TO_NONCONST(imo));
+ IM6O_LOCK_ASSERT_HELD(__DECONST(struct ip6_moptions *, imo));
VERIFY(ifp != NULL);
gidx = im6o_match_group(imo, ifp, group);
lims->im6sl_st[1] = lims->im6sl_st[0];
} else {
/* revert source added t1 */
- MLD_PRINTF(("%s: free in6ms %p\n", __func__, lims));
+ MLD_PRINTF(("%s: free in6ms 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(lims)));
RB_REMOVE(ip6_msource_tree, &imf->im6f_sources, ims);
in6ms_free(lims);
imf->im6f_nsrc--;
lims = (struct in6_msource *)ims;
if ((lims->im6sl_st[0] == MCAST_UNDEFINED) &&
(lims->im6sl_st[1] == MCAST_UNDEFINED)) {
- MLD_PRINTF(("%s: free in6ms %p\n", __func__, lims));
+ MLD_PRINTF(("%s: free in6ms 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(lims)));
RB_REMOVE(ip6_msource_tree, &imf->im6f_sources, ims);
in6ms_free(lims);
imf->im6f_nsrc--;
RB_FOREACH_SAFE(ims, ip6_msource_tree, &imf->im6f_sources, tims) {
lims = (struct in6_msource *)ims;
- MLD_PRINTF(("%s: free in6ms %p\n", __func__, lims));
+ MLD_PRINTF(("%s: free in6ms 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(lims)));
RB_REMOVE(ip6_msource_tree, &imf->im6f_sources, ims);
in6ms_free(lims);
imf->im6f_nsrc--;
RB_INSERT(ip6_msource_tree, &inm->in6m_srcs, nims);
++inm->in6m_nsrc;
ims = nims;
- MLD_PRINTF(("%s: allocated %s as %p\n", __func__,
- ip6_sprintf(addr), ims));
+ MLD_PRINTF(("%s: allocated %s as 0x%llx\n", __func__,
+ ip6_sprintf(addr), (uint64_t)VM_KERNEL_ADDRPERM(ims)));
}
*pims = ims;
im6s_get_mode(const struct in6_multi *inm, const struct ip6_msource *ims,
uint8_t t)
{
- IN6M_LOCK_ASSERT_HELD(IN6M_CAST_TO_NONCONST(inm));
+ IN6M_LOCK_ASSERT_HELD(__DECONST(struct in6_multi *, inm));
t = !!t;
if (inm->in6m_st[t].iss_ex > 0 &&
inm->in6m_st[1].iss_asm++;
}
- MLD_PRINTF(("%s: merged imf %p to inm %p\n", __func__, imf, inm));
+ MLD_PRINTF(("%s: merged imf 0x%llx to inm 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(imf),
+ (uint64_t)VM_KERNEL_ADDRPERM(inm)));
in6m_print(inm);
out_reap:
IN6M_LOCK_ASSERT_HELD(inm);
- MLD_PRINTF(("%s: commit inm %p\n", __func__, inm));
+ MLD_PRINTF(("%s: commit inm 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(inm)));
MLD_PRINTF(("%s: pre commit:\n", __func__));
in6m_print(inm);
ims->im6s_st[1].ex > 0 || ims->im6s_st[1].in > 0 ||
ims->im6s_stp != 0)
continue;
- MLD_PRINTF(("%s: free ims %p\n", __func__, ims));
+ MLD_PRINTF(("%s: free ims 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(ims)));
RB_REMOVE(ip6_msource_tree, &inm->in6m_srcs, ims);
ip6ms_free(ims);
inm->in6m_nsrc--;
IN6M_LOCK_ASSERT_HELD(inm);
RB_FOREACH_SAFE(ims, ip6_msource_tree, &inm->in6m_srcs, tims) {
- MLD_PRINTF(("%s: free ims %p\n", __func__, ims));
+ MLD_PRINTF(("%s: free ims 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(ims)));
RB_REMOVE(ip6_msource_tree, &inm->in6m_srcs, ims);
ip6ms_free(ims);
inm->in6m_nsrc--;
return (NULL);
}
- delay = (delay * PR_SLOWHZ) / hz;
-
error = in6_mc_join(ifp, mcaddr, NULL, &imm->i6mm_maddr, delay);
if (error) {
*errorp = error;
struct in6_mfilter timf;
struct in6_multi *inm = NULL;
int error = 0;
+ struct mld_tparams mtp;
/*
* Sanity: Check scope zone ID was set for ifp, if and
VERIFY(mcaddr->s6_addr16[1] != 0);
}
- MLD_PRINTF(("%s: join %s on %p(%s%d))\n", __func__,
- ip6_sprintf(mcaddr), ifp, ifp->if_name, ifp->if_unit));
+ MLD_PRINTF(("%s: join %s on 0x%llx(%s))\n", __func__,
+ ip6_sprintf(mcaddr), (uint64_t)VM_KERNEL_ADDRPERM(ifp),
+ if_name(ifp)));
+ bzero(&mtp, sizeof (mtp));
*pinm = NULL;
/*
}
MLD_PRINTF(("%s: doing mld downcall\n", __func__));
- error = mld_change_state(inm, delay);
+ error = mld_change_state(inm, &mtp, delay);
if (error) {
MLD_PRINTF(("%s: failed to update source\n", __func__));
+ im6f_rollback(imf);
goto out_in6m_release;
}
out_in6m_release:
if (error) {
- MLD_PRINTF(("%s: dropping ref on %p\n", __func__, inm));
+ MLD_PRINTF(("%s: dropping ref on 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(inm)));
IN6M_UNLOCK(inm);
IN6M_REMREF(inm);
} else {
*pinm = inm; /* keep refcount from in6_mc_get() */
}
+ /* schedule timer now that we've dropped the lock(s) */
+ mld_set_timeout(&mtp);
+
return (error);
}
{
struct in6_mfilter timf;
int error, lastref;
+ struct mld_tparams mtp;
+ bzero(&mtp, sizeof (mtp));
error = 0;
IN6M_LOCK_ASSERT_NOTHELD(inm);
in6_multihead_lock_exclusive();
IN6M_LOCK(inm);
- MLD_PRINTF(("%s: leave inm %p, %s/%s%d, imf %p\n", __func__,
- inm, ip6_sprintf(&inm->in6m_addr),
+ MLD_PRINTF(("%s: leave inm 0x%llx, %s/%s%d, imf 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(inm), ip6_sprintf(&inm->in6m_addr),
(in6m_is_ifp_detached(inm) ? "null" : inm->in6m_ifp->if_name),
- inm->in6m_ifp->if_unit, imf));
+ inm->in6m_ifp->if_unit, (uint64_t)VM_KERNEL_ADDRPERM(imf)));
/*
* If no imf was specified (i.e. kernel consumer),
KASSERT(error == 0, ("%s: failed to merge inm state\n", __func__));
MLD_PRINTF(("%s: doing mld downcall\n", __func__));
- error = mld_change_state(inm, 0);
+ error = mld_change_state(inm, &mtp, 0);
#if MLD_DEBUG
if (error)
MLD_PRINTF(("%s: failed mld downcall\n", __func__));
if (lastref)
IN6M_REMREF(inm); /* for in6_multihead list */
+ /* schedule timer now that we've dropped the lock(s) */
+ mld_set_timeout(&mtp);
+
return (error);
}
size_t idx;
uint16_t fmode;
int error, doblock;
+ struct mld_tparams mtp;
+ bzero(&mtp, sizeof (mtp));
ifp = NULL;
error = 0;
doblock = 0;
MLD_PRINTF(("%s: unknown sopt_name %d\n",
__func__, sopt->sopt_name));
return (EOPNOTSUPP);
- break;
}
if (!IN6_IS_ADDR_MULTICAST(&gsa->sin6.sin6_addr))
}
MLD_PRINTF(("%s: doing mld downcall\n", __func__));
- error = mld_change_state(inm, 0);
+ error = mld_change_state(inm, &mtp, 0);
IN6M_UNLOCK(inm);
#if MLD_DEBUG
if (error)
out_imo_locked:
IM6O_UNLOCK(imo);
IM6O_REMREF(imo); /* from in6p_findmoptions() */
+
+ /* schedule timer now that we've dropped the lock(s) */
+ mld_set_timeout(&mtp);
+
return (error);
}
if (error)
return (error);
/* we never use msfr.msfr_srcs; */
- memcpy(&msfr, &msfr64, sizeof(msfr));
+ memcpy(&msfr, &msfr64, sizeof(msfr64));
} else {
error = sooptcopyin(sopt, &msfr32,
sizeof(struct __msfilterreq32),
if (error)
return (error);
/* we never use msfr.msfr_srcs; */
- memcpy(&msfr, &msfr32, sizeof(msfr));
+ memcpy(&msfr, &msfr32, sizeof(msfr32));
}
if (msfr.msfr_group.ss_family != AF_INET6 ||
return (EADDRNOTAVAIL);
if ((size_t) msfr.msfr_nsrcs >
- SIZE_MAX / sizeof(struct sockaddr_storage))
- msfr.msfr_nsrcs = SIZE_MAX / sizeof(struct sockaddr_storage);
+ UINT32_MAX / sizeof(struct sockaddr_storage))
+ msfr.msfr_nsrcs = UINT32_MAX / sizeof(struct sockaddr_storage);
if (msfr.msfr_nsrcs > in6_mcast_maxsocksrc)
msfr.msfr_nsrcs = in6_mcast_maxsocksrc;
IM6O_UNLOCK(imo);
return (ENOBUFS);
}
- bzero(tss, (size_t) msfr.msfr_nsrcs * sizeof(*tss));
}
/*
msfr32.msfr_ifindex = msfr.msfr_ifindex;
msfr32.msfr_fmode = msfr.msfr_fmode;
msfr32.msfr_nsrcs = msfr.msfr_nsrcs;
- memcpy(&msfr64.msfr_group, &msfr.msfr_group,
+ memcpy(&msfr32.msfr_group, &msfr.msfr_group,
sizeof(struct sockaddr_storage));
error = sooptcopyout(sopt, &msfr32,
sizeof(struct __msfilterreq32));
* If socket is neither of type SOCK_RAW or SOCK_DGRAM,
* or is a divert socket, reject it.
*/
- if (inp->inp_socket->so_proto->pr_protocol == IPPROTO_DIVERT ||
- (inp->inp_socket->so_proto->pr_type != SOCK_RAW &&
- inp->inp_socket->so_proto->pr_type != SOCK_DGRAM)) {
+ if (SOCK_PROTO(inp->inp_socket) == IPPROTO_DIVERT ||
+ (SOCK_TYPE(inp->inp_socket) != SOCK_RAW &&
+ SOCK_TYPE(inp->inp_socket) != SOCK_DGRAM)) {
return (EOPNOTSUPP);
}
if (ro6.ro_rt != NULL) {
ifp = ro6.ro_rt->rt_ifp;
VERIFY(ifp != NULL);
- rtfree(ro6.ro_rt);
}
+ ROUTE_RELEASE(&ro6);
return (ifp);
}
size_t idx;
int error, is_new;
uint32_t scopeid = 0;
+ struct mld_tparams mtp;
+ bzero(&mtp, sizeof (mtp));
ifp = NULL;
imf = NULL;
error = 0;
ifp = ifindex2ifnet[mreq.ipv6mr_interface];
ifnet_head_done();
}
- MLD_PRINTF(("%s: ipv6mr_interface = %d, ifp = %p\n",
- __func__, mreq.ipv6mr_interface, ifp));
+ MLD_PRINTF(("%s: ipv6mr_interface = %d, ifp = 0x%llx\n",
+ __func__, mreq.ipv6mr_interface,
+ (uint64_t)VM_KERNEL_ADDRPERM(ifp)));
break;
}
MLD_PRINTF(("%s: unknown sopt_name %d\n",
__func__, sopt->sopt_name));
return (EOPNOTSUPP);
- break;
}
if (!IN6_IS_ADDR_MULTICAST(&gsa->sin6.sin6_addr))
*/
if (is_new) {
+ /*
+ * See inp_join_group() for why we need to unlock
+ */
+ IM6O_ADDREF_LOCKED(imo);
+ IM6O_UNLOCK(imo);
+ socket_unlock(inp->inp_socket, 0);
+
VERIFY(inm == NULL);
error = in6_mc_join(ifp, &gsa->sin6.sin6_addr, imf, &inm, 0);
VERIFY(inm != NULL || error != 0);
+
+ socket_lock(inp->inp_socket, 0);
+ IM6O_REMREF(imo);
+ IM6O_LOCK(imo);
+
if (error)
goto out_im6o_free;
imo->im6o_membership[idx] = inm; /* from in6_mc_join() */
goto out_im6f_rollback;
}
MLD_PRINTF(("%s: doing mld downcall\n", __func__));
- error = mld_change_state(inm, 0);
+ error = mld_change_state(inm, &mtp, 0);
IN6M_UNLOCK(inm);
if (error) {
MLD_PRINTF(("%s: failed mld downcall\n",
out_imo_locked:
IM6O_UNLOCK(imo);
IM6O_REMREF(imo); /* from in6p_findmoptions() */
+
+ /* schedule timer now that we've dropped the lock(s) */
+ mld_set_timeout(&mtp);
+
return (error);
}
uint32_t ifindex = 0;
size_t idx;
int error, is_final;
+ struct mld_tparams mtp;
+ bzero(&mtp, sizeof (mtp));
ifp = NULL;
error = 0;
is_final = 1;
MLD_PRINTF(("%s: unknown sopt_name %d\n",
__func__, sopt->sopt_name));
return (EOPNOTSUPP);
- break;
}
if (!IN6_IS_ADDR_MULTICAST(&gsa->sin6.sin6_addr))
ip6_sprintf(&gsa->sin6.sin6_addr)));
ifp = in6p_lookup_mcast_ifp(inp, &gsa->sin6);
} else {
+ if (!IF_INDEX_IN_RANGE(ifindex))
+ return (EADDRNOTAVAIL);
ifnet_head_lock_shared();
ifp = ifindex2ifnet[ifindex];
ifnet_head_done();
}
VERIFY(ifp != NULL);
- MLD_PRINTF(("%s: ifp = %p\n", __func__, ifp));
+ MLD_PRINTF(("%s: ifp = 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(ifp)));
/*
* Find the membership in the membership array.
}
ims = im6o_match_source(imo, idx, &ssa->sa);
if (ims == NULL) {
- MLD_PRINTF(("%s: source %p %spresent\n", __func__,
+ MLD_PRINTF(("%s: source %s %spresent\n", __func__,
ip6_sprintf(&ssa->sin6.sin6_addr),
"not "));
error = EADDRNOTAVAIL;
}
MLD_PRINTF(("%s: doing mld downcall\n", __func__));
- error = mld_change_state(inm, 0);
+ error = mld_change_state(inm, &mtp, 0);
if (error) {
MLD_PRINTF(("%s: failed mld downcall\n", __func__));
}
/* Remove the gap in the membership array. */
VERIFY(inm == imo->im6o_membership[idx]);
imo->im6o_membership[idx] = NULL;
+
+ /*
+ * See inp_join_group() for why we need to unlock
+ */
+ IM6O_ADDREF_LOCKED(imo);
+ IM6O_UNLOCK(imo);
+ socket_unlock(inp->inp_socket, 0);
+
IN6M_REMREF(inm);
+
+ socket_lock(inp->inp_socket, 0);
+ IM6O_REMREF(imo);
+ IM6O_LOCK(imo);
+
for (++idx; idx < imo->im6o_num_memberships; ++idx) {
imo->im6o_membership[idx-1] = imo->im6o_membership[idx];
imo->im6o_mfilters[idx-1] = imo->im6o_mfilters[idx];
out_locked:
IM6O_UNLOCK(imo);
IM6O_REMREF(imo); /* from in6p_findmoptions() */
+
+ /* schedule timer now that we've dropped the lock(s) */
+ mld_set_timeout(&mtp);
+
return (error);
}
struct in6_multi *inm;
size_t idx;
int error;
- user_addr_t tmp_ptr;
+ user_addr_t tmp_ptr;
+ struct mld_tparams mtp;
+
+ bzero(&mtp, sizeof (mtp));
if (IS_64BIT_PROCESS(current_proc())) {
error = sooptcopyin(sopt, &msfr64,
}
if ((size_t) msfr.msfr_nsrcs >
- SIZE_MAX / sizeof(struct sockaddr_storage))
- msfr.msfr_nsrcs = SIZE_MAX / sizeof(struct sockaddr_storage);
+ UINT32_MAX / sizeof(struct sockaddr_storage))
+ msfr.msfr_nsrcs = UINT32_MAX / sizeof(struct sockaddr_storage);
if (msfr.msfr_nsrcs > in6_mcast_maxsocksrc)
return (ENOBUFS);
}
MLD_PRINTF(("%s: doing mld downcall\n", __func__));
- error = mld_change_state(inm, 0);
+ error = mld_change_state(inm, &mtp, 0);
IN6M_UNLOCK(inm);
#if MLD_DEBUG
if (error)
IM6O_UNLOCK(imo);
IM6O_REMREF(imo); /* from in6p_findmoptions() */
+ /* schedule timer now that we've dropped the lock(s) */
+ mld_set_timeout(&mtp);
+
return (error);
}
* If socket is neither of type SOCK_RAW or SOCK_DGRAM,
* or is a divert socket, reject it.
*/
- if (inp->inp_socket->so_proto->pr_protocol == IPPROTO_DIVERT ||
- (inp->inp_socket->so_proto->pr_type != SOCK_RAW &&
- inp->inp_socket->so_proto->pr_type != SOCK_DGRAM))
+ if (SOCK_PROTO(inp->inp_socket) == IPPROTO_DIVERT ||
+ (SOCK_TYPE(inp->inp_socket) != SOCK_RAW &&
+ SOCK_TYPE(inp->inp_socket) != SOCK_DGRAM))
return (EOPNOTSUPP);
switch (sopt->sopt_name) {
break; /* abort */
}
RB_FOREACH(ims, ip6_msource_tree, &inm->in6m_srcs) {
- MLD_PRINTF(("%s: visit node %p\n", __func__, ims));
+ MLD_PRINTF(("%s: visit node 0x%llx\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(ims)));
/*
* Only copy-out sources which are in-mode.
*/
panic("%s: Attempt to attach an already attached in6m=%p",
__func__, in6m);
/* NOTREACHED */
- } else if (in6m->in6m_debug & IFD_TRASHED) {
- panic("%s: Attempt to reattach a detached in6m=%p",
- __func__, in6m);
- /* NOTREACHED */
}
in6m->in6m_reqcnt++;
static const char *in6m_statestrs[] = {
"not-member\n",
"silent\n",
+ "reporting\n",
"idle\n",
"lazy\n",
"sleeping\n",
{
int t;
- IN6M_LOCK_ASSERT_HELD(IN6M_CAST_TO_NONCONST(inm));
+ IN6M_LOCK_ASSERT_HELD(__DECONST(struct in6_multi *, inm));
if (mld_debug == 0)
return;
- printf("%s: --- begin in6m %p ---\n", __func__, inm);
- printf("addr %s ifp %p(%s%d) ifma %p\n",
+ printf("%s: --- begin in6m 0x%llx ---\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(inm));
+ printf("addr %s ifp 0x%llx(%s) ifma 0x%llx\n",
ip6_sprintf(&inm->in6m_addr),
- inm->in6m_ifp,
- inm->in6m_ifp->if_name,
- inm->in6m_ifp->if_unit,
- inm->in6m_ifma);
+ (uint64_t)VM_KERNEL_ADDRPERM(inm->in6m_ifp),
+ if_name(inm->in6m_ifp),
+ (uint64_t)VM_KERNEL_ADDRPERM(inm->in6m_ifma));
printf("timer %u state %s refcount %u scq.len %u\n",
inm->in6m_timer,
in6m_state_str(inm->in6m_state),
inm->in6m_refcount,
inm->in6m_scq.ifq_len);
- printf("mli %p nsrc %lu sctimer %u scrv %u\n",
- inm->in6m_mli,
+ printf("mli 0x%llx nsrc %lu sctimer %u scrv %u\n",
+ (uint64_t)VM_KERNEL_ADDRPERM(inm->in6m_mli),
inm->in6m_nsrc,
inm->in6m_sctimer,
inm->in6m_scrv);
inm->in6m_st[t].iss_in,
inm->in6m_st[t].iss_rec);
}
- printf("%s: --- end in6m %p ---\n", __func__, inm);
+ printf("%s: --- end in6m 0x%llx ---\n", __func__,
+ (uint64_t)VM_KERNEL_ADDRPERM(inm));
}
#else