From e8253ebadd1bb494534a977c6a0681bf19df019b Mon Sep 17 00:00:00 2001 From: Jonatan Schlag Date: Sat, 28 Jul 2018 13:59:15 +0200 Subject: [PATCH] Add new function device_get_by_mac_address() We need this function and the command to identify ports in a nitsi test. Signed-off-by: Jonatan Schlag Signed-off-by: Michael Tremer --- src/functions/functions.device | 18 ++++++++++++++++++ src/network | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/functions/functions.device b/src/functions/functions.device index 0cd6e4ea..ace40220 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -1111,3 +1111,21 @@ device_get_by_assigned_ip_address() { print "${device}" return ${EXIT_OK} } + +device_get_by_mac_address() { + local mac=${1} + + assert isset mac + + local device + + for device in $(device_list); do + if [ "${mac}" = "$(device_get_address ${device})" ]; then + print "${device}" + return ${EXIT_OK} + fi + done + + # We could not found a port to the given mac address so we return exit error + return ${EXIT_ERROR} +} diff --git a/src/network b/src/network index b28ecdba..f26c0dc0 100644 --- a/src/network +++ b/src/network @@ -1286,6 +1286,9 @@ cli_raw() { db-dump) db_dump ;; + device-get-by-mac-address) + device_get_by_mac_address "$@" + ;; ipsec-connection-exists) ipsec_connection_exists "$@" ;; -- 2.39.2