How AMX calls UCI: CLI, libuci and backend modules
Grow through practice
No need to finish reading — test now“Calling UCI from AMX” is not one API; it is three different levels of integration. Choosing the wrong level leads either to shell-script patches or to a blocked event loop.
1. Shell
Fastest for debugging and init scripts:
uci set network.lan.ipaddr='192.168.1.1'
uci commit network
/etc/init.d/network reload
setwrites a delta under/tmp/.uci;commitwrites/etc/config/network;reloadmakes the service reread configuration; it does not reload kernel modules.
2. C + libuci
A backend module can use libuci directly:
#include <uci.h>
static int set_lan_ip(const char *value)
{
struct uci_context *ctx = uci_alloc_context();
struct uci_ptr ptr;
int rc = -1;
if (uci_lookup_ptr(ctx, &ptr, "network.lan.ipaddr", true) != UCI_OK)
goto out;
ptr.value = value;
if (uci_set(ctx, &ptr) != UCI_OK)
goto out;
if (uci_commit(ctx, &ptr.pkg, false) != UCI_OK)
goto out;
rc = 0;
out:
uci_free_context(ctx);
return rc;
}
Notes:
uci_setdoes not necessarily persist immediately;commitneeds the package pointer;- new options may need to be created first;
- do not call
system("uci ...")inside a uloop callback; keep libuci file I/O off the hot path.
3. AMX UCI backend module
This is the normal prplOS pattern:
TR-181 object change
→ UCI backend module (listening to dm:object-changed)
→ libuci set/commit
→ /etc/config/network
→ netifd applies it
For example, tr181-routing uses mod-routing-uci for static/OS-level routes; BGP/OSPF use mod-routing-bird2. ODL defines the model; it does not execute UCI commands.
A module is responsible for:
- observing object/parameter changes;
- translating TR-181 semantics into UCI sections/options;
- committing through libuci;
- handling failures and rollback boundaries.
Which level?
| Scenario | Choice |
|---|---|
| Temporary debugging | shell uci |
| Custom C service | libuci |
| prplOS management plane | AMX + UCI backend module |
| Inside uloop callback | do not block; defer or offload |
Series: Inside prplOS: AMX Runtime (Guide) Related: Where the AMX data model lives · UCI backend example · From UCI to a data model
Comments 0
No comments yet — be the first!