From patchwork Mon Jun 30 02:50:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ding Tianhong X-Patchwork-Id: 32678 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1CF7923577 for ; Mon, 30 Jun 2014 02:50:55 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id rd3sf40530074pab.3 for ; Sun, 29 Jun 2014 19:50:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:subject:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=xemKEKSu/QbLCLtNnfjIIp9iTHsxY7j3UyrPZBTxlK8=; b=EyomWSgEoHdzo0/oq49KUtx8MqMLtqVTCZQyKIw//vwJ2NbZovciOvoE2pgLq7uT6h aYy+OLykYkCX8w6sfnx6M1/VnsPTDBjcPHdUcS2GswqADjzrj2uZR117xVDSRIYR168a 0spmbDG6kT/Jlfp/YhHT0VqWArMb7O9rqnEY1UkJWHhwU42FmZj8u8W8SQ61Zgd1ZyYR Bw8zqR2cVzpQxFyqw5fEjvePsc9xZkAEgkVbWPGPJZJJ2Zv5/TV57wNqpqZfGzNkNFRA 8YIM9UxUGYCWK94zUD1UgPHpuoqx14WdFYGrx5NO+6mNF+9wjwNn38AKLGdwh+I5rCKq xXtA== X-Gm-Message-State: ALoCoQkCG1KnCQlkuk7aylwNl8MF1MkULPfmktgH9HeuJctmREssiZ8RcVta4fVPq+J87TNZkcsm X-Received: by 10.66.189.163 with SMTP id gj3mr21970744pac.32.1404096653882; Sun, 29 Jun 2014 19:50:53 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.44.35 with SMTP id f32ls69093qga.54.gmail; Sun, 29 Jun 2014 19:50:53 -0700 (PDT) X-Received: by 10.221.55.70 with SMTP id vx6mr18748021vcb.23.1404096653778; Sun, 29 Jun 2014 19:50:53 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id ha4si9476567veb.1.2014.06.29.19.50.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 29 Jun 2014 19:50:53 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.174 as permitted sender) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id jx11so7598398veb.33 for ; Sun, 29 Jun 2014 19:50:53 -0700 (PDT) X-Received: by 10.58.8.12 with SMTP id n12mr35343386vea.28.1404096653678; Sun, 29 Jun 2014 19:50:53 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp105071vcb; Sun, 29 Jun 2014 19:50:53 -0700 (PDT) X-Received: by 10.66.163.98 with SMTP id yh2mr37390752pab.104.1404096652922; Sun, 29 Jun 2014 19:50:52 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xl4si21534440pab.5.2014.06.29.19.50.52; Sun, 29 Jun 2014 19:50:52 -0700 (PDT) Received-SPF: none (google.com: netdev-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754020AbaF3Cuu (ORCPT + 3 others); Sun, 29 Jun 2014 22:50:50 -0400 Received: from szxga01-in.huawei.com ([119.145.14.64]:55849 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753989AbaF3Cus (ORCPT ); Sun, 29 Jun 2014 22:50:48 -0400 Received: from 172.24.2.119 (EHLO szxeml450-hub.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BXX96886; Mon, 30 Jun 2014 10:50:36 +0800 (CST) Received: from [127.0.0.1] (10.177.22.246) by szxeml450-hub.china.huawei.com (10.82.67.193) with Microsoft SMTP Server id 14.3.158.1; Mon, 30 Jun 2014 10:50:29 +0800 Message-ID: <53B0D06D.30908@huawei.com> Date: Mon, 30 Jun 2014 10:50:21 +0800 From: Ding Tianhong User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: "David S. Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy , Netdev Subject: [PATCH net] igmp: fix the problem when mc leave group X-Originating-IP: [10.177.22.246] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: netdev@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: dingtianhong@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The problem was triggered by these steps: 1) create socket, bind and then setsockopt for add mc group. mreq.imr_multiaddr.s_addr = inet_addr("255.0.0.37"); mreq.imr_interface.s_addr = inet_addr("192.168.1.2"); setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); 2) drop the mc group for this socket. mreq.imr_multiaddr.s_addr = inet_addr("255.0.0.37"); mreq.imr_interface.s_addr = inet_addr("0.0.0.0"); setsockopt(sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); 3) and then drop the socket, I found the mc group was still used by the dev: netstat -g Interface RefCnt Group --------------- ------ --------------------- eth2 1 255.0.0.37 Normally even though the IP_DROP_MEMBERSHIP return error, the mc group still need to be released for the netdev when drop the socket, but this process was broken when route default is NULL, the reason is that: The ip_mc_leave_group() will choose the in_dev by the imr_interface.s_addr, if input addr is NULL, the default route dev will be chosen, then the ifindex is got from the dev, then polling the inet->mc_list and return -ENODEV, but if the default route dev is NULL, the in_dev and ifIndex is both NULL, when polling the inet->mc_list, the mc group will be released from the mc_list, but the dev didn't dec the refcnt for this mc group, so when dropping the socket, the mc_list is NULL and the dev still keep this group. Fix this by checking the ifindex when polling the mc_list in ip_mc_leave_group(), don't release the mc group from the inet->mc_list if the index is 0, leave this work to ip_mc_drop_socket(). Signed-off-by: Ding Tianhong --- net/ipv4/igmp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 6748d42..03e0629 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -1950,10 +1950,9 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr) imlp = &iml->next_rcu) { if (iml->multi.imr_multiaddr.s_addr != group) continue; - if (ifindex) { - if (iml->multi.imr_ifindex != ifindex) + if (ifindex || iml->multi.imr_ifindex != ifindex) continue; - } else if (imr->imr_address.s_addr && imr->imr_address.s_addr != + else if (imr->imr_address.s_addr && imr->imr_address.s_addr != iml->multi.imr_address.s_addr) continue;