commit:     4143e26dd4a56c08fbb99e18913eaafaf2a04f32
Author:     Patrick McLean <chutzpah <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 31 01:07:57 2021 +0000
Commit:     Patrick McLean <chutzpah <AT> gentoo <DOT> org>
CommitDate: Wed Mar 31 01:11:03 2021 +0000
URL:        https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=4143e26d

net/iproute2.sh: in _get_mac_address, don't return multiple addresses

Currently if a device has virtual functions configured, ip will list the mac
addresses for the virtual functions on a device as well as the device itself.
This makes _get_mac_address return these addresses as well, causing functions
that consume this output to fail in "interesting" ways. This makes sure it only
returns 1 address.

Also don't set the mac variable to the address of the interface from sysfs, then
proceed to overwrite it with a call to "ip".

Signed-off-by: Patrick McLean <chutzpah <AT> gentoo.org>

 net/iproute2.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 46f0e48..bd7333e 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -91,10 +91,9 @@ _set_flag()
 _get_mac_address()
 {
        local mac=
-       read -r mac < /sys/class/net/"${IFACE}"/address || return 1
-       local mac=$(LC_ALL=C _ip link show "${IFACE}" | sed -n \
+       mac=$(LC_ALL=C _ip link show "${IFACE}" | sed -n \
                -e 'y/abcdef/ABCDEF/' \
-               -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p')
+               -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p' | head -n1)
 
        case "${mac}" in
                00:00:00:00:00:00) return 1 ;;

Reply via email to