Commit graph

1758 commits

Author SHA1 Message Date
Beniamino Galvani
4c9aa0ced0 build: meson: install ifcfg-rh files and directory
(cherry picked from commit 34ffd9fcab)
2018-10-02 10:02:32 +02:00
Lubomir Rintel
2ffcdb8efa settings/ifupdown/tests: avoid asserting on an array
char[] is not a char *; it can not go NULL.

  test-ifupdown.c:147:27: error: address of array 'n->name' will always evaluate
                                 to 'true' [-Werror,-Wpointer-bool-conversion]
                g_assert (b->name && n->name);
  test-ifupdown.c:156:27: error: address of array 'm->key' will always evaluate
                                 to 'true' [-Werror,-Wpointer-bool-conversion]
                        g_assert (k->key && m->key);

(cherry picked from commit b64ae759ad)
2018-09-19 15:31:00 +02:00
Thomas Haller
fe866fbeb3 libnm: drop API nm_connection_get_setting_{6lowpan,sriov,wpan}()
Note that NMSettingEthtool and NMSettingMatch don't have such
functions either.

We have API

  nm_connection_get_setting (NMConnection *, GType)
  nm_connection_get_setting_by_name (NMConnection *, const char *)

which can be used generically, meaning: the requested setting type
is an argument to the function. That is generally more useful and
flexible.

Don't add API which duplicates existing functionality and is (arguably)
inferiour. Drop it now. This is an ABI/API break for the current development
cycle where the 1.14.0 API is still unstable. Indeed it's already after
1.14-rc1, which is ugly. But it's also unlikely that somebody already uses
this API/ABI and is badly impacted by this change.

Note that nm_connection_get_setting() and nm_connection_get_setting_by_name()
are slightly inconvenient in C still, because they usually require a cast.
We should fix that by changing the return type to "void *". Such
a change may be possibly any time without breaking API/ABI (almost, it'd
be an API change when taking a function pointer without casting).

(cherry picked from commit a10156f516)
2018-09-14 16:30:51 +02:00
Beniamino Galvani
6220bae2d3 ifcfg-rh: fix build with meson
The shared object was missing some files.

(cherry picked from commit bd556c8937)
2018-09-13 14:35:22 +02:00
Beniamino Galvani
44d77a7476 ifcfg-rh: add support for connection.llmnr 2018-09-06 09:07:41 +02:00
Thomas Haller
3091ffa50a settings/ifupdown: use _NMLOG() macros for logging
Does not address the issues that the existing logging is much too verbose
and does not provide necessary context for what it's complaining. The
logging messages should be improved.

At least, the logging macro gives all messages a "ifupdown: " prefix.
2018-09-06 07:41:22 +02:00
Thomas Haller
7064b81bbc settings/ifupdown: various cleanup in nms-ifupdown-parser.c 2018-09-06 07:41:22 +02:00
Thomas Haller
bb273c0881 settings/ifupdown: optimize allocating parser data 2018-09-06 07:41:22 +02:00
Thomas Haller
fe018a7e81 settings/ifupdown: use c-list for data structure of ifupdown parser
We already have a linked-list implementation. Use it.
2018-09-06 07:41:22 +02:00
Thomas Haller
70350bb621 settings/ifupdown: don't use global variables for /e/n/i parser 2018-09-06 07:41:22 +02:00
Thomas Haller
6f14228cb3 settings/ifupdown: hide internal functions in "nms-ifupdown-interface-parser.h" 2018-09-06 07:41:22 +02:00
Thomas Haller
b8da0855fa settings/ifupdown: refactor string prefix matching in parser 2018-09-06 07:41:22 +02:00
Thomas Haller
de2e75e327 settings/ifupdown: use nm_streq() in parser 2018-09-06 07:41:22 +02:00
Thomas Haller
03be91f038 settings/ifupdown: adjust coding style for "nms-ifupdown-interface-parser" 2018-09-06 07:41:22 +02:00
Thomas Haller
518c7be77b settings/ifupdown: in plugin drop listening to udev for devices
Don't listen to udev to find out about devices. First of all, using udev
for this is already very wrong, because we have the platform cache.

Anyway, all that the device information is used, is pointless as well.
Drop it.

It's pointless because:

The entires in eni_ifaces are already indexed by the interface name.
Likewise, all NMIfupdownConnection set "connection.interface-name" to
restict the profile by name.
/e/n/i matches devices is by name, that's it. We don't need udev to
look up the MAC address (by name!!) to later ignore/match devices
by MAC address. Especially, because NetworkMaanger can already
restrict profiles to devices based on the interface name.
Likewise, NetworkMaanger can use the interface name for the
unmanaged-specs.
It's wrong to extend the on-disk configuration from /e/n/i with runtime
information from udev, especially, because other NetworkMaanger layers
are perfectly content using the interface name for this purpose.

Also, bind_device_to_connection() was fundamentally wrong. It's wrong
to modify the settings connection at random moments (on udev event).
If at all, that should only happen during connection load/reload.

This may have been necessary a long time ago, when unmanaged devices were
not expressed by device-match-specs, but by the HAL UDI. That was since
improved, for example by commit c9067d8fed.
2018-09-06 07:41:22 +02:00
Thomas Haller
6aa66426a4 settings/ifupdown: merge eni_ifaces and connections hashes in plugin
The "connections" hash contains a mapping of block->name (iface) to the
NMSettingsConnection. The "eni_ifaces" hash contains the name of all
blocks which are mentioned, but for which no connection was created.

Merge the two hashes. We don't need to keep track of whether a
connections was successfully created ("connections"), but the
same name also has a non-connection block. This information is
unnecessary, so one hash is enough.
2018-09-06 07:41:22 +02:00
Thomas Haller
dfadaaf7f8 settings/ifupdown: change plugin's field @unmanage_well_known to @ifupdown_managed
@unmanage_well_known directly depends on the "ifupdown.managed" setting from
NetworkManager.conf. Rename it (and invert the meaning) so that this
relation ship becomes clearer.

Also, the double negation of "if (!unmanaged_well_known)" hurts the
brain.
2018-09-06 07:41:22 +02:00
Thomas Haller
afb9fa6753 settings/ifupdown: drop unused define ALWAYS_UNMANAGE in plugin
This is only useful for testing. But since the managed flag is configurable
via NetworkManager.conf, there is no point in having a define as well. If
you want to test it, just configure it.

And if you really want to patch the code, then patch
"priv->unmanage_well_known" to be always TRUE.
2018-09-06 07:41:22 +02:00
Thomas Haller
fab0d214b7 settings/ifupdown: cleanup plugin's logging
- use _NMLOG() macro and give logging message a sensible prefix

- downgrade logging severity. Most of these messages are not
  important to warrant <info> or <warn> level.

- the logging is generally rather bad. Messages like

    "bind-to-connection: locking wired connection setting"

  don't indicate which profile is locked to which MAC address.
  TODO.
2018-09-06 07:41:22 +02:00
Thomas Haller
fb04a7b722 settings/ifupdown: cleanup plugin's get_connections() 2018-09-06 07:41:22 +02:00
Thomas Haller
f804b23b64 settings/ifupdown: cleanup parsing bridge in plugin's initialize() 2018-09-06 07:41:22 +02:00
Thomas Haller
f0509205a2 settings/ifupdown: refactor parsing loop in plugin's initialize() 2018-09-06 07:41:22 +02:00
Thomas Haller
f0938948bc settings/ifupdown: replace strcmp() usage with nm_streq()/NM_IN_STRSET() in plugin 2018-09-06 07:41:22 +02:00
Thomas Haller
553c3368ab settings/ifupdown: minor cleanup of auto-ifaces in plugin's initialize()
- use gs_unref_hashtable for managing lifetime

