From daab44944e02523fdd49d2b91db115823b872b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Fri, 8 Jan 2021 20:18:25 +0100 Subject: [PATCH] fff-network: Fix incorrect IPv6 syntax in functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some of our network helper functions did require the use of an invalid ipv6 prefix syntax to function correctly. Specifically, if all 64 bits of the prefix are given, the caller has to omit one colon for our assemble-functions to work properly. Therefore the prefix '2001:db8:1:2::/64' had to be written as '2001:db8:1:2:/64'. Also, our functions did not allow to specify the suffix with leading colons. This changes the behaviour of these functions to accept properly formatted IPv6 prefixes and suffixes. All calls to these functions are adjusted accordingly. There is one notebly exeption: The incorrect prefix syntax in hoodfiles cannot be adjusted yet, because that would break devices with using older firmware. To keep compatibility with older firmware versions, the hoodfiles prefix syntax is not yet adjusted, and a special case is added to configurehood to allow the use of the old incorrect syntax. While this new solution still is kind of hacky and does things that should actually be done by a proper address parser, it does at least fix the before mentioned problems. Fixes: #27 Signed-off-by: Fabian Bläse --- src/packages/fff/fff-hoods/Makefile | 2 +- .../fff-hoods/files/usr/sbin/configurehood | 8 +++++ src/packages/fff/fff-network/Makefile | 2 +- .../files/lib/functions/fff/network | 33 +++++++++++++++---- .../files/usr/sbin/configurenetwork | 2 +- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile index c17d807d..58ca1901 100644 --- a/src/packages/fff/fff-hoods/Makefile +++ b/src/packages/fff/fff-hoods/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-hoods -PKG_RELEASE:=17 +PKG_RELEASE:=18 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood index 1e6745f0..2dab76f5 100755 --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood @@ -190,6 +190,14 @@ if [ -s "$hoodfiletmp" ]; then # Set $prefix::MAC as IP if [ -n "$prefix" ] ; then prefix="$(echo "$prefix" | sed -e 's,\\,,')" + + # in earlier firmware versions the prefix had to be written + # in an incorrect syntax (missing a trailing colon). + # To make hoodfiles with this old incorrect syntax work with + # newer firmware versions like this one, we have to fix the + # incorrect syntax here. + prefix="$(echo "$prefix" | sed -e 's,\([^:]\):\/,\1::/,')" + mac="$(cat "/sys/class/net/br-client/address")" addr="$(ipMacAssemble "$prefix" "$mac")" addr="$(ipTidyColon "$addr")" diff --git a/src/packages/fff/fff-network/Makefile b/src/packages/fff/fff-network/Makefile index 8d67824d..0122a9ab 100644 --- a/src/packages/fff/fff-network/Makefile +++ b/src/packages/fff/fff-network/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-network -PKG_RELEASE:=26 +PKG_RELEASE:=27 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) diff --git a/src/packages/fff/fff-network/files/lib/functions/fff/network b/src/packages/fff/fff-network/files/lib/functions/fff/network index 06a6a84d..ebefc107 100644 --- a/src/packages/fff/fff-network/files/lib/functions/fff/network +++ b/src/packages/fff/fff-network/files/lib/functions/fff/network @@ -2,7 +2,7 @@ # License GPLv3 ipMacSuffix() { - # Returns the lower 64 bits of an IPv6 address (0:aabb:ccdd:eeff) + # Returns the lower 64 bits of an IPv6 address (::aabb:ccdd:eeff) # based on the provided MAC address (aa:bb:cc:bb:ee:ff) # # Argument: MAC address (with colons) @@ -11,12 +11,12 @@ ipMacSuffix() { local mac=$1 - echo "$mac" | awk -F: '{ print "0:"$1$2":"$3$4":"$5$6 }' + echo "$mac" | awk -F: '{ print "::"$1$2":"$3$4":"$5$6 }' return 0 } ipEUISuffix() { - # Returns the EUI (interface ID, a8bb:ccff:fedd:eeff) + # Returns the EUI (interface ID, ::a8bb:ccff:fedd:eeff) # based on the provided MAC address (aa:bb:cc:bb:ee:ff) # # Argument: MAC address (with colons) @@ -25,21 +25,40 @@ ipEUISuffix() { local mac=$1 - echo "$mac" | awk -F: '{ printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }' + echo "$mac" | awk -F: '{ printf("::%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }' return 0 } ipAssemble() { # Concatenates a prefix (1st argument) and a suffix (2nd argument) to a merged IPv6 address # (The prefix has to bear the subnet: fdff::/64) - # (The prefix must only contain the higher 64 bits (correct: 0:0:0:0: or 0:: - wrong: 0:0:0:0::) + # (The prefix must only contain the upper 64 bits (0:0:0:0:: or 0::) + # (The suffix must only contain the lower 64 bits (::0:0:0:0 or ::0) [ $# -ne "2" ] && return 1 local prefix=$1 - local suffix=$2 + local suffix + local result + + # remove leading colons + suffix=$(echo "$2" | sed -e 's,^:*,,') + + # check if prefix contains the mandatory trailing double-colon + if ! echo "$prefix" | grep "::/" >/dev/null; then + return 1 + fi + + # concatenate prefix and suffix + result=$(echo "$prefix" | sed -e "s,/,$suffix/,") + + # remove double-colon if both prefix and suffix are fully expanded + if [ "$(echo "$result" | awk -F":" '{print NF-1}')" -gt 7 ]; then + result=$(echo "$result" | sed -e 's,::,:,') + fi + + echo "$result" - echo "$prefix" | sed -e 's,/,'$suffix'/,' return 0 } diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork index d683e7da..7ab74e24 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -207,7 +207,7 @@ else uci -q set network.client.proto=static # Set $prefix::1 as IP - addr="$(ipAssemble "$prefix" "1")" + addr="$(ipAssemble "$prefix" "::1")" ip -6 addr add $addr dev br-client uci -q add_list network.client.ip6addr=$addr