From patchwork Mon Mar 5 05:24:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 1687 Return-Path: Received: from mail01.ipfire.org (mail01.ipfire.org [IPv6:2001:470:7183:25::1]) by web02.i.ipfire.org (Postfix) with ESMTP id 285A76095C for ; Sun, 4 Mar 2018 19:25:50 +0100 (CET) X-Virus-Scanned: ClamAV at mail01.ipfire.org X-Spam-Flag: NO X-Spam-Score: -1.099 X-Spam-Level: X-Spam-Status: No, score=-1.099 tagged_above=-999 required=5 tests=[ALL_TRUSTED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mail01.i.ipfire.org (localhost [IPv6:::1]) by mail01.ipfire.org (Postfix) with ESMTP id 25D89111C4FE; Sun, 4 Mar 2018 18:25:49 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ipfire.org; s=201801; t=1520187949; x=1522779949; bh=JDNNcNTw29j0zwkLzAMLexUh/6J+hlJ6RoYIPFNznE0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:Sender:From:To:Cc: Date:Content-Type:Message-ID:In-Reply-To:Subject:Reply-To:Sender; b=H0tlgnSzUY3irVMp/DGvc7b/0c41pe5ZNrJRKR07sVp/skq9Fu7h2n2ne/ThK2qJQ GJnf6MJ/EHFBnXhc2KZhOsa1tDH9Bio3OS8OHYZwQI0cuF3NpHcSRyy//YOKOi+vcg s9DcsGpu+BOfOcUO2V/VIL5fUCxvGnA2ggnGU9eDhRk5AdxvOONKtU263yO2GmADXZ tBsX4vSl6CekFvnTm1ZD3TOlmw9jQ/1HR5wFUioCXE8mvkeUgQd9sK9sdUb71ZXT6q 9FsrDMWhJPHAMpEGBbIHtB5G3shLzZwfQL3xKR8uyR3+Y0tihzAX6G+NGg7Ht0TaXg 9tRmpficuoyWQ== X-Virus-Scanned: ClamAV at mail01.ipfire.org Received: from localhost.localdomain (unknown [46.183.103.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4D4D0108C3BF; Sun, 4 Mar 2018 18:25:41 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ipfire.org; s=201801; t=1520187946; x=1522779946; bh=JDNNcNTw29j0zwkLzAMLexUh/6J+hlJ6RoYIPFNznE0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:From:To:Cc:Date: Content-Type:Message-ID:In-Reply-To:Subject:Reply-To:Sender; b=qmVlq2h9ydc8Nm/C4xZgQzyZ2AsQbjdi0kb8IhT7JmCvvwgjqFdWIaTZVNC1/O6+D NpAfNh7Hen7Pcq4bZeu5jLHT8C2eW+Z3o609Sto1TJ6dEwUzTL4DToLVJzXsx77eef +IAoo3P7xp+r+9OFiCDLnHX28vIzdcTOkVs/BWZ45B9tLZnX4LNiOI9UTgazakaxYL g8ShhSmc59ozI7u7f+BXd+KDkvveRZ7ZfbObW+qFxfwdns39Q1aY6oDFaeSRUI31+V TKkGmvH2QoSMPHg7NhtYgkIGPOerjt/KhsDikYFjCXUD6xatkt6RVUrip/RFIcPdLy Of1bW0PI1Bxog== From: Jonatan Schlag To: network@lists.ipfire.org Subject: [PATCH 3/5] device: add new function device_tunnel_get_type() Date: Sun, 4 Mar 2018 18:24:57 +0000 Message-Id: <1520187899-5759-3-git-send-email-jonatan.schlag@ipfire.org> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1520187899-5759-1-git-send-email-jonatan.schlag@ipfire.org> References: <1520187899-5759-1-git-send-email-jonatan.schlag@ipfire.org> X-BeenThere: network@lists.ipfire.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List for the network package List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: network-bounces@lists.ipfire.org Sender: "network" If we already know that the device must be a ip-tunnel device we can save time when we check just for the types a ip-tunnel device can have. To avoid code duplication we call this function from device_get_type() Signed-off-by: Jonatan Schlag --- src/functions/functions.device | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/functions/functions.device b/src/functions/functions.device index a04111e..0cd6e4e 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -396,9 +396,27 @@ device_get_type() { elif device_is_phy ${device}; then echo "phy" + else + echo "$(device_tunnel_get_type "${device}")" + fi +} + +# This function just checks the types a ip-tunnel device usually have +# so when we know that the device is an ip-tunnel device we save time +device_tunnel_get_type() { + local device=${1} + + # If the device does not exist (happens on udev remove events), + # we do not bother to run all checks. + if ! device_exists "${device}"; then + echo "unknown" + elif device_is_vti ${device}; then echo "vti" + elif device_is_vti6 ${device}; then + echo "vti6" + else echo "unknown" fi