Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754006Ab2BTQeZ (ORCPT ); Mon, 20 Feb 2012 11:34:25 -0500 Received: from bhuna.collabora.co.uk ([93.93.135.160]:43234 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753763Ab2BTQdY (ORCPT ); Mon, 20 Feb 2012 11:33:24 -0500 From: Javier Martinez Canillas To: "David S. Miller" Cc: Eric Dumazet , Lennart Poettering , Kay Sievers , Alban Crequy , Bart Cerneels , Rodrigo Moya , Sjoerd Simons , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/10] af_unix: Unsubscribe sockets from their multicast groups on RCV_SHUTDOWN Date: Mon, 20 Feb 2012 17:33:47 +0100 Message-Id: <1329755629-10644-5-git-send-email-javier@collabora.co.uk> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1329755629-10644-1-git-send-email-javier@collabora.co.uk> References: <1329755629-10644-1-git-send-email-javier@collabora.co.uk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2098 Lines: 70 From: Alban Crequy Signed-off-by: Alban Crequy Reviewed-by: Ian Molton --- net/unix/af_unix.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index bd9dc58..07e6b05 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2841,6 +2841,10 @@ static int unix_shutdown(struct socket *sock, int mode) { struct sock *sk = sock->sk; struct sock *other; +#ifdef CONFIG_UNIX_MULTICAST + struct unix_sock *u = unix_sk(sk); + int unsubscribed = 0; +#endif mode = (mode+1)&(RCV_SHUTDOWN|SEND_SHUTDOWN); @@ -2852,7 +2856,38 @@ static int unix_shutdown(struct socket *sock, int mode) other = unix_peer(sk); if (other) sock_hold(other); + +#ifdef CONFIG_UNIX_MULTICAST + /* If the socket subscribed to a multicast group and it is shutdown + * with (mode&RCV_SHUTDOWN), it should be unsubscribed or at least + * stop blocking the peers */ + if (mode&RCV_SHUTDOWN) { + struct unix_mcast *node; + struct hlist_node *pos; + struct hlist_node *pos_tmp; + + spin_lock(&unix_multicast_lock); + hlist_for_each_entry_safe(node, pos, pos_tmp, + &u->mcast_subscriptions, + subscription_node) { + hlist_del_rcu(&node->member_node); + hlist_del_rcu(&node->subscription_node); + atomic_dec(&node->group->mcast_members_cnt); + atomic_inc(&node->group->mcast_membership_generation); + hlist_add_head_rcu(&node->member_dead_node, + &node->group->mcast_dead_members); + unsubscribed = 1; + } + spin_unlock(&unix_multicast_lock); + } +#endif unix_state_unlock(sk); + +#ifdef CONFIG_UNIX_MULTICAST + if (unsubscribed) + wake_up_interruptible_all(&u->peer_wait); +#endif + sk->sk_state_change(sk); if (other && -- 1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/