Commit graph

11443 commits

Author SHA1 Message Date
Thomas Haller
395374cfbe device/trivial: rename device's sysctl function
These functions call platform's sysctl getter and setters.

Note that the called platform functions are called nm_platform_sysctl_get()
and nm_platform_sysctl_set(). Also, in this case they use the ip-conf path
via nm_utils_sysctl_ip_conf_path().

Also, next we will add API nm_platform_sysctl_ip_conf_get() and
nm_platform_sysctl_ip_conf_set(), which will be wrappers around
nm_platform_sysctl_get() and nm_platform_sysctl_set(), using the ip-conf
paths as well.

Rename the device functions, to be more similar to the existing and future
naming in platform.
2018-12-19 09:03:43 +01:00
Thomas Haller
d27fa36272 device: merge IPv4 and IPv6 variants of nm_device_ipv4_sysctl_set()
For one, next we will drop setting rp_filter, hence there are no
more users of an IPv4 variant and nm_device_ipv4_sysctl_set() would
have to be dropped anyway.

However, instead of doing that, merge the IPv4 and IPv6 variant.

With this, the fallback to the default is now also supported for IPv6
(though unused).

Also, don't access nm_device_get_ip_iface(). The interface name might
not be right, we should only rely on the ifindex. Load the interface
name from platform cache instead.
2018-12-19 08:58:50 +01:00
Thomas Haller
8b9fd01ef3 platform: use struct initializer instead of memset()
I think this is preferred over memset(), because it allows the
compiler to better unstand what is happening.

Also, strictly speaking in the C language, %NULL pointers are not
guaranteed to have an all zero bit pattern. Of course, that is already
required on any architecture where NetworkManager is running.
2018-12-19 08:58:12 +01:00
Thomas Haller
67f02b2a14 platform: assert length of stack allocation in NMP_SYSCTL_PATHID_NETDIR_unsafe()
NMP_SYSCTL_PATHID_NETDIR_unsafe() uses alloca() to allocate the string.
Assert that the "path" argument is reasonably short.

In practice, that is of course the case, because there are only 2 callers
which take care not to pass an untrusted, unbounded path argument.
2018-12-19 08:56:51 +01:00
Aleksander Morgado
6ed21e8342 settings,gsm: deprecate and stop using 'number' property
The 'number' property in GSM settings is a legacy thing that comes
from when ModemManager used user-provided numbers, if any, to connect
3GPP modems.

Since ModemManager 1.0, this property is completely unused for 3GPP
modems, and so it doesn't make sense to use it in the NetworkManager
settings. Ofono does not use it either.

For AT+PPP-based 3GPP modems, the 'number' to call to establish the
data connection is decided by ModemManager itself, e.g. for standard
GSM/UMTS/LTE modems it will connect a given predefined PDP context,
and for other modems like Iridium it will have the number to call
hardcoded in the plugin itself.

https://github.com/NetworkManager/NetworkManager/pull/261
2018-12-19 08:54:50 +01:00
Thomas Haller
f877ba8c04 core: avoid calling platform code with invalid ifindex (5)
https://bugzilla.redhat.com/show_bug.cgi?id=1659790

Fixes: 945c904f95
2018-12-16 20:34:45 +01:00
Aleksander Morgado
90e9695af5 wwan: rework when settings/device are blocked for autoconnection
The reasons to block autoconnection at settings level are not the same
as the ones to block autoconnection at device level.

E.g. if the SIM-PIN is wrong, you may want to block autoconnection
both at settings level (as the PIN configured in settings is wrong)
and at device level (so that no other setting is tried automatically).

For some other reasons, you may want to block autoconnection only at
setting level (e.g. wrong APN).

And for some other reasons you may want to block autoconnection at
device level only (e.g. SIM missing), so that the autoconnection
blocking is removed when the device goes away. This is especially
important with SIM hotplug events processed by ModemManager, as a
device without SIM will be removed from MM when a new SIM is
inserted, so that a completely new object is exposed in MM with the
newly detected SIM.

