From patchwork Sat Oct 14 17:19:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [SQUASHED,v17,8/8] Configure the Node a routable IPv6 ULA From: Tim Niemeyer X-Patchwork-Id: 571 Message-Id: <20171014171959.25099-9-tim@tn-x.org> To: franken-dev@freifunk.net Cc: Adrian Schmutzler Date: Sat, 14 Oct 2017 19:19:59 +0200 From: Adrian Schmutzler Signed-off-by: Christian Dresel Signed-off-by: Adrian Schmutzler Signed-off-by: Tim Niemeyer Tested-by: Christian Dresel Changes in v11: - Evaluate ULA block more often Changes in v10: - Replace zeros by :: in addresses - Use ip addresses as selector for deletion Changes in v9: - Add '0:' to suffix - Do not delete ip addresses with same prefix Changes in v8: - Do not delete new ip addresses (in case they don't differ) - Fixed typo in br-mesh - Fixed escape char in prefix Changes in v7: - Add EUI64 address - Change ifconfig to ip Changes in v6: - Typo in echo - Optimized sed Changes in v5: - Only apply if ula_prefix is not empty - Remove escape sign from ula_prefix Changes in v4: - Optimized grep and sed Changes in v3: - Added route block - Inverted condition in address block - Changed if style to "grep -q" - Added some quotes Changes in v2: - Rebased onto keyXchange v2 patchset v15 - correctly handle keyxchangev2data without reloading - added some quotes --- Changes in v17: None Changes in v16: None Changes in v15: None Changes in v14: None Changes in v13: None Changes in v12: None Changes in v11: None Changes in v10: None Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None .../fff/fff-hoods/files/usr/sbin/configurehood | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood index 62b3b3b..0f71104 100755 --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood @@ -181,6 +181,43 @@ if [ -s /tmp/keyxchangev2data ]; then if hasInternet ; then sh /usr/sbin/vpn-select fi + + # now we load the prefix from the hoodfile and set this to br-mesh + json_select network + json_get_var prefix ula_prefix + # Set $prefix::MAC as IP + if [ -n "$prefix" ] ; then + prefix="$(echo "$prefix" | sed -e 's,\\,,')" + suffix="$(awk -F: '{ print "0:"$1$2":"$3$4":"$5$6 }' /sys/class/net/br-mesh/address)" + suffix_eui="$(awk -F: '{ printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }' /sys/class/net/br-mesh/address)" + addr="$(echo "$prefix" | sed -e 's,/,'$suffix'/,')" + echo $addr | grep -q "::" || addr="$(echo "$addr" | sed -e 's,:[0:]*:,::,')" + addr_eui="$(echo "$prefix" | sed -e 's,/,'$suffix_eui'/,')" + echo $addr_eui | grep -q "::" || addr_eui="$(echo "$addr_eui" | sed -e 's,:[0:]*:,::,')" + 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 + done + if ! ( ip -6 addr show dev br-mesh | grep -q "$addr" ) ; then + ip -6 addr add "$addr" dev br-mesh + echo "Set ULA address to br-mesh: $addr" + else + echo "Address already set." + fi + # Set $prefix::link-local as IP + if ! ( ip -6 addr show dev br-mesh | grep -q "$addr_eui" ) ; then + ip -6 addr add "$addr_eui" dev br-mesh + echo "Set ULA EUI-64 address to br-mesh: $addr_eui" + else + echo "Address already set." + fi + if ! ( ip -6 route show dev br-mesh | grep -q "fc00::" ) ; then + ip -6 route add fc00::/7 via fe80::1 dev br-mesh + echo "Set ULA route to br-mesh." + else + echo "Route already set." + fi + fi + json_select ".." # back to root else echo "We haven't got a file. We do nothing. We try it again in 5 minutes..."; exit 0