Commit Graph

24332 Commits

Author SHA1 Message Date
Thomas Haller
57d94e792f libnm: don't emit g_warning() from nm_utils_ip6_dns_from_variant()
The library should not print to stdout/stderr. This function is used to
convert untrusted(!!) input to a normalized and sanitized strv array.
g_warning() is essentially an assertion, and it's wrong to do that
for untrusted data. If the caller had to pre-validate the array, then
having this function would be pointless.
2019-10-27 14:30:51 +01:00
Thomas Haller
1cf4de20eb libnm: add comment about not-implement property NMDeviceVxlan:carrier
The server does not expose this property on D-Bus. It's always FALSE.
Add a comment about that.
2019-10-27 14:30:51 +01:00
Thomas Haller
6a0062e4ff libnm: add comment about not-implement property NMDeviceMacvlan:hw-address
The server does not expose this property on D-Bus. It's always NULL.
Add a comment about that.
2019-10-27 14:30:51 +01:00
Thomas Haller
3ed514cb60 libnm: change default value for NMClient:{networking,wireless-hardware}-enabled properties 2019-10-27 14:30:51 +01:00
Thomas Haller
91f3311e71 libnm: change default value for NMClient:dns-{mode,rc-manager} properties 2019-10-27 14:30:51 +01:00
Thomas Haller
c1ee10c4d9 libnm: change default value for NMDevice:mtu property
Default values should preferably be zero and/or a value that indicates
that the property is unknown/unset.

In practice, this property is not unset because it's present
on the D-Bus API.
2019-10-27 14:30:51 +01:00
Thomas Haller
b59954e355 libnm: change default value for NMDevice:autoconnect property
Yes, by default (server side) devices do autoconnect.
But that does not mean an NMObject, that has its GObject property
not set via D-Bus shall default to TRUE.

Default values preferably should be FALSE, because that is what we get
by default (memset(0)).
2019-10-27 14:30:51 +01:00
Thomas Haller
3f476b7a50 libnm: change default value for NMAccessPoint:mode property
NMAccessPoint is an NMObject, and exclusively created and initialized by
NMClient. In practice, the D-Bus property is always present on D-Bus, so
the default value is not used. However, a better default is anyway
"unknown", also because that has zero numeric value.
2019-10-27 14:30:51 +01:00
Thomas Haller
1c4acc89f1 shared: add NM_IS_REF_STRING() helper 2019-10-27 14:30:51 +01:00
Thomas Haller
a75dccad78 shared: add @deep_copied argument to nm_utils_strv_dup() 2019-10-27 14:30:51 +01:00
Thomas Haller
0bff8d7710 contrib: fix detection of whether being sourced in NM-log script 2019-10-26 14:22:44 +02:00
Beniamino Galvani
487b5df716 core: merge branch 'bg/prefix-route'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/312
https://bugzilla.redhat.com/show_bug.cgi?id=1700415
2019-10-24 11:19:18 +02:00
Beniamino Galvani
d6ee22d198 core: don't add prefix route for /32 addresses without peer
Kernel doesn't do it either, see function fib_add_ifaddr().
2019-10-23 21:52:48 +02:00
Beniamino Galvani
ea1679aac0 core: don't add prefix route for external addresses
If the user adds an address manually, kernel automatically adds a
prefix route for it unless the address has the NOPREFIXROUTE
flag. When ip_config_merge_and_apply() gets called, NM also adds its
prefix route and so we end up with two routes that differ only for the
metric.

This is a problem because the route added by NM is not removed if the
user removes the previously added address. Also, it seems confusing to
have multiple instances of the same routes.

This commit skips the addition of a prefix route for addresses added
manually outside of NetworkManager.
2019-10-23 21:46:26 +02:00
Beniamino Galvani
3eb2f435ae core: track whether IP addresses are external
Track whether IP addresses were added by NM or externally. In this way
it becomes possible in a later commit to add prefix route only for
addresses added by NM.
2019-10-23 17:44:38 +02:00
Beniamino Galvani
01920d3d52 device: allow reapply when the device is activating
Allow a reapply of the connection when the device is still activating
and ensure that each reapply action is performed only at a given
activation stage. For example, the IP configuration is not reactivated
if the device is in the prepare stage.