- only allocate the hashtable if necessary, and use g_hash_table_add()
  which is optimized by HashTable.

- actually copy the block->name that is used as key. While not
  necessary at the moment, it is very ugly how ifparser_getfirst()
  returns static data. Optimally, this would be fixed and we create
  and destroy the parser results. Hence, ensure the lifetime of
  the key.
2018-09-06 07:41:22 +02:00
Thomas Haller
42c2055a31 settings/ifupdown: cleanup lifetime and memory handling of dictionaries in plugin
- initialize the hash tables in the plugins constructor, not during
  initialize().

- let all dictionaries own a copy/reference of the keys and values, and
  properly free them when the values are removed. In general, avoid
  leaks by properly managing lifetimes.

- in @eni_ifaces, don't add a pointless dummy value "known". It has
  overhead for no benefit.
2018-09-06 07:41:22 +02:00
Thomas Haller
0ea810fa96 settings: cleanup loading settings plugins
Drop the unnecessary @list argument and various cleanups.
2018-09-06 07:41:22 +02:00
Thomas Haller
dd5244af3e settings: disconnect signals from plugins when destroying NMSettings
Currently we anyway leak everything on shutdown, so this doesn't matter.
But to be correct, we must disconnect signal handlers.
2018-09-06 07:41:22 +02:00
Thomas Haller
657b0714b8 settings: make NMSettingsPlugin a regular GObject instance and not an interface
NMSettingsPlugin was a glib interface, not a regular GObject
instance. Accordingly, settings plugins would implement this interface
instead of subclassing a parent type.

Refactor the code, and make NMSettingsPlugin a GObject type. Plugins
are now required to subclass this type.

Glib interfaces are more cumbersome than helpful. At least, unless
there is a good reason for using them.

Our settings plugins are all internal API and are entirely under
our control. It also means, this change is fine, as there are no
implementations outside of this source tree.

Using interfaces do would allow more flexibility in implementing the
settings plugin.
For example, the plugin would be able to derive from any other GObject
type, like NMKimchiRefrigerator. But why would we even? Let's not add monster
classes that implement house appliances beside NMSettingsPluginInterface.
The settings plugin should have one purpose only: being a settings plugin.
Hence, requiring it to subclass NMSettingsPlugin is more than resonable. We
don't need interfaces for this.

Now that NMSettingsPlugin is a regular object instance, it may also have
state, and potentially could provide common functionality for the plugin
implementation -- if that turns out to be useful. Arguably, an interface can
have state too, for example by attaching the state somewhere else (like
NMConnection does). But let's just say no.

On a minor note, this also avoids some tiny overhead that comes with
glib interfaces.
2018-09-06 07:41:22 +02:00
Thomas Haller
32442b2661 settings: drop unused get_plugin() checks
Nowadays, keyfile settings plugin is always loaded. Hence,
this function never returns %NULL and the checks always
evalute the the same.
2018-09-06 07:41:22 +02:00
Thomas Haller
194e7f8df6 settings: rename NMSettingsPluginInterface.init() to initialize()
The virtual function init() naturally leads to calling the wrapper
function nm_settings_plugin_init(). However, such ${TYPE}_init() functions
are generated by G_DEFINE_TYPE().

Rename to avoid the naming conflict, which will matter next, when the
interface will be converted to a regular GObject class.

Note that while these are settings plugin, there is no public
or stable API which we need to preserve.
2018-09-06 07:41:22 +02:00
Thomas Haller
122bb485ee settings: remove empty NMSettingsPluginInterface.init() implementations 2018-09-06 07:41:22 +02:00
Thomas Haller
80cb515681 settings/keyfile: always return path from nms_keyfile_writer_connection()
Previously, nms_keyfile_writer_connection() would only return @out_path, if
it differed from @existing_path. That might make sense, if we could thereby
avoid duplicating @existing_path, however, we never did that
optimization.

