Interprocess Communication and Middleware Interaction
UBUS: Message Bus Internals and Protocol
Internals:
ubusddaemon 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
ubusdvia/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
netifdorrpcd. Methods: - Expose functions (e.g.,
network.interface.statusto check interface state). - Called via UBUS CLI (
ubus call) or programmatically. Examples: ubus call network.interface statusretrieves network status.ubus call uci get '{"config":"network"}'reads UCI settings.
Client and Server Implementations in C
Client:
- Uses
libubusto connect toubusdand 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:
libubusfor client/server communication.libuboxfor utilities like JSON parsing.
UCI + UBUS Integration Flow
Integration:
- UCI stores configurations in
/etc/config/. ucicommand orlibuciinteracts with UBUS to apply changes.netifdandLuCIuse UBUS to read/write UCI settings.- Example: Changing Wi-Fi SSID via
LuCItriggers UBUS call touci, which updates/etc/config/wireless.
Event Notification and Subscription Mechanism
Mechanism:
ubussupports event broadcasting (e.g., interface up/down).- Clients subscribe to events using
ubus subscribe. - Example:
netifdnotifies subscribers of link status changes. - Events are lightweight and sent via Unix sockets.
RPCD and Remote Procedure Calls (via JSON-RPC)
Mechanism:
rpcdexposes UBUS methods via JSON-RPC 2.0 over HTTP.- Used by
LuCIand external clients for remote management. - Supports authentication via tokens or credentials.
- Example:
POST /ubuswith JSON payload to query system status.