2

I'm trying to use the D-Bus interface of NetworkManager to add and enable a network bridge connection. Basically I'm trying to mimic this command:

nmcli connection add type bridge ifname br0 stp no

This one-liner creates and activates a new connection, but it also creates a new virtual device br0.

The D-Bus API reference for the /org/freedesktop/NetworkManager lists the following methods:

Both have a similar signature and require a device as input, so an existing device that can be retrieved via the D-Bus GetDevices method. However, a network bridge requires a virtual device (or a virtual device is created for the network bridge?). Naturally I looked into creating a new device first and then passing it to one of the methods listed above, but the reference does not offer any method for creating new devices.

I think the nmcli implementation uses the D-Bus interface under the hood, so it has to be possible somehow?

1 Answer 1

1

nmcli con add does not use AddAndActivate API. It also does not (itself) create the device. What happens is only that it adds a new connection profile with autoconnect enabled, which the NetworkManager will automatically activate, and thereby creating the device.

You should understand what a profile is: it's a bunch of settings for configuring a network device. And that profile may be "activated", which means to actually use the settings (and create the device). You can always manually activate a profile, or Networkmanager may do it automatically, if the conditions are right. The API to "create" a device is activating a profile. In case of a software device (eg. bridge), NetworkManager automatically creates it when you activate the profile.

AddAndActivate is called (in some cases) by nmcli device connect and nmcli device wifi connect. It's different in that it does two steps in one and it does one additional thing: the user may pass an incomplete connection profile that NetworkManager tries to fill out before adding it. As such, it's more than AddConnection + Activate connection alone. Usually, that is not what you want. Best example is to specify only the SSID in a Wi-Fi profile and AddAndActivate automatically fills in the extra settings based in the Wi-Fi scan results. With AddConnection API the profile gets fully determined by the caller and only gets completed with default settings, independent of a device (or Wi-Fi Access Point).

The device argument on D-Bus may be optional. At least for ActivateConnection API. In that case, NetworkManager will automatically find or create a suitable device. Also, the connection profile argument may be optional (if you instead provide only the device).

Yes, most Networkmanager client tools will use the same underlying D-Bus API, including nmcli. That allows you to write your own application that does what other applications do and thereby integrate with those tools. There is also libnm, a glib based library that wraps D-Bus and several client applications use that instead of talking D-Bus directly.

See also the examples at https://gitlab.freedesktop.org/NetworkManager/NetworkManager/tree/ce59e749fbc99152d379b22563d6fd3295c7085a/examples

Networkmanager API is all about creating profiles (connections) and activating them.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .