2017-10-05 15:37:44 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2018-10-31 17:35:27 +01:00
|
|
|
# Allow only one instance
|
|
|
|
lockfile="/var/lock/${0##*/}.lock"
|
|
|
|
if ! lock -n "$lockfile"; then
|
|
|
|
echo "Only one instance of $0 allowed."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
trap "lock -u \"$lockfile\"" INT TERM EXIT
|
|
|
|
|
2017-10-05 15:37:44 +02:00
|
|
|
. /usr/share/libubox/jshn.sh
|
2017-10-30 20:08:27 +01:00
|
|
|
. /lib/functions/fff/keyxchange
|
2017-11-03 09:18:01 +01:00
|
|
|
. /lib/functions/fff/network
|
2017-10-05 15:37:44 +02:00
|
|
|
. /lib/functions/fff/wireless
|
2017-10-05 15:37:46 +02:00
|
|
|
. /lib/functions/fff/timeserver
|
2018-06-12 21:07:00 +02:00
|
|
|
. /usr/lib/functions/fff/hoodfile
|
2017-10-05 15:37:44 +02:00
|
|
|
|
2017-10-30 18:47:16 +01:00
|
|
|
|
2018-07-08 19:57:35 +02:00
|
|
|
hoodfilelocal=/etc/hoodfile
|
|
|
|
|
|
|
|
rm -f "$hoodfiletmp"
|
2017-10-05 15:37:44 +02:00
|
|
|
|
|
|
|
# Gatewaycheck function
|
|
|
|
isGatewayAvailable() {
|
2019-04-14 22:19:36 +02:00
|
|
|
if [ -n "$(batctl gwl -H)" ]; then
|
2017-10-05 15:37:44 +02:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Ping test
|
|
|
|
hasInternet() {
|
2020-05-06 16:48:01 +02:00
|
|
|
internetAddresses="keyserver.freifunk-franken.de heise.de"
|
|
|
|
for addr in $internetAddresses; do
|
|
|
|
ping -w5 -c3 "$addr" &>/dev/null && return 0
|
|
|
|
done
|
2017-10-05 15:37:44 +02:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2018-07-08 19:57:35 +02:00
|
|
|
if [ -s "$hoodfilelocal" ]; then
|
2018-12-03 20:54:55 +01:00
|
|
|
# remove webroot hoodfile to prevent offering local hoodfiles to neighbours
|
|
|
|
rm -f "$hoodfilewww"
|
|
|
|
|
2018-12-03 20:54:54 +01:00
|
|
|
cp "$hoodfilelocal" "$hoodfiletmp"
|
2018-01-02 15:46:37 +01:00
|
|
|
echo "Use local hood file"
|
2017-10-05 15:37:44 +02:00
|
|
|
else
|
fff-hoods: Improve hoodfile gathering logic
Instead of seperately checking for various conditions,
which don't actually guarantee that the hoodfile can be
fetched in a certain way (e.g. internet is available but
keyxchange is down), the already built in return value of
the hoodfile gathering functions is utilized.
This change slightly changes the behaviour of nodes in
certian edge cases:
- If no hoodfile could be fetched from keyxchange, the
next delivery method (getGatewayHoodfile) is used
- If the gateway is unable to deliver a hoodfile, nodes
now behave like the gateway is unreachable, instead of
continuing to use old hoodfiles
These behaviour changes should be an improvement over the
previous behaviour:
- VPN nodes don't disconnect and break the whole network
if the keyxchange is unreachable, but instead try to
fetch the hoodfile from the gateway
- Instead of checking for batman gateway announcements,
which are completely unrelated to hoodfile delivery using
fe80::1, the actual status of the hoodfile download is
utilized. This has two effects:
- hoodfile delivery using fe80::1 works even if batmans
gateway selection isn't used at all
- if the batman gateway selection is active, but fe80::1
hoodfile delivery is broken in the hood, the nodes disconnect
from the hood and try to gather their hoodfile from nerby
nodes. Previously they continued to use the old hoodfile.
This should make misconfigured gateways more apparent.
Signed-off-by: Fabian Bläse <fabian@blaese.de>
Reviewed-by: Robert Langhammer <rlanghammer@web.de>
Reviewed-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
2020-07-31 22:58:49 +02:00
|
|
|
# if internet is available, the hoodfile is downloaded from our keyserver
|
|
|
|
if getKeyserverHoodfile "$hoodfiletmp"; then
|
|
|
|
cp "$hoodfiletmp" "$hoodfilewww"
|
|
|
|
|
|
|
|
# if no internet is available, but the node is already configured,
|
|
|
|
# a gateway with the appropriate hoodfile should be available
|
|
|
|
elif getGatewayHoodfile "$hoodfiletmp"; then
|
|
|
|
cp "$hoodfiletmp" "$hoodfilewww"
|
|
|
|
|
|
|
|
# no internet and no gateway available. the node is either unconfigured,
|
|
|
|
# has lost connectivity or the hood is broken. Try to regain connectivity by
|
|
|
|
# fetching hoodfiles from nearby nodes
|
2018-01-02 15:46:37 +01:00
|
|
|
else
|
fff-hoods: Improve hoodfile gathering logic
Instead of seperately checking for various conditions,
which don't actually guarantee that the hoodfile can be
fetched in a certain way (e.g. internet is available but
keyxchange is down), the already built in return value of
the hoodfile gathering functions is utilized.
This change slightly changes the behaviour of nodes in
certian edge cases:
- If no hoodfile could be fetched from keyxchange, the
next delivery method (getGatewayHoodfile) is used
- If the gateway is unable to deliver a hoodfile, nodes
now behave like the gateway is unreachable, instead of
continuing to use old hoodfiles
These behaviour changes should be an improvement over the
previous behaviour:
- VPN nodes don't disconnect and break the whole network
if the keyxchange is unreachable, but instead try to
fetch the hoodfile from the gateway
- Instead of checking for batman gateway announcements,
which are completely unrelated to hoodfile delivery using
fe80::1, the actual status of the hoodfile download is
utilized. This has two effects:
- hoodfile delivery using fe80::1 works even if batmans
gateway selection isn't used at all
- if the batman gateway selection is active, but fe80::1
hoodfile delivery is broken in the hood, the nodes disconnect
from the hood and try to gather their hoodfile from nerby
nodes. Previously they continued to use the old hoodfile.
This should make misconfigured gateways more apparent.
Signed-off-by: Fabian Bläse <fabian@blaese.de>
Reviewed-by: Robert Langhammer <rlanghammer@web.de>
Reviewed-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
2020-07-31 22:58:49 +02:00
|
|
|
rm -f "$hoodfileref" # delete this, so interfaces are recreated if reconnect with unchanged hood file takes place
|
|
|
|
rm -f "$hoodfilewww" # delete this, so wrong hood file is not broadcasted anymore
|
|
|
|
|
|
|
|
uci -q del "system.@system[0].hood"
|
|
|
|
uci -q del "system.@system[0].hoodid"
|
|
|
|
uci commit system
|
|
|
|
reload_config
|
|
|
|
|
|
|
|
sleep 30 # Wait for the config AP, which may be created at the same time as this script has started
|
2017-10-05 15:37:44 +02:00
|
|
|
|
fff-hoods: Improve hoodfile gathering logic
Instead of seperately checking for various conditions,
which don't actually guarantee that the hoodfile can be
fetched in a certain way (e.g. internet is available but
keyxchange is down), the already built in return value of
the hoodfile gathering functions is utilized.
This change slightly changes the behaviour of nodes in
certian edge cases:
- If no hoodfile could be fetched from keyxchange, the
next delivery method (getGatewayHoodfile) is used
- If the gateway is unable to deliver a hoodfile, nodes
now behave like the gateway is unreachable, instead of
continuing to use old hoodfiles
These behaviour changes should be an improvement over the
previous behaviour:
- VPN nodes don't disconnect and break the whole network
if the keyxchange is unreachable, but instead try to
fetch the hoodfile from the gateway
- Instead of checking for batman gateway announcements,
which are completely unrelated to hoodfile delivery using
fe80::1, the actual status of the hoodfile download is
utilized. This has two effects:
- hoodfile delivery using fe80::1 works even if batmans
gateway selection isn't used at all
- if the batman gateway selection is active, but fe80::1
hoodfile delivery is broken in the hood, the nodes disconnect
from the hood and try to gather their hoodfile from nerby
nodes. Previously they continued to use the old hoodfile.
This should make misconfigured gateways more apparent.
Signed-off-by: Fabian Bläse <fabian@blaese.de>
Reviewed-by: Robert Langhammer <rlanghammer@web.de>
Reviewed-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
2020-07-31 22:58:49 +02:00
|
|
|
getEthernetHoodfile "$hoodfiletmp" || getWirelessHoodfile "$hoodfiletmp"
|
2017-10-05 15:37:44 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-07-08 19:57:35 +02:00
|
|
|
if [ -s "$hoodfiletmp" ]; then
|
2017-10-05 15:37:44 +02:00
|
|
|
|
|
|
|
# we get a json file in this format:
|
|
|
|
# https://pw.freifunk-franken.de/patch/205/
|
|
|
|
# but without signature, every hood file we get is valid!
|
|
|
|
|
2020-08-01 01:28:33 +02:00
|
|
|
sumnew=$(sha256sum "$hoodfiletmp" 2>/dev/null | cut -f1 -d " ")
|
|
|
|
sumold=$(sha256sum "$hoodfileref" 2>/dev/null | cut -f1 -d " ")
|
2017-10-05 15:37:44 +02:00
|
|
|
|
2018-07-08 19:57:35 +02:00
|
|
|
json_load "$(cat "$hoodfiletmp")"
|
2017-10-05 15:37:44 +02:00
|
|
|
|
2017-10-30 18:47:16 +01:00
|
|
|
if [ "$sumnew" != "$sumold" ] ; then
|
|
|
|
echo "New file detected, we reconfigure the Node";
|
2017-10-05 15:37:44 +02:00
|
|
|
|
|
|
|
json_select hood
|
|
|
|
|
|
|
|
json_get_var hood name
|
2018-11-23 16:56:43 +01:00
|
|
|
json_get_var hoodid id
|
2017-10-30 18:47:16 +01:00
|
|
|
[ -n "$mesh_id" ] || json_get_var mesh_id mesh_id
|
|
|
|
[ -n "$mesh_bssid" ] || json_get_var mesh_bssid mesh_bssid
|
|
|
|
[ -n "$mesh_essid" ] || json_get_var mesh_essid mesh_essid
|
|
|
|
[ -n "$essid" ] || json_get_var essid essid
|
2017-10-05 15:37:46 +02:00
|
|
|
json_get_var ntpip ntp_ip
|
2017-10-30 18:47:16 +01:00
|
|
|
[ -n "$chan2ghz" ] || json_get_var chan2ghz channel2
|
|
|
|
[ -n "$mesh_type2" ] || json_get_var mesh_type2 mesh_type2
|
|
|
|
[ -n "$chan5ghz" ] || json_get_var chan5ghz channel5
|
|
|
|
[ -n "$mesh_type5" ] || json_get_var mesh_type5 mesh_type5
|
2017-10-26 08:57:12 +02:00
|
|
|
# Additional parameters may be activated in future versions
|
2017-10-05 15:37:44 +02:00
|
|
|
#json_get_var mode2 mode2
|
|
|
|
#json_get_var mode5 mode5
|
|
|
|
#json_get_var protocol protocol
|
|
|
|
|
|
|
|
json_select ".." # back to root
|
2017-10-30 18:47:16 +01:00
|
|
|
|
2020-08-01 01:28:34 +02:00
|
|
|
if [ -z "$chan2ghz" ] || [ -z "$chan5ghz" ] ; then
|
2017-10-26 08:57:12 +02:00
|
|
|
# If channel is missing, do nothing
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-11-23 16:56:43 +01:00
|
|
|
echo "Setting hood name: $hood (ID $hoodid)"
|
2019-06-16 16:23:25 +02:00
|
|
|
uci set "system.@system[0].hood=$hood"
|
|
|
|
uci set "system.@system[0].hoodid=$hoodid"
|
|
|
|
uci commit system
|
2017-10-05 15:37:44 +02:00
|
|
|
|
2019-06-16 16:23:24 +02:00
|
|
|
for radio in $(wifiListRadio); do
|
|
|
|
freq="$(wifiGetFreq $radio)"
|
2017-10-05 15:37:44 +02:00
|
|
|
|
2019-06-16 16:23:24 +02:00
|
|
|
if [ "$freq" = "5" ]; then
|
|
|
|
uci set wireless.${radio}.channel="$chan5ghz"
|
|
|
|
mesh_type="$mesh_type5"
|
|
|
|
elif [ "$freq" = "2" ]; then
|
|
|
|
uci set wireless.${radio}.channel="$chan2ghz"
|
|
|
|
mesh_type="$mesh_type2"
|
2017-10-15 11:27:58 +02:00
|
|
|
fi
|
|
|
|
|
2020-01-05 21:53:24 +01:00
|
|
|
# Disable wXconfigap
|
2019-06-16 16:23:24 +02:00
|
|
|
uci set wireless.w${freq}configap.disabled='1'
|
|
|
|
|
|
|
|
# Configure wXap
|
|
|
|
uci set wireless.w${freq}ap.ssid="$essid"
|
|
|
|
uci set wireless.w${freq}ap.disabled='0'
|
|
|
|
|
|
|
|
# Configure 802.11s mesh if type = "802.11s"
|
|
|
|
if [ "$mesh_type" = "802.11s" ]; then
|
|
|
|
uci set wireless.w${freq}mesh.mode='mesh'
|
|
|
|
uci -q del wireless.w${freq}mesh.bssid
|
|
|
|
uci -q del wireless.w${freq}mesh.ssid
|
|
|
|
uci -q del wireless.w${freq}mesh.mcast_rate
|
|
|
|
uci set wireless.w${freq}mesh.mesh_id="$mesh_id"
|
|
|
|
uci set wireless.w${freq}mesh.mesh_fwding='0'
|
|
|
|
uci set wireless.w${freq}mesh.disabled='0'
|
|
|
|
# Configure IBSS mesh if type = "ibss"
|
|
|
|
elif [ "$mesh_type" = "ibss" ]; then
|
|
|
|
uci set wireless.w${freq}mesh.mode='adhoc'
|
|
|
|
uci -q del wireless.w${freq}mesh.mesh_id
|
|
|
|
uci -q del wireless.w${freq}mesh.mesh_fwding
|
|
|
|
uci set wireless.w${freq}mesh.bssid="$mesh_bssid"
|
|
|
|
uci set wireless.w${freq}mesh.ssid="$mesh_essid"
|
|
|
|
uci set wireless.w${freq}mesh.mcast_rate='6000'
|
|
|
|
uci set wireless.w${freq}mesh.disabled='0'
|
|
|
|
# Disable mesh by setting no mesh_type
|
|
|
|
else
|
|
|
|
uci set wireless.w${freq}mesh.disabled='1'
|
2017-10-05 15:37:44 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2019-06-16 16:23:24 +02:00
|
|
|
uci commit wireless
|
2019-07-22 22:42:52 +02:00
|
|
|
echo "Reloading wifi"
|
|
|
|
reload_config
|
2017-10-05 15:37:44 +02:00
|
|
|
|
2017-10-05 15:37:46 +02:00
|
|
|
oldntp="$(uci -q get system.ntp.server)"
|
|
|
|
newntp="${ntpip}" # requires routable address, no link-local
|
|
|
|
[ "$newntp" = "$oldntp" ] || setTimeserver "${newntp}" # only rewrite if changed
|
|
|
|
|
2017-10-30 18:47:16 +01:00
|
|
|
# copy the file to webroot so that other mesh routers can download it;
|
2017-10-05 15:37:44 +02:00
|
|
|
# copy only after all other steps so IF can be reentered if something goes wrong
|
2018-07-25 15:58:15 +02:00
|
|
|
cp "$hoodfiletmp" "$hoodfileref"
|
2017-10-05 15:37:44 +02:00
|
|
|
|
2017-12-22 13:10:25 +01:00
|
|
|
# This is a workaround to enable alfred on devices which do not see a configap during initial setup
|
|
|
|
/etc/init.d/alfred restart
|
2017-10-05 15:37:44 +02:00
|
|
|
else
|
|
|
|
echo "We have no new file. We do nothing. We try it again in 5 minutes...";
|
|
|
|
fi
|
|
|
|
|
2017-10-05 15:37:45 +02:00
|
|
|
# and now we get to vpn-select script and load VPNs directly from /tmp/keyxchangev2data
|
2017-10-05 15:37:44 +02:00
|
|
|
|
|
|
|
if hasInternet ; then
|
2018-07-29 12:36:36 +02:00
|
|
|
/usr/sbin/vpn-select "$hoodfiletmp"
|
2018-02-13 13:27:37 +01:00
|
|
|
else
|
2018-07-29 12:36:36 +02:00
|
|
|
/usr/sbin/vpn-stop
|
2017-10-05 15:37:44 +02:00
|
|
|
fi
|
2017-10-08 18:28:54 +02:00
|
|
|
|
2020-12-18 20:49:01 +01:00
|
|
|
# now we load the prefix from the hoodfile and set this to br-client
|
2017-10-08 18:28:54 +02:00
|
|
|
json_select network
|
|
|
|
json_get_var prefix ula_prefix
|
|
|
|
# Set $prefix::MAC as IP
|
|
|
|
if [ -n "$prefix" ] ; then
|
2021-01-13 21:12:54 +01:00
|
|
|
# remove escape character
|
|
|
|
prefix=$(echo "$prefix" | sed -e 's,\\,,')
|
2021-01-27 12:33:08 +01:00
|
|
|
|
|
|
|
# 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. Both the old, incorrect and
|
|
|
|
# the correct syntax work with this fix.
|
|
|
|
prefix="$(echo "$prefix" | sed -e 's,\([^:]\):/,\1::/,')"
|
|
|
|
|
2021-01-13 21:12:54 +01:00
|
|
|
mac=$(cat "/sys/class/net/br-client/address")
|
|
|
|
addr=$(owipcalc "$prefix" add "::$(ipMacSuffix "$mac")")
|
|
|
|
addr_eui=$(owipcalc "$prefix" add "::$(ipEUISuffix "$mac")")
|
2020-12-18 20:49:01 +01:00
|
|
|
for ip in $(ip -6 addr show dev br-client | grep inet6 | grep -v -e " $addr" -e " $addr_eui" -e " fe80::" -e " fdff::" | cut -f6 -d " "); do
|
|
|
|
ip -6 addr del "$ip" dev br-client
|
2017-10-08 18:28:54 +02:00
|
|
|
done
|
2020-12-18 20:49:01 +01:00
|
|
|
if ! ( ip -6 addr show dev br-client | grep -q "$addr" ) ; then
|
|
|
|
ip -6 addr add "$addr" dev br-client
|
|
|
|
echo "Set ULA address to br-client: $addr"
|
2017-10-08 18:28:54 +02:00
|
|
|
else
|
|
|
|
echo "Address already set."
|
|
|
|
fi
|
|
|
|
# Set $prefix::link-local as IP
|
2020-12-18 20:49:01 +01:00
|
|
|
if ! ( ip -6 addr show dev br-client | grep -q "$addr_eui" ) ; then
|
|
|
|
ip -6 addr add "$addr_eui" dev br-client
|
|
|
|
echo "Set ULA EUI-64 address to br-client: $addr_eui"
|
2017-10-08 18:28:54 +02:00
|
|
|
else
|
|
|
|
echo "Address already set."
|
|
|
|
fi
|
2020-12-18 20:49:01 +01:00
|
|
|
if ! ( ip -6 route show dev br-client | grep -q "fc00::" ) ; then
|
|
|
|
ip -6 route add fc00::/7 via fe80::1 dev br-client
|
|
|
|
echo "Set ULA route to br-client."
|
2017-10-08 18:28:54 +02:00
|
|
|
else
|
|
|
|
echo "Route already set."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
json_select ".." # back to root
|
2017-10-05 15:37:44 +02:00
|
|
|
else
|
|
|
|
echo "We haven't got a file. We do nothing. We try it again in 5 minutes...";
|
|
|
|
exit 0
|
|
|
|
fi
|
2020-05-06 16:48:03 +02:00
|
|
|
|
|
|
|
# Hidden AP check
|
|
|
|
if [ -s "$hoodfilewww" ] && isGatewayAvailable; then
|
|
|
|
needwifi="0"
|
|
|
|
for radio in $(wifiListRadio); do
|
|
|
|
freq="$(wifiGetFreq $radio)"
|
|
|
|
|
|
|
|
# Break: wXconfig is up
|
|
|
|
[ "$(uci get "wireless.w${freq}configap.disabled")" = "0" ] && continue
|
|
|
|
# Break: No mesh interface
|
|
|
|
[ "$(uci get "wireless.w${freq}mesh.disabled")" = "0" ] || continue
|
|
|
|
|
|
|
|
# Enable configap
|
|
|
|
uci set wireless.w${freq}configap.disabled='0'
|
|
|
|
uci commit wireless
|
|
|
|
needwifi="1"
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$needwifi" = "1" ]; then
|
|
|
|
reload_config
|
|
|
|
sleep 10
|
|
|
|
fi
|
|
|
|
fi
|