Just consistently always return the path, let the caller deal with this.
2018-09-06 07:41:22 +02:00
Thomas Haller
ac6d62cd2d keyfile: fix crash wrongly treating NMSettingsConnection as NMConnection
Fixes: d17d26887c
2018-09-05 15:01:28 +02:00
Michael Biebl
e4c7a60854 ifupdown: properly handle special "none" keyword for bridge_ports
If this option is set, we should not add a device named "none" but
simply don't add any devices at all.

https://manpages.debian.org/testing/bridge-utils/bridge-utils-interfaces.5.en.html

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/11
2018-09-05 09:14:52 +02:00
Thomas Haller
e3ac45c026 ifcfg-rh: don't use 802-1x certifcate setter functions
The certificate setter function like nm_setting_802_1x_set_ca_cert()
actually load the file from disk, and validate whether it is a valid
certificate. That is very wrong to do.

For one, the certificates are external files, which are not embedded
into the NMConnection. That means, strongly validating the files while
loading the ifcfg files, is wrong because:
 - if validation fails, loading the file fails in its entirety with
   a warning in the log. That is not helpful to the user, who now
   can no longer use nmcli to fix the path of the certificate (because
   the profile failed to load in the first place).
 - even if the certificate is valid at load-time, there is no guarantee
   that it is valid later on, when we actually try to use the file. What
   good does such a validation do? nm_setting_802_1x_set_ca_cert() might
   make sense during nmcli_connection_modify(). At the moment when we
   create or update the profile, we do want to validate the input and
   be helpful to the user. Validating the file later on, when reloading
   the profile from disk seems undesirable.
 - note how keyfile also does not perform such validations (for good
   reasons, I presume).

Also, there is so much wrong with how ifcfg reader handles EAP files.
There is a lot of duplication, and trying to be too smart. I find it
wrong how the "eap_readers" are nested. E.g. both eap_peap_reader() and
"tls" method call to eap_tls_reader(), making it look like that
NMSetting8021x can handle multiple EAP profiles separately. But it cannot. The
802-1x profile is a flat set of properties like ca-cert and others. All
EAP methods share these properties, so having this complex parsing
is not only complicated, but also wrong. The reader should simply parse
the shell variables, and let NMSetting8021x::verify() handle validation
of the settings. Anyway, the patch does not address that.

Also, the setting of the likes of NM_SETTING_802_1X_CLIENT_CERT_PASSWORD was
awkwardly only done when
     privkey_format != NM_SETTING_802_1X_CK_FORMAT_PKCS12
  && scheme == NM_SETTING_802_1X_CK_SCHEME_PKCS11
It is too smart. Just read it from file, if it contains invalid data, let
verify() reject it. That is only partly addressed.

Also note, how writer never actually writes the likes of
IEEE_8021X_CLIENT_CERT_PASSWORD. That is another bug and not fixed
either.
2018-09-04 07:38:30 +02:00
Thomas Haller
6b763af1b7 ifcfg-rh: rework parsing secrets
- rename secret related functions to have a "_secret" prefix.
  Also, rename read_8021x_password() because it's not only useful
  for 802-1x.

- In particular, this patch adds _secret_read_ifcfg() helper (formerly
  read_8021x_password()), which is smart enough to obtain secrets from
  the keys ifcfg file. We have other places where we don't get this
  right.

- on a minor note, the patch also makes an effort to clear passwords
  and certifcate data from memory. Yes, there are countless places
  where we don't do that, but in this case, it's done and is as simple
  as replacing gs_free with nm_auto_free_secret, etc.
2018-09-04 07:38:30 +02:00
Thomas Haller
4b6aa207b2 ifcfg-rh/trivial: rename variable for ifcfg keys file
The term "keys" is used ambigiously. Rename occurances which reference
the "keys" ifcfg-rh file.

