This is an old revision of the document!
uBus IPC/RPC System
uBus - IPC/RPC
uBus is the interconnect system used by most services running on a OpenWrt setup. Services can connect to the bus and provide methods that can be called by other services or clients.
There is a CLI that can be used to communicate with services on the bus.
root@OpenWrt:/# ubus
Usage: ubus [<options>] <command> [arguments...]
Options:
-s <socket>: Set the unix domain socket to connect to
-t <timeout>: Set the timeout (in seconds) for a command to complete
-S: Use simplified output (for scripts)
-v: More verbose output
-m <type>: (for monitor): include a specific message type
(can be used more than once)
-M <r|t> (for monitor): only capture received or transmitted traffic
Commands:
- list [<path>] List objects
- call <path> <method> [<message>] Call an object method
- listen [<path>...] Listen for events
- send <type> [<message>] Send an event
- wait_for <object> [<object>...] Wait for multiple objects to appear on ubus
- monitor Monitor ubus traffic
To find out which services are currently running on the bus simply use the list command. This will show a complete list.
root@OpenWrt:/# ubus list dhcp dnsmasq file iwinfo log luci luci-rpc network network.device network.interface network.interface.lan network.interface.loopback network.rrdns network.wireless service session system uci
To find out which methods a specific service provides also use the list command but add a few more parameters to see a complete list
root@OpenWrt:/# ubus -v list system
'system' @651f206c
"board":{}
"info":{}
"reboot":{}
"watchdog":{"frequency":"Integer","timeout":"Integer","magicclose":"Boolean","stop":"Boolean"}
"signal":{"pid":"Integer","signum":"Integer"}
"validate_firmware_image":{"path":"String"}
"sysupgrade":{"path":"String","force":"Boolean","backup":"String","prefix":"String","command":"String","options":"Table"}
You can now call a remote method and receive a reply. A reply may be a simple integer return code or a more complete reply. Internally the bus uses a blob format, the CLI conveniently converts this to JSON.
root@OpenWrt:/# ubus call system board
{
"kernel": "4.9.198",
"hostname": "OpenWrt",
"system": "Qualcomm Atheros QCA956X ver 1 rev 0",
"model": "TP-Link TL-WR1043N\/ND v4",
"board_name": "tl-wr1043nd-v4",
"release": {
"distribution": "OpenWrt",
"version": "18.06.5",
"revision": "r7897-9d401013fc",
"target": "ar71xx\/generic",
"description": "OpenWrt 18.06.5 r7897-9d401013fc"
}
}
You can call a method and pass it some parameters by simply appending a JSON structure to the CLI command.
root@OpenWrt:/# ubus call system signal '{ "pid": 123, "signum": 9 }'
root@OpenWrt:/# echo $?
0
Reference documentation for ubus
Path only contains the first context. E.g. network for network.interface.wan
| path | Description | Package |
|---|---|---|
| dhcp | dhcp server | odhcpd |
| file | file | rpcd |
| hostapd | acesspoints | wpad/hostapd |
| iwinfo | wireless informations | rpcd iwinfo |
| log | logging | procd |
| mdns | mdns avahi replacement | mdnsd |
| network | network | netifd |
| service | init/service | procd |
| session | Session management | rpcd |
| system | system misc | procd |
| uci | Unified Configuration Interface | rpcd |