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
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} +}