netifd can (probably) bring up a wired, static ip configuration without shell scripts. For everything else (PPPoE or 3G) it needs protocol handlers implemented as sets of shell functions.
Each protocol handler is a shell script in
/lib/netifd/proto/. It is run (or maybe sourced) when netifd daemon starts. Changes made to the scripts do not take effect until netifd restarts. The name of the file usually matches
option proto in
To be able to access the network functions, the script needs to include the necessary shell scripts at the beginning:
Current working directory is
/lib/netifd/proto/ when the handler is sourced.
At the end of the script a handler should register itself by calling
A handler should at least define 2 shell functions:
The main purpose of this function is to let netifd know which parameters does this protocol have. These parameters then can be stored in
The setup procedure implements the actual protocol specifc configuration logic and interface bringup.
When called, one or two parameters are passed:
This function must be implemented by any protocol backend.
There's usually no need to call
ifconfig iface up at the end of this function. If
no_device=0, netifd won't even try to start our profile until the device is already up. It waits for
carrier=1, then starts the profile.
no_device=1, netifd will bring it up, when it receives a notification from us:
However, this only works once. If someone called
ifconfig iface down, netifd won't try to bring it up again (at least in BB), so just in case you may put the “up” command in the function.
Protocols that need special shutdown handling, for example to kill associated daemons, may implement a stop procedure. This procedure is called when an interface is brought down before the associated UCI state is cleared.
The function is called when we do
ifdown profile or when
no_device=0 and netifd detects link connectivity loss.
When called, two parameters are passed:
This function is optional.
By default, only interfaces present in
/proc/net/dev, like eth0, are brought up on boot.
Protocols which use virtual interfaces must set two variables at the beginning of init_config.
Note: some of these function exit immediately.
We can start a daemon that maintains the connection asynchronously by calling
proto_run_command “$config” custom_script. Netifd remembers its pid. It can be killed manually by calling
proto_kill_command “$config”. Netifd can automatically kill it, when the profile stopped.