From patchwork Tue Mar 24 02:43:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shirshov X-Patchwork-Id: 11454393 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 184E61668 for ; Tue, 24 Mar 2020 02:44: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 D7D4820409 for ; Tue, 24 Mar 2020 02:44:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D7D4820409 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 1BF9960748E0; Tue, 24 Mar 2020 02:44:29 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 bastion01.phx2.fedoraproject.org 1BF9960748E0 Received: from mailman01.phx2.fedoraproject.org (localhost [IPv6:::1]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 101295DB4A2BF; Tue, 24 Mar 2020 02:44:29 +0000 (UTC) Received: by mailman01.phx2.fedoraproject.org (Postfix, from userid 991) id C6D3B5DB4A2BA; Tue, 24 Mar 2020 02:44:24 +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,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=disabled version=3.4.0 Received: from smtp-mm-ib01.fedoraproject.org (smtp-mm-ib01.vpn.fedoraproject.org [192.168.1.83]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 0A77D5DB4A2A6 for ; Tue, 24 Mar 2020 02:44:24 +0000 (UTC) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) (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-ib01.fedoraproject.org (Postfix) with ESMTPS id 95D256081519 for ; Tue, 24 Mar 2020 02:44:23 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id h11so6777880plr.11 for ; Mon, 23 Mar 2020 19:44:23 -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=TjH/fRa3hjlwpMGSEaCSuxLGtU18hGHQhrFKX5xy6xbRJr9PfQMCLhyrATbdsfwJ03 wDbAROWfOILllw5F2GekbXTjPU0N4+vTBV2D+/NlvmOkiuKuwftKjzCBJtKwJsU0Gm9k PkUaxoVcCaUySWUEVEV3P6bKh8V9eFMpj2uaAnVSoUfL3Svc1bzwDaKGIQ21ta0CEsi+ 5/a6YqfuQ/bj25NiQPegWEyJXVP5gCey/VLngrLfvmV+v0fZyx/s8kTHYRJuj/XhwFyj Bby8Pc/Ev9c3T8ToT0JpXnSrJAQZorPT92XGoO+7j4wlnKB99lVK4Xofbu51FRyupHe/ HZhQ== X-Gm-Message-State: ANhLgQ0uUq1hug/tulZWTkjA9mXBfA+Fs9VC45cr0nI3ml4cfmorXdEm A+SqdhoQvbQ5DHCHTbif4IV2voEn X-Google-Smtp-Source: ADFU+vtko53rmWc8xm+a9KhXrtN26JnRYWo4S83ZWWGUBqzT4x+DfIrD0kFONNd6Uo5cod9qEwd45g== X-Received: by 2002:a17:90a:e287:: with SMTP id d7mr2714141pjz.76.1585017862336; Mon, 23 Mar 2020 19:44:22 -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 y30sm15058636pff.67.2020.03.23.19.44.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Mar 2020 19:44:21 -0700 (PDT) From: Shuotian Cheng X-Google-Original-From: Shuotian Cheng To: libteam@lists.fedorahosted.org Subject: [PATCH] Fix ifinfo_link_with_port race condition with newlink Date: Mon, 23 Mar 2020 19:43:47 -0700 Message-Id: <1585017827-25417-1-git-send-email-shuche@microsoft.com> X-Mailer: git-send-email 2.7.4 Message-ID-Hash: JOXMEUVQTVFICOAFA4S5QIUKHZIBCTTK X-Message-ID-Hash: JOXMEUVQTVFICOAFA4S5QIUKHZIBCTTK 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: Pavel Shirshov , 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)