summaryrefslogtreecommitdiffstats
path: root/sys/netinet6
diff options
context:
space:
mode:
authorbms <bms@FreeBSD.org>2009-11-19 13:30:06 +0000
committerbms <bms@FreeBSD.org>2009-11-19 13:30:06 +0000
commitd8ea9b2a5b7aea2ef3f7fbd0e576d5554cf1594d (patch)
treea4938eee28d1a133ce7669d18ea3e99c1d316344 /sys/netinet6
parent8c86c2baadd1d3d5c5dbba8c1598400f9f99ce43 (diff)
downloadFreeBSD-src-d8ea9b2a5b7aea2ef3f7fbd0e576d5554cf1594d.zip
FreeBSD-src-d8ea9b2a5b7aea2ef3f7fbd0e576d5554cf1594d.tar.gz
Adapt r197132 to IPv6 stack:
Tighten input checking in in6p_join_group(): * Don't try to use the source address, when its family is unspecified. * If we get a join without a source, on an existing inclusive mode group, this is an error, as it would change the filter mode. Fix a problem with the handling of in6_mfilter for new memberships: * Do not rely on im6f being NULL; it is explicitly initialized to a non-NULL pointer when constructing a membership. * Explicitly initialize *im6f to EX mode when the source address is unspecified. This fixes a problem with in_mfilter slot recycling in the join path. MFC after: 1 day
Diffstat (limited to 'sys/netinet6')
-rw-r--r--sys/netinet6/in6_mcast.c50
1 files changed, 35 insertions, 15 deletions
diff --git a/sys/netinet6/in6_mcast.c b/sys/netinet6/in6_mcast.c
index 9fc3c48..c1e4f12 100644
--- a/sys/netinet6/in6_mcast.c
+++ b/sys/netinet6/in6_mcast.c
@@ -1917,11 +1917,6 @@ in6p_join_group(struct inpcb *inp, struct sockopt *sopt)
*/
(void)in6_setscope(&gsa->sin6.sin6_addr, ifp, NULL);
- /*
- * MCAST_JOIN_SOURCE on an exclusive membership is an error.
- * On an existing inclusive membership, it just adds the
- * source to the filter list.
- */
imo = in6p_findmoptions(inp);
idx = im6o_match_group(imo, ifp, &gsa->sa);
if (idx == -1) {
@@ -1929,15 +1924,33 @@ in6p_join_group(struct inpcb *inp, struct sockopt *sopt)
} else {
inm = imo->im6o_membership[idx];
imf = &imo->im6o_mfilters[idx];
- if (ssa->ss.ss_family != AF_UNSPEC &&
- imf->im6f_st[1] != MCAST_INCLUDE) {
- error = EINVAL;
- goto out_in6p_locked;
- }
- lims = im6o_match_source(imo, idx, &ssa->sa);
- if (lims != NULL) {
- error = EADDRNOTAVAIL;
- goto out_in6p_locked;
+ if (ssa->ss.ss_family != AF_UNSPEC) {
+ /*
+ * MCAST_JOIN_SOURCE_GROUP on an exclusive membership
+ * is an error. On an existing inclusive membership,
+ * it just adds the source to the filter list.
+ */
+ if (imf->im6f_st[1] != MCAST_INCLUDE) {
+ error = EINVAL;
+ goto out_in6p_locked;
+ }
+ /* Throw out duplicates. */
+ lims = im6o_match_source(imo, idx, &ssa->sa);
+ if (lims != NULL) {
+ error = EADDRNOTAVAIL;
+ goto out_in6p_locked;
+ }
+ } else {
+ /*
+ * MCAST_JOIN_GROUP on an existing inclusive
+ * membership is an error; if you want to change
+ * filter mode, you must use the userland API
+ * setsourcefilter().
+ */
+ if (imf->im6f_st[1] == MCAST_INCLUDE) {
+ error = EINVAL;
+ goto out_in6p_locked;
+ }
}
}
@@ -1970,7 +1983,8 @@ in6p_join_group(struct inpcb *inp, struct sockopt *sopt)
/*
* Graft new source into filter list for this inpcb's
* membership of the group. The in6_multi may not have
- * been allocated yet if this is a new membership.
+ * been allocated yet if this is a new membership, however,
+ * the in_mfilter slot will be allocated and must be initialized.
*/
if (ssa->ss.ss_family != AF_UNSPEC) {
/* Membership starts in IN mode */
@@ -1987,6 +2001,12 @@ in6p_join_group(struct inpcb *inp, struct sockopt *sopt)
error = ENOMEM;
goto out_im6o_free;
}
+ } else {
+ /* No address specified; Membership starts in EX mode */
+ if (is_new) {
+ CTR1(KTR_MLD, "%s: new join w/o source", __func__);
+ im6f_init(imf, MCAST_UNDEFINED, MCAST_EXCLUDE);
+ }
}
/*
OpenPOWER on IntegriCloud