aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2021-07-17 10:53:36 +0100
committerSam James <sam@gentoo.org>2023-01-19 18:49:25 +0000
commit46f8a90fef9d9bff21760dab52124bfbbb62e064 (patch)
tree7e41ddd3dd0bf092503ff4b7607f79e6498833da
parentnet/l2tp.sh: Don't try to evaluate l2tptunnel_${IFVAR} if unset (diff)
downloadnetifrc-46f8a90fef9d9bff21760dab52124bfbbb62e064.tar.gz
netifrc-46f8a90fef9d9bff21760dab52124bfbbb62e064.tar.bz2
netifrc-46f8a90fef9d9bff21760dab52124bfbbb62e064.zip
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@plushkava.net> Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r--net/iproute2.sh16
1 files 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()