commit:     46f8a90fef9d9bff21760dab52124bfbbb62e064
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jul 17 09:53:36 2021 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Jan 19 18:49:25 2023 +0000
URL:        https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=46f8a90f

net/iproute2.sh: Fix two regressions in _get_mac_address

Commit 4143e26 re-introduced the ip(8) parser in the course of adding
network namespace support. In doing so, it also introduced two
regressions. Firstly, in the case that no MAC address is successfully
discerned, the function will return 0. Secondly, FF:FF:FF:FF:FF:FF is
no longer handled as a special case.

This patch, once again, does away with the ip(8) parser and, instead,
collects the address from sysfs. The _netns function is used to ensure
that the procedure is carried out within the applicable network
namespace, if necessary. In the event that the address file cannot be
read, or that it contains nothing, the function will now return 1,
which addresses the first issue. The second issue is addressed by
uppercasing the applicable case pattern.

As an aside, this patch also addresses an issue whereby sed(1) was used
to match against a pattern containing \< and \>, which are GNU-specific
extensions.

Fixes: 4143e26dd4a56c08fbb99e18913eaafaf2a04f32
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 net/iproute2.sh | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index bd7333e..ea0a6f7 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -91,17 +91,15 @@ _set_flag()
 _get_mac_address()
 {
        local mac=
-       mac=$(LC_ALL=C _ip link show "${IFACE}" | sed -n \
-               -e 'y/abcdef/ABCDEF/' \
-               -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p' | head -n1)
+       mac=$(_netns sed -e 'y/abcdef/ABCDEF/;q' 
/sys/class/net/"${IFACE}"/address) || return
 
        case "${mac}" in
-               00:00:00:00:00:00) return 1 ;;
-               44:44:44:44:44:44) return 1 ;;
-               ff:ff:ff:ff:ff:ff) return 1 ;;
-       esac
-
-       printf '%s\n' "${mac}" | LC_ALL=C tr '[:lower:]' '[:upper:]'
+               '')                false ;;
+               00:00:00:00:00:00) false ;;
+               44:44:44:44:44:44) false ;;
+               FF:FF:FF:FF:FF:FF) false ;;
+       esac &&
+       printf '%s\n' "${mac}"
 }
 
 _set_mac_address()

Reply via email to