Developing lightweight computation at the DSG edge

Commit 0c19540e authored by p4u's avatar p4u
Browse files

Adapt some functions to the new mode adhoc_ap

parent 05b45d68
...@@ -168,18 +168,30 @@ qmp_get_devices() { ...@@ -168,18 +168,30 @@ qmp_get_devices() {
qmp_get_rescue_ip() { qmp_get_rescue_ip() {
local device=$1 local device=$1
local mac=""
[ -z "$device" ] && return 1 [ -z "$device" ] && return 1
local rprefix=$(uci get qmp.networks.rescue_prefix24 2>/dev/null) local rprefix=$(qmp_uci_get networks.rescue_prefix24 2>/dev/null)
[ -z "$rprefix" ] && return 0 [ -z "$rprefix" ] && return 0
# if device is virtual, get the ifname # if device is virtual, get the ifname
if qmp_uci_test network.$device.ifname; then if qmp_uci_test network.$device.ifname; then
device="$(uci get network.$device.ifname | tr -d @)" local devvirt="$(qmp_uci_get_raw network.$device.ifname | tr -d @)"
device=${devvirt:-$device}
fi fi
local mac=$(ip addr show dev $device | grep -m 1 "link/ether" | awk '{print $2}') # is it a wireless device?
[ -z "$mac" ] && return 2 if qmp_uci_test wireless.$device.device; then
local radio="$(qmp_uci_get_raw wireless.$device.device)"
mac=$(qmp_uci_get_raw wireless.$radio.macaddr)
else
mac=$(ip addr show dev $device | grep -m 1 "link/ether" | awk '{print $2}')
fi
[ -z "$mac" ] && {
qmp_log Warning: MAC for $device cannot be found, using 55:55:55:55:55:55 for rescue IP
mac="55:55:55:55:55:55"
}
#local xoctet=$(printf "%d\n" 0x$(echo $mac | cut -d: -f5)) #local xoctet=$(printf "%d\n" 0x$(echo $mac | cut -d: -f5))
local yoctet=$(printf "%d\n" 0x$(echo $mac | cut -d: -f6)) local yoctet=$(printf "%d\n" 0x$(echo $mac | cut -d: -f6))
...@@ -192,33 +204,22 @@ qmp_attach_device_to_interface() { ...@@ -192,33 +204,22 @@ qmp_attach_device_to_interface() {
local device=$1 local device=$1
local conf=$2 local conf=$2
local interface=$3 local interface=$3
# local intype="$(qmp_uci_get_raw network.$interface.type)" <-- does not work ¿? local intype="$(qmp_uci_get_raw $conf.$interface.type)"
echo "Attaching device $device to interface $interface" echo "Attaching device $device to interface $interface"
devcl="$(echo $device | cut -d- -f1)" # wlan0-1 -> wlan0
local wifi_config="$(uci -qX show wireless | sed -n -e "s/wireless\.\([^\.]\+\)\.device=$devcl/\1/p")"
# is it a wifi device? # is it a wifi device?
if [ -n "$wifi_config" -a $(echo $(qmp_uci_get_raw wireless.$devcl) | grep -c wifi) -ge 1 ]; then if qmp_uci_test wireless.$device; then
wifidev_i="$(echo $device | tr -d [A-z] | cut -d- -f2)" # wlan0-1 -> 1 qmp_uci_set_raw wireless.$device.network="$interface"
wifidev_i=${wifidev_i:-0} uci commit wireless
id="0" echo " -> $device wireless attached to $interface"
for wc in $wifi_config ; do
if [ "$id" = "$wifidev_i" ]; then
echo " -> wireless.$wc attached to $interface"
uci set wireless.$wc.network="$interface"
uci commit wireless
fi
id=$(($id+1))
done
# if it is not # if it is not
else else
if [ "$interface" == "lan" ]; then if [ "$intype" == "bridge" ]; then
uci add_list $conf.$interface.ifname="$device" qmp_uci_add_list_raw $conf.$interface.ifname="$device"
echo " -> $device attached to $interface bridge" echo " -> $device attached to $interface bridge"
else else
uci set $conf.$interface.ifname="$device" qmp_uci_set_raw $conf.$interface.ifname="$device"
echo " -> $device attached to $interface" echo " -> $device attached to $interface"
fi fi
fi fi
...@@ -585,7 +586,7 @@ qmp_configure_rescue_ip_device() ...@@ -585,7 +586,7 @@ qmp_configure_rescue_ip_device()
elif qmp_is_in "$dev" $(qmp_get_devices mesh) && [ "$dev" != "br-lan" ] elif qmp_is_in "$dev" $(qmp_get_devices mesh) && [ "$dev" != "br-lan" ]
then then
# If it is only mesh device # If it is only mesh device
qmp_configure_rescue_ip $dev qmp_configure_rescue_ip $dev
qmp_attach_device_to_interface $dev $conf $viface qmp_attach_device_to_interface $dev $conf $viface
fi fi
} }
...@@ -593,8 +594,9 @@ qmp_configure_rescue_ip_device() ...@@ -593,8 +594,9 @@ qmp_configure_rescue_ip_device()
qmp_configure_prepare() { qmp_configure_prepare() {
local conf=$1 local conf=$1
echo "-----------------------"
echo "configuring /etc/config/$conf" echo "Configuring networking"
echo "-----------------------"
if ! [ -f /etc/config/$conf.orig ]; then if ! [ -f /etc/config/$conf.orig ]; then
echo "saving original config in: /etc/config/$conf.orig" echo "saving original config in: /etc/config/$conf.orig"
...@@ -613,7 +615,7 @@ qmp_configure_network() { ...@@ -613,7 +615,7 @@ qmp_configure_network() {
qmp_configure_prepare $conf qmp_configure_prepare $conf
if qmp_uci_test qmp.interfaces.mesh_devices && qmp_uci_test qmp.networks.mesh_protocol_vids && qmp_uci_test qmp.networks.mesh_vid_offset; then if qmp_uci_test qmp.interfaces.mesh_devices && qmp_uci_test qmp.networks.mesh_protocol_vids && qmp_uci_test qmp.networks.mesh_vid_offset; then
local vids="$(uci -q get qmp.networks.mesh_protocol_vids | awk -F':' -v RS=" " '{print $2 + '$(uci -q get qmp.networks.mesh_vid_offset)'}')" local vids="$(qmp_uci_get networks.mesh_protocol_vids | awk -F':' -v RS=" " '{print $2 + '$(uci -q get qmp.networks.mesh_vid_offset)'}')"
fi fi
if [[ -n "$vids" ]] && qmp_is_routerstationpro ; then if [[ -n "$vids" ]] && qmp_is_routerstationpro ; then
...@@ -622,7 +624,7 @@ qmp_configure_network() { ...@@ -622,7 +624,7 @@ qmp_configure_network() {
elif qmp_uci_test qmp.interfaces.configure_switch ; then elif qmp_uci_test qmp.interfaces.configure_switch ; then
local switch_device="$(uci get qmp.interfaces.configure_switch)" local switch_device="$(qmp_uci_get interfaces.configure_switch)"
uci set $conf.$switch_device="switch" uci set $conf.$switch_device="switch"
uci set $conf.$switch_device.enable="1" uci set $conf.$switch_device.enable="1"
...@@ -683,7 +685,7 @@ qmp_configure_network() { ...@@ -683,7 +685,7 @@ qmp_configure_network() {
local LSB_PRIM_MAC="$(qmp_get_mac_for_dev $primary_mesh_device | awk -F':' '{print $6}' )" local LSB_PRIM_MAC="$(qmp_get_mac_for_dev $primary_mesh_device | awk -F':' '{print $6}' )"
if qmp_uci_test qmp.node.community_node_id; then if qmp_uci_test qmp.node.community_node_id; then
community_node_id="$(uci get qmp.node.community_node_id)" community_node_id="$(qmp_uci_get node.community_node_id)"
elif ! [ -z "$primary_mesh_device" ] ; then elif ! [ -z "$primary_mesh_device" ] ; then
community_node_id=$LSB_PRIM_MAC community_node_id=$LSB_PRIM_MAC
fi fi
...@@ -692,12 +694,12 @@ qmp_configure_network() { ...@@ -692,12 +694,12 @@ qmp_configure_network() {
# If it is enabled, apply the non-overlapping DHCP-range preset policy # If it is enabled, apply the non-overlapping DHCP-range preset policy
LAN_MASK="$(uci get qmp.networks.lan_netmask)" LAN_MASK="$(qmp_uci_get networks.lan_netmask)"
LAN_ADDR="$(uci get qmp.networks.lan_address)" LAN_ADDR="$(qmp_uci_get networks.lan_address)"
START=2 START=2
LIMIT=253 LIMIT=253
if [ $(uci get qmp.non_overlapping.ignore) -eq 0 ]; then if [ $(qmp_uci_get non_overlapping.ignore) -eq 0 ]; then
LAN_MASK="255.255.0.0" LAN_MASK="255.255.0.0"
# Last byte of lan adress must be "1" to avoid overlappings # Last byte of lan adress must be "1" to avoid overlappings
LAN_ADDR=$(echo $LAN_ADDR | sed -e 's/\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)\.[0-9]\{1,3\}/\1.1/1') LAN_ADDR=$(echo $LAN_ADDR | sed -e 's/\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)\.[0-9]\{1,3\}/\1.1/1')
...@@ -705,14 +707,14 @@ qmp_configure_network() { ...@@ -705,14 +707,14 @@ qmp_configure_network() {
OFFSET=0 OFFSET=0
NUM_GRP=256 NUM_GRP=256
UCI_OFFSET="$(uci get qmp.non_overlapping.dhcp_offset)" UCI_OFFSET="$(qmp_uci_get non_overlapping.dhcp_offset)"
[ $UCI_OFFSET -lt $NUM_GRP ] && OFFSET=$UCI_OFFSET [ $UCI_OFFSET -lt $NUM_GRP ] && OFFSET=$UCI_OFFSET
START=$(( 0x$community_node_id * $NUM_GRP + $OFFSET )) START=$(( 0x$community_node_id * $NUM_GRP + $OFFSET ))
LIMIT=$(( $NUM_GRP - $OFFSET )) LIMIT=$(( $NUM_GRP - $OFFSET ))
uci set dhcp.lan.leasetime="$(uci get qmp.non_overlapping.qmp_leasetime)" uci set dhcp.lan.leasetime="$(qmp_uci_get non_overlapping.qmp_leasetime)"
fi fi
uci set dhcp.lan.start=$START uci set dhcp.lan.start=$START
...@@ -720,7 +722,7 @@ qmp_configure_network() { ...@@ -720,7 +722,7 @@ qmp_configure_network() {
local disable_dhcp=0 local disable_dhcp=0
if qmp_uci_test qmp.networks.disable_lan_dhcp; then if qmp_uci_test qmp.networks.disable_lan_dhcp; then
disable_dhcp="$(uci get qmp.networks.disable_lan_dhcp)" disable_dhcp="$(qmp_uci_get networks.disable_lan_dhcp)"
fi fi
if [ "$disable_dhcp" != "1" ]; then if [ "$disable_dhcp" != "1" ]; then
...@@ -742,29 +744,32 @@ qmp_configure_network() { ...@@ -742,29 +744,32 @@ qmp_configure_network() {
uci set $conf.lan.proto="static" uci set $conf.lan.proto="static"
uci set $conf.lan.ipaddr=$LAN_ADDR uci set $conf.lan.ipaddr=$LAN_ADDR
uci set $conf.lan.netmask=$LAN_MASK uci set $conf.lan.netmask=$LAN_MASK
uci set $conf.lan.dns="$(uci get qmp.networks.dns)" uci set $conf.lan.dns="$(qmp_uci_get networks.dns)"
fi fi
# MESH DEVICES CONFIGURATION # MESH DEVICES CONFIGURATION
local counter=1 local counter=1
if uci get qmp.interfaces.mesh_devices && uci get qmp.networks.mesh_protocol_vids && uci get qmp.networks.mesh_vid_offset; then if qmp_uci_test qmp.interfaces.mesh_devices &&
qmp_uci_test qmp.networks.mesh_protocol_vids &&
qmp_uci_test qmp.networks.mesh_vid_offset; then
for dev in $(qmp_get_devices mesh); do for dev in $(qmp_get_devices mesh); do
# If dev is empty, nothing to do # If dev is empty, nothing to do
[ -z "$dev" ] || ! qmp_check_device $dev && continue [ -z "$dev" ] && continue
# Let's configure the mesh device # Let's configure the mesh device
echo "Configuring "$dev" for Meshing" echo "Configuring "$dev" for Meshing"
# Check if the current device is configured as no-vlan # Check if the current device is configured as no-vlan
local use_vlan=1 local use_vlan=1
for no_vlan_int in $(uci get qmp.interfaces.no_vlan_devices 2>/dev/null); do for no_vlan_int in $(qmp_uci_get interfaces.no_vlan_devices 2>/dev/null); do
[ "$no_vlan_int" == "$dev" ] && use_vlan=0 [ "$no_vlan_int" == "$dev" ] && use_vlan=0
done done
local protocol_vids="$(uci get qmp.networks.mesh_protocol_vids 2>/dev/null)" local protocol_vids="$(qmp_uci_get qmp.networks.mesh_protocol_vids 2>/dev/null)"
[ -z "$protocol_vids" ] && protocol_vids="olsr6:1 bmx6:2" [ -z "$protocol_vids" ] && protocol_vids="olsr6:1 bmx6:2"
for protocol_vid in $protocol_vids; do for protocol_vid in $protocol_vids; do
...@@ -772,7 +777,7 @@ qmp_configure_network() { ...@@ -772,7 +777,7 @@ qmp_configure_network() {
# Calculating the VID offset for VLAN tag # Calculating the VID offset for VLAN tag
local protocol_name="$(echo $protocol_vid | awk -F':' '{print $1}')" local protocol_name="$(echo $protocol_vid | awk -F':' '{print $1}')"
local vid_suffix="$(echo $protocol_vid | awk -F':' '{print $2}')" local vid_suffix="$(echo $protocol_vid | awk -F':' '{print $2}')"
local vid_offset="$(uci get qmp.networks.mesh_vid_offset)" local vid_offset="$(qmp_uci_get networks.mesh_vid_offset)"
local vid="$(( $vid_offset + $vid_suffix ))" local vid="$(( $vid_offset + $vid_suffix ))"
# virtual interface # virtual interface
......
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