From 46f8a90fef9d9bff21760dab52124bfbbb62e064 Mon Sep 17 00:00:00 2001 From: Kerin Millar Date: Sat, 17 Jul 2021 10:53:36 +0100 Subject: 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 Signed-off-by: Sam James --- 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() -- cgit v1.2.3-65-gdbad