Developing lightweight computation at the DSG edge

Commit 8d26005d authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[qmp-system] 802.1ad VLANs for the routing protocol are created on top of the physical interface

Previously, when an interface (i.e. eth0) was configured as "lan" and "mesh",
it was added to the LAN bridge and, on top of the virtual "br-lan" interface,
the VLAN for the routing protocol was created (i.e. lan_12). This was wrong in
some cases, for example, when another interface was in the bridge but not meant
to be meshing. Now the VLANs are created on the interfaces actually configured
as "mesh".
parent 4fdd709d
...@@ -43,12 +43,24 @@ qmp_check_device() { ...@@ -43,12 +43,24 @@ qmp_check_device() {
ip link show $1 1> /dev/null 2>/dev/null ip link show $1 1> /dev/null 2>/dev/null
return $? return $?
} }
# Function qmp_set_vlan()
#
# This function creates a VLAN interface on top of an interface in order to
# isolate the routing protocol traffic there:
#
# - 802.1 VLANs are used for wireless interfaces.
# - 802.1ad (QinQ) VLANs are used for wired devices since qMp > 3.2.1
qmp_set_vlan() { qmp_set_vlan() {
local viface="$1" # lan/wan/meshX local viface="$1" # lan/wan/meshX
local vid=$2 local vid=$2
echo "Setting VLAN $vid for interface $viface"
[ -z "$viface" ] || [ -z "$vid" ] && return [ -z "$viface" ] || [ -z "$vid" ] && return
or_viface="$viface"
viface="$(echo $viface | sed -r 's/\./_/g')"
uci set network.${viface}_${vid}=device uci set network.${viface}_${vid}=device
if [ -e "/sys/class/net/$dev/phy80211" ]; then if [ -e "/sys/class/net/$dev/phy80211" ]; then
# 802.1q VLANs for wireless interfaces # 802.1q VLANs for wireless interfaces
...@@ -61,10 +73,10 @@ qmp_set_vlan() { ...@@ -61,10 +73,10 @@ qmp_set_vlan() {
uci set network.${viface}_${vid}.name=${viface}_${vid} uci set network.${viface}_${vid}.name=${viface}_${vid}
if [ -e "/sys/class/net/$dev/phy80211" ]; then if [ -e "/sys/class/net/$dev/phy80211" ]; then
# 802.1q VLANs for wireless interfaces # 802.1q VLANs for wireless interfaces
uci set network.${viface}_${vid}.ifname='@'${viface} uci set network.${viface}_${vid}.ifname='@'${or_viface}
else else
# 802.1ad VLANs for wired interfaces # 802.1ad VLANs for wired interfaces
uci set network.${viface}_${vid}.ifname=$3 uci set network.${viface}_${vid}.ifname=$or_viface
fi fi
uci set network.${viface}_${vid}.vid=${vid} uci set network.${viface}_${vid}.vid=${vid}
...@@ -144,28 +156,30 @@ qmp_get_devices() { ...@@ -144,28 +156,30 @@ qmp_get_devices() {
local devices="" local devices=""
if [ "$1" == "mesh" ]; then if [ "$1" == "mesh" ]; then
local brlan_enabled=0 devices="$(uci get qmp.interfaces.mesh_devices 2>/dev/null)"
for dev in $(uci get qmp.interfaces.mesh_devices 2>/dev/null); do fi
# local brlan_enabled=0
# Looking if device is defined as LAN, in such case dev=br-lan, but only once # for dev in $(uci get qmp.interfaces.mesh_devices 2>/dev/null); do
# except eth1 for RouterStation Pro #
if ! ( [[ "$dev" == "eth1" ]] && qmp_is_routerstationpro ) ; then # # Looking if device is defined as LAN, in such case dev=br-lan, but only once
for landev in $(uci get qmp.interfaces.lan_devices 2>/dev/null); do # # except eth1 for RouterStation Pro
if [ "$landev" == "$dev" ] && [ ! -e "/sys/class/net/$dev/phy80211" ] ; then # if ! ( [[ "$dev" == "eth1" ]] && qmp_is_routerstationpro ) ; then
if [ $brlan_enabled -eq 0 ]; then # for landev in $(uci get qmp.interfaces.lan_devices 2>/dev/null); do
dev="br-lan" # if [ "$landev" == "$dev" ] && [ ! -e "/sys/class/net/$dev/phy80211" ] ; then
brlan_enabled=1 # if [ $brlan_enabled -eq 0 ]; then
else # dev="br-lan"
dev="" # brlan_enabled=1
fi # else
break # dev=""
fi # fi
done # break
fi # fi
# done
[ -n "$dev" ] && devices="$devices $dev" # fi
done #
fi # [ -n "$dev" ] && devices="$devices $dev"
# done
# fi
if [ "$1" == "lan" ]; then if [ "$1" == "lan" ]; then
devices="$(uci get qmp.interfaces.lan_devices 2>/dev/null)" devices="$(uci get qmp.interfaces.lan_devices 2>/dev/null)"
...@@ -797,31 +811,32 @@ fi ...@@ -797,31 +811,32 @@ fi
then then
local counter=1 local counter=1
for dev in $(qmp_get_devices mesh); do for dev in $(qmp_get_devices mesh); do
for protocol_vid in $(uci get qmp.networks.mesh_protocol_vids); do echo "Configuring interface $dev in BMX6"
local protocol_name="$(echo $protocol_vid | awk -F':' '{print $1}')" for protocol_vid in $(uci get qmp.networks.mesh_protocol_vids); do
local protocol_name="$(echo $protocol_vid | awk -F':' '{print $1}')"
if [ "$protocol_name" = "bmx6" ] ; then if [ "$protocol_name" = "bmx6" ] ; then
# 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 $(qmp_uci_get interfaces.no_vlan_devices); do
for no_vlan_int in $(qmp_uci_get interfaces.no_vlan_devices); do [ "$no_vlan_int" == "$dev" ] && use_vlan=0
[ "$no_vlan_int" == "$dev" ] && use_vlan=0 done
done
# Check if the protocol has VLAN tag configured # Check if the protocol has VLAN tag configured
local vid="$(echo $protocol_vid | awk -F':' '{print $2}')" local vid="$(echo $protocol_vid | awk -F':' '{print $2}')"
[ -z "$vid" -o $vid -lt 1 ] && use_vlan=0 [ -z "$vid" -o $vid -lt 1 ] && use_vlan=0
# Check if the protocol has VLAN tag configured # Check if the protocol has VLAN tag configured
local vid="$(echo $protocol_vid | awk -F':' '{print $2}')" local vid="$(echo $protocol_vid | awk -F':' '{print $2}')"
[ -z "$vid" -o $vid -lt 1 ] && use_vlan=0 [ -z "$vid" -o $vid -lt 1 ] && use_vlan=0
# If vlan tagging # If vlan tagging
if [ $use_vlan -eq 1 ]; then if [ $use_vlan -eq 1 ]; then
local viface="$(qmp_get_virtual_iface $dev)" # For interfaces like eth0.1, replace the dot with an underscore
local ifname="${viface}_${vid}" local viface="$(echo $dev | sed -r 's/\./_/g')"
local ifname="${viface}_${vid}"
# If not vlan tagging # If not vlan tagging
else else
......
...@@ -357,10 +357,9 @@ qmp_configure_mesh() { ...@@ -357,10 +357,9 @@ qmp_configure_mesh() {
# if no vlan is specified do not use vlan # if no vlan is specified do not use vlan
[ -z "$vid" ] && vid=1 && use_vlan=0 [ -z "$vid" ] && vid=1 && use_vlan=0
# virtual interface # virtual interface
local viface=$(qmp_get_virtual_iface $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 # put typical IPv6 prefix (2002::), otherwise ipv6 calc assumes mapped or embedded ipv4 address
local ip6_suffix="2002::${counter}${vid}" local ip6_suffix="2002::${counter}${vid}"
...@@ -368,33 +367,23 @@ qmp_configure_mesh() { ...@@ -368,33 +367,23 @@ qmp_configure_mesh() {
# in case of not use vlan tag, device definition is not needed. # in case of not use vlan tag, device definition is not needed.
[ $use_vlan -eq 1 ] && { [ $use_vlan -eq 1 ] && {
#### [QinQ] qmp_set_vlan $dev $vid
####
#### Using the rescue interface here does not make much sense as of
#### current qMp status and does not work for 802.1-ad
####
#### # If device is WAN use rescue for the VLAN tag
####
if [ $(qmp_get_devices wan | grep -c $dev) -gt 0 ]; then
qmp_set_vlan ${viface}_rescue $vid $dev
else
qmp_set_vlan $viface $vid $dev
fi
} }
dev="$(echo $dev | sed -r 's/\./_/g')"
# Configure IPv6 address only if mesh_prefix48 is defined (bmx6 does not need it) # 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 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)" 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" echo "Configuring $ip6 for $protocol_name"
qmp_uci_set_raw network.${viface}_$vid.proto=static qmp_uci_set_raw network.${dev}_$vid.proto=static
qmp_uci_set_raw network.${viface}_$vid.ip6addr="$ip6" qmp_uci_set_raw network.${dev}_$vid.ip6addr="$ip6"
else else
qmp_uci_set_raw network.${viface}_$vid.proto=none qmp_uci_set_raw network.${dev}_$vid.proto=none
qmp_uci_set_raw network.${viface}_$vid.auto=1 qmp_uci_set_raw network.${dev}_$vid.auto=1
fi fi
done done
qmp_configure_rescue_ip_device "$dev" "$viface" echo qmp_configure_rescue_ip_device "$dev" "$viface"
counter=$(( $counter + 1 )) counter=$(( $counter + 1 ))
done done
fi fi
...@@ -407,10 +396,15 @@ qmp_configure_rescue_ip_device() { ...@@ -407,10 +396,15 @@ qmp_configure_rescue_ip_device() {
local viface="$2" local viface="$2"
if qmp_is_in "$dev" $(qmp_get_devices wan) || [ "$dev" == "br-lan" ]; then if qmp_is_in "$dev" $(qmp_get_devices wan) || [ "$dev" == "br-lan" ]; then
echo "WAN_OR_LAN"
# If it is WAN or LAN # If it is WAN or LAN
qmp_configure_rescue_ip $dev ${viface}_rescue qmp_configure_rescue_ip $dev ${viface}_rescue
qmp_attach_device_to_interface $dev ${viface}_rescue if qmp_is_in "$dev" $(qmp_get_devices wan) ; then
#qmp_attach_device_to_interface $dev ${viface}_rescue
qmp_attach_device_to_interface $dev $viface
fi
elif qmp_is_in "$dev" $(qmp_get_devices mesh) && [ "$dev" != "br-lan" ]; then elif qmp_is_in "$dev" $(qmp_get_devices mesh) && [ "$dev" != "br-lan" ]; then
echo "MESH_NOT_LAN"
# 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 $viface qmp_attach_device_to_interface $dev $viface
......
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