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>
This commit is contained in:
parent
04f06787f1
commit
c3e252d080
|
@ -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/
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue