forked from freifunk-franken/firmware
fff-autoconfig: Add IPv4 support
With this script, IPv4 can configurate automaticaly Signed-off-by: Christian Dresel <freifunk@dresel.systems>
This commit is contained in:
parent
8581bd76c4
commit
5f22c2131c
|
@ -0,0 +1,74 @@
|
|||
#!/bin/sh
|
||||
|
||||
# first check is fff.autol3.ipv4 enabled
|
||||
if [ -z $(uci -q get fff.autol3.ipv4) ] ; 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.ipv4assigner)
|
||||
IPOWN=$(uci -q get fff.autol3.ipv4address)
|
||||
|
||||
asknew() {
|
||||
# Load Blocklist
|
||||
ipv6assignerblock=$(uci get fff.autol3.ipv6assignerblock)
|
||||
for ipv6assignerblock in $ipv6assignerblock; do
|
||||
block="$block -T /ipv6/usethis/+/$ipv6assignerblock"
|
||||
done
|
||||
mosquitto_pub -h $MQTTSERVER -p 1883 -t '/ipv4/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 '/ipv4/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
|
||||
ip=$(echo $ip | sed 's/\/.*//')
|
||||
uci del gateway.meta.peer_ip
|
||||
uci del gateway.@client[0].nat
|
||||
uci del gateway.@client[0].ipaddr
|
||||
uci del gateway.@client[0].dhcp_start
|
||||
uci set gateway.meta.peer_ip=$ip
|
||||
uci set gateway.@client[0].nat='1'
|
||||
uci set gateway.@client[0].ipaddr='192.168.0.1/16'
|
||||
uci set gateway.@client[0].dhcp_start='192.168.1.1'
|
||||
uci commit gateway
|
||||
uci set fff.autol3.ipv4address=$ip
|
||||
uci set fff.autol3.ipv4assigner=$assigner
|
||||
uci set fff.autol3.autoconfigl3=1
|
||||
uci commit fff
|
||||
exit;
|
||||
}
|
||||
|
||||
canusethis() {
|
||||
mosquitto_pub -h $MQTTSERVER -p 1883 -t /ipv4/canusethis/$ASSIGNEROWN -m "{ \"mac\":\"$MACADDR\", \"ip\":\"$IPOWN/32\" }"
|
||||
canusethisanswer=$(mosquitto_sub -h $MQTTSERVER -p 1883 -t /ipv4/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.ipv4address
|
||||
uci del fff.autol3.ipv4assigner
|
||||
uci set fff.autol3.autoconfigl3=1
|
||||
uci commit fff
|
||||
uci del gateway.meta.peer_ip
|
||||
uci del gateway.@client[0].nat
|
||||
uci del gateway.@client[0].ipaddr
|
||||
uci del gateway.@client[0].dhcp_start
|
||||
uci commit gateway
|
||||
asknew
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -n $(uci -q get fff.autol3) ] && [ -z $(uci -q get fff.autol3.ipv4address) ] ; then
|
||||
asknew
|
||||
fi
|
||||
|
||||
if [ -n $(uci -q get fff.autol3.ipv4address) ] ; then
|
||||
canusethis
|
||||
fi
|
||||
|
Loading…
Reference in New Issue