Developing lightweight computation at the DSG edge

Commit c1fdeb9d authored by p4u's avatar p4u
Browse files

Added support for ULA Lan.

By default the prefix fd00:1714:1714::/48 is used
Radvd is configured and started to get IPv6 to end users
parent ba40efe9
......@@ -921,7 +921,7 @@ qmp_configure() {
qmp_configure_network
qmp_configure_bmx6
qmp_configure_olsr6
qmp_configure_lan_v6
qmp_configure_system
}
......@@ -20,7 +20,6 @@
##############################
# Global variable definition
##############################
QMP_PATH="/etc/qmp"
TMP="/tmp"
QMPINFO="/etc/qmp/qmpinfo"
......@@ -64,36 +63,30 @@ qmp_publish_lan() {
fi
}
# Usage: qmp_publish_hna_bmx6_ipv4 10.22.33.64/27 [name_id]
# Usage: qmp_publish_hna_bmx6 <NETADDR/PREFIX> [Name ID]
# Example: qmp_publish_hna_bmx6 fd00:1714:1714::/64 my_lan
qmp_publish_hna_bmx6() {
netid=$(echo $1 | cut -d / -f1)
netmask=$(echo $1 | cut -d / -f2)
name_id="$2"
local netid=$(echo $1 | cut -d / -f1)
local netmask=$(echo $1 | cut -d / -f2)
local 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)"
local is_ipv6=$(echo $netid | grep : -c)
[ $is_ipv6 -lt 1 ] && { echo "Error in IPv6/Prefix format"; return; }
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"
if [ -z "$name_id" ]; then
local ucfg=$(uci add bmx6 unicastHna)
[ -z "$ucfg" ] && { echo "Cannot add unicastHna entry to UCI"; return; }
uci set bmx6.$ucfg.unicastHna="$netid/$netmask"
else
hna="$netid/$netmask"
fi
uci set bmx6.$name_id=hna
uci set bmx6.$name_id.hna="$hna"
uci commit
uci set bmx6.$name_id=unicastHna
uci set bmx6.$name_id.unicastHna="$netid/$netmask"
fi
uci commit bmx6
bmx6 -c --test -a $hna > /dev/null
bmx6 -c --test -u $netid/$netmask > /dev/null
if [ $? -eq 0 ]; then
bmx6 -c --configReload
else
......@@ -101,10 +94,169 @@ qmp_publish_hna_bmx6() {
fi
}
# Unpublish a HNA, first argument is ID
# Unpublish a HNA, first argument is IPv6 HNA or name id
qmp_unpublish_hna_bmx6() {
[ -z "$1" ] && return
uci delete bmx6.$1
if [ $(echo $1 | grep : -c) -ne 0 ]; then
uci show bmx6.@unicastHna[].unicastHna | while read hna
do
if [ "$(echo $hna | cut -d= -f2)" == "$1" ]; then
uci del bmx6.$(echo $hna | cut -d. -f2)
return
fi
done
else
uci delete bmx6.$1
fi
uci commit
bmx6 -c --configReload
}
qmp_radvd_enable_dev() {
local dev="$1"
local cfg=""
echo "Enabling interface $1 for radvd"
for i in $(uci show radvd.@interface[].interface 2>/dev/null); do
if [ "$(echo $i | cut -d= -f2)" == "$dev" ]; then
cfg="$(echo $i | cut -d. -f2)"
break
fi
done
if [ -z "$cfg" ]; then
echo "Cannot find radvd config for $dev. Addind new one"
cfg="$(uci add radvd interface)"
uci set radvd.$cfg.interface=$dev
fi
uci set radvd.$cfg.ignore=0
uci set radvd.$cfg.AdvSendAdvert=1
uci set radvd.$cfg.AdvManagedFlag=1
uci set radvd.$cfg.IgnoreIfMissing=1
uci commit
echo "Done"
}
qmp_radvd_enable_prefix() {
local dev="$1"
local prefix="$2"
echo "Adding prefix $route $dev to radvd"
[ -z "$dev" -o -z "$prefix" ] && { echo "Dev or route missing, exiting"; return; }
# Looking for the already configured device
local cfg=""
for i in $(uci show radvd.@prefix[].interface 2>/dev/null); do
if [ "$(echo $i | cut -d= -f2)" == "$dev" ]; then
cfg="$(echo $i | cut -d. -f2)"
break
fi
done
# Checking if this prefix already exists in the device
for p in $(uci get radvd.$cfg.prefix 2>/dev/null); do
if [ "$p" == "$prefix" ]; then
echo "Prefix found in $dev radvd configuration, nothing to do"
return
fi
done
# If the configuration is not found, creating new one"
if [ -z "$cfg" ]; then
cfg=$(uci add radvd prefix)
uci set radvd.$cfg.interface=$dev
fi
# Configuring parameters of radvd
uci set radvd.$cfg.ignore=0
uci set radvd.$cfg.AdvOnLink=1
uci add_list radvd.$cfg.prefix=$prefix
uci commit
echo "Done"
}
qmp_radvd_enable_route() {
local dev="$1"
local route="$2"
echo "Adding route $route $dev to radvd"
[ -z "$dev" -o -z "$route" ] && { echo "Dev or route missing, exiting"; return; }
# Looking for the already configured device
local cfg=""
for i in $(uci show radvd.@route[].interface 2>/dev/null); do
if [ "$(echo $i | cut -d= -f2)" == "$dev" ]; then
cfg="$(echo $i | cut -d. -f2)"
break
fi
done
# Checking if this prefix already exists in the device
for p in $(uci get radvd.$cfg.prefix 2>/dev/null); do
if [ "$p" == "$route" ]; then
echo "Prefix found in $dev radvd configuration, nothing to do"
return
fi
done
# If the configuration is not found, creating new one"
if [ -z "$cfg" ]; then
cfg=$(uci add radvd route)
uci set radvd.$cfg.interface=$dev
fi
# Configuring parameters of radvd
uci set radvd.$cfg.ignore=0
uci set radvd.$cfg.AdvRouteLifetime="infinity"
uci add_list radvd.$cfg.prefix=$route
uci commit
echo "Done"
}
qmp_configure_lan_v6() {
echo "Starting ULA LAN configuration"
local prefix="$(qmp_uci_get networks.lan_ula_prefix48)"
[ -z "$prefix" ] && { echo "No lan ULA prefix configured, skiping LAN IPv6 ULA configuration"; return; }
local dev="$(qmp_uci_get node.primary_device)"
if [ -z "$dev" ]; then
lanid="$(cat /var/log/*.log | md5sum | awk '{print $1}' | cut -c1-4)"
else
lanid="$(qmp_get_mac_for_dev $dev | tr -d : | cut -c9-12)"
fi
if [ $(echo $prefix | grep :: -c) -eq 0 ]; then
ulan_net="$prefix:$lanid::/64"
ulan_ip="$prefix:$lanid::1/64"
else
ulan_net="$prefix:$lanid:0000:0000:0000:0000/64"
ulan_ip="$prefix:$lanid:0000:0000:0000:0001/64"
fi
echo "Configuring $ulan_ip as LAN ULA address"
qmp_uci_set_raw network.lan.ip6addr=$ulan_ip
ifup lan
echo "Publishing $ulan_net over the mesh network"
qmp_publish_hna_bmx6 $ulan_net ulan
echo "Configuring radvd"
qmp_radvd_enable_dev lan
qmp_radvd_enable_prefix lan $ulan_ip
qmp_radvd_enable_route lan fc00::/7
/etc/init.d/radvd restart
echo "Adding quick hack to solve bmx6 ipv6 throw rules problem"
if [ $(cat /etc/rc.local | grep -c ^#BMX6_ULA_LAN_IPV6_HACK) -lt 1 ]; then
sed -i -e "/^exit 0/d" /etc/rc.local
echo "#BMX6_ULA_LAN_IPV6_HACK" >> /etc/rc.local
echo "ip -6 route add $ulan_net dev br-lan table 60" >> /etc/rc.local
fi
ip -6 route add $ulan_net dev br-lan table 60
echo "Done"
}
#!/bin/sh
if ! uci get qmp.networks.lan_ula_prefix48 2>/dev/null; then
uci set qmp.networks.lan_ula_prefix48=fd00:1714:1714
uci commit
fi
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