Developing lightweight computation at the DSG edge

Commit 6dd7a4af authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[qmp-system] Migrate to new UCI network model



With commit 892fc7caa9eee9f5ef9e172677f871c02841bae8 OpenWrt introduced
a new model for the br-lan device. For instance, it is split between a
device and an interface.

This commit adapts the configuration of wired interfaces to the new
UCI-based model.

Partial for #489
Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent 16b6cde3
#!/bin/sh #!/bin/sh /etc/rc.common
SOURCE_COMMON=1 SOURCE_COMMON=1
#DEBUG="/tmp/qmp_common.debug" #DEBUG="/tmp/qmp_common.debug"
...@@ -24,6 +24,34 @@ qmp_uci_get_raw() { ...@@ -24,6 +24,34 @@ qmp_uci_get_raw() {
return $r return $r
} }
qmp_uci_get_raw_item_space() {
u="$(uci -q get ${4}.${1}.${3})"
r=$?
echo "$u"
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci get $@)"
qmp_debug "qmp_uci_get_raw: uci -q get $@"
return $r
}
qmp_uci_get_raw_id_space() {
u="$(qmp_uci_get_raw_item_space ${1} dummy ${3} ${4})"
if [ "$u" == "$2" ]; then
echo $1
fi
}
qmp_uci_get_item_by_unnamed_section_type_and_name() {
config_load $1
local u="$(config_foreach qmp_uci_get_raw_item_space $2 $3 $4 $1)"
echo $u
}
qmp_uci_get_unnamed_section_id_by_type_and_name() {
config_load $1
local u="$(config_foreach qmp_uci_get_raw_id_space $2 $3 name $1)"
echo $u
}
qmp_uci_set() { qmp_uci_set() {
section="$1" section="$1"
shift shift
...@@ -59,7 +87,7 @@ qmp_uci_del() { ...@@ -59,7 +87,7 @@ qmp_uci_del() {
} }
qmp_uci_del_raw() { qmp_uci_del_raw() {
uci -q delete $@ uci -q delete $@
r=$? r=$?
uci commit uci commit
r=$(( $r + $? )) r=$(( $r + $? ))
......
#!/bin/sh #!/bin/sh /etc/rc.common
# requires ip ipv6calc awk sed grep # requires ip ipv6calc awk sed grep
QMP_PATH="/etc/qmp" QMP_PATH="/etc/qmp"
SOURCE_FUNCTIONS=1 SOURCE_FUNCTIONS=1
...@@ -380,6 +380,10 @@ qmp_attach_device_to_interface() { ...@@ -380,6 +380,10 @@ qmp_attach_device_to_interface() {
local device=$1 local device=$1
local interface=$2 local interface=$2
local intype="$(qmp_uci_get_raw network.$interface.type)" local intype="$(qmp_uci_get_raw network.$interface.type)"
# Fix for #489 after introduction of UCI bridge model (OpenWrt >= 21.02)
local inucibrlan="$(qmp_uci_get_raw network.$interface.device)"
local inucitype="$(qmp_uci_get_item_by_unnamed_section_type_and_name network device ${inucibrlan} type)"
local brlanid="$(qmp_uci_get_unnamed_section_id_by_type_and_name network device ${inucibrlan})"
echo "Attaching device $device to interface $interface" echo "Attaching device $device to interface $interface"
...@@ -390,11 +394,12 @@ qmp_attach_device_to_interface() { ...@@ -390,11 +394,12 @@ qmp_attach_device_to_interface() {
# if it is not # if it is not
else else
if [ "$intype" == "bridge" ]; then # Fix for #489 after introduction of UCI bridge model (OpenWrt >= 21.02)
qmp_uci_add_list_raw network.$interface.ifname=$device if [ "$intype" == "bridge" ] || [ "$inucitype" == "bridge" ]; then
qmp_uci_add_list_raw network.$brlanid.ports=$device
echo " -> $device attached to $interface bridge" echo " -> $device attached to $interface bridge"
else else
qmp_uci_set_raw network.$interface.ifname=$device qmp_uci_set_raw network.$interface.device=$device
echo " -> $device attached to $interface" echo " -> $device attached to $interface"
fi fi
fi fi
......
...@@ -39,6 +39,11 @@ qmp_configure_prepare_network() { ...@@ -39,6 +39,11 @@ qmp_configure_prepare_network() {
for i in $toRemove; do for i in $toRemove; do
uci del network.$i uci del network.$i
done done
# Fix for #489 after introduction of UCI bridge model (OpenWrt >= 21.02)
# Delete the unnamed br-lan device section
uci del "network.$(qmp_uci_get_unnamed_section_id_by_type_and_name network device br-lan)"
uci commit network uci commit network
} }
...@@ -295,6 +300,14 @@ qmp_configure_lan() { ...@@ -295,6 +300,14 @@ qmp_configure_lan() {
# LAN device (br-lan) configuration # LAN device (br-lan) configuration
echo "Configuring LAN bridge" echo "Configuring LAN bridge"
# Fix for #489 after introduction of UCI bridge model (OpenWrt >= 21.02)
# Create the bridge device
local sectionid=$(uci add network device)
uci set network.${sectionid}.type="bridge"
uci set network.${sectionid}.name="br-lan"
uci commit
qmp_uci_set_raw network.lan="interface" qmp_uci_set_raw network.lan="interface"
# Fix for #489 after introduction of UCI bridge model (OpenWrt >= 21.02) # Fix for #489 after introduction of UCI bridge model (OpenWrt >= 21.02)
#qmp_uci_set_raw network.lan.type="bridge" #qmp_uci_set_raw network.lan.type="bridge"
......
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