fff-network/fff-hoods: Only use MAC address in network lib

Previously, IPv6 addresses were constructed by reading from
the device config file in the function. To have more options,
it is better to use the address itself as parameter.

By this way we can decide what we use for getting the MAC when
calling.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Reviewed-by: Tim Niemeyer <tim@tn-x.org>
This commit is contained in:
Adrian Schmutzler 2018-01-03 00:37:07 +01:00 committed by Tim Niemeyer
parent de36cb4c17
commit 6ad42be496
3 changed files with 20 additions and 18 deletions

View File

@ -288,9 +288,10 @@ if [ -s "$hoodfile" ]; then
# Set $prefix::MAC as IP
if [ -n "$prefix" ] ; then
prefix="$(echo "$prefix" | sed -e 's,\\,,')"
addr="$(ipMacAssemble "$prefix" "br-mesh")"
mac="$(cat "/sys/class/net/br-mesh/address")"
addr="$(ipMacAssemble "$prefix" "$mac")"
addr="$(ipTidyColon "$addr")"
addr_eui="$(ipEUIAssemble "$prefix" "br-mesh")"
addr_eui="$(ipEUIAssemble "$prefix" "$mac")"
addr_eui="$(ipTidyColon "$addr_eui")"
for ip in $(ip -6 addr show dev br-mesh | grep inet6 | grep -v -e " $addr" -e " $addr_eui" -e " fe80::" -e " fdff::" | cut -f6 -d " "); do
ip -6 addr del "$ip" dev br-mesh

View File

@ -4,29 +4,29 @@
ipMacSuffix() {
# Returns the lower 64 bits of an IPv6 address (0:aabb:ccdd:eeff)
# based on the mac address (aa:bb:cc:bb:ee:ff) of a specified interface
# based on the provided MAC address (aa:bb:cc:bb:ee:ff)
#
# Argument: name of interface (e.g. br-mesh)
# Argument: MAC address (with colons)
[ $# -ne "1" ] && return 1
local iface=$1
local mac=$1
awk -F: '{ print "0:"$1$2":"$3$4":"$5$6 }' "/sys/class/net/${iface}/address"
echo "$mac" | awk -F: '{ print "0:"$1$2":"$3$4":"$5$6 }'
return 0
}
ipEUISuffix() {
# Returns the EUI (interface ID, a8bb:ccff:fedd:eeff)
# based on the mac address (aa:bb:cc:bb:ee:ff) of a specified interface
# based on the provided MAC address (aa:bb:cc:bb:ee:ff)
#
# Argument: name of interface (e.g. br-mesh)
# Argument: MAC address (with colons)
[ $# -ne "1" ] && return 1
local iface=$1
local mac=$1
awk -F: '{ printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }' "/sys/class/net/${iface}/address"
echo "$mac" | awk -F: '{ printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }'
return 0
}
@ -45,29 +45,29 @@ ipAssemble() {
}
ipMacAssemble() {
# Concatenates a prefix (1st argument) and a MAC-based suffix (interface as 2nd argument) to a merged IPv6 address
# Concatenates a prefix (1st argument) and a MAC-based suffix (MAC address as 2nd argument) to a merged IPv6 address
# (Details on prefix: Check ipAssemble(), details on suffix: Check ipMacSuffix())
[ $# -ne "2" ] && return 1
local prefix=$1
local iface=$2
local mac=$2
suffix="$(ipMacSuffix "$iface")"
suffix="$(ipMacSuffix "$mac")"
ipAssemble "$prefix" "$suffix"
return 0
}
ipEUIAssemble() {
# Concatenates a prefix (1st argument) and an EUI-based suffix (interface as 2nd argument) to a merged IPv6 address
# Concatenates a prefix (1st argument) and an EUI-based suffix (MAC address as 2nd argument) to a merged IPv6 address
# (Details on prefix: Check ipAssemble(), details on suffix: Check ipEUISuffix())
[ $# -ne "2" ] && return 1
local prefix=$1
local iface=$2
local mac=$2
suffix="$(ipEUISuffix "$iface")"
suffix="$(ipEUISuffix "$mac")"
ipAssemble "$prefix" "$suffix"
return 0
}

View File

@ -220,7 +220,8 @@ else
prefix="fdff:0::/64"
# Set $prefix::MAC as IP
addr="$(ipMacAssemble "$prefix" "br-mesh")"
mac="$(cat "/sys/class/net/br-mesh/address")"
addr="$(ipMacAssemble "$prefix" "$mac")"
ip -6 addr add $addr dev br-mesh
uci -q del network.globals
@ -235,7 +236,7 @@ else
uci -q add_list network.mesh.ip6addr=$addr
# Set $prefix::link-local as IP
addr="$(ipEUIAssemble "$prefix" "br-mesh")"
addr="$(ipEUIAssemble "$prefix" "$mac")"
ip -6 addr add $addr dev br-mesh
uci -q add_list network.mesh.ip6addr=$addr