From 905b13b37cfd96011d12617cc3b55b11b2a76a55 Mon Sep 17 00:00:00 2001 From: Jonatan Schlag via network Date: Fri, 23 Feb 2018 11:05:33 +0000 Subject: [PATCH] Add new function: device_get_by_assigned_ip_address() 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 Signed-off-by: Michael Tremer --- src/functions/functions.device | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/functions/functions.device b/src/functions/functions.device index cb4911f9..2de1ad94 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} +} -- 2.39.2