summaryrefslogtreecommitdiff
path: root/src/NetworkManagerUtils.c
Commit message (Collapse)AuthorAgeFilesLines
* core: extend nm_shutdown_wait_obj_*() to support notification via a GCancellableThomas Haller2019-09-221-4/+28
| | | | | | | | | | | | | | | | | | | | Now nm_shutdown_wait_obj_*() supports two styles: - NM_SHUTDOWN_WAIT_TYPE_OBJECT: this just registers a weak pointer on a source GObject. As long as the object is not destroyed (and the object is not unregistered), the shutdown gets blocked. - now new is NM_SHUTDOWN_WAIT_TYPE_CANCELLABLE: this source object is a GCancellable, and during shutdown, the system will cancel the instances to notify about the shutdown. That aside, the GCancellable is tracked exactly like a regular NM_SHUTDOWN_WAIT_TYPE_OBJECT (meaning: a weak pointer is registered and shutdown gets delayed as long as the instance lives). As the rest of the shutdown, it's not yet implemented on the shutdown-side. What is now possible is to register such cancellables, so that users can make use of this API before we fix shutdown. We cannot fix it all at the same time, so first users must be ready for this approach.
* all: SPDX header conversionLubomir Rintel2019-09-101-14/+1
| | | | | $ find * -type f |xargs perl contrib/scripts/spdx.pl $ git rm contrib/scripts/spdx.pl
* libnm,core: add support for "suppress_prefixlength" rule attributeThomas Haller2019-07-161-21/+22
| | | | | | | | | | | | | | | WireGuard's wq-quick configures such rules to avoid routing loops. While we currently don't have an automatic solution for this, at least we should support it via explicit user configuration. One problem is that suppress_prefixlength is relatively new and kernel might not support this attribute. That can lead to odd results, because the NetworkManager is valid but it cannot be configured on the current kernel. But this is a general problem, and we would require a general solution. The solution cannot be to only support rule attributes that are supported by the oldest possible kernel. It's not clear how much of a problem there really is, or which general solution is required (if any).
* core: add flag to nm_shutdown_wait_obj_register_full() for freeing allcated ↵Thomas Haller2019-06-261-13/+21
| | | | | | | | | | | | | | | | message string In fact, nm_shutdown_wait_obj_register*() API is still not implemented and registering an object has no effect currently. That is, blocking shutdown and waiting for instances to be destroyed during shutdown is not yet implemented. Still, we already implement the API so that components can register themself to block the shutdown. The point is of course, that the callers already use this API, although it's not yet implemented. Anyway, sometimes the message string is not static. Add an option to pass an allocated string and let the string be destroyed when no longer needed.
* ipv6: add 'disabled' methodBeniamino Galvani2019-06-111-0/+1
| | | | | | | Add a new ipv6.method value 'disabled' that completely disables IPv6 for the interface. https://bugzilla.redhat.com/show_bug.cgi?id=1643841
* all: drop emacs file variables from source filesThomas Haller2019-06-111-1/+0
| | | | | | | | | | | | | | | | | | | | | | We no longer add these. If you use Emacs, configure it yourself. Also, due to our "smart-tab" usage the editor anyway does a subpar job handling our tabs. However, on the upside every user can choose whatever tab-width he/she prefers. If "smart-tabs" are used properly (like we do), every tab-width will work. No manual changes, just ran commands: F=($(git grep -l -e '-\*-')) sed '1 { /\/\* *-\*- *[mM]ode.*\*\/$/d }' -i "${F[@]}" sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}" Check remaining lines with: git grep -e '-\*-' The ultimate purpose of this is to cleanup our files and eventually use SPDX license identifiers. For that, first get rid of the boilerplate lines.
* utils: add ifname argument to nm_utils_complete_generic()Lubomir Rintel2019-05-281-4/+8
| | | | | | It's a common thing to complete a connection with an interface name; adding it to the common path is goint to save as a few tens of lines later on.
* shared: build helper "libnm-libnm-core-{intern|aux}.la" library for libnm-coreThomas Haller2019-04-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "libnm-core" implements common functionality for "NetworkManager" and "libnm". Note that clients like "nmcli" cannot access the internal API provided by "libnm-core". So, if nmcli wants to do something that is also done by "libnm-core", , "libnm", or "NetworkManager", the code would have to be duplicated. Instead, such code can be in "libnm-libnm-core-{intern|aux}.la". Note that: 0) "libnm-libnm-core-intern.la" is used by libnm-core itsself. On the other hand, "libnm-libnm-core-aux.la" is not used by libnm-core, but provides utilities on top of it. 1) they both extend "libnm-core" with utlities that are not public API of libnm itself. Maybe part of the code should one day become public API of libnm. On the other hand, this is code for which we may not want to commit to a stable interface or which we don't want to provide as part of the API. 2) "libnm-libnm-core-intern.la" is statically linked by "libnm-core" and thus directly available to "libnm" and "NetworkManager". On the other hand, "libnm-libnm-core-aux.la" may be used by "libnm" and "NetworkManager". Both libraries may be statically linked by libnm clients (like nmcli). 3) it must only use glib, libnm-glib-aux.la, and the public API of libnm-core. This is important: it must not use "libnm-core/nm-core-internal.h" nor "libnm-core/nm-utils-private.h" so the static library is usable by nmcli which couldn't access these. Note that "shared/nm-meta-setting.c" is an entirely different case, because it behaves differently depending on whether linking against "libnm-core" or the client programs. As such, this file must be compiled twice. (cherry picked from commit af07ed01c04867e281cc3982a7ab0d244d4f8e2e)
* shared: move most of "shared/nm-utils" to "shared/nm-glib-aux"Thomas Haller2019-04-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From the files under "shared/nm-utils" we build an internal library that provides glib-based helper utilities. Move the files of that basic library to a new subdirectory "shared/nm-glib-aux" and rename the helper library "libnm-core-base.la" to "libnm-glib-aux.la". Reasons: - the name "utils" is overused in our code-base. Everything's an "utils". Give this thing a more distinct name. - there were additional files under "shared/nm-utils", which are not part of this internal library "libnm-utils-base.la". All the files that are part of this library should be together in the same directory, but files that are not, should not be there. - the new name should better convey what this library is and what is isn't: it's a set of utilities and helper functions that extend glib with funcitonality that we commonly need. There are still some files left under "shared/nm-utils". They have less a unifying propose to be in their own directory, so I leave them there for now. But at least they are separate from "shared/nm-glib-aux", which has a very clear purpose. (cherry picked from commit 80db06f768e47541eae7d66ef48fbe47bf1a69ce)
* core: add handling of IP routing rules to NMDeviceThomas Haller2019-03-271-0/+44
|
* core: use nm_connection_get_setting_ip_config() helperThomas Haller2019-03-051-4/+1
| | | | (cherry picked from commit 2be022ad68158acd544704244a7d3193aa6545a7)
* core: accept %NULL as source argument for ↵Thomas Haller2019-03-051-2/+2
| | | | | | | | nm_utils_ipx_address_clear_host_address() Just for convenience. (cherry picked from commit be107c75c9eca0f306e79e1e15355166a0db44bd)
* core: use NM_CMP_*() macro in route_compare()th/missing-braces-warningThomas Haller2019-02-091-24/+19
| | | | | | | | | | | | | | nm_ip_route_get_prefix() and plen are guint type, hence the following is not correct: plen = nm_ip_route_get_prefix (route1); r = plen - nm_ip_route_get_prefix (route2); if (r) return r > 0 ? 1 : -1; Use the macro, it gets subtle cases like this right. Fixes: b32bb36c61c102e73d73cbc78c5fa412af706e0b
* shared: avoid "-Wmissing-braces" warning initalizing NMIPAddrThomas Haller2019-02-081-2/+3
| | | | | | | | | | NMIPAddr contains an unnamed union. We have to either explicitly initialize one field, or omit it. ../shared/nm-utils/nm-shared-utils.c:38:36: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces] const NMIPAddr nm_ip_addr_zero = { 0 }; ^ {}
* systemd: move basic systemd library to shared/nm-utilsThomas Haller2019-01-021-1/+1
| | | | | | | | | | | | | | | | For better or worse, we already pull in large parts of systemd sources. I need a base64 decode implementation (because glib's g_base64_decode() cannot reject invalid encodings). Instead of coming up with my own or copy-paste if from somewhere, reuse systemd's unbase64mem(). But for that, make systemd's basic bits an independent static library first because I will need it in libnm-core. This doesn't really change anything except making "libnm-systemd-core.la" an indpendent static library that could be used from "libnm-core". We shall still be mindful about which internal code of systemd we use, and only access functionality that is exposed via "systemd/nm-sd-utils-shared.h".
* core: use streq() instead of strcmp() for comparing ip-config methodsThomas Haller2018-12-131-36/+34
| | | | | | | | 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.
* core: use addr-family argument for nm_utils_get_ip_config_method()Thomas Haller2018-12-131-21/+22
| | | | | | | | | | 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.
* device: add "dhcp-plugin" match spec for deviceThomas Haller2018-11-011-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The need for this is the following: "ipv4.dhcp-client-id" can be specified via global connection defaults. In absence of any configuration in NetworkManager, the default depends on the DHCP client plugin. In case of "dhclient", the default further depends on /etc/dhcp. For "internal" plugin, we may very well want to change the default client-id to "mac" by universally installing a configuration snippet [connection-use-mac-client-id] ipv4.dhcp-client-id=mac However, if we the user happens to enable "dhclient" plugin, this also forces the client-id and overrules configuration from /etc/dhcp. The real problem is, that dhclient can be configured via means outside of NetworkManager, so our defaults shall not overwrite defaults from /etc/dhcp. With the new device spec, we can avoid this issue: [connection-dhcp-client-id] match-device=except:dhcp-plugin:dhclient ipv4.dhcp-client-id=mac This will be part of the solution for rh#1640494. Note that merely dropping a configuration snippet is not yet enough. More fixes for DHCP will follow. Also, bug rh#1640494 may have alternative solutions as well. The nice part of this new feature is that it is generally useful for configuring connection defaults and not specifically for the client-id issue. Note that this match spec is per-device, although the plugin is selected globally. That makes some sense, because in the future we may or may not configure the DHCP plugin per-device or per address family. https://bugzilla.redhat.com/show_bug.cgi?id=1640494
* core: add nm_utils_file_is_in_path() for checking pathsThomas Haller2018-10-231-0/+60
| | | | | | | | Add a helper function for the common check whether a file is inside a path. Also, this function handles special cases like repeated file separators. However, as it is still entirely text based, it also cannot recognize if two (literally) different paths reference the same inode/file.
* settings: use delegation instead of inheritance for NMSettingsConnection and ↵Thomas Haller2018-08-281-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* core: add nm_shutdown_register_watchdog() for marking object to wait for ↵Thomas Haller2018-05-251-0/+89
| | | | | | | | | | | | | | | shutdown Eventually we should do a coordinated shutdown when NetworkManager exits. That is a large work, ensuring that all asynchronous actions are cancellable (in time), and that we wait for all pending operations to complete. Add a function nm_shutdown_register_watchdog(), so that objects can register themselves, to block shutdown until they are destroyed. It's not yet used, because actually iterating the mainloop during shutdown can only be done, once the code is prepared to be ready for that. But we already need the function, so that we can refactor individual parts of the code, in preparation of using it in the future.
* all: remove consecutive empty linesBeniamino Galvani2018-04-301-1/+0
| | | | | | | Normalize coding style by removing consecutive empty lines from C sources and headers. https://github.com/NetworkManager/NetworkManager/pull/108
* all: unify spelling of translators hint in source codeThomas Haller2018-04-131-1/+1
| | | | | | | | | Use the same form everywhere: "TRANSLATORS" instead of "Translators". The manual also seems to prefer the upper-case form [1]. $ sed 's/\<Translators\>: /TRANSLATORS: /g' $(git grep -l Translators) -i [1] https://www.gnu.org/software/gettext/manual/gettext.html
* Revert "core: merge branch 'bg/restart-assume-rh1551958'"Thomas Haller2018-04-041-1/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit cc1920d71470042c4e0837848da9183526b663d0, reversing changes made to eb8257dea5802a004af9cccacb30af98440e2172. This breaks restart, at least for Wi-Fi devices: #0 0x00007ffff5ee8771 in _g_log_abort (breakpoint=breakpoint@entry=1) at gmessages.c:554 #1 0x00007ffff5ee9a5b in g_logv (log_domain=0x7ffff671a738 "GLib-GIO", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd720) at gmessages.c:1362 #2 0x00007ffff5ee9baf in g_log (log_domain=log_domain@entry=0x7ffff671a738 "GLib-GIO", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7ffff5f347ea "%s: assertion '%s' failed") at gmessages.c:1403 #3 0x00007ffff5eea0f9 in g_return_if_fail_warning (log_domain=log_domain@entry=0x7ffff671a738 "GLib-GIO", pretty_function=pretty_function@entry=0x7ffff673fc10 <__func__.25628> "g_dbus_proxy_call_internal", expression=expression@entry=0x7ffff673fb1c "G_IS_DBUS_PROXY (proxy)") at gmessages.c:2702 #4 0x00007ffff66cdc5f in g_dbus_proxy_call_internal (proxy=0x0, method_name=method_name@entry=0x555555810510 "Scan", parameters=0x555555c7a530, flags=flags@entry=G_DBUS_CALL_FLAGS_NONE, timeout_msec=timeout_msec@entry=-1, fd_list=fd_list@entry=0x0, cancellable=0x0, callback=0x55555574cb96 <scan_request_cb>, user_data=0x555555ac2220) at gdbusproxy.c:2664 #5 0x00007ffff66cf686 in g_dbus_proxy_call (proxy=<optimized out>, method_name=method_name@entry=0x555555810510 "Scan", parameters=<optimized out>, flags=flags@entry=G_DBUS_CALL_FLAGS_NONE, timeout_msec=timeout_msec@entry=-1, cancellable=cancellable@entry=0x0, callback=0x55555574cb96 <scan_request_cb>, user_data=0x555555ac2220) at gdbusproxy.c:2970 #6 0x000055555574e026 in nm_supplicant_interface_request_scan (self=0x555555ac2220 [NMSupplicantInterface], ssids=ssids@entry=0x0) at src/supplicant/nm-supplicant-interface.c:1821 #7 0x00007fffe1038276 in request_wireless_scan (self=self@entry=0x555555c6ee60 [NMDeviceWifi], periodic=periodic@entry=0, force_if_scanning=force_if_scanning@entry=0, ssids=<optimized out>, ssids@entry=0x0) at src/devices/wifi/nm-device-wifi.c:1347 #8 0x00007fffe1039011 in device_state_changed (device=0x555555c6ee60 [NMDeviceWifi], new_state=NM_DEVICE_STATE_DISCONNECTED, old_state=<optimized out>, reason=<optimized out>) at src/devices/wifi/nm-device-wifi.c:2998 #9 0x00007ffff432ed1e in ffi_call_unix64 () at ../src/x86/unix64.S:76 #10 0x00007ffff432e68f in ffi_call (cif=cif@entry=0x7fffffffdc70, fn=fn@entry=0x7fffe1038e1e <device_state_changed>, rvalue=<optimized out>, avalue=avalue@entry=0x7fffffffdb60) at ../src/x86/ffi64.c:525 #15 0x00007ffff63db66f in <emit signal ??? on instance 0x555555c6ee60 [NMDeviceWifi]> (instance=instance@entry=0x555555c6ee60, signal_id=<optimized out>, detail=detail@entry=0) at gsignal.c:3447 #11 0x00007ffff63bff39 in g_cclosure_marshal_generic (closure=0x555555c22ea0, return_gvalue=0x0, n_param_values=<optimized out>, param_values=<optimized out>, invocation_hint=<optimized out>, marshal_data=<optimized out>) at gclosure.c:1490 #12 0x00007ffff63bf73d in g_closure_invoke (closure=0x555555c22ea0, return_value=0x0, n_param_values=4, param_values=0x7fffffffdea0, invocation_hint=0x7fffffffde20) at gclosure.c:804 #13 0x00007ffff63d1f30 in signal_emit_unlocked_R (node=node@entry=0x555555c22750, detail=detail@entry=0, instance=instance@entry=0x555555c6ee60, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7fffffffdea0) at gsignal.c:3673 #14 0x00007ffff63dad05 in g_signal_emit_valist (instance=0x555555c6ee60, signal_id=<optimized out>, detail=0, var_args=var_args@entry=0x7fffffffe0b0) at gsignal.c:3391 #16 0x00005555556f0f18 in _set_state_full (self=self@entry=0x555555c6ee60 [NMDeviceWifi], state=state@entry=NM_DEVICE_STATE_DISCONNECTED, reason=reason@entry=NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED, quitting=quitting@entry=0) at src/devices/nm-device.c:13268 #17 0x00005555556f1774 in nm_device_state_changed (self=self@entry=0x555555c6ee60 [NMDeviceWifi], state=state@entry=NM_DEVICE_STATE_DISCONNECTED, reason=reason@entry=NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED) at src/devices/nm-device.c:13435 #18 0x00005555555bcf95 in recheck_assume_connection (self=self@entry=0x555555b09140 [NMManager], device=device@entry=0x555555c6ee60 [NMDeviceWifi]) at src/nm-manager.c:2297 #19 0x00005555555bd53e in _device_realize_finish (self=self@entry=0x555555b09140 [NMManager], device=device@entry=0x555555c6ee60 [NMDeviceWifi], plink=plink@entry=0x555555ae43d8) at src/nm-manager.c:2473 #20 0x00005555555c01d0 in platform_link_added (self=self@entry=0x555555b09140 [NMManager], ifindex=<optimized out>, plink=plink@entry=0x555555ae43d8, guess_assume=<optimized out>, dev_state=<optimized out>) at src/nm-manager.c:2789 #21 0x00005555555c0cec in platform_query_devices (self=self@entry=0x555555b09140 [NMManager]) at src/nm-manager.c:2901 #22 0x00005555555c439e in nm_manager_start (self=0x555555b09140 [NMManager], error=<optimized out>) at src/nm-manager.c:5632 #23 0x000055555558498e in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:413
* core: remove @indicated argument of nm_utils_match_connection()Beniamino Galvani2018-04-041-23/+1
| | | | It is not needed anymore.
* core: avoid clone of all-connections list for nm_utils_complete_generic()Thomas Haller2018-03-201-44/+39
| | | | | | | | | | | | | | | | | | | NMSettings exposes a cached list of all connection. We don't need to clone it. Note that this is not save against concurrent modification, meaning, add/remove of connections in NMSettings will invalidate the list. However, it wasn't save against that previously either, because altough we cloned the container (GSList), we didn't take an additional reference to the elements. This is purely a performance optimization, we don't need to clone the list. Also, since the original list is of type "NMConnection *const*", use that type insistently, instead of dependent API requiring GSList. IMO, GSList is anyway not a very nice API for many use cases because it requires an additional slice allocation for each element. It's slower, and often less convenient to use.
* core: cleanup of nm_utils_complete_generic()Thomas Haller2018-03-201-28/+28
| | | | | | Also, endlessly try searching for a unused name. Why limit it arbitrarily to 10000 or 500? Just try, eventually we will find a match.
* core/dbus: rework D-Bus implementation to use lower layer GDBusConnection APIThomas Haller2018-03-121-57/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, we used the generated GDBusInterfaceSkeleton types and glued them via the NMExportedObject base class to our NM types. We also used GDBusObjectManagerServer. Don't do that anymore. The resulting code was more complicated despite (or because?) using generated classes. It was hard to understand, complex, had ordering-issues, and had a runtime and memory overhead. This patch refactors this entirely and uses the lower layer API GDBusConnection directly. It replaces the generated code, GDBusInterfaceSkeleton, and GDBusObjectManagerServer. All this is now done by NMDbusObject and NMDBusManager and static descriptor instances of type GDBusInterfaceInfo. This adds a net plus of more then 1300 lines of hand written code. I claim that this implementation is easier to understand. Note that previously we also required extensive and complex glue code to bind our objects to the generated skeleton objects. Instead, now glue our objects directly to GDBusConnection. The result is more immediate and gets rid of layers of code in between. Now that the D-Bus glue us more under our control, we can address issus and bottlenecks better, instead of adding code to bend the generated skeletons to our needs. Note that the current implementation now only supports one D-Bus connection. That was effectively the case already, although there were places (and still are) where the code pretends it could also support connections from a private socket. We dropped private socket support mainly because it was unused, untested and buggy, but also because GDBusObjectManagerServer could not export the same objects on multiple connections. Now, it would be rather straight forward to fix that and re-introduce ObjectManager on each private connection. But this commit doesn't do that yet, and the new code intentionally supports only one D-Bus connection. Also, the D-Bus startup was simplified. There is no retry, either nm_dbus_manager_start() succeeds, or it detects the initrd case. In the initrd case, bus manager never tries to connect to D-Bus. Since the initrd scenario is not yet used/tested, this is good enough for the moment. It could be easily extended later, for example with polling whether the system bus appears (like was done previously). Also, restart of D-Bus daemon isn't supported either -- just like before. Note how NMDBusManager now implements the ObjectManager D-Bus interface directly. Also, this fixes race issues in the server, by no longer delaying PropertiesChanged signals. NMExportedObject would collect changed properties and send the signal out in idle_emit_properties_changed() on idle. This messes up the ordering of change events w.r.t. other signals and events on the bus. Note that not only NMExportedObject messed up the ordering. Also the generated code would hook into notify() and process change events in and idle handle, exhibiting the same ordering issue too. No longer do that. PropertiesChanged signals will be sent right away by hooking into dispatch_properties_changed(). This means, changing a property in quick succession will no longer be combined and is guaranteed to emit signals for each individual state. Quite possibly we emit now more PropertiesChanged signals then before. However, we are now able to group a set of changes by using standard g_object_freeze_notify()/g_object_thaw_notify(). We probably should make more use of that. Also, now that our signals are all handled in the right order, we might find places where we still emit them in the wrong order. But that is then due to the order in which our GObjects emit signals, not due to an ill behavior of the D-Bus glue. Possibly we need to identify such ordering issues and fix them. Numbers (for contrib/rpm --without debug on x86_64): - the patch changes the code size of NetworkManager by - 2809360 bytes + 2537528 bytes (-9.7%) - Runtime measurements are harder because there is a large variance during testing. In other words, the numbers are not reproducible. Currently, the implementation performs no caching of GVariants at all, but it would be rather simple to add it, if that turns out to be useful. Anyway, without strong claim, it seems that the new form tends to perform slightly better. That would be no surprise. $ time (for i in {1..1000}; do nmcli >/dev/null || break; echo -n .; done) - real 1m39.355s + real 1m37.432s $ time (for i in {1..2000}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects > /dev/null || break; echo -n .; done) - real 0m26.843s + real 0m25.281s - Regarding RSS size, just looking at the processes in similar conditions, doesn't give a large difference. On my system they consume about 19MB RSS. It seems that the new version has a slightly smaller RSS size. - 19356 RSS + 18660 RSS
* core: extend nm_match_spec_device_by_pllink() with the device-typeThomas Haller2017-12-271-1/+2
| | | | | | | | | | | | | | nm_match_spec_device_by_pllink() does not support matching on all parameters, unlike nm_match_spec_device(). The reason is that certain parameters are only available when having a NMDevice instance. Add an argument "match_device_type", so that the caller can inject the device type to be used. Note that for NMDevice, the device-type is nm_device_get_type_description(), which usually depends on the device class only. The only caller of nm_match_spec_device_by_pllink() is the wifi factory, and it already knows that it wants to create a device of type NMDeviceWifi. Hence, it knows and can specify "wifi" as match_device_type.
* core: add nm_match_spec_device_by_pllink()Thomas Haller2017-12-271-0/+34
| | | | | | | | | | | | | | | | Add a variant of nm_device_spec_match_list() that looks up the match paramters from a platform link instance. Usually, we have a NMDevice instance that we use for matching. However, at some places (like inside the device factory's create_device() method), we might not have a NMDevice instance to get the match paramters. Add an alternative form, that gets the match paramters from a platform link instance. The code is placed inside src/NetworkManagerUtils.c, because src/nm-core-utils.c is supposed to be independent of platform.
* device: add "indicated" argument to nm_utils_match_connection()Thomas Haller2017-11-301-1/+23
| | | | | | | | | | | | | | The matching works fuzzy and is not reliable. That is why we store which connection should be assumed after restart in the state file of NetworkManager. In that case, we don't need to do a full check (with the possibility of a false-reject). Just check for the minimum required properties: the type and slave-type. Yes, if the user modifies the connection while restarting NM, then we might wrongly assume a connection that no longer would match. But NM should not read minds, it should do as indicated.
* utils: don't assume a device with master won't have IP configurationLubomir Rintel2017-10-301-20/+12
| | | | | Whether the ip[46]-config exists is a better way, and we already check that.
* core,clients: use our own string hashing function nm_str_hash()Thomas Haller2017-10-181-1/+1
| | | | | | | | | | | | | | | | | | | | Replace the usage of g_str_hash() with our own nm_str_hash(). GLib's g_str_hash() uses djb2 hashing function, just like we do at the moment. The only difference is, that we use a diffrent seed value. Note, that we initialize the hash seed with random data (by calling getrandom() or reading /dev/urandom). That is a change compared to before. This change of the hashing function and accessing the random pool might be undesired for libnm/libnm-core. Hence, the change is not done there as it possibly changes behavior for public API. Maybe we should do that later though. At this point, there isn't much of a change. This patch becomes interesting, if we decide to use a different hashing algorithm.
* core: add nm_utils_connection_has_default_route()Thomas Haller2017-09-081-0/+49
| | | | Taken from "src/nm-default-route-manager.c".
* core: ignore host-routes routes when matching generated connectionThomas Haller2017-09-011-13/+37
| | | | | | | | | | | | | | | | | | | | When we generate the connection in nm_device_generate_connection(), we add all routes that have rt_source (roundtrip(NM_IP_CONFIG_SOURCE_USER)). Especially since commit e470e1392242a088573c4fc317b7b5ffaca4df19, this includes automatically added host-routes to the gateway, added by ip4_config_merge_and_apply(). Later, during nm_utils_match_connection() this route most not prevent matching. Either nm_device_generate_connection() should not add it, or nm_utils_match_connection() should ignore it. I think adjusting the matching is better, because ip-configs are used for several things, including exposing routes on D-Bus. We don't want to hide this route on D-Bus. Fixes: e470e1392242a088573c4fc317b7b5ffaca4df19 https://bugzilla.redhat.com/show_bug.cgi?id=1487384
* all: fix typo 'entires' -> 'entries'Beniamino Galvani2017-05-051-1/+1
| | | | (cherry picked from commit a4cbfe6f0a1fe19ddf7d98cf7a0e1914fe085aff)
* src: only compare network parts of routes in nm_utils_match_connection()Thomas Haller2017-04-151-9/+19
| | | | | | | | | | | | Kernel requires that routes have a host part of zero. For NetworkManager configuration we allow non-zero host parts (but ignore them). Fix route_compare() to ignore the host part. This has only effect during assuming connections. That means, on restart NM would fail to match a connection with static routes if it has a non-zero host part. So, the impact is rather small. (cherry picked from commit 034b7fb51c1d16a4002d2902c60aac05e946bb4f)
* manager: simplify searching assumed connectionThomas Haller2017-03-161-4/+6
| | | | | | Now we only search for a candiate with matching UUID. No need to first lookup all activatable connections, just find the candidate by UUID and see if it is activatable.
* core: fix matching routes for assuming connectionsThomas Haller2017-03-161-4/+9
| | | | | | | | | | | | If the connection candidate contains a static route without route-metric, but overrides the default route-metric, matching would have failed: ipv4.route-metric: 200 ipv4.routes: { ip = 192.168.5.0/32 } Then, we must not compare existing routes using the device's metric, but must use the overwrite from the connection.
* all: use stack-allocated uuid at various placesThomas Haller2017-03-021-4/+4
| | | | No need to create a UUID on the heap in this case.
* build: don't add subdirectories to include search path but require qualified ↵Thomas Haller2016-11-211-1/+1
| | | | | | | | | | | | | | | include Keep the include paths clean and separate. We use directories to group source files together. That makes sense (I guess), but then we should use this grouping also when including files. Thus require to #include files with their path relative to "src/". Also, we build various artifacts from the "src/" tree. Instead of having individual CFLAGS for each artifact in Makefile.am, the CFLAGS should be unified. Previously, the CFLAGS for each artifact differ and are inconsistent in which paths they add to the search path. Fix the inconsistency by just don't add the paths at all.
* all: modify line separator comments to be 80 chars wideThomas Haller2016-10-031-4/+4
| | | | sed 's#^/\*\{5\}\*\+/$#/*****************************************************************************/#' $(git grep -l '\*\{5\}' | grep '\.[hc]$') -i
* device: fix nm_utils_match_connection() for NMSettingInfiniband:mac-addressThomas Haller2016-09-221-0/+36
| | | | | | | <debug> [1474469475.3318] Connection 'inf_ib0' differs from candidate 't-inf' in infiniband.mac-address <debug> [1474469475.3318] manager: (inf_ib0): generated connection 'inf_ib0' https://bugzilla.redhat.com/show_bug.cgi?id=1375558
* device: extend MAC address handling including randomization for ethernet and ↵Thomas Haller2016-06-301-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | wifi Extend the "ethernet.cloned-mac-address" and "wifi.cloned-mac-address" settings. Instead of specifying an explicit MAC address, the additional special values "permanent", "preserve", "random", "random-bia", "stable" and "stable-bia" are supported. "permanent" means to use the permanent hardware address. Previously that was the default if no explict cloned-mac-address was set. The default is thus still "permanent", but it can be overwritten by global configuration. "preserve" means not to configure the MAC address when activating the device. That was actually the default behavior before introducing MAC address handling with commit 1b49f941a69af910b0e68530be7339e8053068e5. "random" and "random-bia" use a randomized MAC address for each connection. "stable" and "stable-bia" use a generated, stable address based on some token. The "bia" suffix says to generate a burned-in address. The stable method by default uses as token the connection UUID, but the token can be explicitly choosen via "stable:<TOKEN>" and "stable-bia:<TOKEN>". On a D-Bus level, the "cloned-mac-address" is a bytestring and thus cannot express the new forms. It is replaced by the new "assigned-mac-address" field. For the GObject property, libnm's API, nmcli, keyfile, etc. the old name "cloned-mac-address" is still used. Deprecating the old field seems more complicated then just extending the use of the existing "cloned-mac-address" field, although the name doesn't match well with the extended meaning. There is some overlap with the "wifi.mac-address-randomization" setting. https://bugzilla.gnome.org/show_bug.cgi?id=705545 https://bugzilla.gnome.org/show_bug.cgi?id=708820 https://bugzilla.gnome.org/show_bug.cgi?id=758301
* all: move NM_AUTH_PERMISSION_* defines to "nm-common-macros.h" headerThomas Haller2016-06-011-0/+1
|
* utils: inject platform into nm_utils_complete_generic()Thomas Haller2016-03-151-4/+6
|
* core: split "nm-core-utils.h" out of "NetworkManagerUtils.h"Thomas Haller2016-03-011-2914/+11
| | | | | | | | | | | | | | | | "NetworkManagerUtils.h" contains a bunch of helper tools for core daemon ("src/"). Unfortunately, it has dependencies to other parts of core, such as "nm-device.h" and "nm-platform.h". Split out a part of tools that are independent so that they can be used without dragging in other dependencies. "nm-core-utils.h" should only use libnm-core, "nm-logging.h" and shared. "NetworkManagerUtils.h" should provide all "nm-core-utils.h" and possibly other utilities that have larger dependencies.
* libnm,core: fix syntax of 'transfer' annotationBeniamino Galvani2016-02-241-2/+2
|
* utils: add nm_utils_parse_debug_string() to replace g_parse_debug_string()Thomas Haller2016-02-211-0/+62
| | | | | g_parse_debug_string() interprets the string "help" special and accepts an "all" tag to invert the result. We don't want that.
* all: cleanup includes and let "nm-default.h" include "config.h"Thomas Haller2016-02-191-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | - All internal source files (except "examples", which are not internal) should include "config.h" first. As also all internal source files should include "nm-default.h", let "config.h" be included by "nm-default.h" and include "nm-default.h" as first in every source file. We already wanted to include "nm-default.h" before other headers because it might contains some fixes (like "nm-glib.h" compatibility) that is required first. - After including "nm-default.h", we optinally allow for including the corresponding header file for the source file at hand. The idea is to ensure that each header file is self contained. - Don't include "config.h" or "nm-default.h" in any header file (except "nm-sd-adapt.h"). Public headers anyway must not include these headers, and internal headers are never included after "nm-default.h", as of the first previous point. - Include all internal headers with quotes instead of angle brackets. In practice it doesn't matter, because in our public headers we must include other headers with angle brackets. As we use our public headers also to compile our interal source files, effectively the result must be the same. Still do it for consistency. - Except for <config.h> itself. Include it with angle brackets as suggested by https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers