From patchwork Wed Sep 9 13:45:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Dedecker X-Patchwork-Id: 515860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 70968140281 for ; Wed, 9 Sep 2015 23:46:22 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=rXw0/gq4; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 3114A286F0B; Wed, 9 Sep 2015 15:45:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 6E0542845AF for ; Wed, 9 Sep 2015 15:45:02 +0200 (CEST) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Wed, 9 Sep 2015 15:45:01 +0200 (CEST) Received: by wicgb1 with SMTP id gb1so117263104wic.1 for ; Wed, 09 Sep 2015 06:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=SKMoz9kY3xDedPZ3s/tL7l8M3nidYmaRgffQyPshZoA=; b=rXw0/gq4J1kKTc2KfmbJ2L70AU2/YdKbXjTfgsueehHwn6Lyptvm6Cz0w8lRvyZeR6 2cOaHKDZ/oLMw38Ox/t8Vif4r7dYJGQUPI2mdx6T1x839+lOTz5jS9mgCN2l1XYa9btd tlTr69zHnL9k6ZLC7JyT8UYSIjlFhv6ntIA6irQ7mWlkihZy1WrdKuMzq834UEowDCBz UTa9jld7wnQgIAe8DA0pHllW1QKxf9hYKolgmrVuGGQMJeTY4WnvoFe2+T0j4+Q0H5b5 KzWCHlMAC17knOoB2lMPnYw1TjSRtKqZHzcULTk3obVKs7GjWqCH9iyVBQxADNqn6wlM loRg== X-Received: by 10.194.87.4 with SMTP id t4mr62759390wjz.84.1441806366427; Wed, 09 Sep 2015 06:46:06 -0700 (PDT) Received: from cplx43.eu.thmulti.com ([141.11.62.7]) by smtp.gmail.com with ESMTPSA id fu5sm6764421wic.0.2015.09.09.06.46.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Sep 2015 06:46:05 -0700 (PDT) From: Hans Dedecker To: openwrt-devel@lists.openwrt.org Date: Wed, 9 Sep 2015 15:45:47 +0200 Message-Id: <1441806352-18030-1-git-send-email-dedeckeh@gmail.com> X-Mailer: git-send-email 1.9.1 Cc: Hans Dedecker , cyrus@openwrt.org Subject: [OpenWrt-Devel] [PATCH netifd 1/6] device: Resolve ifindex for external claimed devices X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Fixes regression issues introduced by commit 3224b80 as external (PPP) device ifindex was not in sync with kernel device ifindex due to re-creation of the device by the PPP daemon Signed-off-by: Hans Dedecker --- device.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/device.c b/device.c index 21b436f..a29c981 100644 --- a/device.c +++ b/device.c @@ -74,15 +74,14 @@ void device_unlock(void) static int set_device_state(struct device *dev, bool state) { if (state) { - /* Set ifindex for all devices being enabled so a valid */ + /* Get ifindex for all devices being enabled so a valid */ /* ifindex is in place avoiding possible race conditions */ device_set_ifindex(dev, system_if_resolve(dev)); if (!dev->ifindex) return -1; - } - if (state) system_if_up(dev); + } else system_if_down(dev); @@ -332,7 +331,13 @@ int device_claim(struct device_user *dep) return 0; device_broadcast_event(dev, DEV_EVENT_SETUP); - if (!dev->external) + if (dev->external) { + /* Get ifindex for external claimed devices so a valid */ + /* ifindex is in place avoiding possible race conditions */ + device_set_ifindex(dev, system_if_resolve(dev)); + if (!dev->ifindex) + ret = -1; + } else ret = dev->set_state(dev, true); if (ret == 0)