From b44625a708481deebd7a2b3b238f5c2903fa7a6b Mon Sep 17 00:00:00 2001 From: javierbrk Date: Mon, 23 Dec 2024 12:52:59 -0300 Subject: [PATCH] fix get node status to work with busybox ip --- .../files/usr/lib/lua/lime/node_status.lua | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/ubus-lime-utils/files/usr/lib/lua/lime/node_status.lua b/packages/ubus-lime-utils/files/usr/lib/lua/lime/node_status.lua index d5c0cc959..0fc8699d7 100644 --- a/packages/ubus-lime-utils/files/usr/lib/lua/lime/node_status.lua +++ b/packages/ubus-lime-utils/files/usr/lib/lua/lime/node_status.lua @@ -134,22 +134,24 @@ end function node_status.dsa_get_link_status(ports) for _, port in ipairs(ports) do - local dsa = utils.unsafe_shell("ip -j -p link show " .. port['num']) - local dsa_json = json.parse(dsa) - - port['device'] = port['num'] - port['num'] = dsa_json[1]['ifindex'] - port['role'] = dsa_json[1]['link'] - if dsa_json[1]['link'] == nil then - port['role'] = dsa_json[1]['ifname'] - end - port['link'] = dsa_json[1]['operstate'] - if dsa_json[1]['operstate'] == "LOWERLAYERDOWN" then - port['link'] = "DOWN" - end - end - return ports -end + local dsa = utils.unsafe_shell("ip link show " .. port['num']) + -- Match ifindex, ifname, link (optional), and operstate + local ifindex, ifname, link, operstate = dsa:match("^(%d+): ([^:@]+)@?([^:]*):.-state (%S+)") + if ifindex and ifname and operstate then + port['device'] = port['num'] + port['num'] = tonumber(ifindex) + port['role'] = link ~= "" and link or nil -- Handle optional link field + if port['role'] == nil then + port['role'] = ifname + end + port['link'] = operstate + if operstate == "LOWERLAYERDOWN" then + port['link'] = "DOWN" + end + end + end + return ports +end function node_status.swconfig_get_link_status(ports)