From patchwork Fri Apr 3 00:24:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shirshov X-Patchwork-Id: 11471713 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 5C4A0912 for ; Fri, 3 Apr 2020 00:24:30 +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 24E8520787 for ; Fri, 3 Apr 2020 00:24:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 24E8520787 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 54FB6621336B; Fri, 3 Apr 2020 00:24:29 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 bastion01.phx2.fedoraproject.org 54FB6621336B Received: from mailman01.phx2.fedoraproject.org (localhost [IPv6:::1]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 435135DD3805F; Fri, 3 Apr 2020 00:24:29 +0000 (UTC) Received: by mailman01.phx2.fedoraproject.org (Postfix, from userid 991) id A9D225DD38044; Fri, 3 Apr 2020 00:24:25 +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 2E4BC5DD37B12 for ; Fri, 3 Apr 2020 00:24:25 +0000 (UTC) Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) (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 DE57E90B97 for ; Fri, 3 Apr 2020 00:24:24 +0000 (UTC) Received: by mail-pj1-x1042.google.com with SMTP id m15so2189552pje.3 for ; Thu, 02 Apr 2020 17:24:24 -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=nwafTvh4qjdFvvPWBRKB3mezWF+GqnDQkeoL733rXQM=; b=iqZR2xSgtwdWxrSAogEvuudZrf073XS9rsJnAAeVk8klwOJZKeupCiPXqmnwQES8SO QGqnyCL6YOy2X3Y3OZ32CMxup42Dgjgm6YIMIxHAfi5pe27hLJ7WnKab19LZnMar4PZi BHEQV8+EpD/dP/vw8Y6mf5qB0i0bJSnWSv2qamHgztYncODCxeoeMAo7howpSwpPqTZS d7Qs3NU0YNpAODInnqbL5yV4UQLpdXHTVrfU8umz5JpUbF2nLFRFfboMKDPLLR5i6DqK TaEpp5e/oMcIEX2LYSH+6nnr9wNOMKRsq6UM3v17zUkMVsGXqexdul/CoT6EWBjBxYTx HgCA== X-Gm-Message-State: AGi0PuYrxJg+f/HD+IF8kqw9aqllw2RHUDZmsAmzSxWx2BM/ApYrw3Es qhWlgutmp5YZOH+h0Rvj6KlxXYgr X-Google-Smtp-Source: APiQypLT5/3OWqhYMGwdZg5v1eHw/Uxx8BNbkhBvu8HqbY68+RzRjJ8xxNBQaCzgwtbuN/5rk8RhXg== X-Received: by 2002:a17:902:8609:: with SMTP id f9mr5165230plo.203.1585873464040; Thu, 02 Apr 2020 17:24:24 -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 y14sm4567195pfp.127.2020.04.02.17.24.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Apr 2020 17:24:23 -0700 (PDT) From: Pavel Shirshov To: libteam@lists.fedorahosted.org Subject: [PATCH] Fix ifinfo_link_with_port race condition with newlink Date: Thu, 2 Apr 2020 17:24:05 -0700 Message-Id: <1585873445-25752-1-git-send-email-pavel.contrib@gmail.com> X-Mailer: git-send-email 2.7.4 Message-ID-Hash: 6AUAK2PTKKY64NSDLA2PNUAQ2JKC3QJL X-Message-ID-Hash: 6AUAK2PTKKY64NSDLA2PNUAQ2JKC3QJL 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: Shuotian Cheng , jiri@resnulli.us 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 When a member port is enslaved into a port channel immediately after the port channel was created, it is possible to get member port ifinfo structure not initialized for the member port because of a race condition. The race condition here occurs because order of following events is not strict: - adding the member port to the port channel; - creating ifinfo structure for the member port. The error message "Failed to link port with ifinfo" is thrown when a member port is tried to be added to the team handler's port list before ifinfo structure was initialized. To fix this situation ifinfo_find_create() is used to search member ports ifinfo structure in ifinfo_link_with_port(). Signed-off-by: Shuotian Cheng Signed-off-by: Pavel Shirshov --- 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)