Message ID | 1519383935-3556-1-git-send-email-jonatan.schlag@ipfire.org |
---|---|
State | Accepted |
Commit | 905b13b37cfd96011d12617cc3b55b11b2a76a55 |
Headers |
Return-Path: <network-bounces@lists.ipfire.org> 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 <patchwork@web02.i.ipfire.org>; 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 <network.lists.ipfire.org> List-Unsubscribe: <https://lists.ipfire.org/mailman/options/network>, <mailto:network-request@lists.ipfire.org?subject=unsubscribe> List-Archive: <https://lists.ipfire.org/pipermail/network/> List-Post: <mailto:network@lists.ipfire.org> List-Help: <mailto:network-request@lists.ipfire.org?subject=help> List-Subscribe: <https://lists.ipfire.org/mailman/listinfo/network>, <mailto:network-request@lists.ipfire.org?subject=subscribe> From: Jonatan Schlag via network <network@lists.ipfire.org> Reply-To: Jonatan Schlag <jonatan.schlag@ipfire.org> Errors-To: network-bounces@lists.ipfire.org Sender: "network" <network-bounces@lists.ipfire.org> |
Series |
[1/3] Add new function: device_get_by_assigned_ip_address()
|
|
Commit Message
Jonatan Schlag via network
Feb. 23, 2018, 10:05 p.m. UTC
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 <jonatan.schlag@ipfire.org>
---
src/functions/functions.device | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
Comments
Hello, what happens when the same IP address is assigned to multiple interfaces? That should not be because it doesn't make much sense, but people configure stupid things and we should make sure that that doesn't crash other parts of networking. -Michael On Fri, 2018-02-23 at 11:05 +0000, Jonatan Schlag via network wrote: > 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 <jonatan.schlag@ipfire.org> > --- > 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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} > +}
Hi, Am Sa, 24. Feb, 2018 um 12:50 schrieb Michael Tremer <michael.tremer@ipfire.org>: > Hello, > > what happens when the same IP address is assigned to multiple > interfaces? > > That should not be because it doesn't make much sense, but people > configure > stupid things and we should make sure that that doesn't crash other > parts of > networking. > > -Michael We take only the first line of the $(ip addr show to ...), so we take the first device we get. But I see no way to catch this stupid configuration. When the configuration is wrong, I see no problem when the code "fails" Jonatan > > > On Fri, 2018-02-23 at 11:05 +0000, Jonatan Schlag via network wrote: >> 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 <jonatan.schlag@ipfire.org> >> --- >> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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} >> +} Hi,<br><br>Am Sa, 24. Feb, 2018 um 12:50 schrieb Michael Tremer <michael.tremer@ipfire.org>:<br> <blockquote type="cite"><div class="plaintext" style="white-space: pre-wrap;">Hello, what happens when the same IP address is assigned to multiple interfaces? That should not be because it doesn't make much sense, but people configure stupid things and we should make sure that that doesn't crash other parts of networking. -Michael</div></blockquote><div><br></div><div>We take only the first line of the $(ip addr show to ...), so we take the first device we get.</div><div>But I see no way to catch this stupid configuration. When the configuration is wrong, I see no problem when the code "fails"</div><div><br></div>Jonatan<br><blockquote type="cite"><div class="plaintext" style="white-space: pre-wrap;"> On Fri, 2018-02-23 at 11:05 +0000, Jonatan Schlag via network wrote: <blockquote> 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 <<a href="mailto:jonatan.schlag@ipfire.org">jonatan.schlag@ipfire.org</a>> --- 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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} +} </blockquote></div></blockquote>
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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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} +}