aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files/files/lib
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2013-02-16 11:50:22 +0000
committerGabor Juhos <juhosg@openwrt.org>2013-02-16 11:50:22 +0000
commit5a8c63b47e19f6569f54a046cfd74925d35550a6 (patch)
tree793e4cf1dbc808df9ad1e6b4fd1a501af2b90947 /package/base-files/files/lib
parent753d713e92d593b8eab74625fccddc866667ec66 (diff)
downloadupstream-5a8c63b47e19f6569f54a046cfd74925d35550a6.tar.gz
upstream-5a8c63b47e19f6569f54a046cfd74925d35550a6.tar.bz2
upstream-5a8c63b47e19f6569f54a046cfd74925d35550a6.zip
base-files: add macaddr_{add,2bin,setbit_la} helpers
Signed-off-by: Gabor Juhos <juhosg@openwrt.org> SVN-Revision: 35614
Diffstat (limited to 'package/base-files/files/lib')
-rwxr-xr-xpackage/base-files/files/lib/functions.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh
index 2022e8a3aa..a488f4dc01 100755
--- a/package/base-files/files/lib/functions.sh
+++ b/package/base-files/files/lib/functions.sh
@@ -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"