Work in progress
This is a pure Rust library for implementing OpenWRT ubus clients.
- make sure
ubusdis running, and you are usingrootto run examples (or hackubusd'subusd_acl_check()) to skip root check, see above - make sure your rust toolchain is nightly, because I use the
try_collect()features cargo run --example=addserver- start the servercargo run --example=invoke- invoke server's method and print resultcargo run --example=ubuscall ttt echo '{"1": true}'- another way to invoke server's method and print resultcargo run --example=subscribe- subscribe to server and get notifications
- High-level abstraction for
lookupcommand - High level abstraction for
callcommand - High level abstraction for server object
- High level abstraction for
subscribe/notifycommands - Async with Tokio
- JSON support
- Strongly typed result
unsubscribe/remove_server- handle IO/channel errors better instead of panic
This is a fork of shavac/ubus-rs, using allocations (Vec and String) to convert raw bytes to native rust types.
There are almost none documention about libubus, especially about server object. And the libubus source code has no comments at all... I draw a Figma from what I learned by reading source code and debugging.
This makes strong assumption that ubus only use limited size of types of Blob, and actual data is always json (Vec<BlobMsg>), to make parsing more specific:
Blobwith its most-significat-bit1isBlobMsg, which can represents json dataBlobwith its most-significat-bit0isUbusBlob, which has fixed size oftypes, no othertypes of Blob used inubus, except the containerBlobinUbusMsgUbusMsgalways has aUbusMsgHeader, followed by a giant containerBlobthat hastype 0- The container
Blobcontains multipleUbusBlobs, andUbusBlobs' payload data type is tied toUbusBlobs'type- e.g. If
UbusBlobhastype STATUS, then its payload is au32 - e.g. If
UbusBlobhastype DATA, then its payload is multipleBlobMsgs, which can be converted to one json object
- e.g. If
Seems only root can connect to ubusd? To tests and development, I add an early return 0; to beginning of ubusd_acl.c -> ubusd_acl_check() in ubusd to skip auth.
Signature varification is skipped, (ubusd also doesn't care about it), making transfer any valid json possible. This is the behaviour of libubus and ubus cli.
Seems ubusd even doesn't care about method existence, its server object's responsibilty to return a method not found status.