Commit graph

21251 commits

Author SHA1 Message Date
Thomas Haller
7d3fba9366 keyfile: also add ".nmconnection" extension when writing keyfiles in /etc
This is a change in behavior regarding the filename that we choose when
writing files to "/etc/NetworkManager/system-connections/".

(cherry picked from commit d37ad15f12)
2018-10-19 15:24:15 +02:00
Thomas Haller
095bac3019 initrd: add .nmconnection extension when writing keyfiles
initrd does not use keyfile API from "src/settings/plugins/keyfile",
hence it does not use nms_keyfile_utils_escape_filename() to add
the ".nmconnection" file extension.

I think that is problematic, because it also misses escapings which
are necessary so that NetworkManager will accept the file.

Anyway, the proper solution here would be to move the keyfile utility
functions to libnm-core, alongside base keyfile API. That way, it
could be used by initrd generator.

For now, just dirty fix the generated filename.

Fixes: 648c256b90
(cherry picked from commit 4ca7fa7f4a)
2018-10-19 12:39:53 +02:00
Thomas Haller
3a368f351b keyfile: merge branch 'th/nm-1-14-keyfile-changes'
https://github.com/NetworkManager/NetworkManager/pull/237
2018-10-19 10:14:50 +02:00
Thomas Haller
7685cf2840 keyfile: write keyfiles to "/run" directory with ".nmconnection" file suffix
For profiles in "/etc/NetworkManager/system-connections", we did not enforce
that the keyfiles have a special suffix, nor did we generate the
filenames in such a manner. In hindsight, I think that was a mistake.

Recently we added "/run/NetworkManager/system-connections" as additional
keyfile directory. Enforce a suffix and write keyfiles with such a name.

In principle, we could also start writing keyfiles in /etc with the
same suffix. But let's not do that, because we anyway cannot enforce
it.

An ugly part is, that during `nmcli connection load` we need to
determine whether the to-be-loaded connection is under /etc or /run.
Preferably, we would allow any kind of symlinking as what matters
is the file object (inode) and not the path. Anyway, we don't do
that but compare plain paths. That means, paths which are not
in an expected form, will be rejected. In particular, the paths
starting with "/run/..." and "/var/run/..." will be treated differently,
and one of them will be rejected.

Note that ifcfg-rh plugin strictly enforces that the path
starts with IFCFG_DIR as well. So, while this is a breaking
change for keyfile, I think it's reasonable.

(cherry picked from commit 648c256b90)
2018-10-19 00:14:54 +02:00
Thomas Haller
ae5a09d720 keyfile: split automatically setting ID/UUID for keyfile
keyfile already supports omitting the "connection.id" and
"connection.uuid". In that case, the ID would be taken from the
keyfile's name, and the UUID was generated by md5 hashing the
full filename.

No longer do this during nm_keyfile_read(), instead let all
callers call nm_keyfile_read_ensure_*() to their liking. This is done
for two reasons:

 - a minor reason is, that one day we want to expose keyfile API
   as public API. That means, we also want to read keyfiles from
   stdin, where there is no filename available. The implementation
   which parses stdio needs to define their own way of auto-generating
   ID and UUID. Note how nm_keyfile_read()'s API no longer takes a
   filename as argument, which would be awkward for the stdin case.

 - Currently, we only support one keyfile directory, which (configurably)
   is "/etc/NetworkManager/system-connections".
   In the future, we want to support multiple keyfile dirctories, like
   "/var/run/NetworkManager/profiles" or "/usr/lib/NetworkManager/profiles".
   Here we want that a file "foo" (which does not specify a UUID) gets the
   same UUID regardless of the directory it is in. That seems better, because
   then the UUID won't change as you move the file between directories.
   Yes, that means, that the same UUID will be provided by multiple
   files, but NetworkManager must already cope with that situation anyway.
   Unfortunately, the UUID generation scheme hashes the full path. That
   means, we must hash the path name of the file "foo" inside the
   original "system-connections" directory.
   Refactor the code so that it accounds for a difference between the
   filename of the keyfile, and the profile_dir used for generating
   the UUID.

(cherry picked from commit 837d44ffa4)
2018-10-19 00:14:54 +02:00
Thomas Haller
0642fc2d35 keyfile: refactor setting default ID/UUID in nm_keyfile_read()
Split out the functionality for auto-detecting the ID and UUID of
a connection. First of all, nm_keyfile_read() is already overcomplicated.
The next commit will require the caller to explicitly call these
functions.

