Developing lightweight computation at the DSG edge

Commit 264d2b76 authored by p4u's avatar p4u
Browse files

New config option publish_lan to publish lan network using HNA. New functions...

New config option publish_lan to publish lan network using HNA. New functions in qmpcontrol: publish_hna and unpublish_hna
parent 468783cd
...@@ -22,7 +22,8 @@ config 'qmp' 'networks' ...@@ -22,7 +22,8 @@ config 'qmp' 'networks'
option 'dns' '141.1.1.1' option 'dns' '141.1.1.1'
option 'lan_address' '172.30.22.1' option 'lan_address' '172.30.22.1'
option 'lan_netmask' '255.255.255.0' option 'lan_netmask' '255.255.255.0'
option 'niit_prefix96' '0:0:0:0:0:ffff' # omit trailing 32 ipv4 bits ! option 'publish_lan' '0'
option 'niit_prefix96' '0:0:0:0:0:ffff' # omit trailing 32 ipv4 bits !
option 'mesh_protocol_vids' 'olsr6:1 bmx6:2' # means olsr6 use vlantag 10+1, bmx6 use vlantag 10+2 option 'mesh_protocol_vids' 'olsr6:1 bmx6:2' # means olsr6 use vlantag 10+1, bmx6 use vlantag 10+2
option 'mesh_vid_offset' '10' option 'mesh_vid_offset' '10'
......
...@@ -222,3 +222,13 @@ qmp_get_dec_node_id() { ...@@ -222,3 +222,13 @@ qmp_get_dec_node_id() {
echo $(printf %d 0x$COMMUNITY_NODE_ID) echo $(printf %d 0x$COMMUNITY_NODE_ID)
} }
# Returns the prefix /XX from netmask
qmp_get_prefix_from_netmask() {
echo "$(ipcalc.sh 1.1.1.1 $1| grep PREFIX | cut -d= -f2)"
}
# Returns the netid from IP NETMASK
qmp_get_netid_from_network() {
echo "$(ipcalc.sh $1 $2 | grep NETWORK | cut -d= -f2)"
}
...@@ -53,6 +53,7 @@ configure_network() { ...@@ -53,6 +53,7 @@ configure_network() {
/etc/init.d/bmx6 restart /etc/init.d/bmx6 restart
/etc/init.d/dnsmasq restart /etc/init.d/dnsmasq restart
/etc/init.d/firewall restart /etc/init.d/firewall restart
qmp_publish_lan
apply_netserver apply_netserver
} }
...@@ -66,6 +67,16 @@ enable_ns_ppt() { ...@@ -66,6 +67,16 @@ enable_ns_ppt() {
echo 1 > /sys/class/gpio/gpio8/value echo 1 > /sys/class/gpio/gpio8/value
} }
publish_hna() {
[ -z "$1" ] && help
qmp_publish_hna_bmx6 $1 $2
}
unpublish_hna() {
[ -z "$1" ] && help
qmp_unpublish_hna_bmx6 $1
}
help() { help() {
echo "Use: $0 <function> [params]" echo "Use: $0 <function> [params]"
echo "" echo ""
...@@ -75,13 +86,16 @@ help() { ...@@ -75,13 +86,16 @@ help() {
echo " configure_wifi : Configure and apply current wifi settings" echo " configure_wifi : Configure and apply current wifi settings"
echo " configure_network : Configure and apply current network settings" echo " configure_network : Configure and apply current network settings"
echo " configure_system : Configure and apply current system settings (qmp.node section and so on)" echo " configure_system : Configure and apply current system settings (qmp.node section and so on)"
echo " publish_hna : Publish an IP range (v4 or v6): publish_hna <IP/NETMASK> [ID]"
echo " unpublish_hna : Unpublish a current HNA: unpublish_hna <ID>"
echo " apply_netserver : Start/stop nerserver depending on qmp configuration" echo " apply_netserver : Start/stop nerserver depending on qmp configuration"
echo " enable_ns_ppt : Enable POE passtrought from NanoStation M2/5 devices. Be careful with this" echo " enable_ns_ppt : Enable POE passtrought from NanoStation M2/5 devices. Be careful with this"
echo "" echo ""
exit 1
} }
[ -z "$1" ] && { help; exit 0; } [ -z "$1" ] && help
echo "executing function $1" echo "executing function $1"
$@ $@
......
...@@ -42,4 +42,65 @@ qmp_disable_netserver() { ...@@ -42,4 +42,65 @@ qmp_disable_netserver() {
killall -9 netserver || true killall -9 netserver || true
} }
# Publish or unpublish lan HNA depending on qmp configuration
qmp_publish_lan() {
is_publish_on=$(qmp_uci_get networks.publish_lan)
[ -z "$is_publish_on" ] && is_publish_on=0
if [ $is_publish_on -eq 1 ]; then
lan_addr=$(qmp_uci_get networks.lan_address)
lan_mask=$(qmp_uci_get networks.lan_netmask)
lan_prefix=$(qmp_get_prefix_from_netmask $lan_mask)
lan_netid=$(qmp_get_netid_from_network $lan_addr $lan_mask)
echo "Publishing LAN network: $lan_netid/$lan_prefix"
qmp_publish_hna_bmx6 $lan_netid/$lan_prefix qMp_lan
else
qmp_unpublish_hna_bmx6 qMp_lan
fi
}
# Usage: qmp_publish_hna_bmx6_ipv4 10.22.33.64/27 [name_id]
qmp_publish_hna_bmx6() {
netid=$(echo $1 | cut -d / -f1)
netmask=$(echo $1 | cut -d / -f2)
name_id="$2"
[ -z "$netid" -o -z "$netmask" ] && { echo "Error, IP/MASK must be specified"; return; }
is_ipv6=$(echo $netid | grep : -c)
is_ipv4=$(echo $netid | grep . -c)
[ $is_ipv6 -eq $is_ipv4 ] && { echo "Error in IP format"; return; }
# if not name_id provided, getting one from netid md5sum
[ -z "$name_id" ] && name_id="$(echo $netid | md5sum | cut -c1-5)"
if [ $is_ipv4 ]; then
# Checking if netmask is in ipv4 format and converting it to ipv6
[ $netmask -lt 33 ] && netmask=$(( 128 - (32-$netmask) ))
hna="::ffff:$netid/$netmask"
else
hna="$netid/$netmask"
fi
uci set bmx6.$name_id=hna
uci set bmx6.$name_id.hna="$hna"
uci commit
bmx6 -c --test -a $hna > /dev/null
if [ $? -eq 0 ]; then
bmx6 -c --configReload
else
echo "ERROR in bmx6, check log"
fi
}
# Unpublish a HNA, first argument is ID
qmp_unpublish_hna_bmx6() {
[ -z "$1" ] && return
uci delete bmx6.$1
uci commit
bmx6 -c --configReload
}
...@@ -38,6 +38,9 @@ eth_section:option(Value, "lan_address", "LAN address","IPv4 address for LAN int ...@@ -38,6 +38,9 @@ eth_section:option(Value, "lan_address", "LAN address","IPv4 address for LAN int
-- Option: lan addresses -- Option: lan addresses
eth_section:option(Value, "lan_netmask", "LAN netmask","IPv4 netmask for LAN interfaces") eth_section:option(Value, "lan_netmask", "LAN netmask","IPv4 netmask for LAN interfaces")
-- Option: publish lan
eth_section:option(Flag, "publish_lan", "Publish LAN", "Publish LAN network through the mesh")
-- Option bmx6_ipv4_address -- Option bmx6_ipv4_address
eth_section:option(Value, "bmx6_ipv4_address", "IPv4 address for BMX6","IPv4 address used for BMX6 (main address)") eth_section:option(Value, "bmx6_ipv4_address", "IPv4 address for BMX6","IPv4 address used for BMX6 (main address)")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment