Hurdle 4: Identifying Where uci
Interop Actually Occurs
Previously:
Task 1: Code-Search
I believe uci
interop occurs in the following modules:
luci.model.uci
Like we've discussed before, LuCI uses an older version of Lua that allows the module
function to be used. This allows LuCI to name modules consistently regradless of whether they are Lua or C modules.
After searching for "luci.model.uci"
, we discover that it is defined in Lua:
The API doc for luci.model.uci
is available at:
One can see how uci
may be interacted with by using regex search (?<!l>)uci
in code search. Unfortunately, Github code search does not support regex, so we will have to do this locally. Here is a PowerShell script that does that for us:
function Find-InSource {
param(
[string] $Pattern,
[string] $Repository = ".\luci",
[string[]] $Extensions = @(
".lua",
".c",
".js",
".mjs"
),
[switch] $Verbose
)
$gitRoot = (git rev-parse --show-toplevel 2>$null)
$output = [ordered]@{}
If( $Verbose ) {
Write-Host "Aggregating source files with extensions: $($Extensions -join ', ')" -ForegroundColor Yellow
Write-Host "- Wait a moment, this may take a bit..." -ForegroundColor DarkGray
}
$files = Get-ChildItem -Path $Repository -File -Recurse | Where-Object {
$_.Extension -in $Extensions
}
if ($files.Count -eq 0) {
Write-Host "No files found with the specified extensions." -ForegroundColor Yellow
return $output
} elseif ( $Verbose ) {
Write-Host "Searching in $($files.Count) files with extensions: $($Extensions -join ', ')" -ForegroundColor Black -BackgroundColor DarkYellow
}
$files | ForEach-Object {
$filename = $_.FullName.Replace($gitRoot, '').TrimStart('\/')
$fileContent = Get-Content $_.FullName
$hits = for ($ln = 0; $ln -lt $fileContent.Count; $ln++) {
$line = $fileContent | Select-Object -Index $ln
if ($line -match $pattern) {
@{
Line = $ln + 1
Content = $line.Trim()
}
}
}
if ($hits.Count -gt 0) {
$output."$filename" = [ordered]@{}
$hits | ForEach-Object {
$output."$filename"."$($_.Line)" = $_.Content
}
If( $Verbose ){
Write-Host "$filename`:" -ForegroundColor Cyan
$hits | ForEach-Object {
Write-Host "L$($_.Line)" -NoNewline -ForegroundColor Gray
Write-Host ": $($_.Content)"
}
Write-Host ""
}
}
}
If( $Verbose ) {
$total_files = $output.Keys.Count
$total_hits = ($output.Values | ForEach-Object { $_.Count }) -as [int[]] | Measure-Object -Sum | Select-Object -ExpandProperty Sum
Write-Host "Found $total_hits hits in $total_files files." -ForegroundColor Green
}
return $output
}
& { # Search for `uci` in the source code
$hits = Find-InSource -Pattern '(?<!l)uci' -Verbose
$hits | ConvertTo-Json -Depth 5 | Out-File "porting/searches/uci/hits.json" -Encoding UTF8
$hits.Keys | Out-File "porting/searches/uci/hits.txt" -Encoding UTF8
}
I will be making this script available in the porting
directory of the repository, so that it can be used for future searches.
- see the README for usage instructions
After running our first search, I've aggregated the following results:
-
Results of interest:
- applications:
- applications/luci-app-dockerman/luasrc/controller/dockerman.lua
- applications/luci-app-dockerman/luasrc/model/docker.lua
- applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua
- applications/luci-app-lxc/luasrc/controller/lxc.lua
- applications/luci-app-bmx7/root/usr/lib/lua/luci/controller/bmx7.lua
- applications/luci-app-nft-qos/luasrc/model/cbi/nft-qos/nft-qos.lua
- applications/luci-app-ocserv/luasrc/model/cbi/ocserv/users.lua
- applications/luci-app-openvpn/luasrc/controller/openvpn.lua
- applications/luci-app-openvpn/luasrc/model/cbi/openvpn-file.lua
- applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua
- applications/luci-app-splash/luasrc/controller/splash/splash.lua
- applications/luci-app-splash/luasrc/model/cbi/splash/splash.lua
- contrib:
- contrib/package/ucode-mod-html/src/html.c
- libs:
- libs/luci-lib-nixio/axTLS/crypto/aes.c
- libs/rpcd-mod-luci/src/luci.c
- modules:
- modules/luci-base/src/contrib/lemon.c
- modules/luci-compat/luasrc/cbi.lua
- modules/luci-compat/luasrc/cbi/datatypes.lua
- modules/luci-compat/luasrc/model/firewall.lua
- modules/luci-compat/luasrc/model/network.lua
- modules/luci-compat/luasrc/tools/webadmin.lua
- modules/luci-lua-runtime/luasrc/config.lua
- modules/luci-lua-runtime/luasrc/dispatcher.lua
- modules/luci-lua-runtime/luasrc/sys.lua
- modules/luci-lua-runtime/luasrc/model/uci.lua
- modules/luci-lua-runtime/luasrc/sys/zoneinfo/tzdata.lua
- modules/luci-lua-runtime/src/contrib/lemon.c
- modules/luci-mod-rpc/luasrc/controller/rpc.lua
- modules/luci-mod-rpc/luasrc/jsonrpcbind/uci.lua
-
The rest of the results can be found here:
Task 2: Reviewing the Results
For this we are going scope it down to just libs, and modules. Applications are third-party. We may want to port them later, but for now we will focus on the core LuCI codebase. Contrib was matched by mistake. The referenced C file is a html special character parser for ucode. The search script matched the û
which is html for û
, which is not what we are looking for.
Libs:
-
libs/luci-lib-nixio/axTLS/crypto/aes.c
- This only had one match, and it was a mistake:
"/* Perform doubling in Galois Field GF(2^8) using the irreducible polynomial"
- This only had one match, and it was a mistake:
-
modules/luci-base/src/contrib/lemon.c - also a mistake
- modules/luci-lua-runtime/src/contrib/lemon.c - also a mistake
modules/luci-lua-runtime/luasrc/sys/zoneinfo/tzdata.lua - also a mistake
-
- This C file is a plugin for
rpcd
. It shares certain RPC functions useful for LuCI with the entire ubus. Not entirely sure why LuCI does this, because I believe LuCI is the only user of these functions. - These will have to be ported to lumi. We may not use the same mechanism, but we can use some of the logic.
- This C file is a plugin for
-
modules/luci-compat/luasrc/cbi.lua and modules/luci-compat/luasrc/cbi/datatypes.lua
- This is a part of LuCI's Configuration Bind Interface (CBI)
- This is a high-value target for porting. It helps map UCI configuration files to HTML forms.
-
modules/luci-compat/luasrc/model/firewall.lua
- Provides a model for the configuring the firewall in LuCI.
- This is a valuable target for porting.
-
modules/luci-compat/luasrc/model/network.lua
- Provides a model for configuring network interfaces, devices, and L2 (sometimes L3) protocols.
- This is a valuable target for porting.
-
modules/luci-compat/luasrc/tools/webadmin.lua
- Provides a small set of utility tools for LuCI.
- Low value target for porting, but a target nonetheless.
-
modules/luci-lua-runtime/luasrc/config.lua
- This is a convenience wrapper around the
uci
module that provides a more Lua-like interface. - Codebase and changes required are small, but a very high-value target for porting.
- It is called 'luci.config' in LuCI,
- This is a convenience wrapper around the
-
modules/luci-lua-runtime/luasrc/dispatcher.lua
- This is the HTTP Router for LuCI
- It mainly provides auth protection for
uci
- Valuable target for porting
-
modules/luci-lua-runtime/luasrc/sys.lua
- This module provides a set of system utilities for LuCI.
- It minimally interacts with
uci
. In fact its only interaction appears to be pulling IPs from it. - We need to port this, but low priority
-
modules/luci-lua-runtime/luasrc/model/uci.lua
- This is a wrapper around the
uci
module that provides a more Lua-like interface. - Definitely a high-value target for porting.
- This is a wrapper around the
-
modules/luci-mod-rpc/luasrc/controller/rpc.lua
- This is a utility for doing RPC calls in LuCI.
- I believe that
mgmt
uses a different RPC mechanism, so any ubus and RPC functionality may also have to be ported.
-
modules/luci-mod-rpc/luasrc/jsonrpcbind/uci.lua
- A convenience wrapper around
uci
. Honestly seems kind of redundant withluci.model.uci
. - Will still be ported, but may iterate over LuCI packages and drop its usage in favor of
luci.model.uci
.
- A convenience wrapper around
Top comments (0)