#!/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 set fff.autol3.autoconfigl3=1 uci commit fff uci del gateway.@client[0].ip6addr uci add_list gateway.@client[0].ip6addr=$ip uci commit gateway # call canusethis that assigner know we use the ipv6 canusethis } 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.ipv6address) ] ; then canusethis fi if [ -n $(uci -q get fff.autol3) ] && [ -z $(uci -q get fff.autol3.ipv6address) ] ; then asknew fi