commit: 6632c348cce8be19c7a960cabb2f6f41ec4c6d51 Author: Kerin Millar <kfm <AT> plushkava <DOT> net> AuthorDate: Sun Jan 24 02:49:43 2021 +0000 Commit: Lars Wendler <polynomial-c <AT> gentoo <DOT> org> CommitDate: Sun Jan 24 10:21:20 2021 +0000 URL: https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=6632c348
Use sysfs to obtain the MAC address in net/iproute2.sh Dispense with the hideous ip-link(8) parser. Instead, collect the MAC address by reading from the relevant sysfs file. While at it, tidy up the remainder of the function so that the control flow is easier to ascertain at a glance. Note that the address will be rendered in upper case, just as it was before. Signed-off-by: Kerin Millar <kfm <AT> plushkava.net> Closes: https://bugs.gentoo.org/766758 Signed-off-by: Lars Wendler <polynomial-c <AT> gentoo.org> net/iproute2.sh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/net/iproute2.sh b/net/iproute2.sh index 4c32acc..2289587 100644 --- a/net/iproute2.sh +++ b/net/iproute2.sh @@ -70,19 +70,16 @@ _set_flag() _get_mac_address() { - local mac=$(LC_ALL=C ip link show "${IFACE}" | sed -n \ - -e 'y/abcdef/ABCDEF/' \ - -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p') + local mac= + read -r mac < /sys/class/net/"${IFACE}"/address || return 1 case "${mac}" in - 00:00:00:00:00:00);; - 44:44:44:44:44:44);; - FF:FF:FF:FF:FF:FF);; - "");; - *) echo "${mac}"; return 0;; + 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 - return 1 + printf '%s\n' "${mac}" | LC_ALL=C tr '[:lower:]' '[:upper:]' } _set_mac_address()
