From patchwork Fri Feb 23 22:05:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag via network X-Patchwork-Id: 1671 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 577C060AB7 for ; Fri, 23 Feb 2018 12:05:49 +0100 (CET) X-Virus-Scanned: ClamAV at mail01.ipfire.org Received: from mail01.i.ipfire.org (localhost [IPv6:::1]) by mail01.ipfire.org (Postfix) with ESMTP id 2B17C108B8A1; Fri, 23 Feb 2018 11:06:04 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.ipfire.org; s=201801; t=1519383964; x=1521975964; bh=7RdgPw9le1tQS6iF5oU/MVEAAWQ+iLiOtM/STGLaJxU=; h=To:Subject:Date:Message-Id:From:Reply-To:Sender:From:To:Cc:Date: Content-Type:Message-ID:In-Reply-To:Subject:Reply-To:Sender; b=pWKuyXG9Mp20EKxERzpYmV7YsCg9b/O7ZFphRRF0nAH26UGEb0nYeWDvacn5KwtjU inHLmv9JUbXEJcpfHzvMwiafbbWFLcfSLR074S8k0UdJelwI/onRSrwqXkHYDe4kqU +kH2bu6eSctiDmN0oMEMFZSpqyfSHFDKdomVIq38z3AH2aD8LA2qeih9iO9h1FPhZH N6B+KmkjMQcW9+7H2hkW7DLxh7OJ597Q5Z+ySQGpxExUYaWhfacR017+kA3fDBGCW4 8n892zixD8Q/eE1zqSX6kRUzb5SxXFqD+zwXvi/NQylLPSX66N5Od3oAKMoaVHSEJv XFbiDHDaNVEnA== X-Virus-Scanned: ClamAV at mail01.ipfire.org Received: from localhost.localdomain (unknown [10.172.1.10]) (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 660AE108B8A1; Fri, 23 Feb 2018 11:06:00 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ipfire.org; s=201801; t=1519383960; x=1521975960; bh=7RdgPw9le1tQS6iF5oU/MVEAAWQ+iLiOtM/STGLaJxU=; h=From:To:Cc:Subject:Date:Message-Id:From:To:Cc:Date:Content-Type: Message-ID:In-Reply-To:Subject:Reply-To:Sender; b=dsiT91EMGS3TQ6tHeppZz6FqS3LoLf+N80tPSFzM1mUGxQb4YLt4+NUvyVxBbyqBe NSxhvnW/S06jqvTWt6LxJE3/REAA3On/M3+ZKo5UYHz2R73g33Bdt39VpsjxYu+lQX 8X3em6eCrXPIctpNElz5gH6t6hG34lGh1HQZ7C7pKmvWss4nao9UZCZozalId6+hsT Sxa4LXtnCXfal2QZHG8Kjo0szdpYrQrfsy+jMFGYBtBbOOp+qvtO010wS62sv8bVkD 59YSLD5rLezFJ6ac+YIhP41UzU+JuhZDSzOuYXi09cMT244QSQtrd/SkggvGRv/yaS +utceyrF57QGw== To: network@lists.ipfire.org Subject: [PATCH 1/3] Add new function: device_get_by_assigned_ip_address() Date: Fri, 23 Feb 2018 11:05:33 +0000 Message-Id: <1519383935-3556-1-git-send-email-jonatan.schlag@ipfire.org> X-Mailer: git-send-email 2.6.3 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: , X-Patchwork-Original-From: Jonatan Schlag via network From: Jonatan Schlag via network Reply-To: Jonatan Schlag Errors-To: network-bounces@lists.ipfire.org Sender: "network" This function is used to get a device from an IP address which is assigned to the device. This function needs to be introduced to set the routes for IPsec correctly. Signed-off-by: Jonatan Schlag --- src/functions/functions.device | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/functions/functions.device b/src/functions/functions.device index cb4911f..2de1ad9 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -1058,3 +1058,30 @@ device_queue_set_smp_affinity() { __processor_id_to_bitmap ${processor} > ${path} } + +# Tries to find a device which has the given IP address assigned +device_get_by_assigned_ip_address() { + local ip=${1} + + assert isset ip + + local device + + # Read the first line of ip addr show to + read -r device <<< $(ip addr show to "${ip}") + + # If we did not found a device we return with ${EXIT_ERROR} + if ! isset device; then + return ${EXIT_ERROR} + fi + + # We get something like: + # 3: upl0: mtu 1500 qdisc mq state UP group default qlen 1000 + # and we want upl0 so we take the second word and removing the : + device=(${device}) + device=${device[1]} + device=${device%:} + + print "${device}" + return ${EXIT_OK} +}