https://github.com/NetworkManager/NetworkManager/pull/259
2018-12-14 14:25:36 +01:00
Thomas Haller
672852c4d3 dhcp: support generating DHCP client-id/duid for infiniband
https://bugzilla.redhat.com/show_bug.cgi?id=1658057
2018-12-14 13:49:54 +01:00
Thomas Haller
6e48e99be4 core: add nm_utils_detect_arp_type_from_addrlen() helper
and use it in "nm-dhcp-systemd.c".
2018-12-14 09:53:47 +01:00
Beniamino Galvani
0819563e01 ifcfg-rh: fix reading SR-IOV settings
Fixes: d48f389cbf
2018-12-13 18:06:43 +01:00
Aleksander Morgado
87bed48974 devices,bluetooth: fix default CDMA number setting
https://github.com/NetworkManager/NetworkManager/pull/260

Fixes: 215306f5a1
2018-12-13 16:58:05 +01:00
Thomas Haller
b1082aa9a7 device: disable rp_filter handling
Don't let NetworkManager change rp_filter sysctl [1]. By default, various
distributions set rp_filter rather strict. That works badly, in common cases
where the user connects multiple interfaces to the same IP network (for
example, using Wi-Fi and ethernet in your home network). It also confuses
connectivity checking. For that reason, NetworkManager would loosen the
rp_filter setting.

However, that was not configurable and users who really wanted a strict
setting could not prevent NetworkManager from doing it ([2], [3], [4]).

Hence it was decided, that a better solution is for NetworkManager not
to do anything about rp_filter. Instead, distibutions should not enable
it strictly (or at least, only for certain setups where it makes sense
-- if it ever makes sense) ([5], [6]);

Disble this behavior for the moment. In the future, the code will be
removed entirely.

[1] https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1492472
[4] https://bugzilla.redhat.com/show_bug.cgi?id=1593194
[3] https://bugzilla.redhat.com/show_bug.cgi?id=1651097
[5] https://bugzilla.redhat.com/show_bug.cgi?id=1653824
[6] https://github.com/systemd/systemd/pull/10971

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1651097
2018-12-13 14:23:07 +01:00
Beniamino Galvani
a3383726dc settings: apply agent-owned secrets from the new connection on update
When updating a connection passing agent-owned secret, they are lost
from @reread_connection after the settings-plugin persists the
connection. Therefore we need to cache and reapply them separately to
the connection so that they can be saved to secret agents later.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/82
2018-12-13 11:14:21 +01:00
Benjamin Berg
1371414e3d supplicant: Add methods to start/stop a P2P Find operation
The timeout is limited to be in the range of 1-600s. This is arbitrary,
but the point is that a timeout of 0 is not permitted to prevent a
client from making us run a find continuously simply by forgetting to
call the stop method.
2018-12-13 09:20:55 +01:00
Benjamin Berg
c05aa3b309 supplicant: Add API to join/cancel/disconnect a P2P Group 2018-12-13 09:20:55 +01:00
Benjamin Berg
6352213e16 supplicant: Export group path of active group
This can be used to check whether a peer is joined to our group.
2018-12-13 09:20:55 +01:00
Benjamin Berg
f05b7a78c9 supplicant: Track P2P Group information, creation and destruction
Add basic tracking of P2P group information and the creation and
destruction of them.
2018-12-13 09:20:55 +01:00
Benjamin Berg
15b7b36718 supplicant: Allow creating an interface from object path
wpa_supplicant will create a new interface for P2P devices. In this case
we need to fetch the supplicant interface using the object path and then
fetch the interface name via dbus to setup the IP interface of the P2P
device later.
2018-12-13 09:20:55 +01:00
Benjamin Berg
08c28ef96b supplicant: Monitor existance of P2P Peers found 2018-12-13 09:20:55 +01:00
Benjamin Berg
ae22631d66 supplicant: Connect to P2PDevice supplicant interface
The wpa_supplicant interface has a P2PDevice when P2P is supported.
Create a proxy for this and wait for it to be ready before marking the
interface as ready.
2018-12-13 09:20:55 +01:00
Benjamin Berg
e2a99cabda supplicant: Detect P2P and WFD support
Add detection for P2P and WFD support in wpa_supplicant and pass the
information to the NMSupplicantInterface.
2018-12-13 09:20:55 +01:00
Benjamin Berg
55407fd027 supplicant: Handle interface removal
The signal was not handled, potentially creating corner cases where
NetworkManager may not notice an interface removal. Add a handler and
ensure the supplicant interface is brought down when it is removed from
wpa_supplicant for a reason other than NetworkManager requesting it.
2018-12-13 09:20:55 +01:00
Thomas Haller
b16e09a707 core: use streq() instead of strcmp() for comparing ip-config methods
Refactor some code to use nm_streq() and NM_IN_STRSET() instead of
strcmp().