https://bugzilla.redhat.com/show_bug.cgi?id=1763062
2019-10-23 16:09:56 +02:00
Thomas Haller
dab1d780fd libnm: retire deprecated WiMAX NMObject types
WiMAX is deprecated since NetworkManager 1.2.0. Note that also
NetworkManager on server side no longer supports this type, hence
the server's D-Bus API will never expose devices of this type.

Note that NMDeviceWimax and NMWimaxNsp are NMObject types. That means,
they are instantiated by NMClient to represent information on the D-Bus
interface. As NetworkManager no longer exposes WiMAX devices, such
devices are never created. Note that it makes no sense that a user would
directly instantiate NMObject types, because they only work together with
NMClient.

Don't drop the related symbols and definitions from libnm, so that there
is no API/ABI change (as far as building and linking is concerned). But
make the types defunctional (which of course is a behavioral API change).
Calling the API now triggers a g_return_*() warning.

Also belatedly mark the WimaxNsp API as deprecated. It should have been
done in 1.2. Note that here we deprecate the API and retire it at the
same time. Optimally, we would have deprecated it a few releases ago,
before retiring it. However, marking something for deprecation is anyway
no excuse for anything. I mean, removing or retiring API is usually
painful, regardless whether it was marked for deprecation or not. In this
case, there is no possibility that a libnm user gets hold on a NMDeviceWimax
or NMWimaxNsp instance, because NMClient simply no longer instantiates
them. Hence, this change should not affect any user in practice.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/316
2019-10-23 15:31:51 +02:00
Thomas Haller
e346bdc550 device/wwan: merge branch 'afaure/protect-self-variable'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/303
2019-10-23 15:27:24 +02:00
Thomas Haller
ae21d851e8 device/wwan: fix leak of "error" variable in connect_ready()
Fixes: 105ee6e5a9 ('device: fix crash by handling connection cancellation')
2019-10-23 15:25:46 +02:00
Antoine Faure
105ee6e5a9 device: fix crash by handling connection cancellation 2019-10-23 15:23:52 +02:00
Thomas Haller
7efc3c479f dhcp: truncate client-id for n-dhcp4 client at arbitrary limit
RFC does not define how long the client ID can be. However,
n-dhcp4 enforces that the server replies with a client ID that
matches the request. Also, the client ID gets encoded as a DHCP
option, hence it cannot be longer than 255 bytes.

While n-dhcp4 doesn't enforce a certain length, a too long client
ID is not going to work. Hence, truncate it at 133 bytes.

This is the same limit that also systemd's DHCP client has. It's chosen
to fit an RFC4361-complient client ID with a DUID of length
MAX_DUID_LEN (which is 128 bytes according to RFC 3315 section 9.1).

Fixes-test: @ipv4_set_very_long_dhcp_client_id

