From patchwork Wed Mar 11 18:56:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shirshov X-Patchwork-Id: 11432553 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B066B92A for ; Wed, 11 Mar 2020 18:56:36 +0000 (UTC) Received: from bastion.fedoraproject.org (bastion01.fedoraproject.org [209.132.181.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0F6EE206BE for ; Wed, 11 Mar 2020 18:56:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F6EE206BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=libteam-bounces@lists.fedorahosted.org Received: from mailman01.phx2.fedoraproject.org (mailman01.phx2.fedoraproject.org [10.5.126.36]) by bastion01.phx2.fedoraproject.org (Postfix) with ESMTP id 18A62608E6C1; Wed, 11 Mar 2020 18:56:34 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 bastion01.phx2.fedoraproject.org 18A62608E6C1 Received: from mailman01.phx2.fedoraproject.org (localhost [IPv6:::1]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 104D95D58A29F; Wed, 11 Mar 2020 18:56:34 +0000 (UTC) Received: by mailman01.phx2.fedoraproject.org (Postfix, from userid 991) id 78F525D58A28F; Wed, 11 Mar 2020 18:56:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mailman01.phx2.fedoraproject.org X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=disabled version=3.4.0 Received: from smtp-mm-osuosl01.fedoraproject.org (smtp-mm-osuosl01.vpn.fedoraproject.org [192.168.1.23]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id AFD955D58A28D for ; Wed, 11 Mar 2020 18:56:29 +0000 (UTC) Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by smtp-mm-osuosl01.fedoraproject.org (Postfix) with ESMTPS id 5095A98054 for ; Wed, 11 Mar 2020 18:56:29 +0000 (UTC) Received: by mail-pg1-x541.google.com with SMTP id h8so1678352pgs.9 for ; Wed, 11 Mar 2020 11:56:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=gTPOjUQaw8CShvefLCyFUPYs0xI3MAv8eyKp9NirtBU=; b=ZyNGWoqsCmjFvQNStM0eZosdqGG3gJfVvJfMT8TmrDiPzq9UGZxFjoCqPAJufWB019 hbUOiE3SGo4TBBbW7ruxvJVqzUVSfpeHRRpPjx2SyZma67F5QWt7pOEpAIMx8dJpDmu3 ptlC70uXuFYaMlp+DAKV+d7l6F7Goo+UCgz/whUAVlHyCkA+JmfGlm9MxJLw8/lOaXTB Cx3DayvCCdQA8Rrx4YI8rUUreOO84wRJ8Z8bsO8ANmSWaOEJgYgXKij9U5oY4cbbgvgQ dAzfHdQFhI9xhdgOjFxV4bOO8Fqf2014kV5UtKL22O6sV4BOpUw/lP8LD5LElJdNju5R FJLQ== X-Gm-Message-State: ANhLgQ1/A+gMQ3gcRkCOhtnTvxHY7vnXFJGaUWbMcQ2k8zUlhfigVIkC FkXy+kFjJ8J7VTKOjFy5Xc4j43lTkDY= X-Google-Smtp-Source: ADFU+vtI3LJ14J6WhjgzdbJ/XIbtF5B9st90Zq7giAAwyjIj4SDftCN2xDp/avwOia5lsGjjE5v6oA== X-Received: by 2002:a63:da45:: with SMTP id l5mr3919272pgj.273.1583952988521; Wed, 11 Mar 2020 11:56:28 -0700 (PDT) Received: from localhost.localdomain (50-47-141-89.evrt.wa.frontiernet.net. [50.47.141.89]) by smtp.gmail.com with ESMTPSA id p21sm51760937pfn.103.2020.03.11.11.56.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Mar 2020 11:56:28 -0700 (PDT) From: Pavel Shirshov To: libteam@lists.fedorahosted.org Subject: [PATCH] Fix ifinfo_link_with_port race condition with newlink Date: Wed, 11 Mar 2020 11:56:19 -0700 Message-Id: <1583952979-583-1-git-send-email-pavel.contrib@gmail.com> X-Mailer: git-send-email 2.7.4 Message-ID-Hash: Q4X3FJWBFMK4QO3FZHRG4MCMXDQOEHO5 X-Message-ID-Hash: Q4X3FJWBFMK4QO3FZHRG4MCMXDQOEHO5 X-MailFrom: pavel.contrib@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: jpirko@redhat.com, Shu0T1an ChenG X-Mailman-Version: 3.1.1 Precedence: list List-Id: Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The race condition could happen like this: When an interface is enslaved into the port channel immediately after it is created, the order of creating the ifinfo and linking the ifinfo to the port is not guaranteed. The team handler will listen to both netlink message to track new links get created to allocate the ifinfo and add the ifinfo into its linked list, and the team port change message to link the new port with ifinfo found in its linkedin list. However, when the ifinfo is not yet created, the error message "Failed to link port with ifinfo" is thrown with member port failed to be added into the team handler's port list. This fix adds a condition to check if ifinfo_link_with_port is linking ifinfo to a port or to the team interface itself. If it is a port, ifinfo_find_create function is used to fix the race condition. Signed-off-by: Shu0T1an ChenG --- libteam/ifinfo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libteam/ifinfo.c b/libteam/ifinfo.c index 46d56a2..a15788b 100644 --- a/libteam/ifinfo.c +++ b/libteam/ifinfo.c @@ -453,7 +453,10 @@ int ifinfo_link_with_port(struct team_handle *th, uint32_t ifindex, { struct team_ifinfo *ifinfo; - ifinfo = ifinfo_find(th, ifindex); + if (port) + ifinfo = ifinfo_find_create(th, ifindex); + else + ifinfo = ifinfo_find(th, ifindex); if (!ifinfo) return -ENOENT; if (ifinfo->linked)