Interprocess Communication and Middleware Interaction
UBUS: Message Bus Internals and Protocol
Internals:
ubusd
daemon manages the bus, handling client connections.- Uses Unix sockets for communication.
- Supports JSON-formatted messages for method calls and events.
- Provides namespaces for organizing objects (e.g.,
network
,system
).
Protocol:
- Clients connect to
ubusd
via/var/run/ubus.sock
. - Messages include method calls, responses, and event notifications.
- Lightweight and optimized for low-resource devices.
UBUS Objects and Methods
Objects:
- Represent system components (e.g.,
network.interface
,uci
). - Registered by services like
netifd
orrpcd
. Methods: - Expose functions (e.g.,
network.interface.status
to check interface state). - Called via UBUS CLI (
ubus call
) or programmatically. Examples: ubus call network.interface status
retrieves network status.ubus call uci get '{"config":"network"}'
reads UCI settings.
Client and Server Implementations in C
Client:
- Uses
libubus
to connect toubusd
and call methods. - Example: Querying network status via
ubus_call()
. Server: - Registers objects and methods with
ubusd
. - Example: A custom service exposing status via UBUS. Libraries:
libubus
for client/server communication.libubox
for utilities like JSON parsing.
UCI + UBUS Integration Flow
Integration:
- UCI stores configurations in
/etc/config/
. uci
command orlibuci
interacts with UBUS to apply changes.netifd
andLuCI
use UBUS to read/write UCI settings.- Example: Changing Wi-Fi SSID via
LuCI
triggers UBUS call touci
, which updates/etc/config/wireless
.
Event Notification and Subscription Mechanism
Mechanism:
ubus
supports event broadcasting (e.g., interface up/down).- Clients subscribe to events using
ubus subscribe
. - Example:
netifd
notifies subscribers of link status changes. - Events are lightweight and sent via Unix sockets.
RPCD and Remote Procedure Calls (via JSON-RPC)
Mechanism:
rpcd
exposes UBUS methods via JSON-RPC 2.0 over HTTP.- Used by
LuCI
and external clients for remote management. - Supports authentication via tokens or credentials.
- Example:
POST /ubus
with JSON payload to query system status.