2021-02-10 01:53:21 +01:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#
|
2017-11-03 09:18:01 +01:00
|
|
|
# Copyright 2017 Adrian Schmutzler
|
|
|
|
|
|
|
|
ipMacSuffix() {
|
|
|
|
# Returns the lower 64 bits of an IPv6 address (0:aabb:ccdd:eeff)
|
2018-01-03 00:37:07 +01:00
|
|
|
# based on the provided MAC address (aa:bb:cc:bb:ee:ff)
|
2017-11-03 09:18:01 +01:00
|
|
|
#
|
2018-01-03 00:37:07 +01:00
|
|
|
# Argument: MAC address (with colons)
|
2017-11-03 09:18:01 +01:00
|
|
|
|
|
|
|
[ $# -ne "1" ] && return 1
|
|
|
|
|
2018-01-03 00:37:07 +01:00
|
|
|
local mac=$1
|
2017-11-03 09:18:01 +01:00
|
|
|
|
2018-01-03 00:37:07 +01:00
|
|
|
echo "$mac" | awk -F: '{ print "0:"$1$2":"$3$4":"$5$6 }'
|
2017-11-03 09:18:01 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
ipEUISuffix() {
|
|
|
|
# Returns the EUI (interface ID, a8bb:ccff:fedd:eeff)
|
2018-01-03 00:37:07 +01:00
|
|
|
# based on the provided MAC address (aa:bb:cc:bb:ee:ff)
|
2017-11-03 09:18:01 +01:00
|
|
|
#
|
2018-01-03 00:37:07 +01:00
|
|
|
# Argument: MAC address (with colons)
|
2017-11-03 09:18:01 +01:00
|
|
|
|
|
|
|
[ $# -ne "1" ] && return 1
|
|
|
|
|
2018-01-03 00:37:07 +01:00
|
|
|
local mac=$1
|
2017-11-03 09:18:01 +01:00
|
|
|
|
2018-01-03 00:37:07 +01:00
|
|
|
echo "$mac" | awk -F: '{ printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }'
|
2017-11-03 09:18:01 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2017-11-11 11:39:00 +01:00
|
|
|
macFlipLocalBit() {
|
|
|
|
# Returns given MAC-address with locally administered bit flipped
|
|
|
|
#
|
|
|
|
# Argument: MAC-address
|
|
|
|
|
|
|
|
local mac=$1
|
|
|
|
|
|
|
|
echo "$mac" | awk -F: '{ printf("%02x:%s:%s:%s:%s:%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }'
|
|
|
|
return 0
|
|
|
|
}
|