From: Jonatan Schlag Date: Sat, 28 Jul 2018 11:59:15 +0000 (+0200) Subject: Add new function device_get_by_mac_address() X-Git-Tag: 010~124 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e8253ebadd1bb494534a977c6a0681bf19df019b;p=network.git 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 --- 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 "$@" ;;