Skip to content, sitemap or skip to search.

Ubus inter-process comunication.

Some applications in gnuinos rely on the U-Bus framework (OpenWRT inter-process communication) that allows users to access and use services from the same place. Such is the case with simple-netaid, as well as usbmount.

The main piece of U-Bus (micro Bus) is the ubusd daemon. It provides an interface for other daemons to register themselves as well as sending messages. Therefore, ubusd must be run in first place before the daemons of simple-netaid and usbmount can be started.

Often, U-Bus makes use of a collection of utilities widely used in the OpenWRT project, and taken from U-Box (micro Box) such as polling, event handling, socket helper functions, and so on. Such utilities are provided by the libubox library.

The ubus command line tool allows to interact with the ubusd server, giving us a very powerful tool for accessing services both locally and remotely.

For example, to show which services are running on the bus:

root@gnuinos:/# ubus list ering.netaid ering.usbmount

This is the list of all namespaces currently registered in the server. To find out the complete list of procedures and their argument signatures the specific service ering.netaid provides:

root@gnuinos:/# ubus -v list ering.netaid 'ering.netaid' @e2e9e42a "interface_down":{"id":"Integer","ifname":"String"} "interface_up":{"id":"Integer","ifname":"String"} "ifdown":{"id":"Integer","ifname":"String","tty":"Integer"} "ifup":{"id":"Integer","ifname":"String","tty":"Integer"} "ipaddr_flush":{"id":"Integer","ifname":"String"} "wpa_passphrase":{"id":"Integer","essid":"String","passwd":"String","filename":"String"} "wpa_supplicant":{"id":"Integer","ifname":"String","filename":"String","tty":"Integer"} "uninstall":{"id":"Integer","filename":"String"} "scan_active_wifis":{"id":"Integer","ifname":"String"}

We can call a given procedure within the ering.netaid namespace passing arguments to it as a regular user without granted permissions. For instance (ignore the first argument "id" so far):

user@gnuinos:~$ ubus call ering.netaid interface_down '{ "ifname": "eth0" }' { "Server reply - Request has been proceeded: ": "interface eth0 down" }

The above command will beep down the wired interface. The result is the same as running ip link set eth0 down with root privilegies.

As you can see in the output of ubus -v list ering.netaid, some procedures require an argument called tty. That's the case of ifup and ifdown, which will invoke /sbin/ifup and /sbin/ifdown respectively in the server side:

user@gnuinos:~$ ubus call ering.netaid ifdown '{ "ifname": "eth0" , "tty": 4 }'

The system call will be thrown then to the client side as long as the user specifies the current tty passed throughout the last argument signature (i.e. tty). For the sake of the example, we assumed above that

user@gnuinos:~$ tty /dev/pts/4

In doing so, the root-owned program ifdown will be executed within the non-privileged console session:

user@gnuinos:~$ ubus call ering.netaid ifdown '{ "ifname": "eth0" , "tty": 4 }' Killed old client process Internet Systems Consortium DHCP Client 4.4.1 Copyright 2004-2018 Internet Systems Consortium. All rights reserved. For info, please visit Listening on LPF/eth0/........ ..............................

The ACLs related to ubus are located in /usr/share/acl.d. Simple-netaid involves netaid-server.json:

{ "group": "netaid", "access": { "ering.netaid": { "methods": [ "interface_down" , "interface_up" , "ifup" , "ifdown" , "ipaddr_flush" , "wpa_passphrase" , "wpa_supplicant" , "uninstall" , "scan_active_wifis" ] } } }

This configuration is customizable. For example, it's possible to use something like "user": "devuanita" or even wildcards (*), as explained in the website of the OpenWRT project.

Related links:

     - Ubus (OpenWrt micro bus architecture)
     - The ubus mechanism of OpenWRT
     - Everything ubus
     - OpenWRT Modules: U-BUS

This website is free of cookies.