base-files: add macaddr_{add,2bin,setbit_la} helpers
authorGabor Juhos <juhosg@openwrt.org>
Sat, 16 Feb 2013 11:50:22 +0000 (11:50 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Sat, 16 Feb 2013 11:50:22 +0000 (11:50 +0000)
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
SVN-Revision: 35614

package/base-files/Makefile
package/base-files/files/lib/functions.sh

index 26fa1b723d6683c4b9269ca623a038b77645e909..789b5f6792c78cda3dda205f0c7764a99f703fe6 100644 (file)
@@ -11,7 +11,7 @@ include $(INCLUDE_DIR)/kernel.mk
 include $(INCLUDE_DIR)/version.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=132
+PKG_RELEASE:=133
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
 PKG_BUILD_DEPENDS:=opkg/host
index 2022e8a3aa7b5e289f8f04bc2eb66bcecfafdcc3..a488f4dc01af370a74979f2a253d328ac9e7b7f6 100755 (executable)
@@ -274,6 +274,30 @@ mtd_get_mac_binary() {
        dd bs=1 skip=$offset count=6 if=$part 2>/dev/null | hexdump -v -n 6 -e '5/1 "%02x:" 1/1 "%02x"'
 }
 
+macaddr_add() {
+       local mac=$1
+       local val=$2
+       local oui=${mac%:*:*:*}
+       local nic=${mac#*:*:*:}
+
+       nic=$(printf "%06x" $((0x${nic//:/} + $val & 0xffffff)) | sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/')
+       echo $oui:$nic
+}
+
+macaddr_setbit_la()
+{
+       local mac=$1
+
+       printf "%02x:%s" $((0x${mac%%:*} | 0x02)) ${mac#*:}
+}
+
+macaddr_2bin()
+{
+       local mac=$1
+
+       echo -ne \\x${mac//:/\\x}
+}
+
 strtok() { # <string> { <variable> [<separator>] ... }
        local tmp
        local val="$1"