[Networkmanager] Cancel connection up/connection down from dispatcher scripts or other hooks?

Thomas Haller thaller at redhat.com
Fri Apr 21 12:00:57 UTC 2023

On Fri, 2023-04-21 at 13:23 +0200, Farblos wrote:
> Hi.
> I can imagine some use cases where it would be useful to actively
> cancel a user request to bring up/down some connection, regardless of
> the UI used by the user:
> - close open files on networked devices before connection is lost
> - prevent from using a certain VPN if some conditions are not
> fulfilled
> The pre-up/pre-down hooks (NetworkManager-dispatcher(8)) seem to be
> close to that requirement, but from what I understand I can only
> delay connection up/down in these hooks and not cancel or prevent
> them.
> Is there anything else?
> Thanks!


can you not call `nmcli connection down` from the dispatcher scripts?

One problem is, that the dispatcher's environment does not contain the
D-Bus path to the active connection.

Otherwise, you could do:

if [ "$2" = pre-up -a $MORE_CONDITIONS ]; then
    nmcli connection down apath "$ACTIVE_CONNECTION_DBUS_PATH"

which would be more reliable (because the D-Bus path uniquely
identifies the activation in question, and never repeats.

patch welcome for that too.


More information about the Networkmanager mailing list