aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files
diff options
context:
space:
mode:
authorDavid Bauer <mail@david-bauer.net>2020-07-11 13:48:40 +0200
committerDavid Bauer <mail@david-bauer.net>2020-07-28 15:52:44 +0200
commitc3e252d08032de80e7c82759cc9763a310a97144 (patch)
tree32dda0aced50b6a1feff389d9f72e0c5aa7f61c8 /package/base-files
parent04f06787f1c0f1d89f6b8c71430d0d0bbb62ffa5 (diff)
downloadupstream-c3e252d08032de80e7c82759cc9763a310a97144.tar.gz
upstream-c3e252d08032de80e7c82759cc9763a310a97144.tar.bz2
upstream-c3e252d08032de80e7c82759cc9763a310a97144.zip
base-files: add function for generating random MAC
This adds a function for generating a valid random MAC address (unset MC bit / set locally administered bit). It is necessary for devices which do not have a MAC address programmed by the manufacturer. Signed-off-by: David Bauer <mail@david-bauer.net>
Diffstat (limited to 'package/base-files')
-rw-r--r--package/base-files/Makefile2
-rw-r--r--package/base-files/files/lib/functions/system.sh12
2 files changed, 13 insertions, 1 deletions
diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index 284899bd69..d32bae8635 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
include $(INCLUDE_DIR)/feeds.mk
PKG_NAME:=base-files
-PKG_RELEASE:=223
+PKG_RELEASE:=224
PKG_FLAGS:=nonshared
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh
index f3c901ff79..80e417182a 100644
--- a/package/base-files/files/lib/functions/system.sh
+++ b/package/base-files/files/lib/functions/system.sh
@@ -174,6 +174,18 @@ macaddr_setbit_la() {
macaddr_setbit $1 7
}
+macaddr_unsetbit_mc() {
+ local mac=$1
+
+ printf "%02x:%s" $((0x${mac%%:*} & ~0x01)) ${mac#*:}
+}
+
+macaddr_random() {
+ local randsrc=$(get_mac_binary /dev/urandom 0)
+
+ echo "$(macaddr_unsetbit_mc "$(macaddr_setbit_la "${randsrc}")")"
+}
+
macaddr_2bin() {
local mac=$1