Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/lime-proto-batadv/files/usr/lib/lua/lime/proto/batadv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,25 @@ function batadv.runOnDevice(linuxDev, args)
--! TODO: as of today ubus silently fails to properly setting up a linux network
--! device for batman ADV usage dinamycally work around it by using
--! shell commands instead
network.createStatic(devName)
utils.unsafe_shell("batctl if add "..devName)
local id = utils.get_id(devName)
local original_mac = network.get_mac(devName)
local vMacaddr = { }
-- Set first byte to 02 (locally administered unicast)
vMacaddr[1] = "02"
-- Use id[2] and id[3] from interface name for next bytes
vMacaddr[2] = id[2]
vMacaddr[3] = id[3]
-- Use last 3 bytes from main interface MAC
vMacaddr[4] = original_mac[4]
vMacaddr[5] = original_mac[5]
vMacaddr[6] = original_mac[6]
macaddr = table.concat(vMacaddr, ":")

utils.unsafe_shell("ip link set dev "..devName.." address "..macaddr)
local ifnames = network.createStatic(devName)
utils.log("batadv created vlan "..devName.." with address:".. macaddr .." and static ".. ifnames)
--this seems not to be needed
--utils.unsafe_shell("batctl if add "..devName)
end

return batadv
113 changes: 113 additions & 0 deletions packages/lime-proto-batadv/tests/test_bat_apup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash
# configure at least three routers with apup and limed, only leave one of them
# on and turn the rest off.
# run this script on a computer connected to the node to start limed and u-bus
# listen.
# turn on the other nodes and wait for them to connect

NODE_IP="thisnode.info"
SSH_USER="root"
SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"

ssh $SSH_OPTS "$SSH_USER@$NODE_IP" <<EOF

echo "[0/4] Killing any running limed processes..."
service limed stop
killall limed

echo "[1/4] Bringing Wi-Fi down..."
wifi down


echo "[2/4] Starting limed and ubus listen ..."
echo "------------------------------------------"
(
/usr/bin/limed 2>&1 | while IFS= read -r line; do
echo "[\$(date +'%Y-%m-%d %H:%M:%S')] [limed] \$line"
done &
LIMED_PID=\$!

ubus listen 2>&1 | while IFS= read -r line; do
echo "[\$(date +'%Y-%m-%d %H:%M:%S')] [ubus] \$line"
done &
UBUS_PID=\$!

sleep 2
echo "------------------------------------------"
sleep 2
echo "------------------------------------------"
sleep 2

echo "[3/4] Bringing Wi-Fi up..."
wifi up

echo "[4/4] Now you should be able to see new connections. Press Ctrl+C to stop."
wait \$LIMED_PID \$UBUS_PID
)
EOF


###### sample output
# [1/4] Bringing Wi-Fi down...
# [2/4] Starting limed and ubus listen ...
# ------------------------------------------
# [2025-07-31 21:35:06] [limed] 'hostapd' namespace exists...
# [2025-07-31 21:35:07] [ubus] { "ubus.object.remove": {"id":1399214265,"path":"hostapd.wlan1-apup"} }
# ------------------------------------------
# ------------------------------------------
# [3/4] Bringing Wi-Fi up...
# [4/4] Now you should be able to see new connections. Press Ctrl+C to stop.
# [2025-07-31 21:35:16] [ubus] { "ubus.object.add": {"id":-1307156726,"path":"hostapd.wlan1-apup"} }


