netplan writes Keyfiles for NetworkManager with GString instead of GKeyFile API

Bug #1824110 reported by Thomas Haller
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Netplan
New
Undecided
Unassigned

Bug Description

netplan uses C and glib. However, it constructs the keyfiles for NetworkManager (in /etc/NetworkManager/system-connections) simply with GString.

It should use GKeyFile API instead. This takes care of handling string and escape them accordingly. At the end, the keyfile can be converted to string (or written to file).

A possible alternative would be that libnm would finally start exposing its API for Keyfiles. Then, netplan could use libnm, it would create an `NMConnection`, and that could then be converted to a GKeyfile (if that API was added to libnm: https://bugzilla.gnome.org/show_bug.cgi?id=744702#c1). The pro and cons of that approach:

 - it requires libnm API that does not exist yet (but this is something that really should be added. So, investing work here would not be for naught).

 - it makes netplan dependent at libnm.so. That might be acceptable, because if you use NetworkManager, libnm.so will also be around. And you can install libnm.so without NetworkManager (and of course, NetworkManager does not need to be running to use libnm). Albeit cumbersome, the part of netplan that requires libnm could be packaged separately and loaded as a plugin (dlopen).

 + the NMConnection API of libnm may be more convenient to use.

 + NMConnection provides nm_connection_verify(). This allows for better validation of the input instead of writing text to disk and hope to get all special cases right.

 + NMConnection's can also be converted to GVariant and sent over on D-Bus. That means, the code that creates the NMConnection would be independent from whether to store it as keyfiles or use on the D-Bus API. That would netplan allow not only to write profiles to file (before starting NetworkManager) but also to make changes at runtime. Yes, the alternative is `nmcli connection load "/etc/NetworkManger/system-connections/$FILE", but that is more crude as you can only write+load files. You cannot compare what's currently configured and compare it with what you have. NMConnection provides not only API to write them to keyfile/GVariant, but also to load them and compare them.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.