Commit graph

21243 commits

Author SHA1 Message Date
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
Lubomir Rintel
d7d085a88d po: update from Red Hat translators
https://bugzilla.redhat.com/show_bug.cgi?id=1608323
2018-10-16 16:30:11 +02:00
Thomas Haller
8c24119859 ndisc: merge branch 'th/ndisc-addr-lifetime'
https://github.com/NetworkManager/NetworkManager/pull/228

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/57
https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1796622

(cherry picked from commit 3baa016f89)
2018-10-13 17:39:32 +02:00
Thomas Haller
036d1f56ea ndisc: don't update dad_counter for addresses in router config
I am not sure, we ever call complete_address() for router-configurations.
Maybe not, so the dad-counter is never incremented and does not matter either.

If we however do, then we certainly want to preserve the DAD counter
when the address is already tracked.

(cherry picked from commit 8c6629b356)
2018-10-13 17:39:15 +02:00
Thomas Haller
8e2ccd3921 ndisc: fix updating address lifetime on Router Announcement according to RFC4862
This is a denial-of-service protection, where a malicious router
advertisement can expire the addresses.

See-also: 6554550f35
See-also: https://tools.ietf.org/search/rfc4862#section-5.5.3

https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1796622
(cherry picked from commit 27be3e0338)
2018-10-13 17:39:15 +02:00
Thomas Haller
fe60843232 ndisc: handle integer overflows better for lifetime handling
we use get_expiry() to compare two lifetimes. Note, that previously,
it would correctly truncate the calculated expiry at G_MAXINT32-1.

However, that means, that two different lifetimes that both lie
more than 68 years in the future would compare equal.

Fix that, but extending the range to int64, so that no overflow
can happen.

(cherry picked from commit b086535cb7)
2018-10-13 17:39:15 +02:00
Thomas Haller
3cecb4d018 ndisc: minor refactoring loop in nm_ndisc_add_address()
No change in behavior. Just don't do so much work inside
the deeper nesting of the loop.

(cherry picked from commit 9d0a138ef0)
2018-10-13 17:39:15 +02:00
Thomas Haller
ac5669633c ndisc: only generate address interface identifer after checking existing prefix
RFC4862 5.5.3, points d) and e) make it clear, that the list of
addresses should be compared based on the prefix.

  d)  If the prefix advertised is not equal to the prefix of an
    address configured by stateless autoconfiguration already in the
    list of addresses associated with the interface (where "equal"
    means the two prefix lengths are the same and the first prefix-
    length bits of the prefixes are identical), and if the Valid
    Lifetime is not 0, form an address (and add it to the list) by
    combining the advertised prefix with an interface identifier of
    the link as follows:

That means, we should not initialize the interface identifier first
(via complete_address()) and then search for the full address.

See-also: https://tools.ietf.org/search/rfc4862#section-5.5.3
(cherry picked from commit 23c417854a)
2018-10-13 17:39:15 +02:00
Thomas Haller
e0e698e463 ndisc: ensure we skip unspecified IPv6 address in ndisc_set_router_config()
Later, nm_ndisc_add_address() asserts that the address is not an
unspecified address. Skip it, just to be sure.

(cherry picked from commit 700b04d0de)
2018-10-13 17:39:15 +02:00