From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1244896-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 9A0031382C5
	for <garchives@archives.gentoo.org>; Sun, 24 Jan 2021 10:37:28 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id E3311E083B;
	Sun, 24 Jan 2021 10:37:27 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id C73CEE083B
	for <gentoo-commits@lists.gentoo.org>; Sun, 24 Jan 2021 10:37:27 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 1E986340EF9
	for <gentoo-commits@lists.gentoo.org>; Sun, 24 Jan 2021 10:37:26 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id AFE94328
	for <gentoo-commits@lists.gentoo.org>; Sun, 24 Jan 2021 10:37:24 +0000 (UTC)
From: "Lars Wendler" <polynomial-c@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Lars Wendler" <polynomial-c@gentoo.org>
Message-ID: <1611483680.6632c348cce8be19c7a960cabb2f6f41ec4c6d51.polynomial-c@OpenRC>
Subject: [gentoo-commits] proj/netifrc:master commit in: net/
X-VCS-Repository: proj/netifrc
X-VCS-Files: net/iproute2.sh
X-VCS-Directories: net/
X-VCS-Committer: polynomial-c
X-VCS-Committer-Name: Lars Wendler
X-VCS-Revision: 6632c348cce8be19c7a960cabb2f6f41ec4c6d51
X-VCS-Branch: master
Date: Sun, 24 Jan 2021 10:37:24 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: be8156c8-e845-417d-9179-d90a57777fc1
X-Archives-Hash: bb7137be8f66fd96bb9d6ba2973b1905

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()