Note that nm_utils_get_ip_config_method() never returns %NULL (not even
with g_return*() assertion failures). nm_streq() is sufficent.
2018-12-13 09:16:32 +01:00
Thomas Haller
589063db3b core: use addr-family argument for nm_utils_get_ip_config_method()
Recently, more and more code was refactored to use an addr_family
integer to distinguish between IPv4 and IPv6.

Refactor nm_utils_get_ip_config_method() and nm_device_get_effective_ip_config_method()
to do that too. If we use different identifiers, we need to translate from one to
another and its inconsistent. Also, accessing a GType is an unnecessary function call,
instead of a plain constant.
2018-12-13 09:16:32 +01:00
Benjamin Berg
adbb9eb246 core: allow devices to modify the meaning of the AUTO IP config method
For P2P wifi we need to do DHCP if we are a peer or provide DHCP if we
are the group owner. This may only be decided while establishing the
connection, making the meaning of the AUTO method dynamic.

This adds a way for the device subclass to override the meaning of AUTO.

Patch cherry picked early from [1].

[1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/24
2018-12-13 09:14:27 +01:00
Beniamino Galvani
1e41495d9a platform: sriov: write new values when we can't read old ones
Fixes: 7df3333879
2018-12-12 14:38:18 +01:00
Beniamino Galvani
e01a7c1154 core: use NMTernary for SR-IOV autoprobe-drivers 2018-12-12 14:38:18 +01:00
Beniamino Galvani
d48f389cbf ifcfg-rh: fix persisting sriov setting
The writer should write all properties of the sriov setting when the
setting exists without additional logic. Likewise, the reader should
instantiate a sriov setting when any sriov key is present and blindly
set properties from keys.

The old code did not always preserve the presence of a sriov setting
after a write/read cycle.

Fixes: c02d1c488f
2018-12-12 14:20:32 +01:00
Beniamino Galvani
529533a50c device: reset SR-IOV VFs on deactivation
If the connection has a sriov setting we configure SR-IOV VFs on
activation. We should also clear resources when the connection
deactivates.
2018-12-12 14:18:53 +01:00
Beniamino Galvani
75024e11b3 device: configure static number of VFs in unavailable state
Don't configure the static number of VFs when the device is realized
because the device could still be unmanaged. Instead, do it when the
device becomes managed.
2018-12-12 14:18:53 +01:00
Beniamino Galvani
769e0726a8 cli: strictly validate SR-IOV attributes
Report an error when the user tries to add an unknown attribute
instead of silently accepting (and ignoring) it.

Note that this commit also changes the behavior of public API
nm_utils_sriov_vf_from_str() to return an error when an unknown
attribute is found. I think the previous behavior was buggy as wrong
attributes were simply ignored without any way for the user to know.

Fixes: a9b4532fa7
2018-12-12 14:18:53 +01:00
Thomas Haller
a68d027ba4 core: never fail reading host-id timestamp and never change it
The timestamp of the host-id is the timestamp of the secret_key file.
Under normal circumstances, reading the timestamp should never fail,
and reading it multiple times should always yield the same result.

If we unexpectedly fail to read the timestamp from the file we want:

- log a warning, so that the user can find out what's wrong. But
  do so only once.

- we don't want to handle errors or fail operation due to a missing
  timestamp. Remember, it's not supposed to ever fail, and if it does,
  just log a warning and proceed with a fake timestamp instead. In
  that case something is wrong, but using a non-stable, fake timestamp
  is the least of the problems here.
  We already have a stable identifier (the host-id) which we can use to
  generate a fake timestamp. Use it.

In case the user would replace the secret_key file, we also don't want
that accessing nm_utils_host_id_get_timestamp*() yields different
results. It's not implemented (nor necessary) to support reloading a
different timestamp. Hence, nm_utils_host_id_get_timestamp() should
memoize the value and ensure that it never changes.
2018-12-12 14:03:35 +01:00
Thomas Haller
e9887d4816 core: split initializing host-id singleton out of nm_utils_host_id_get() 2018-12-12 12:52:55 +01:00
Thomas Haller
d693e03a74 core/trivial: rename nm_utils_get_boot_id_*()
Rename to nm_utils_boot_id_*(), it matches nm_utils_machine_id_*()
and nm_utils_host_id_get().
2018-12-12 12:52:55 +01:00
Thomas Haller
6ffcd26317 core/trivial: rename secret-key to host-key
Now that the secret-key is hashed with the machine-id, the name is
no longer best.

Sure, part of the key are persisted in /var/lib/NetworkManager/secret_key
file, which the user is well advised to keep secret.

But what nm_utils_secret_key_get() returns is first and foremost a binary
key that is per-host and used for hashing a per-host component. It's
really the "host-id". Compare that to what we also have, the
"machine-id" and the "boot-id".

Rename.
2018-12-12 12:52:55 +01:00
Thomas Haller
bc9f18c609 core: fix race creating secret-key
Reading the secret key may result in generating and
writing a new key to disk.

Do that under the lock.
2018-12-12 09:43:07 +01:00
Thomas Haller
deb19abf22 core: combine secret-key with /etc/machine-id
NetworkManager loads (and generates) a secret key as
"/var/lib/NetworkManager/secret_key".

The secret key is used for seeding a per-host component when generating
hashed, stable data. For example, it contributes to "ipv4.dhcp-client-id=duid"
"ipv6.addr-gen-mode=stable-privacy", "ethernet.cloned-mac-address=stable", etc.
As such, it corresponds to the identity of the host.

Also "/etc/machine-id" is the host's identity. When cloning a virtual machine,
it may be a good idea to generate a new "/etc/machine-id", at least in those
cases where the VM's identity shall be different. Systemd provides various
mechanisms for doing that, like accepting a new machine-id via kernel command line.
For the same reason, the user should also regenerate a new NetworkManager's
secrey key when the host's identity shall change. However, that is less obvious,
less understood and less documented.

Support and use a new variant of secret key. This secret key is combined
with "/etc/machine-id" by sha256 hashing it together. That means, when the
user generates a new machine-id, NetworkManager's per-host key also changes.

Since we don't want to change behavior for existing installations, we
only do this when generating a new secret key file. For that, we encode
a version tag inside the "/var/lib/NetworkManager/secret_key" file.

Note that this is all abstracted by nm_utils_secret_key_get(). For
version 2 secret-keys, it internally combines the secret_key file with
machine-id (via sha256). The advantage is that callers don't care that
the secret-key now also contains the machine-id. Also, since we want to
stick to the previous behavior if we have an old secret-key, this is
nicely abstracted. Otherwise, the caller would not only need to handle
two per-host parts, but it would also need to check the version to
determine whether the machine-id should be explicitly included.
At this point, nm_utils_secret_key_get() should be renamed to
nm_utils_host_key_get().
2018-12-12 09:42:17 +01:00
Thomas Haller
2c7c333297 core: use define for secret_key filename 2018-12-12 08:22:12 +01:00
Thomas Haller
7b9cd2e3d7 core: fix printing error for failure reading secret-key
g_file_get_contents() fails with G_FILE_ERROR, G_FILE_ERROR_NOENT when the
file does not exist.

That wasn't obvious to me, nm_utils_error_is_notfound() to the rescue.

Fixes: dbcb1d6d97
2018-12-12 08:22:12 +01:00
Thomas Haller
a7ef23b326 core: fix match spec behavior for a list of all "except:"
If the spec specifies only negative matches (and none of them matches),
then the result shall be positive.

Meaning:

    [connection*] match-device=except:dhcp-plugin:dhclient
    [connection*] match-device=except:interface-name:eth0
    [.config] enabled=except:nm-version:1.14

should be the same as:

    [connection*] match-device=*,except:dhcp-plugin:dhclient
    [connection*] match-device=*,except:interface-name:eth0
    [.config] enabled=*,except:nm-version:1.14

and match by default. Previously, such specs would never yield a
positive match, which seems wrong.

Note that "except:" already has a special meaning. It is not merely
"not:". That is because we don't support "and:" nor grouping, but all
matches are combined by an implicit "or:". With such a meaning, having
a "not:" would be unclear to define. Instead it is defined that any
"except:" match always wins and makes the entire condition to explicitly
not match. As such, it makes sense to treat a match that only consists
of "except:" matches special.

This is a change in behavior, but the alternative meaning makes
little sense.
2018-12-11 13:58:24 +01:00
Thomas Haller
d48904c9a9 src/tests: add test for except match spec 2018-12-11 13:20:55 +01:00
Thomas Haller
1bff602c46 device: fix matching device-spec for DHCP plugin
https://bugzilla.redhat.com/show_bug.cgi?id=1658057

Fixes: b9eb264efe
2018-12-11 12:43:39 +01:00
Thomas Haller
54ebe32f68 connectivity: consider default route for global connectivity state
When we agregate the connectivity state, only devices that
have the best default route should be considered.

Since we do connectivity checking per-device, the per-device check
does not care whether traffic to the internet is really routed via this
device.

But when talking about the global connectivity state, we care mostly
about the (best) default route. So, we should not allow a device with
worse or now default route, to contribute its connectivity state.

Fixes: 6b7e9f9b22
2018-12-11 09:23:47 +01:00
Thomas Haller
128aec5c2e connectivity: issue connectivity check right away on configuration reload 2018-12-11 09:23:47 +01:00
Thomas Haller
1fac911cf0 connectivity: log address family for device's connectivity checks 2018-12-11 09:23:47 +01:00
Thomas Haller
3e04d5a715 connectivity: use 443 port for https URIs
If the URI does not specify a port, we always assumed "80". That is
wrong for https. Arguably, https is discouraged for connectivity checking,
but we still shouldn't break it.

Fixes: 9664f284a1
2018-12-11 09:23:47 +01:00
Thomas Haller
2e8ea1f1da connectivity: ensure uri and response stays alive during connectivity check
The settings of NMConnectivity can change any time, by reloading the
configuration.

When reloading the configration, we don't want to interrupt or cancel
the pending reuqests, they should just complete with the old settings with
which they started. Note, that NMDevice is smart enough, that when a
newer request completes earlier, it invalidates all older, still pending
requests.

Anyway, that means, we cannot rely on the value to stay alive. Fix that,
by adding adding a new ref-counted struct for these parameters.

Fixes: 2cec94bacc
2018-12-11 09:23:47 +01:00
Thomas Haller
1156074a96 connectivity: improve warning about URI config change
During a config change notification, we determine a "changed" value,
to know whether things significantly changed.

Also, we want to log a warning about invalid configuration,
only when the config actually changed. Previously, when the URI was
invalid, on every reload (SIGHUP) we would log an error message,
even if the configuration did not change. There is no need to
warn multiple times about the same thing.

Keep track of the original URI in priv->uri. Whenever that changed,
we know the user reconfigured something. But also, now the URI might
be set to an invalid value. That means, we need to remember whether
the URI is valid.

Also, log a warning if we fail to parse the host and port. Already
before, such an URI was considered invalid and we would effectively
not to connectivity checking.
2018-12-11 09:23:47 +01:00
Thomas Haller
77fbe191fd connectivity: various cleanup in resolve_cb()
- use cleanup attribute except explicit free/unref.

- check that the result has the expected address family.
  Arguably, it should always, unless there is a bug in systemd-resolved.
  By that reasoning, we also wouldn't have to check the address length
  either.

- don't use strndup() for values that are later freed by g_free().
  We should always agree whether to malloc/free or g_malloc/g_free.

- don't use strcasecmp(). Always use the locale independent g_ascii_strcasecmp()
  instead.

- use nm_utils_inet_ntop() instead of inet_ntop(). It's our preferred
  wrapper, which as a stricter semantic (for example, it cannot fail
  and it's input arguments are stricter defined).

- use nm_clear_g_free() instead of g_clear_pointer().
2018-12-11 09:23:47 +01:00
Thomas Haller
c7d8864511 connectivity: honor "main.systemd-resolved" setting to not resolve names first
If the user disabled systemd-resolved, two things seem apparent:

 - the user does not want us to use systemd-resolved

 - NetworkManager is not pushing the DNS configuration to
   systemd-resoved.

It seems to me, we should not consult systemd-resolved in that case.
2018-12-11 09:23:47 +01:00