[OpenWrt-Devel] [PATCH 1/1] netifd: add pre-up/down post-up/down callback handling

Florian Eckert fe at dev.tdt.de
Thu Mar 19 08:03:20 EDT 2020

In some situations it is useful to execute callback scripts when
manually triggering an ifdown/ifup event via the CLI/LuCI.

In my case I have a monitoring for a cellular connection.
If this fails the command `ubus call network.interface up` is execute to
restart the connection if a config option in uci of the interface
(keep_connected) flag is set.

But for me to disconnect correctly I need to know about a user
interaction with performed with CLI/LuCI.

With this change we can decide if this is a user interaction with CLI/LuCI,
because with the new callback mechanism I can set/delete a uci config flag so
that the connection should really disconnected. And so does not restart on a
failed connetion tracking again because the uci config flag is not set.

Signed-off-by: Florian Eckert <fe at dev.tdt.de>
 package/network/config/netifd/files/sbin/ifup | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/package/network/config/netifd/files/sbin/ifup b/package/network/config/netifd/files/sbin/ifup
index 5515b91f76..c92dd46550 100755
--- a/package/network/config/netifd/files/sbin/ifup
+++ b/package/network/config/netifd/files/sbin/ifup
@@ -6,7 +6,9 @@ setup_wifi=
 if_call() {
 	local interface="$1"
 	for mode in $modes; do
+		env -i ACTION="pre-${mode}" INTERFACE="$interface" /sbin/hotplug-call netifd
 		ubus call network.interface $mode "{ \"interface\" : \"$interface\" }"
+		env -i ACTION="post-${mode}" INTERFACE="$interface" /sbin/hotplug-call netifd

openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list