aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2021-01-24 02:49:43 +0000
committerLars Wendler <polynomial-c@gentoo.org>2021-01-24 11:21:20 +0100
commit6632c348cce8be19c7a960cabb2f6f41ec4c6d51 (patch)
tree41a19cefb987440eba40a9109991d4b151c1c3d1 /net
parentudev_helper/net.sh: Ignore wireguard interfaces (diff)
downloadnetifrc-6632c348cce8be19c7a960cabb2f6f41ec4c6d51.tar.gz
netifrc-6632c348cce8be19c7a960cabb2f6f41ec4c6d51.tar.bz2
netifrc-6632c348cce8be19c7a960cabb2f6f41ec4c6d51.zip
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@plushkava.net> Closes: https://bugs.gentoo.org/766758 Signed-off-by: Lars Wendler <polynomial-c@gentoo.org>
Diffstat (limited to 'net')
-rw-r--r--net/iproute2.sh15
1 files 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()