While at it, rename the file "parsed" to "main_ifcfg". It follows the
same pattern as the "keys_ifcfg" name.
2018-09-04 07:38:30 +02:00
Thomas Haller
e01f7f2c6d build: enable building both crypto backends for tests
If the library is available, let's at least compile both
crypto backends.

That is helpful when developing on crypto backends, so that
one does not have to configure the build twice.

With autotools, the build is only run during `make check`.
Not for meson, but that is generally the case with our meson
setup, that it also builds tests during the regular build step.
2018-09-04 07:38:30 +02:00
Thomas Haller
ff163d9d0d shared: move file-get-contents and file-set-contents helper to shared/
These functions are not specific to "src/". Also, they will be needed
by outside of "src/" soon.
2018-09-04 07:38:30 +02:00
Thomas Haller
6b813b904f core: extend nm_utils_*_get_contents() to zero temporary memory
When reading a file, we may allocate intermediate buffers (realloc()).
Also, reading might fail halfway through the process.

Add a new flag that makes sure that this memory is cleared. The
point is when reading secrets, that we don't accidentally leave
private sensitive material in memory.
2018-09-04 07:38:30 +02:00
Thomas Haller
dd4a6f307c tests: minor code cleanup in tests
Use nmtst_assert_success(), nm_auto() macros, and minor
cleanups.
2018-08-30 11:17:09 +02:00
Thomas Haller
1b448aeb30 all: use nm_utils_gbytes_equal_mem() 2018-08-30 11:17:09 +02:00
Thomas Haller
38273a8871 settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).

NMSettingsConnection does a lot of things already:

  1) it "is-a" NMDBusObject and exports the API of a connection profile
     on D-Bus
  2) it interacts with NMSettings and contains functionality
     for tracking the profiles.
  3) it is the base-class of types like NMSKeyfileConnection and
     NMIfcfgConnection. These handle how the profile is persisted
     on disk.
  4) it implements NMConnection interface, to itself track the
     settings of the profile.

3) and 4) would be better implemented via delegation than inheritance.

Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.

Advantages:

  - by delegating, there is a clearer separation of what
    NMSettingsConnection does. For example, in C we often required
    casts from NMSettingsConnection to NMConnection. NMConnection
    is a very trivial object with very little logic. When we have
    a NMConnection instance at hand, it's good to know that it is
    *only* that simple instead of also being an entire
    NMSettingsConnection instance.

    The main purpose of this patch is to simplify the code by separating
    the NMConnection from the NMSettingsConnection. We should generally
    be aware whether we handle a NMSettingsConnection or a trivial
    NMConnection instance. Now, because NMSettingsConnection no longer
    "is-a" NMConnection, this distinction is apparent.

  - NMConnection is implemented as an interface and we create
    NMSimpleConnection instances whenever we need a real instance.
    In GLib, interfaces have a performance overhead, that we needlessly
    pay all the time. With this change, we no longer require
    NMConnection to be an interface. Thus, in the future we could compile
    a version of libnm-core for the daemon, where NMConnection is not an
    interface but a GObject implementation akin to NMSimpleConnection.

  - In the previous implementation, we cannot treat NMConnection immutable
    and copy-on-write.
    For example, when NMDevice needs a snapshot of the activated
    profile as applied-connection, all it can do is clone the entire
    NMSettingsConnection as a NMSimpleConnection.
    Likewise, when we get a NMConnection instance and want to keep
    a reference to it, we cannot do that, because we never know
    who also references and modifies the instance.
    By separating NMSettingsConnection we could in the future have
    NMConnection immutable and copy-on-write, to avoid all unnecessary
    clones.
2018-08-28 22:27:55 +02:00
Thomas Haller
5cd4e6f3e6 wifi: don't use GBytesArray for NMWifiAP's ssid
GBytes makes more sense, because it's immutable.

Also, since at other places we use GBytes, having
different types is combersome and requires needless
conversions.

Also:

- avoid nm_utils_escape_ssid() instead of _nm_utils_ssid_to_string().
  We use nm_utils_escape_ssid() when we want to log the SSID. However, it
  does not escape newlines, which is bad.

- also no longer use nm_utils_same_ssid(). Since it no longer
  treated trailing NUL special, it is not different from
  g_bytes_equal().

- also, don't use nm_utils_ssid_to_utf8() for logging anymore.
  For logging, _nm_utils_ssid_escape_utf8safe() is better because
  it is loss-less escaping which can be unambigously reverted.
2018-08-22 10:49:34 +02:00
Beniamino Galvani
d47e0beb7d ifcfg-rh: add support for 'match' setting 2018-08-11 09:41:07 +02:00
Beniamino Galvani
6a51d393b2 shared: add @allow_escaping argument to @nm_utils_strsplit_set 2018-08-11 09:41:07 +02:00
Thomas Haller
da109a291c all/ethtool: add support for all currently supported kernel features
As of upstream kernel v4.18-rc8.

Note that we name the features like they are called in ethtool's
ioctl API ETH_SS_FEATURES.

Except, for features like "tx-gro", which ethtool utility aliases
as "gro". So, for those features where ethtool has a built-in,
alternative name, we prefer the alias.

And again, note that a few aliases of ethtool utility ("sg", "tso", "tx")
actually affect more than one underlying kernel feature.

Note that 3 kernel features which are announced via ETH_SS_FEATURES are
explicitly exluded because kernel marks them as "never_changed":

    #define NETIF_F_NEVER_CHANGE (NETIF_F_VLAN_CHALLENGED | \
                                  NETIF_F_LLTX | NETIF_F_NETNS_LOCAL)
2018-08-10 10:38:19 +02:00
Thomas Haller
c085b6e3a7 platform/ethtool: add code to get/set offload features via ethtool
Also, add two more features "tx-tcp-segmentation" and
"tx-tcp6-segmentation". There are two reasons for that:

 - systemd-networkd supports setting these two features,
   so lets support them too (apparently they are important
   enough for networkd).

 - these two features are already implicitly covered by "tso".
   Like for the "ethtool" program, "tso" is an alias for several
   actual features. By adding two features that are already
   also covered by an alias (which sets multiple kernel names
   at once), we showcase how aliases for the same feature can
   coexist. In particular, note how setting
   "tso on tx-tcp6-segmentation off" will behave as one would
   expect: all 4 tso features covered by the alias are enabled,
   except that particular one.
2018-08-10 10:38:19 +02:00
Thomas Haller
df30651b89 libnm, cli, ifcfg-rh: add NMSettingEthtool setting
Note that in NetworkManager API (D-Bus, libnm, and nmcli),
the features are called "feature-xyz". The "feature-" prefix
is used, because NMSettingEthtool possibly will gain support
for options that are not only -K|--offload|--features, for
example -C|--coalesce.

The "xzy" suffix is either how ethtool utility calls the feature
("tso", "rx"). Or, if ethtool utility specifies no alias for that
feature, it's the name from kernel's ETH_SS_FEATURES ("tx-tcp6-segmentation").
If possible, we prefer ethtool utility's naming.

Also note, how the features "feature-sg", "feature-tso", and
"feature-tx" actually refer to multiple underlying kernel features
at once. This too follows what ethtool utility does.

The functionality is not yet implemented server-side.
2018-08-10 10:38:19 +02:00
Thomas Haller
bcbea6fe35 ifcfg-rh: refactor parsing in parse_ethtool_option() to not call helper functions
Parsing can be complicated enough. It's simpler to just work
top-to-bottom, without calling various helper functions. This was,
you can see all the code in one place, without need to jump to
the helper function to see what it is doing.

In general, a static function that is only called once, does sometimes
not simplify but obfuscate the code.
2018-08-10 10:38:19 +02:00