(cherry picked from commit 02c8844178)
2018-10-19 00:14:54 +02:00
Thomas Haller
1460ce9f51 keyfile: refactor check whether filename starts with a dot
check_prefix() was only ever called with "." as prefix.
Simplify the implementation to explicitly check for a leading
dot.

(cherry picked from commit 2e5985f2e9)
2018-10-19 00:14:54 +02:00
Thomas Haller
8db02e240b keyfile: move file permission check of keyfile to helper function
(cherry picked from commit 345c91a0a4)
2018-10-19 00:14:54 +02:00
Thomas Haller
12f78af0ec keyfile/tests: assert against auto generated UUID for keyfile
The algorithm for generating the UUID must be stable. Assert
against that.

(cherry picked from commit 2e0a95530f)
2018-10-19 00:14:54 +02:00
Thomas Haller
f8f7b3d160 keyfile/tests: drop unused variables
Fixes: e886e5364e
(cherry picked from commit 8de09bb119)
2018-10-19 00:14:54 +02:00
Thomas Haller
5b8e252d5c keyfile/tests: refactor loading of keyfiles in tests
(cherry picked from commit e886e5364e)
2018-10-19 00:13:08 +02:00
Thomas Haller
2c685fc3e0 shared: add nm_strndup_a() helper
(cherry picked from commit ba491a6674)
2018-10-19 00:13:08 +02:00
Thomas Haller
a1831d1832 man: document nmcli device connect behaviour
Already since 1.0.0 release and commit "3784678177 cli: create a connection
if none exist in 'nmcli dev connect' (rh #1113941)", device-connect can
also create a profile.

That is useful, in particular as opposed to

  $ nmcli connection up ifname "$DEVICE"

which wouldn't create a profile (ever).

Document it.

(cherry picked from commit 1b732e28f7)
2018-10-17 18:19:08 +02:00
Lubomir Rintel
7f173bcfdf initrd/cmdline-reader: fix whitespace errors
Detected by checkpatch.pl

(cherry picked from commit ecde3e9034)
2018-10-17 17:13:01 +02:00
Beniamino Galvani
065551c634 initrd: enable meson builds
(cherry picked from commit 470c5c0a82)
2018-10-17 17:13:00 +02:00
Lubomir Rintel
03e1a2559d manager: initialize a potentially uninitialized variable
(cherry picked from commit a82e9083c1)
2018-10-17 17:13:00 +02:00
Lubomir Rintel
45f7d05629 initrd-generator: add a missing include
(cherry picked from commit 7c270f0860)
2018-10-17 17:07:57 +02:00
Lubomir Rintel
f6c37b6f14 man/NetworkManager: document --configure-and-quit option
(cherry picked from commit 9dab0a5eba)
2018-10-17 17:07:23 +02:00
Lubomir Rintel
9e5d19f38b build: disable ibft settings plugin by default
(cherry picked from commit 298f698c9e)
2018-10-17 17:07:23 +02:00
Lubomir Rintel
bfd7d79fe1 initrd: add configuration generator
nm-initrd-generator scans the command line for options relevant to network
configuration and creates configuration files for an early instance of
NetworkManager run from the initial ramdisk during early boot.

(cherry picked from commit 9f9609555d)
2018-10-17 17:07:21 +02:00
Lubomir Rintel
2a65d1bb80 initrd: add command line parser
(cherry picked from commit ecc074b2f8)
2018-10-17 17:06:29 +02:00
Lubomir Rintel
c24e505b6a initrd: add iBFT reader
This is loosely based on nms-ibft-reader, but with some significant
changes. Notably, it parses /sys/firmware/ibft directly instead of
iscsiadm output.

iscsiadm is not available on early boot (perhaps it's too large) and
turns out that parsing sysfs directly is easier and more
straightforwared anyways. A win-win situation.

It is not useful alone, it's in a separate commit just for the sake of
easier review.

(cherry picked from commit b544f7243d)
2018-10-17 17:06:29 +02:00
Lubomir Rintel
ed6b734297 config: add --configure-and-quit=initrd mode
We need a mode that:

* doesn't leave processes behind
* doesn't force an internal dhclient
* doesn't auto-generate default connections
* doesn't write out files into libdir, only /run

The original configure-and-quit mode doesn't really fit the initrd use. But
it's proobably not a good idea to just change its behavior.

(cherry picked from commit c263f5355c)
2018-10-17 17:06:29 +02:00
Lubomir Rintel
35056e426d dbus: don't even bother connecting in configure-and-quit mode
It makes no sense, results in unnecessary complexity both in code and in
code comments.

(cherry picked from commit e03d9ad1e0)
2018-10-17 17:06:18 +02:00
Lubomir Rintel
10a5185770 keyfile: write in-memory connections to /run
This is useful for in-memory connections to persist NetworkManager
restarts (as opposed to machine restarts).

Perhaps most improtantly, this allows generating in-memory connections outside
NetworkManager, e.g. passing configuration from early boot firmware in initrd.

Note that this does *not* aspire to do more than it says on the tin:
Notably, it doesn't touch the problem of provisioning connections in multiple
persistent connection directories and thus doesn't have to deal with the
problem of deleting or overlaying the connections tha (rh #772414) deals
with.

(cherry picked from commit ce4dbd7daf)
2018-10-17 17:05:05 +02:00
Lubomir Rintel
5865d01117 manager: don't save deactivating connections in the state file
Especially with configure-and-quit, it's easy to encounter a condition,
where the device reached a failed state, policy decides to quit, but the
active connection is not yet torn down from the device.

Upon the next start NetworkManager would think the connection succeeded
activating.

(cherry picked from commit e98ebc7e3b)
2018-10-17 17:05:05 +02:00
Lubomir Rintel
a3686b1dda dns: don't let the plugins assert the bus manager has a connection
Make them just ask for connections from GDBus, as other D-Bus clients
do. GDBus anyway reuses the connection if it has one, but allows us to
deal with errors in a more civilized manner.

(cherry picked from commit e1fc005239)
2018-10-17 17:05:05 +02:00
Lubomir Rintel
cd1c9108cc devices: make sure the generated connections are normalized
Using these unormalized was wrong all along, but by chance didn't hit
paths that needed normalized connections. This may change if we
actually write in memory connections to /run with the keyfile plugin,
because that one wants them normalized.

This also saves some work, because normalization does boring things for
us, such as adding default ipv4/ipv6/proxy settings everywhere.

(cherry picked from commit 89d1c9fb30)
2018-10-17 17:05:05 +02:00
Lubomir Rintel
0c10ae713b core/setting: don't assume we have a connection when synthesizing a property
nm_setting_to_string() operates on the setting alone, without a
connection. Tolerate that.

This fixed nm_connection_dump(vlan_connection).

(cherry picked from commit c39b134da1)
2018-10-17 17:05:05 +02:00
Lubomir Rintel
4890f943bd build: drop unused SBINDIR
(cherry picked from commit acbeda57fc)
2018-10-17 17:05:05 +02:00
Lubomir Rintel
58c13e7799 config: change formatting for no reason
(cherry picked from commit 639a45f6c3)
2018-10-17 17:05:05 +02:00
Lubomir Rintel
ee6b737c53 device: don't leave dhclient running upon device removal
Leaving processes behind is a no-no for early boot, but probably a wrong
thing to do in any other cases either.

(cherry picked from commit 47b877a7a6)
2018-10-17 17:05:05 +02:00
Lubomir Rintel
8c8e712d87 dhcp: save root-path in the state file
On networked boot we need to somehow communicate this to the early boot
machinery. Sadly, no DBus there and we're running in configure-and-quit
mode.

Abusing the state file for this sounds almost reasonable and is
reasonably straightforward thing to do.

(cherry picked from commit 55d24ba94e)
2018-10-17 17:05:05 +02:00
Thomas Haller
a6387156c2 release: fix spelling in NEWS file
(partially cherry picked from commit 58510ed566)
2018-10-17 16:58:38 +02:00
Thomas Haller
fa8ffd0a5b release: update NEWS 2018-10-17 16:55:27 +02:00
Thomas Haller
d237cec2f8 cli: merge branch 'th/cli-fix-serial-properties'
https://github.com/NetworkManager/NetworkManager/pull/233

(cherry picked from commit 92696036d2)
2018-10-17 16:46:37 +02:00
Thomas Haller
632effb2e5 cli/tests: add test for adding and displaying gsm/serial settings
(cherry picked from commit 1b4f765c59)
2018-10-17 16:45:03 +02:00
Thomas Haller
051a53db60 tests: support UInt64 type in test-networkmanager-service.py
and also accept "gsm" connection-type. Both will be used next.

(cherry picked from commit 0f503efd64)
2018-10-17 16:39:16 +02:00
Thomas Haller
3b782ece71 cli: minor cleanup of _set_fcn_gobject_enum()
No need to check again the gtype_class. We did it above already.

(cherry picked from commit 085105fc0e)
2018-10-17 16:39:16 +02:00
Thomas Haller
7c78398d3e cli: fix setting "serial.parity" enum
The meta data type descriptor must set .get_gtype only for
GObject properties which are of type int or uint. That is, when
the enum type cannot be automatically detected.

However, NM_SETTING_SERIAL_PARITY is a g_param_spec_enum()
of type NM_TYPE_SETTING_SERIAL_PARITY, so setting the get_gtype()
hook is wrong and leads to a crash

   $ /bin/nmcli connection add type gsm autoconnect no con-name t ifname '*' apn xyz serial.parity 5

   (process:11086): libnmc-CRITICAL **: 15:04:35.180: file clients/common/nm-meta-setting-desc.c: line 1283 (_set_fcn_gobject_enum): should not be reached
   Segmentation fault (core dumped)

That is because the enum property setter does:

    »···if (   has_gtype
    »···    && NM_IN_SET (gtype_prop,
    »···                  G_TYPE_INT,
    »···                  G_TYPE_UINT)
    »···    && G_TYPE_IS_CLASSED (gtype)
    »···    && (gtype_class = g_type_class_ref (gtype))
    »···    && (   (is_flags = G_IS_FLAGS_CLASS (gtype_class))
    »···        || G_IS_ENUM_CLASS (gtype_class))) {
    »···»···/* valid */

meaning, it only allows "has_gtype" if the native "gtype_prop" is
G_TYPE_INT or G_TYPE_UINT.

Fixes: 9a68123827
(cherry picked from commit 127ac25ef8)
2018-10-17 16:39:16 +02:00
Thomas Haller
1b987a5366 cli: fix handling uint64 connection property "serial.send-delay"
libnm currently has only one GObject property of type uint64:
"serial.send-delay". However, it's broken because uint64 handling
is not implemented.

    $ nmcli connection add type gsm autoconnect no con-name t ifname '*' apn 'xyz' serial.baud 5
    Connection 't' (4c929f17-9fda-41d6-8f90-897f6d46b078) successfully added.

    $ nmcli connection show t
    ...
    ipv6.dhcp-duid:                         --
    ipv6.dhcp-send-hostname:                yes
    ipv6.dhcp-hostname:                     --
    ipv6.token:                             --

    (process:14016): libnmc-CRITICAL **: 14:08:32.591: file clients/common/nm-meta-setting-desc.c: line 811 (_get_fcn_gobject_int): should not be reached
    serial.baud:                            5
    serial.bits:                            8
    serial.parity:                          none
    serial.stopbits:                        1
    serial.send-delay:                      --
    gsm.number:                             *99#
    ...

    $ nmcli connection add type gsm autoconnect no con-name t ifname '*' apn 'xyz' serial.baud 5 serial.send-delay 100

    (process:14852): libnmc-CRITICAL **: 14:12:24.259: file clients/common/nm-meta-setting-desc.c: line 1131 (_set_fcn_gobject_int): should not be reached
    Segmentation fault (core dumped)

Fixes: b6d9bdcee8
(cherry picked from commit a600b3a3b2)
2018-10-17 16:39:16 +02:00
Thomas Haller
79ddb280de shared: add _nm_utils_ascii_str_to_uint64() helper
(cherry picked from commit c0d292d255)
2018-10-17 16:39:16 +02:00
Thomas Haller
78cca81c45 core: merge branch 'th/device-availability'
https://bugzilla.redhat.com/show_bug.cgi?id=1639254

(cherry picked from commit 9cf64e2ee2)
2018-10-17 15:54:48 +02:00
Thomas Haller
38ed054acd core: ignore unmanaged devices for explicit activation request depending on multi-connect
When a device is unmanaged, an explicit activation request can
still activate it. In particular, that is the case for

  $ nmcli connection up "$PROFILE" ifname "$DEVICE"

It is also the case, for plain

  $ nmcli connection up "$PROFILE"

where NetworkManager searches for a suitable device -- depending on
multi-connect setting of the profile.

The idea is, that a profile with "multi-connect=single" is expected
to sufficently and uniquely match a device, based on matching properties
like "connection.interface-name". In that case, an explicit activation
request from the user shows the intent to manage the device.
Note that it's hard to understand whether the profile really uniquely
selects a particular device. For example, if the profile doesn't specify
"connection.interface-name", it might still uniquely identify
an ethernet device, if you only have one such device.

On the other hand, with "connection.multi-connect" other than "single",
it is very much expected that the profile does not strictly match
one device.

Change the behavior here for multi-connect profiles. This allows the
user to block individual devices from activation via

  $ nmcli device set "$DEVICE" managed not

A subsequent

  $ nmcli connection up "$MULTI_PROFILE"

will not consider "$DEVICE" as suitable candidate for activation.

Likewise, in the future we may want to add a

  $ nmcli connection up --all "$MULTI_PROFILE"

command, to activate the profile on all suitable device.
In that case again, unmanaged devices probably also should be skipped
for multi-connect profiles.

https://bugzilla.redhat.com/show_bug.cgi?id=1639254
(cherry picked from commit 0cb8bed23c)
2018-10-17 15:54:37 +02:00
Thomas Haller
de8aa07f4f device: add and use overrule-unmanaged flag for nm_device_check_connection_available()
This flag is more granular in whether to consider the connection
available or not. We probably should never check for the combined
flag NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST directly, but
always explicitly for the relevant parts.

Also, improve the error message, to indicate whether the device is
strictly unmanaged or whether it could be overruled.

(cherry picked from commit 920346a5b9)
2018-10-17 15:54:33 +02:00
Thomas Haller
2c7f986b81 device: cleanup checking device avilability for ignoring carrier
The flags NMDeviceCheckConAvailableFlags and NMDeviceCheckDevAvailableFlags
both control whether a device appears available (either, available in
general, or related to a particular profile).

Also, both flag types strictly increase availability. Meaning: more flags,
more available.

There is some overlap between the flags, however they still have
their own distinct parts.

Improve the mapping from NMDeviceCheckConAvailableFlags to
NMDeviceCheckDevAvailableFlags, by picking exactly the flags
that are relevant.

(cherry picked from commit 5412fd389b)
2018-10-17 15:54:03 +02:00
Thomas Haller
0e2f08165d core/trivial: add code comment for NMDeviceCheckDevAvailableFlags and NMDeviceCheckConAvailableFlags
(cherry picked from commit e6523fbbbc)
2018-10-17 15:54:03 +02:00
Thomas Haller
477cde3a10 core/trivial: add code comment for nm_manager_get_best_device_for_connection()
(cherry picked from commit c37b028aba)
2018-10-17 15:54:03 +02:00
Thomas Haller
20f4c68fc6 core: fix checking multi-connect flag in nm_manager_get_best_device_for_connection()
We should not check @sett_conn, but @connection.

Fixes: 09719bc479
(cherry picked from commit 45913c11df)
2018-10-17 15:54:03 +02:00
Thomas Haller
559e9a79d9 core: improve selection of device when activating profile on any device
With

  $ nmcli connection up "$PROFILE" ifname "$DEVICE"

it's clear that the user means the particular device. That also
is taken as a indication to make $DEVICE as managed, in case it was
unmanaged before. So, this command implies a previous

  $ nmcli device set $DEVICE managed yes

On the other hand, if the user just issues

  $ nmcli connection up "$PROFILE"

without a particular device, then we should prefer devices which
are marked as managed instead of unmanaged once.

Likewise, we should consider the device's state when selecting
a device. This means, when activating a profile which is activatable on
multiple devices, it will now prefer devices which are not already
active. The exception to this is that if the profile itself is already
active (and multi-connect "single"), then it will prefer to re-activate
the profile on the same device. This was done previously already. What's
new is that if the the profile is not multi-connect "single", the said
exception no longer applies, and we prefer to activate the profile on a
hitherto unactivated device.

https://bugzilla.redhat.com/show_bug.cgi?id=1639254

https://github.com/NetworkManager/NetworkManager/pull/232
(cherry picked from commit 09719bc479)
2018-10-17 15:53:36 +02:00