Developing lightweight computation at the DSG edge

Commit 1525fd49 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[qmp-system] Put wired interfaces with MESH role in a virtual interface



Interfaces (e.g., eth2) with only MESH role, now without rescue addres
nor VLANs on top, need to be put inside a virtual interface (e.g.,
mesh_e2) for them to be activated by OpenWrt's network daemon, so that
they can be used by BMX6.

Fixes #493
Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent ba712452
......@@ -94,7 +94,29 @@ qmp_set_vlan() {
uci set network.${uiface}_${vid}_${vtype}.proto=${none}
uci set network.${uiface}_${vid}_${vtype}.auto=1
uci commit network
}
# Function qmp_set_viface()
#
# This function creates a virtual dummy interface (e.g., mesh_e2) on top of a
# network device (e.g., eth2). This is needed for wired devices working only as
# MESH, which otherwise are not brought up even if they have link. Fixes #493.
qmp_set_viface() {
local dev="${1}" # The physical interface
local viface="${2}" # The virtual device
echo "Setting virtual interface ${viface} for device ${dev}"
[ -z "${dev}" ] || [ -z "${viface}" ] && return
# Replace dots by underscores, in case there is any
local viface="$(echo $viface | sed -r 's/\./_/g')"
uci set network.${viface}="interface"
uci set network.${viface}.device=${dev}
uci set network.${viface}.auto=1
uci set network.${viface}.proto="none"
uci commit network
}
qmp_get_virtual_iface() {
......@@ -138,12 +160,12 @@ qmp_get_virtual_iface() {
return;
}
# id_char is the first char of the device: [e]th0 [w]lan1a
# id_char is the first char of the device: [e]th0, [e]th0.2, [w]lan1a
local id_char=$(echo $device | cut -c 1)
# id_num is the number of the device: eth[0], wlan[1]a
# id_num is the number of the device: eth[0], eth[0,2] wlan[1]a
local id_num=$(echo $device | tr -d "[A-z]" | tr - _ | tr . _)
# id_extra are the extra characters after the number: eth0[], wlan1[a]
local id_extra=$(echo $device | sed -e 's/^[a-z]*[0-9]*//g')
# id_extra are the extra characters after the number: eth0[], eth0.2[], wlan1[a]
local id_extra=$(echo $device | sed -e 's/\.//g' | sed -e 's/^[a-z]*[0-9]*//g')
# It it a WAN device?
for w in $(qmp_get_devices wan); do
......@@ -160,8 +182,8 @@ qmp_get_virtual_iface() {
# Is it mesh?
for w in $(qmp_get_devices mesh); do
if [ "$w" == "$device" ]; then
qmp_log "LOG: 9"
viface="mesh_${id_char}${id_num}${id_extra}"
qmp_log "LOG: 8"
qmp_log "Viface: $viface"
qmp_log "$device $viface"
echo "$viface"
......
......@@ -363,69 +363,71 @@ qmp_configure_mesh() {
if qmp_uci_test qmp.interfaces.mesh_devices &&
qmp_uci_test qmp.networks.mesh_protocol_vids; then
for dev in $(qmp_get_devices mesh); do
echo "Configuring ${dev} for meshing"
# Check if the current device is configured as no-vlan
local use_vlan=1
for no_vlan_int in $(qmp_uci_get interfaces.no_vlan_devices 2>/dev/null); do
[ "$no_vlan_int" == "$dev" ] && use_vlan=0
done
echo " -> Using VLAN: $use_vlan"
local protocol_vids="$(qmp_uci_get networks.mesh_protocol_vids 2>/dev/null)"
[ -z "$protocol_vids" ] && protocol_vids="bmx6:12"
local primary_mesh_device="$(qmp_get_primary_device)"
for protocol_vid in $protocol_vids; do
local protocol_name="$(echo $protocol_vid | awk -F':' '{print $1}')"
local vid="$(echo $protocol_vid | awk -F':' '{print $2}')"
# if no vlan is specified do not use vlan
[ -z "$vid" ] && vid=1 && use_vlan=0
# virtual interface
echo " -> Getting virtual interface for ${dev}"
local viface=$(qmp_get_virtual_iface $dev)
echo " -> Device ${dev} is in viface ${viface}"
# put typical IPv6 prefix (2002::), otherwise ipv6 calc assumes mapped or embedded ipv4 address
local ip6_suffix="2002::${counter}${vid}"
# Since all interfaces are defined somewhere (LAN, WAN or with Rescue IP),
# in case of not use vlan tag, device definition is not needed.
[ $use_vlan -eq 1 ] && {
for dev in $(qmp_get_devices mesh); do
echo "Configuring ${dev} for meshing"
qmp_set_vlan $dev $vid $viface
}
# Check if the current device is configured as no-vlan
local use_vlan=1
for no_vlan_int in $(qmp_uci_get interfaces.no_vlan_devices 2>/dev/null); do
[ "$no_vlan_int" == "$dev" ] && use_vlan=0
done
echo " -> Using VLAN: $use_vlan"
local protocol_vids="$(qmp_uci_get networks.mesh_protocol_vids 2>/dev/null)"
[ -z "$protocol_vids" ] && protocol_vids="bmx6:12"
local primary_mesh_device="$(qmp_get_primary_device)"
for protocol_vid in $protocol_vids; do
local protocol_name="$(echo $protocol_vid | awk -F':' '{print $1}')"
local vid="$(echo $protocol_vid | awk -F':' '{print $2}')"
# if no vlan is specified do not use vlan
[ -z "$vid" ] && vid=1 && use_vlan=0
# virtual interface
echo " -> Getting virtual interface for ${dev}"
local viface=$(qmp_get_virtual_iface $dev)
echo " -> Device ${dev} is in viface ${viface}"
# put typical IPv6 prefix (2002::), otherwise ipv6 calc assumes mapped or embedded ipv4 address
local ip6_suffix="2002::${counter}${vid}"
# Since all interfaces are defined somewhere (LAN, WAN or with Rescue IP),
# in case of not use vlan tag, device definition is not needed.
[ $use_vlan -eq 1 ] && {
qmp_set_vlan $dev $vid $viface
}
dev="$(echo $dev | sed -r 's/\./_/g')"
# Configure IPv6 address only if mesh_prefix48 is defined (bmx6 does not need it)
if qmp_uci_test qmp.networks.${protocol_name}_mesh_prefix48; then
local ip6="$(qmp_get_ula96 $(uci get qmp.networks.${protocol_name}_mesh_prefix48):: $primary_mesh_device $ip6_suffix 128)"
echo "Configuring $ip6 for $protocol_name"
qmp_uci_set_raw network.${dev}_$vid.proto=static
qmp_uci_set_raw network.${dev}_$vid.ip6addr="$ip6"
else
qmp_uci_set_raw network.${dev}_$vid.proto=none
qmp_uci_set_raw network.${dev}_$vid.auto=1
fi
done
dev="$(echo $dev | sed -r 's/\./_/g')"
# Configure IPv6 address only if mesh_prefix48 is defined (bmx6 does not need it)
if qmp_uci_test qmp.networks.${protocol_name}_mesh_prefix48; then
local ip6="$(qmp_get_ula96 $(uci get qmp.networks.${protocol_name}_mesh_prefix48):: $primary_mesh_device $ip6_suffix 128)"
echo "Configuring $ip6 for $protocol_name"
qmp_uci_set_raw network.${dev}_$vid.proto=static
qmp_uci_set_raw network.${dev}_$vid.ip6addr="$ip6"
else
qmp_uci_set_raw network.${dev}_$vid.proto=none
qmp_uci_set_raw network.${dev}_$vid.auto=1
# Rescue IPs are no longer needed since all the interfaces have link-local
# IPv6 address. However, the radios must be "assigned" to some interface to
# bring them up; otherwise the VLAN interface on top of the radio interface
# can't be brought up
if ( [ -e "/sys/class/net/$dev" ] && [ -e "/sys/class/net/$dev/phy80211" ] ); then
local wireless_network="$(uci get wireless.${dev}.network)"
if [ -z "$wireless_network" ]; then
qmp_configure_rescue_ip_device "$dev" "$viface"
else
qmp_configure_rescue_ip_device "$dev" "$wireless_network"
fi
# Add to the virtual interface those wired interfaces that wouldn't be brought up (Fixes #493)
elif ( ! ( qmp_is_in "$dev" $(qmp_get_devices wan) || qmp_is_in "$dev" $(qmp_get_devices lan) ) ); then
qmp_set_viface $dev $viface
fi
counter=$(( $counter + 1 ))
done
# Rescue IPs are no longer needed since all the interfaces have link-local
# IPv6 address. However, the radios must be "assigned" to some interface to
# bring them up; otherwise the VLAN interface on top of the radio interface
# can't be brought up
if ! ( [ -e "/sys/class/net/$dev" ] && [ ! -e "/sys/class/net/$dev/phy80211" ] ); then
local wireless_network="$(uci get wireless.${dev}.network)"
if [ -z "$wireless_network" ]; then
qmp_configure_rescue_ip_device "$dev" "$viface"
else
qmp_configure_rescue_ip_device "$dev" "$wireless_network"
fi
fi
counter=$(( $counter + 1 ))
done
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