# [2025-07-31 21:36:02] [limed] Subscribing: hostapd.wlan1-apup
# [2025-07-31 21:36:03] [limed] peerSubscriber type: apup-newpeer data.ifname: wlan1-peer1
# [2025-07-31 21:36:03] [ubus] { "ubus.object.add": {"id":565721540,"path":"network.interface.lm_net_lm_net_wlan1_peer1_static"} }
# [2025-07-31 21:36:03] [limed] lime.network.runProtocols(wlan1-peer1, ...)
# [2025-07-31 21:36:03] [limed] lime.proto.batadv.runOnDevice(wlan1-peer1, ...)
# [2025-07-31 21:36:03] [limed] lime.network.createVlan(wlan1-peer1, ...)
# [2025-07-31 21:36:03] [limed] vid = 29
# [2025-07-31 21:36:03] [limed] type = 8021ad
# [2025-07-31 21:36:03] [limed] name = wlan1-peer1_29
# [2025-07-31 21:36:03] [ubus] { "ubus.object.add": {"id":-1500836794,"path":"network.interface.lm_net_wlan1-peer1_batadv"} }
# [2025-07-31 21:36:03] [limed] ifname = wlan1-peer1
# [2025-07-31 21:36:04] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer1_29_static"} }
# [2025-07-31 21:36:04] [ubus] { "ubus.object.add": {"id":-1232818779,"path":"network.interface.lm_net_lm_net_wlan1_peer1_29_static"} }
# [2025-07-31 21:36:04] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_wlan1-peer1_batadv"} }
# [2025-07-31 21:36:04] [limed] batadv createdwlan1-peer1_29 with address:02:58:11:22:55:bc and static lm_net_lm_net_wlan1_peer1_29_static
# [2025-07-31 21:36:04] [limed] lime.proto.babeld.runOnDevice(wlan1-peer1, ...)
# [2025-07-31 21:36:04] [limed] lime.network.createVlan(wlan1-peer1, ...)
# [2025-07-31 21:36:04] [limed] vid = 17
# [2025-07-31 21:36:04] [limed] type = 8021ad
# [2025-07-31 21:36:04] [limed] name = wlan1-peer1_17
# [2025-07-31 21:36:04] [limed] ifname = wlan1-peer1
# [2025-07-31 21:36:04] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer1_17_static"} }
# [2025-07-31 21:36:04] [ubus] { "ubus.object.add": {"id":-1137476629,"path":"network.interface.lm_net_lm_net_wlan1_peer1_17_static"} }
# [2025-07-31 21:36:05] [limed] ip: RTNETLINK answers: File exists
# [2025-07-31 21:36:05] [ubus] { "ubus.object.add": {"id":-366401286,"path":"network.interface.lm_net_lm_net_wlan1_peer2_static"} }
# [2025-07-31 21:36:06] [ubus] { "ubus.object.add": {"id":-82673599,"path":"network.interface.lm_net_wlan1-peer2_batadv"} }
# [2025-07-31 21:36:06] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer2_29_static"} }
# [2025-07-31 21:36:06] [ubus] { "ubus.object.add": {"id":-1777215837,"path":"network.interface.lm_net_lm_net_wlan1_peer2_29_static"} }
# [2025-07-31 21:36:07] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_wlan1-peer2_batadv"} }
# [2025-07-31 21:36:07] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer2_17_static"} }
# [2025-07-31 21:36:07] [ubus] { "ubus.object.add": {"id":-1538210722,"path":"network.interface.lm_net_lm_net_wlan1_peer2_17_static"} }
# [2025-07-31 21:36:08] [limed] peerSubscriber type: apup-newpeer data.ifname: wlan1-peer2
# [2025-07-31 21:36:08] [limed] ip: RTNETLINK answers: File exists
# [2025-07-31 21:36:08] [limed] lime.network.runProtocols(wlan1-peer2, ...)
# [2025-07-31 21:36:08] [limed] lime.proto.batadv.runOnDevice(wlan1-peer2, ...)
# [2025-07-31 21:36:08] [limed] lime.network.createVlan(wlan1-peer2, ...)
# [2025-07-31 21:36:08] [limed] vid = 29
# [2025-07-31 21:36:08] [limed] type = 8021ad
# [2025-07-31 21:36:08] [limed] name = wlan1-peer2_29
# [2025-07-31 21:36:08] [limed] ifname = wlan1-peer2
# [2025-07-31 21:36:08] [limed] ip: RTNETLINK answers: File exists
# [2025-07-31 21:36:08] [limed] ip: RTNETLINK answers: File exists
# [2025-07-31 21:36:09] [limed] batadv createdwlan1-peer2_29 with address:02:f4:ce:22:55:bc and static lm_net_lm_net_wlan1_peer2_29_static
# [2025-07-31 21:36:09] [limed] lime.proto.babeld.runOnDevice(wlan1-peer2, ...)
# [2025-07-31 21:36:09] [limed] lime.network.createVlan(wlan1-peer2, ...)
# [2025-07-31 21:36:09] [limed] vid = 17
# [2025-07-31 21:36:09] [limed] type = 8021ad
# [2025-07-31 21:36:09] [limed] name = wlan1-peer2_17
# [2025-07-31 21:36:09] [limed] ifname = wlan1-peer2
# [2025-07-31 21:36:09] [limed] ip: RTNETLINK answers: File exists
# [2025-07-31 21:36:09] [limed] ip: RTNETLINK answers: File exists
25 changes: 22 additions & 3 deletions packages/lime-system/files/usr/bin/limed
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,27 @@ local peerSubscriber = {
notify = function(nData, nType)
if nType ~= "apup-newpeer" then return end

utils.log("peerSubscriber:", nType, nData.ifname)
utils.log("peerSubscriber type: %s data.ifname: %s ", nType, nData.ifname)

network.createStatic(nData.ifname)
--! interfaces should exist, but just in case we need to check,
--! to avoid
--! [2025-07-31 20:06:09] [limed] ip: SIOCGIFFLAGS: No such device
--! [2025-07-31 20:06:10] [limed] ip: can't find device 'wlan1-peer2'
--! [2025-07-31 20:06:10] [limed] lime.network.runProtocols(wlan1-peer2, ...)
--! [2025-07-31 20:06:10] [limed] lime.proto.batadv.runOnDevice(wlan1-peer2, ...)
--! [2025-07-31 20:06:11] [limed] lime.network.createVlan(wlan1-peer2, ...)
--! [2025-07-31 20:06:11] [limed] vid = 29
--! [2025-07-31 20:06:11] [limed] type = 8021ad
--! [2025-07-31 20:06:11] [limed] name = wlan1-peer2_29
--! [2025-07-31 20:06:11] [limed] ifname = wlan1-peer2
--! [2025-07-31 20:06:12] [limed] ip: can't find device 'wlan1-peer2'
--! [2025-07-31 20:06:12] [ubus] { "ubus.object.add":
--{"id":-1478746778,"path":"network.interface.lm_net_wlan1-peer2_batadv"} }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

! missing

if not network.device_exists(nData.ifname) then
utils.log("Device does not exist, skipping:", nData.ifname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this condition something that may happen in normal situation, or should it be reported as an error? It is not clear to me from the log message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition arises when using commands WiFi down WiFi up. It seems that apup interfaces do not go down with all the others and some times the daemon is notified about interfaces that do not exist. I created a script to make it easy to check this situation.
I will create an issue with more details later this week.
In this case I made a defensive approach that checks the existence of the interface before trying to add it. If it fails and the daemon breaks some notifications might not be handled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can reproduce the problem using tree devices.

This happens in this sequence.

LR2_a is running the test script from the pull request.
LR2_b and LR1 are turned on
Everything works as expected:

  1. They both get registered
  2. iwinfo shows wlan1-peer1 wlan1-peer2 and wlan1-apup

After using "wifi down" command in LR2_a, wlan1-apup goes down but wlan1-peer1 and wlan1-peer2 will still be displayed.

Then I do "wifi up"

And only wlan1-peer2 works as expected but wlan1-peer1 no,
limed is notified about a new interface but no interface was created
wlan1-peer1 is no longer available.

after some time the other peer finally appears they both get notified and every thing works as expected.

This is the log of the run.

 
 _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 LibreRouterOs 24.10.1, r28597-0425664679
 -----------------------------------------------------
  ___   __ __                _______             __
 |   |_|__|  |--.----.-----.|   |   |-----.-----|  |--.
 |     |  |  _  |   _|  -__||       |  -__|__ --|     |
 |_____|__|_____|__| |_____||__|_|__|_____|_____|__|__|

 ------------------------------------------------------
 %LIME_DESCRIPTION%
 ------------------------------------------------------
 https://libremesh.org
 ------------------------------------------------------

 === System Notes =================================================

 = edit via http://thisnode.info/app/#/notes or /etc/banner.notes =

=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
[0/4] Killing any running limed processes...
killall: limed: no process killed
[1/4] Bringing Wi-Fi down...
[2/4] Starting limed and ubus listen ...
------------------------------------------
[2025-07-31 19:03:26] [limed]  'hostapd' namespace exists...
[2025-07-31 19:03:26] [ubus] { "ubus.object.remove": {"id":-88125505,"path":"wpa_supplicant.wlan0-sta"} }
[2025-07-31 19:03:26] [ubus] { "ubus.object.remove": {"id":-559228225,"path":"hostapd.wlan1-apup"} }
------------------------------------------
------------------------------------------
[3/4] Bringing Wi-Fi up...
[4/4] Now you should be able to see new connections. Press Ctrl+C to stop.
[2025-07-31 19:03:33] [ubus] { "ubus.object.add": {"id":363302232,"path":"wpa_supplicant.wlan0-sta"} }
[2025-07-31 19:03:34] [ubus] { "ubus.object.add": {"id":-1452635026,"path":"hostapd.wlan1-apup"} }

---

two new devices are turned on

---

[2025-07-31 19:04:41] [limed] Subscribing:
[2025-07-31 19:04:41] [limed] peerSubscriber:
[2025-07-31 19:04:41] [ubus] { "ubus.object.add": {"id":-199291730,"path":"network.interface.lm_net_lm_net_wlan1_peer1_static"} }
[2025-07-31 19:04:41] [limed] lime.network.runProtocols(wlan1-peer1, ...)
[2025-07-31 19:04:41] [limed] lime.proto.batadv.runOnDevice(wlan1-peer1, ...)
[2025-07-31 19:04:41] [limed] lime.network.createVlan(wlan1-peer1, ...)
[2025-07-31 19:04:41] [limed] 		vid	 = 	29
[2025-07-31 19:04:41] [limed] 		type	 = 	8021ad
[2025-07-31 19:04:41] [limed] 		name	 = 	wlan1-peer1_29
[2025-07-31 19:04:41] [ubus] { "ubus.object.add": {"id":1943448621,"path":"network.interface.lm_net_wlan1-peer1_batadv"} }
[2025-07-31 19:04:41] [limed] 		ifname	 = 	wlan1-peer1
[2025-07-31 19:04:41] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer1_29_static"} }
[2025-07-31 19:04:41] [ubus] { "ubus.object.add": {"id":-650912589,"path":"network.interface.lm_net_lm_net_wlan1_peer1_29_static"} }
[2025-07-31 19:04:41] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_wlan1-peer1_batadv"} }
[2025-07-31 19:04:41] [limed] batadv createdwlan1-peer1_29 with address:02:58:11:c1:00:59 and static lm_net_lm_net_wlan1_peer1_29_static
[2025-07-31 19:04:41] [limed] lime.proto.babeld.runOnDevice(wlan1-peer1, ...)
[2025-07-31 19:04:41] [limed] lime.network.createVlan(wlan1-peer1, ...)
[2025-07-31 19:04:41] [limed] 		vid	 = 	17
[2025-07-31 19:04:41] [limed] 		type	 = 	8021ad
[2025-07-31 19:04:41] [limed] 		name	 = 	wlan1-peer1_17
[2025-07-31 19:04:41] [limed] 		ifname	 = 	wlan1-peer1
[2025-07-31 19:04:42] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer1_17_static"} }
[2025-07-31 19:04:42] [ubus] { "ubus.object.add": {"id":187664330,"path":"network.interface.lm_net_lm_net_wlan1_peer1_17_static"} }
[2025-07-31 19:05:17] [limed] peerSubscriber:
[2025-07-31 19:05:17] [ubus] { "ubus.object.add": {"id":838939608,"path":"network.interface.lm_net_lm_net_wlan1_peer2_static"} }
[2025-07-31 19:05:17] [limed] lime.network.runProtocols(wlan1-peer2, ...)
[2025-07-31 19:05:17] [limed] lime.proto.batadv.runOnDevice(wlan1-peer2, ...)
[2025-07-31 19:05:17] [limed] lime.network.createVlan(wlan1-peer2, ...)
[2025-07-31 19:05:17] [limed] 		vid	 = 	29
[2025-07-31 19:05:17] [limed] 		type	 = 	8021ad
[2025-07-31 19:05:17] [limed] 		name	 = 	wlan1-peer2_29
[2025-07-31 19:05:17] [limed] 		ifname	 = 	wlan1-peer2
[2025-07-31 19:05:17] [ubus] { "ubus.object.add": {"id":-876835113,"path":"network.interface.lm_net_wlan1-peer2_batadv"} }
[2025-07-31 19:05:17] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer2_29_static"} }
[2025-07-31 19:05:17] [ubus] { "ubus.object.add": {"id":1735019273,"path":"network.interface.lm_net_lm_net_wlan1_peer2_29_static"} }
[2025-07-31 19:05:17] [limed] batadv createdwlan1-peer2_29 with address:02:f4:ce:c1:00:59 and static lm_net_lm_net_wlan1_peer2_29_static
[2025-07-31 19:05:17] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_wlan1-peer2_batadv"} }
[2025-07-31 19:05:17] [limed] lime.proto.babeld.runOnDevice(wlan1-peer2, ...)
[2025-07-31 19:05:17] [limed] lime.network.createVlan(wlan1-peer2, ...)
[2025-07-31 19:05:17] [limed] 		vid	 = 	17
[2025-07-31 19:05:17] [limed] 		type	 = 	8021ad
[2025-07-31 19:05:17] [limed] 		name	 = 	wlan1-peer2_17
[2025-07-31 19:05:17] [limed] 		ifname	 = 	wlan1-peer2
[2025-07-31 19:05:17] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer2_17_static"} }
[2025-07-31 19:05:17] [ubus] { "ubus.object.add": {"id":-942311592,"path":"network.interface.lm_net_lm_net_wlan1_peer2_17_static"} }

---

on another terminal of the device LR2_a (running the script) issue "wifi down" coomand.

---
[2025-07-31 19:07:16] [ubus] { "ubus.object.remove": {"id":-1452635026,"path":"hostapd.wlan1-apup"} }
[2025-07-31 19:07:17] [ubus] { "network.interface": {"action":"ifdown","interface":"lm_net_wlan1-peer2_batadv"} }
[2025-07-31 19:07:17] [ubus] { "ubus.object.remove": {"id":-876835113,"path":"network.interface.lm_net_wlan1-peer2_batadv"} }
[2025-07-31 19:07:17] [ubus] { "network.interface": {"action":"ifdown","interface":"lm_net_wlan1-peer1_batadv"} }
[2025-07-31 19:07:17] [ubus] { "ubus.object.remove": {"id":1943448621,"path":"network.interface.lm_net_wlan1-peer1_batadv"} }
[2025-07-31 19:07:17] [ubus] { "ubus.object.remove": {"id":363302232,"path":"wpa_supplicant.wlan0-sta"} }
[2025-07-31 19:08:53] [ubus] { "ubus.object.add": {"id":-1976344305,"path":"wpa_supplicant.wlan0-sta"} }
[2025-07-31 19:08:53] [ubus] { "ubus.object.add": {"id":-562794743,"path":"hostapd.wlan1-apup"} }
[2025-07-31 19:08:54] [ubus] { "network.interface": {"action":"ifdown","interface":"lm_net_lm_net_wlan1_peer2_17_static"} }
[2025-07-31 19:08:54] [ubus] { "network.interface": {"action":"ifdown","interface":"lm_net_lm_net_wlan1_peer2_17_static"} }
[2025-07-31 19:08:54] [limed] Subscribing:
[2025-07-31 19:08:54] [limed] peerSubscriber:
[2025-07-31 19:08:54] [ubus] { "ubus.object.remove": {"id":-942311592,"path":"network.interface.lm_net_lm_net_wlan1_peer2_17_static"} }
[2025-07-31 19:08:54] [ubus] { "network.interface": {"action":"ifdown","interface":"lm_net_lm_net_wlan1_peer2_29_static"} }
[2025-07-31 19:08:54] [ubus] { "network.interface": {"action":"ifdown","interface":"lm_net_lm_net_wlan1_peer2_29_static"} }
[2025-07-31 19:08:54] [ubus] { "ubus.object.remove": {"id":1735019273,"path":"network.interface.lm_net_lm_net_wlan1_peer2_29_static"} }
[2025-07-31 19:08:54] [ubus] { "network.interface": {"action":"ifdown","interface":"lm_net_lm_net_wlan1_peer1_17_static"} }
[2025-07-31 19:08:54] [ubus] { "network.interface": {"action":"ifdown","interface":"lm_net_lm_net_wlan1_peer1_17_static"} }
[2025-07-31 19:08:55] [ubus] { "ubus.object.remove": {"id":187664330,"path":"network.interface.lm_net_lm_net_wlan1_peer1_17_static"} }
[2025-07-31 19:08:55] [ubus] { "network.interface": {"action":"ifdown","interface":"lm_net_lm_net_wlan1_peer1_29_static"} }
[2025-07-31 19:08:55] [ubus] { "network.interface": {"action":"ifdown","interface":"lm_net_lm_net_wlan1_peer1_29_static"} }
[2025-07-31 19:08:55] [ubus] { "ubus.object.remove": {"id":-650912589,"path":"network.interface.lm_net_lm_net_wlan1_peer1_29_static"} }
---

after "wifi up"

---
[2025-07-31 19:08:55] [limed] Cannot find device "wlan1-peer1"
[2025-07-31 19:08:55] [limed] Cannot find device "wlan1-peer1"
[2025-07-31 19:08:55] [limed] lime.network.runProtocols(wlan1-peer1, ...)
[2025-07-31 19:08:55] [limed] lime.proto.batadv.runOnDevice(wlan1-peer1, ...)
[2025-07-31 19:08:55] [limed] lime.network.createVlan(wlan1-peer1, ...)
[2025-07-31 19:08:55] [limed] 		vid	 = 	29
[2025-07-31 19:08:55] [limed] 		type	 = 	8021ad
[2025-07-31 19:08:55] [limed] 		name	 = 	wlan1-peer1_29
[2025-07-31 19:08:55] [limed] 		ifname	 = 	wlan1-peer1
[2025-07-31 19:08:55] [limed] Cannot find device "wlan1-peer1"
[2025-07-31 19:08:56] [ubus] { "ubus.object.add": {"id":-1148713626,"path":"network.interface.lm_net_wlan1-peer1_batadv"} }
[2025-07-31 19:08:56] [limed] /usr/lib/lua/lime/utils.lua:53: attempt to index local 'string' (a nil value)
[2025-07-31 19:08:56] [limed] stack traceback:
[2025-07-31 19:08:56] [limed] 	/usr/lib/lua/lime/network.lua:631: in function </usr/lib/lua/lime/network.lua:631>
[2025-07-31 19:08:56] [limed] 	/usr/lib/lua/lime/utils.lua:53: in function </usr/lib/lua/lime/utils.lua:51>
[2025-07-31 19:08:56] [limed] 	(tail call): ?
[2025-07-31 19:08:56] [limed] 	/usr/lib/lua/lime/proto/batadv.lua:137: in function 'runOnDevice'
[2025-07-31 19:08:56] [limed] 	/usr/lib/lua/lime/network.lua:630: in function </usr/lib/lua/lime/network.lua:630>
[2025-07-31 19:08:56] [limed] 	[C]: in function 'xpcall'
[2025-07-31 19:08:56] [limed] 	/usr/lib/lua/lime/network.lua:630: in function 'runProtocols'
[2025-07-31 19:08:56] [limed] 	/usr/bin/limed:51: in function </usr/bin/limed:46>
[2025-07-31 19:08:56] [limed] 	[C]: in function 'run'
[2025-07-31 19:08:56] [limed] 	/usr/bin/limed:91: in main chunk
[2025-07-31 19:08:56] [limed] 	[C]: ?
[2025-07-31 19:08:56] [limed] lime.proto.babeld.runOnDevice(wlan1-peer1, ...)
[2025-07-31 19:08:56] [limed] lime.network.createVlan(wlan1-peer1, ...)
[2025-07-31 19:08:56] [limed] 		vid	 = 	17
[2025-07-31 19:08:56] [limed] 		type	 = 	8021ad
[2025-07-31 19:08:56] [limed] 		name	 = 	wlan1-peer1_17
[2025-07-31 19:08:56] [limed] 		ifname	 = 	wlan1-peer1
[2025-07-31 19:08:56] [limed] Cannot find device "wlan1-peer1"
[2025-07-31 19:08:56] [ubus] { "ubus.object.add": {"id":1783125576,"path":"network.interface.lm_net_lm_net_wlan1_peer1_17_static"} }
[2025-07-31 19:08:56] [limed] Cannot find device "wlan1-peer1_17"
[2025-07-31 19:08:56] [limed] Cannot find device "wlan1-peer1_17"
[2025-07-31 19:08:57] [limed] peerSubscriber:
[2025-07-31 19:08:57] [limed] lime.network.runProtocols(wlan1-peer2, ...)
[2025-07-31 19:08:57] [limed] lime.proto.batadv.runOnDevice(wlan1-peer2, ...)
[2025-07-31 19:08:57] [limed] lime.network.createVlan(wlan1-peer2, ...)
[2025-07-31 19:08:57] [limed] 		vid	 = 	29
[2025-07-31 19:08:57] [limed] 		type	 = 	8021ad
[2025-07-31 19:08:57] [limed] 		name	 = 	wlan1-peer2_29
[2025-07-31 19:08:57] [limed] 		ifname	 = 	wlan1-peer2
[2025-07-31 19:08:57] [ubus] { "ubus.object.add": {"id":-1829193661,"path":"network.interface.lm_net_wlan1-peer2_batadv"} }
[2025-07-31 19:08:57] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer2_29_static"} }
[2025-07-31 19:08:57] [ubus] { "ubus.object.add": {"id":-1080074008,"path":"network.interface.lm_net_lm_net_wlan1_peer2_29_static"} }
[2025-07-31 19:08:57] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_wlan1-peer2_batadv"} }
[2025-07-31 19:08:57] [limed] batadv createdwlan1-peer2_29 with address:02:f4:ce:c1:00:59 and static lm_net_lm_net_wlan1_peer2_29_static
[2025-07-31 19:08:57] [limed] lime.proto.babeld.runOnDevice(wlan1-peer2, ...)
[2025-07-31 19:08:57] [limed] lime.network.createVlan(wlan1-peer2, ...)
[2025-07-31 19:08:57] [limed] 		vid	 = 	17
[2025-07-31 19:08:57] [limed] 		type	 = 	8021ad
[2025-07-31 19:08:57] [limed] 		name	 = 	wlan1-peer2_17
[2025-07-31 19:08:57] [limed] 		ifname	 = 	wlan1-peer2
[2025-07-31 19:08:57] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer2_17_static"} }
[2025-07-31 19:08:57] [ubus] { "ubus.object.add": {"id":-1692506623,"path":"network.interface.lm_net_lm_net_wlan1_peer2_17_static"} }
---

after some minutes the device associates again and every thing is fine

---
[2025-07-31 19:13:55] [limed] peerSubscriber:
[2025-07-31 19:13:55] [limed] lime.network.runProtocols(wlan1-peer1, ...)
[2025-07-31 19:13:55] [limed] lime.proto.batadv.runOnDevice(wlan1-peer1, ...)
[2025-07-31 19:13:55] [limed] lime.network.createVlan(wlan1-peer1, ...)
[2025-07-31 19:13:55] [limed] 		vid	 = 	29
[2025-07-31 19:13:55] [limed] 		type	 = 	8021ad
[2025-07-31 19:13:55] [limed] 		name	 = 	wlan1-peer1_29
[2025-07-31 19:13:55] [limed] 		ifname	 = 	wlan1-peer1
[2025-07-31 19:13:55] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer1_29_static"} }
[2025-07-31 19:13:55] [ubus] { "ubus.object.add": {"id":1069843693,"path":"network.interface.lm_net_lm_net_wlan1_peer1_29_static"} }
[2025-07-31 19:13:55] [limed] batadv createdwlan1-peer1_29 with address:02:58:11:c1:00:59 and static lm_net_lm_net_wlan1_peer1_29_static
[2025-07-31 19:13:55] [limed] lime.proto.babeld.runOnDevice(wlan1-peer1, ...)
[2025-07-31 19:13:55] [limed] lime.network.createVlan(wlan1-peer1, ...)
[2025-07-31 19:13:55] [limed] 		vid	 = 	17
[2025-07-31 19:13:55] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_lm_net_wlan1_peer1_17_static"} }
[2025-07-31 19:13:55] [ubus] { "network.interface": {"action":"ifup","interface":"lm_net_wlan1-peer1_batadv"} }
[2025-07-31 19:13:55] [limed] 		type	 = 	8021ad
[2025-07-31 19:13:55] [limed] 		name	 = 	wlan1-peer1_17
[2025-07-31 19:13:55] [limed] 		ifname	 = 	wlan1-peer1

return
end
network.runProtocols(nData.ifname)
end
}
Expand All @@ -61,7 +80,7 @@ local apupSubscriber = {

local evPath = "hostapd." .. apupDev

utils.log("Subscribing:", evPath)
utils.log("Subscribing: %s", evPath)
ubus:subscribe(evPath, peerSubscriber)
end
}
Expand All @@ -78,7 +97,7 @@ function limed.waitForHostapd()
end
if not found then
utils.log("Waiting for 'hostapd' namespace...")
os.execute("sleep 1") -- Wait for 1 second before retrying
os.execute("sleep 1")
else
utils.log(" 'hostapd' namespace exists...")
end
Expand Down
15 changes: 14 additions & 1 deletion packages/lime-system/files/usr/lib/lua/lime/network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ network.protoParamsSeparator=":"
network.protoVlanSeparator="_"
network.limeIfNamePrefix="lm_net_"


--! Retuns the mac address of the interface or nill if it does not exist
function network.get_mac(ifname)
local _, macaddr = next(network.get_own_macs(ifname))
--! this is to avoid the error:
--! ...ackages/lime-system/files/usr/lib/lua/lime/utils.lua:53: attempt to index local 'string' (a nil value)
if macaddr == nil then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAK, I think it is better to fail ASAP if the MAC address for a non-existent device is requested, instead of propagating a nil value upstream in the call stack, because requesting the MAC address of a non-existent device is indicative of an already pathological situation.

return nil
end
return utils.split(macaddr, ":")
end

Expand Down Expand Up @@ -594,6 +599,14 @@ function network.createStatic(linuxBaseIfname)
return ifaceConf.name
end

--! Check if a device exists in the system
function network.device_exists(dev)
local handle = io.popen("ip link show " .. dev .. " 2>/dev/null")
local result = handle:read("*a")
handle:close()
return result ~= nil and result ~= ""
end

--! Create a vlan at runtime via ubus
function network.createVlan(linuxBaseIfname, vid, vlanProtocol)
local vlanConf = {
Expand Down
6 changes: 6 additions & 0 deletions packages/lime-system/files/usr/lib/lua/lime/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ end

function utils.split(string, sep)
local ret = {}
if sep == nil or sep == '' then
sep = '%s' --! default to whitespace
end
if string == nil or string == '' then
return ret
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAK, empty separator should be treated as error, the function should fail in that case because calling it without separator is symptomatic of something wrong in the caller.

for token in string.gmatch(string, "[^"..sep.."]+") do table.insert(ret, token) end
return ret
end
Expand Down
12 changes: 12 additions & 0 deletions packages/lime-system/tests/test_lime_network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ describe('LiMe Network tests', function()
assert.are.same({'00', '00', '00', '00', '00', '00'}, network.get_mac('lo'))
end)

it('test get_mac for ethernet', function()
assert.is_nil (network.get_mac('nonexistent-interface'))
end)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAK

it('test primary_interface configured interface', function()
config.set('network', 'lime')
config.set('network', 'primary_interface', 'test0')
Expand Down Expand Up @@ -161,6 +165,14 @@ describe('LiMe Network tests', function()
assert.are.Not.same(network.get_own_macs("wlan0"), network.get_own_macs("lo"))
end)

it('test device_exists returns true for existing device', function()
assert.is_true(network.device_exists('lo'))
end)

it('test device_exists returns false for non-existing device', function()
assert.is_false(network.device_exists('definitelynotadevicename'))
end)

before_each('', function()
uci = test_utils.setup_test_uci()
end)
Expand Down