forked from freifunk-franken/firmware
fff-autoconfig: Add IPv6 support
With this script, IPv6 can configurate automaticaly Signed-off-by: Christian Dresel <freifunk@dresel.systems>
This commit is contained in:
parent
b94f2ee10e
commit
8581bd76c4
|
@ -0,0 +1,64 @@
|
|||
#!/bin/sh
|
||||
|
||||
# first check is fff.autol3.ipv6 enabled
|
||||
if [ -z $(uci -q get fff.autol3.ipv6) ] ; then
|
||||
exit;
|
||||
fi
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
MACADDR=$(cat /sys/class/net/br-client/address | /bin/sed 's/://g')
|
||||
MQTTSERVER=$(uci -q get fff.mqtt.server)
|
||||
ASSIGNEROWN=$(uci -q get fff.autol3.ipv6assigner)
|
||||
IPOWN=$(uci -q get fff.autol3.ipv6address)
|
||||
|
||||
asknew() {
|
||||
# Load Blocklist
|
||||
ipv6assignerblock=$(uci get fff.autol3.ipv6assignerblock)
|
||||
for ipv6assignerblock in $ipv6assignerblock; do
|
||||
block="$block -T /ipv6/usethis/+/$ipv6assignerblock"
|
||||
done
|
||||
echo $block
|
||||
mosquitto_pub -h $MQTTSERVER -p 1883 -t '/ipv6/asknew' -m "$MACADDR"
|
||||
# use the first income message
|
||||
# cancel after 5 second, after this time we don't get any IP address
|
||||
autol3config=$(mosquitto_sub -h $MQTTSERVER -p 1883 -t '/ipv6/usethis/#' -C 1 $block)
|
||||
if [ -z "$autol3config" ] ; then
|
||||
echo "No IP get"
|
||||
exit 1;
|
||||
fi
|
||||
json_load "$autol3config"
|
||||
json_get_var assigner assigner
|
||||
json_get_var ip ip
|
||||
uci set fff.autol3.ipv6address=$ip
|
||||
uci set fff.autol3.ipv6assigner=$assigner
|
||||
uci commit fff
|
||||
uci del gateway.@client[0].ip6addr
|
||||
uci add_list gateway.@client[0].ip6addr=$ip
|
||||
uci commit gateway
|
||||
yes | configure-layer3 -c
|
||||
configure-layer3 -a
|
||||
exit;
|
||||
}
|
||||
|
||||
canusethis() {
|
||||
mosquitto_pub -h $MQTTSERVER -p 1883 -t /ipv6/canusethis/$ASSIGNEROWN -m "{ \"mac\":\"$MACADDR\", \"ip\":\"$IPOWN\" }"
|
||||
canusethisanswer=$(mosquitto_sub -h $MQTTSERVER -p 1883 -t /ipv6/canusethisanswer/$MACADDR -C 1 -W 5)
|
||||
# check if we get answer, if no load asknew again and get new ip address
|
||||
if [ -z $canusethisanswer ] ; then
|
||||
uci del fff.autol3.ipv6address
|
||||
uci del fff.autol3.ipv6assigner
|
||||
uci commit fff
|
||||
uci del gateway.@client[0].ip6addr
|
||||
uci commit gateway
|
||||
asknew
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -n $(uci -q get fff.autol3) ] && [ -z $(uci -q get fff.autol3.ipv6address) ] ; then
|
||||
asknew
|
||||
fi
|
||||
|
||||
if [ -n $(uci -q get fff.autol3.ipv6address) ] ; then
|
||||
canusethis
|
||||
fi
|
Loading…
Reference in New Issue