See-also: https://github.com/nettools/n-dhcp4/pull/6

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/307
2019-10-23 14:58:13 +02:00
Thomas Haller
907bd28203 po/da: merge branch 'scootergrisen:patch-2' (#313)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/313
2019-10-23 13:53:36 +02:00
scootergrisen
fa8dc1c314 Fix missing \n 2019-10-23 05:07:14 +00:00
scootergrisen
03f51ef671 Update da.po 2019-10-23 03:20:00 +00:00
Thomas Haller
f2d3f29c73 libnm: merge branch 'th/libnm-hide-gobject-structs'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/314
2019-10-22 10:59:49 +02:00
Thomas Haller
57aa5e2a9d libnm: hide GObject structs from public API and embed private data
These types are all subclasses of NMObject. These instances are commonly
created by NMClient itself. It makes no sense that a user would
instantiate the type. Much less does it make sense to subclass them.

Hide the object and class structures from public API.

This is an API and ABI break, but of something that is very likely
unused.

This is mainly done to embed the private structure in the object itself.
This has benefits for performance and debugability. But most
importantly, we can obtain a static offset where to access the private data.
That means, we can use the information to access the data pointer
generically, as we will need later.

This is not done for the internal types NMManager, NMRemoteSettings,
and NMDnsManager. These types will be dropped later.
2019-10-22 10:58:52 +02:00
Thomas Haller
35b024acaa libnm: hide NMClient struct from public headers and use direct private field
Having the NMClient/NMClientClass structs in the public header allows
the user to subclass these types. Subclassing this type was never
intended, nor is it supported, nor does it seem useful. Subclassing only
makes sense if the type has suitable hooks to extend the type in a
meaningful way. NMClient hasn't, and everybody trying to derive from
this class would better delegate the actions.

Also, having these structs in the public header prevents us from
embedding the private data in the object structure itself.
It has thus an runtime overhead and is less convenient for debugging (it's
hard to find the private data pointer in gdb).

Most importantly, there is no easy way to find the offset of the private
data fields, short of calling NM_CLIENT_GET_PRIVATE() -- which currently
is a macro. Later we want to generically lookup the offset of the
private data, we would need NM_CLIENT_GET_PRIVATE() as a function.
Instead, by having an internally, statically known offset, we can use
that offset instead.

Also drop all signal hooks. They are also not useful.

This is an ABI and API change, but of something that we never wanted to
be part of the ABI/API, and which hopefull nobody is using.
2019-10-21 18:34:54 +02:00
Thomas Haller
ba64c162dc libnm: merge branch 'th/libnm-no-dbus-codegen-2'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/309
2019-10-18 22:09:44 +02:00
Thomas Haller
6662536d44 libnm: include "nm-types.h" in "nm-libnm-utils.h"
We now include "libnm/nm-libnm-utils.h" for all compilation of libnm sources.
Let that one also include "nm-types.h". In the end, it's anyway needed
almost everywhere.
2019-10-18 22:09:18 +02:00
Thomas Haller
4400f6de77 libnm: include "nm-libnm-utils.h" by default in libnm sources
The majority of sources in "libnm/" are implementations of NMObject.
"nm-libnm-utils.h" will contain common definitions for handling such
objects. This means, most of the source files under libnm will require
this include. Include it by default.
2019-10-18 22:09:18 +02:00
Thomas Haller
419ce1178e libnm: move wincaps_to_dash() function to "nm-libnm-utils.h"
We will need it, if only for testing/asserting.
2019-10-18 22:09:18 +02:00
Thomas Haller
166095fe4e libnm: don't use GSimpleAsyncResult for nm_client_new_async()
As we don't have any data or our own, we don't need a
GSimpleAsyncResult/GTask. Just pass the caller's @callback to
g_async_initable_new_async().
2019-10-18 22:09:18 +02:00
Thomas Haller
a5b2ba02ea libnm: add logging NML_DBUS_LOG*() for debugging D-Bus for NMClient
Commonly, a library (like libnm) is not supposed to log anything.
Logging is not a suitable way to notify the calling application
about anything. When something of importance happens, then the
application must be notified via the library's API.

However, logging can be very useful for debugging to see what is going
on. Add a logging macro that by default does nothing, but can be turned
on via an environment variable "LIBNM_CLIENT_DEBUG=debug".

Another point is that libnm relies on the server side NetworkManager
D-Bus interface to be in an expected manner. For example, we require a
D-Bus object "org.freedesktop.NetworkManager" to be present and certain
D-Bus interfaces implemented.

However libnm should treat NetworkManager as external and untrusted component.
That means, we cannot assert against the expectations we have. There are two
reasons for this:

  - a bug in NetworkManager, dbus-daemon or else may cause such errors.
    This must not trigger an assertion failure in the client
    application, at least not unless requested.

  - libnm must be forward and backward compatible against a different
    NetworkManager server version. That is only possibly by ignoring
    anything that is unexpected. Asserting by default might prevent
    to implement API changes, both on libnm and server side.

Note that we also don't notify the calling application via dedicated
API. On the one hand, these things *can* happen. On the other hand, what
would the calling appication do about it anyway? libnm by default must
just behave gracefully and pretend all is good.

For testing, development and debugging that is however not useful. We
want the user to opt in to strict API validation. The user will be able
to do that by setting "LIBNM_CLIENT_DEBUG=warning", which causes API
violations being logged with g_warning(). These are assertions when
running with G_DEBUG=fatal-warnings.

This is inspired by GDBus' G_DBUS_DEBUG variable.

Note that LIBNM_CLIENT_DEBUG environment variables is undocumented, unstable
API. It's used for debugging and testing of the current libnm version at hand.
There is no guaranteed stable behavior how a different libnm version
might behave.
2019-10-18 22:09:18 +02:00
Thomas Haller
27fa6bad0c libnm: add NM_CLIENT_DBUS_NAME_OWNER property
It's not yet implemented. But obviously it's interesting to
get the name owner to which the NMClient is currently connected.

Note only that: the name-owner property really says whether
NM is currently running or not.
2019-10-18 22:09:18 +02:00
Thomas Haller
b2f7197b29 libnm: add NM_CLIENT_DBUS_CONNECTION property
The used GDBusConnection should be configurable when creating the
NMClient instance. Automatically choosing one of the g_bus_get()
singletons is fine by default, but it's an unnecessary limitation.
2019-10-18 22:09:18 +02:00
Thomas Haller
fe24797241 libnm: remember the caller's GMainContext when creating NMClient
We will require this later. The NMClient shall be tied to the GMainContext
at the moment when the instance gets created. This allows the user to have
multiple, indendent NMClient instances (on different threads and GMainContext).

Currently this is still unused, it will be later.
2019-10-18 22:09:18 +02:00
Thomas Haller
ec63919818 libnm/trivial: move code in "nm-client.c" 2019-10-18 22:09:18 +02:00
Thomas Haller
15cc1d8770 libnm: avoid g_object_notify() in favor of _notify()
This looks up the GParamSpec from the obj_properties and is
thus more efficient. Also, the generated _notify() function
has the proper argument type and is thus generally preferable.
2019-10-18 22:09:18 +02:00
Thomas Haller
e761d230c3 libnm: use obj_properties array in libnm and cleanup
This is not merely cosmetic. I will need the obj_properties
array to lookup GParamSpec by their PROP_* enum value. The
alternative would be lookup by name, which is more expensive.
2019-10-18 22:09:18 +02:00
Thomas Haller
aa00469e80 libnm/trivial: rename property enum to match property name 2019-10-18 22:09:18 +02:00
Thomas Haller
389c2ebe8a libnm: fix GObject properties of "NMDeviceModem"
Fixes: f18b09b3f6 ('libnm/modem: add device id getter')
Fixes: 0b3dd18c2b ('libnm/modem: add network id getter')
Fixes: 8e270de05e ('libnm/modem: add APN getter')
2019-10-18 22:09:18 +02:00
Thomas Haller
57c1b03c5c libnm: add G_PARAM_STATIC_STRINGS flag to NM_VPN_SERVICE_PLUGIN_DBUS_WATCH_PEER property 2019-10-18 22:09:18 +02:00
Thomas Haller
f1bd85634a libnm: belatedly add GObject property "NMDeviceOvs{Bridge,Port}:slaves"
Fixes: 5f30a2b525 ('libnm: add accessors for ovs port/bridge slaves')
2019-10-18 22:09:18 +02:00
Thomas Haller
26391a92da libnm: remove unused enum value from "nm-object.c" 2019-10-18 22:09:18 +02:00
Thomas Haller
58a48acfd9 libnm: rework caching singleton value in _nm_dbus_bus_type()
No need for g_once_init_enter(). In case of a race, we can just
twice determine the value. As long as only one thread wins the race,
this is totally fine (also, both threads probably would give the same
result anyway).
2019-10-18 22:09:18 +02:00
Thomas Haller
a57a1ba2fc libnm/tests: add test for checking types
If a "nm_${TYPE}_class_init()" function has a bug, then this
code only runs when the class gets instanciated. And for types
like NMDeviceBridge, that didn't happen for unit tests (so far).

Instanciate all glib types. In the future we may want to perform
additional checks on the types.
2019-10-18 22:09:18 +02:00
Thomas Haller
8f37a0ae0a build: link "nm-enum-types.c" with the base "liblibnm" instead of "libnm"
This way the symbols are also available to the unit tests.
2019-10-18 22:09:18 +02:00
Thomas Haller
69de5ee4e9 shared: move nm_utils_parse_debug_string() from core to shared 2019-10-18 22:09:18 +02:00
Thomas Haller
308beb85fe shared: add nm_c_list_for_each_entry_prev() helper macro
It's non-trivial to get this right. Add the macro for iterating the list
in reverse.
2019-10-18 22:09:18 +02:00
Thomas Haller
c02710bb0f shared: add nm_g_source_destroy_and_unref() helper 2019-10-18 22:09:18 +02:00