]> git.ipfire.org Git - people/ms/network.git/commitdiff
Add new function device_get_by_mac_address()
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sat, 28 Jul 2018 11:59:15 +0000 (13:59 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 28 Jul 2018 12:28:08 +0000 (13:28 +0100)
We need this function and the command to identify ports in a nitsi test.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.device
src/network

index 0cd6e4ea0cf3cc74f78077c1e118d3fc9206c7ad..ace402209134fbd486c440644a4055957a7a3ee7 100644 (file)
@@ -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}
+}
index b28ecdbad633c8399d7710ff6b4a03982f244d32..f26c0dc0ecf5ae7cb056e40e4b78ee9d868993f5 100644 (file)
@@ -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 "$@"
                        ;;