Commit Graph

173 Commits

Author SHA1 Message Date
Thomas Haller
72de503d39 manager: simplify searching assumed connection
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.
2017-03-16 18:27:33 +01:00
Thomas Haller
2eab5ed347 utils: inject platform into nm_utils_complete_generic() 2016-03-15 12:56:58 +01:00
Thomas Haller
adb56d137e core: split "nm-core-utils.h" out of "NetworkManagerUtils.h"
"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.
2016-03-01 12:42:42 +01:00
Thomas Haller
eb80f69098 utils: add nm_utils_strbuf_init() macro 2016-02-29 17:46:41 +01:00
Thomas Haller
a51a1cde36 utils: add nm_utils_parse_debug_string() to replace g_parse_debug_string()
g_parse_debug_string() interprets the string "help" special and accepts
an "all" tag to invert the result. We don't want that.
2016-02-21 18:31:39 +01:00
Thomas Haller
8c1a9bbb8c utils: fix NM_UTILS_ENUM2STR_DEFINE() which always returned the last element
Fixes: 174b25d98c
2016-02-17 15:17:11 +01:00
Beniamino Galvani
08c3378f64 core: fix matching of default metric value for static routes
When NM tries to match a generated connection to a persistent one, it
considers also the metric of static routes. However, if the field is
set to -1 (use default value for the device) on the persistent
connection, the comparison will always fail because the generated
connection contains the actual value read from kernel.

To fix the issue, modify check_possible_match() to deal correctly with
-1 and translate it to the expected value for the current device when
performing the comparison.

This allows connections with static routes and default metric to
properly be re-assumed when NM is restarted.

https://bugzilla.redhat.com/show_bug.cgi?id=1302532
2016-02-11 21:57:45 +01:00
Thomas Haller
174b25d98c utils: reimplement NM_UTILS_ENUM2STR_DEFINE() without helper function
The compiler might be able to optimize the switch better.
But more importantly, it has the type information of the enum
and can give warnings about unmentioned enum values.
2016-02-01 14:52:55 +01:00
Thomas Haller
72255b71d7 utils: pass entire return statement to NM_UTILS_LOOKUP_DEFINE() 2016-02-01 14:20:26 +01:00
Thomas Haller
572b60a203 utils: change _NM_UTILS_LOOKUP_DEFINE() to generate compiler warning about missing enum values
Don't implement a "default" case so that we get a compiler warning
about unused enum values.
2016-02-01 14:10:04 +01:00
Thomas Haller
6c6ab10dea core/trivial: rename NM_UTILS_STRING_LOOKUP_TABLE* to NM_UTILS_LOOKUP*
Due to using a switch stetement, it is no longer only useful for looking
up strings, and it certainly doesn't use a table anymore.
2016-01-24 14:29:37 +01:00
Thomas Haller
b9df6009ff utils: implement NM_UTILS_STRING_LOOKUP_TABLE_DEFINE() as switch() statement
The compiler will likely optimize a  switch() statement also to a table
lookup, but it also works for negative values and values with large
gaps.
2016-01-24 14:21:14 +01:00
Thomas Haller
8956ea661c utils: add NM_UTILS_STRING_LOOKUP_TABLE_ITEM() macro 2016-01-24 14:20:57 +01:00
Thomas Haller
0ce83890bf utils: fix out-of-bound access for negative indexes in _NM_UTILS_STRING_LOOKUP_TABLE_DEFINE() 2016-01-24 11:31:15 +01:00
Thomas Haller
1d15d8c3ef core: add nm_utils_enum2str() 2016-01-18 13:10:18 +01:00
Thomas Haller
a291ecc29c utils: add NM_UTILS_STRING_LOOKUP_TABLE() macro 2015-12-07 14:34:59 +01:00
Thomas Haller
01ea90b57a utils: minor refactoring of NM_UTILS_FLAGS2STR_DEFINE() macro 2015-12-07 14:34:59 +01:00
Thomas Haller
531f07b06a utils: add NM_UTILS_FLAGS2STR_DEFINE() macro
Make it neater to implement a nm_utils_flags2str() function.
2015-12-04 16:28:43 +01:00
Dan Williams
15d305c07f utils: add @filter_func argument to nm_utils_g_value_set_object_path_array() 2015-12-04 12:15:12 +01:00
Dan Williams
09a2be3b65 core: fix builds with older gcc (like 4.4.x) 2015-11-10 11:10:03 -06:00
Lubomir Rintel
e603c86926 core: add support for RFC7217 stable privacy addressing
RFC7217 introduces an alternative mechanism for creating addresses during
stateless IPv6 address configuration. It's supposed to create addresses whose
host part stays stable in a particular network but changes when the hosts
enters another network to mitigate possibility of tracking the host movement.

It can be used alongside RFC 4941 privacy extensions (temporary addresses)
and replaces the use of RFC 4862 interface identifiers.

The address creation mode is controlld by ip6.addr_gen_mode property
(ADDR_GEN_MODE in ifcfg-rh), with values of "stable-privacy" and "eui-64",
defaulting to "eui-64" if unspecified.

The host part of an address is computed by hashing a system-specific secret
salted with various stable values that identify the connection with a secure
hash algorithm:

  RID = F(Prefix, Net_Iface, Network_ID, DAD_Counter, secret_key)

For NetworkManager we use these parameters:

* F()
  SHA256 hash function.

* Prefix
  This is a network part of the /64 address

* Net_Iface
  We use the interface name (e.g. "eth0"). This ensures the address won't
  change with the change of interface hardware.

* Network_ID
  We use the connection UUID here. This ensures the salt is different for
  wireless networks with a different SSID as suggested by RFC7217.

* DAD_Counter
  A per-address counter that increases with each DAD failure.

* secret_key
  We store the secret key in /var/lib/NetworkManager/secret_key. If it's
  shorter than 128 bits then it's rejected. If the file is not present we
  initialize it by fetching 256 pseudo-random bits from /dev/urandom on
  first use.

Duplicate address detection uses IDGEN_RETRIES = 3 and does not utilize the
IDGEN_DELAY delay (despite it SHOULD). This is for ease of implementation
and may change in future. Neither parameter is currently configurable.
2015-11-02 20:27:36 +01:00
Thomas Haller
dae0dbd533 utils: add flags2str utility functions 2015-11-02 13:57:01 +01:00
Thomas Haller
9369fac8ca core: add nm_utils_to_string_buffer global buffer
Having a static string buffer for convenience is useful not only
for platform. Define the string buffer in NetworkManagerUtils.h,
so that all to-string functions can reuse *one* buffer.

Of course, this has the potential danger, that different
to-string method might reuse the same buffer. Hence, low-level
library functions are adviced to use their own buffer, because
an upper level might already use the global buffer for another
string.
2015-11-02 13:57:01 +01:00
Thomas Haller
7182304684 config: allow to enable/disable configuration snippets
Support a new configuration option

  [.config]
  enable=<ENABLED>

for configuration snippets.

This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.

Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.

<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"

There are several motivations for this:

- the user can disable an entire configuration snippet by toggeling
  one entry.
  This generalizes  the functionality of the global-dns.enable
  setting, but in a way that applies to configuration on a per-file
  basis.

- for developing, we often switch between different versions of
  NetworkManager. Thus, we might want to use different configuration.
  E.g. before global-dns options, I want to use "dns=none" and manage
  resolv.conf myself. Now, I can use global-dns setting to do that.
  That can be achieved with something like the following (not exactly,
  it's an example only):

      [.config]
      enable=nm-version-min:1.1
      [main]
      dns=default
      [global-dns-domain-*]
      nameserver=127.0.0.1

  Arguably, this would be more awesome, if we would bump our micro devel
  version (1.1.0) more often while developing 1.2.0 (*hint*).

- in principle, packages could drop configuration snippets and enable
  them based on the NetworkManager version.

- with the "env:" spec, you can enable/disable snippets by configuring
  an environment variable. Again, useful for testing and developing.
2015-10-05 17:12:50 +02:00
Thomas Haller
72ff5e8cac core: add nm_utils_ascii_str_to_bool()
This is effectively the same as nm_config_parse_boolean(). The difference is,
that "nm-config.c" is not available to the interface-helper, thus any
code used by interface-helper (like "NetworkManager.c") cannot use this
function.

Still don't drop nm_config_parse_boolean() entirely, because it's better
to have the explicit notion of parsing a string in the config-context.

I ended up not using the function. But I'd still keep this patch.
2015-10-05 17:12:50 +02:00
Thomas Haller
44f3f18797 core: add NM_UTILS_ERROR 2015-09-25 10:34:02 +02:00
Thomas Haller
ab0e3a223d core/utils: add NM_UTILS_KEEP_ALIVE() utility 2015-08-13 10:06:42 +02:00
Thomas Haller
633deb0a98 utils: add nm_utils_is_valid_path_component() 2015-08-11 18:31:46 +02:00
Dan Winship
1cf35cb26b core: final gdbus porting
Port remaining bits to gdbus and remove stray dbus-glib references

Drop the dbus-glib version check from configure, since nothing depends
on new dbus-glib any more.

Move nm-dbus-glib-types.h and nm-gvaluearray-compat.h from include/ to
libnm-util/ since they are now only used by libnm-util and libnm-glib.
2015-08-10 09:41:26 -04:00
Dan Winship
6c8f860820 core: port IP/DHCP config to gdbus 2015-08-10 09:41:26 -04:00
Colin Walters
50f9c8aa7e utils: use (void) for empty arguments
In C, `()` doesn't do what you want by default.

Fixes: 2cf274c03e
2015-08-05 16:03:06 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Thomas Haller
2cf274c03e core: order destruction of singleton instances
Previously, the order of destructing singleton instances
was undefined. Now, have singleton instances register their
destruction via nm_singleton_instance_register().

Objects that are registered later, will be destructed earlier. IOW,
they will be destroyed in reverse order of construction.

This is only a crude method to get the lifetime of singleton instances
right by default. Having singletons ref other singletons to keep them
alive gives more control over the lifetimes of singletons. This change
of having a defined order of destruction does not conflict with taking
references to singletons (and thus extending their lifetime).

Note that previously, NMPlatform was not registered for destruction.
We don't change that yet and intenionally leak a reference.
2015-08-05 15:23:57 +02:00
Dan Winship
c1dd3b6eed core: move D-Bus export/unexport into NMExportedObject
Move D-Bus export/unexport handling into NMExportedObject and remove
type-specific export/get_path methods (export paths are now specified
at the class level, and NMExportedObject handles the counters for all
exported types automatically).

Since all exportable objects now use the same get_path() method, we
can also add some helper methods to simplify get_property()
implementations for object-path and object-path-array properties.
2015-07-24 13:25:47 -04:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Thomas Haller
8bca864111 core: move NM_DEFINE_SINGLETON macros to src/NetworkManagerUtils.h
NM_DEFINE_SINGLETON is used only by core and makes use of nm-logging.
It does not belong to "include/nm-macros-internal.h". Move it to "src/".
2015-07-24 18:07:16 +02:00
Thomas Haller
981817e998 Revert "core: move NM_DEFINE_SINGLETON macros to src/NetworkManagerUtils.h"
This reverts commit 1bca459865.

I accidentely pushed that commit. Revert.
2015-07-24 16:24:22 +02:00
Thomas Haller
1bca459865 core: move NM_DEFINE_SINGLETON macros to src/NetworkManagerUtils.h
NM_DEFINE_SINGLETON is used only by core and makes use of nm-logging.
It does not belong to "include/nm-macros-internal.h". Move it to "src/".
2015-07-24 15:45:46 +02:00
Thomas Haller
bd57d76af8 core: add nm_match_spec_join() function
We have a special implemenation nm_match_spec_split() to split
a string. We also need the reverse operation to be able to convert
a list of specs to string without loss.
2015-07-02 15:50:04 +02:00
Thomas Haller
7c9eefa767 core: return parent pid from nm_utils_get_start_time_for_pid() 2015-06-30 16:15:17 +02:00
Thomas Haller
7dc65df020 core: add @max_wait_msec argument to nm_utils_kill_process_sync() 2015-06-30 14:19:30 +02:00
Thomas Haller
69c98a336e core: fix nm_utils_kill_process_sync() not to hang for a zombie process
kill(pid,sig) can return success for zombie processes. This
caused nm_utils_kill_process_sync() to hang indefinitely.

Fix it by also checking the process state.
2015-06-30 14:19:15 +02:00
Thomas Haller
39f2b51abb core: add option to suppress error logging if nm_utils_modprobe() fails
We don't want error logging for nm_platform_link_add() which
tries to load the bonding module. Later we will run tests as non-root,
where modprobe will fail. Logging an error would break the tests.
2015-06-05 16:52:49 +02:00
Thomas Haller
3fb60edf9f device: add device-spec "type:"
Support a device-spec to match by device-type.
This matches on the value as shown by

  nmcli -f GENERAL.TYPE device show
2015-06-05 12:38:29 +02:00
Thomas Haller
dce00f0d10 utils: move NM_FLAGS_*() macros to header file "include/nm-utils-internal.h" 2015-05-29 16:28:33 +02:00
Thomas Haller
d4dd9ba3cf keyfile: readd owner check of files (bgo #701112)
Commit 5dc4be54e6 dropped the
owner check for keyfiles to allow running `make check` as root.
Re-add it, but disable the check for tests.

https://bugzilla.gnome.org/show_bug.cgi?id=701112
2015-05-19 09:57:46 +02:00
Thomas Haller
b9d8dc050a core/tests: add nm_utils_get_testing() function
Code that is testable often needs special hooks to work
both for unit-tests and production.

Add a function nm_utils_get_testing() that returns whether
the code is run as part of a unit-test.

For non-testing mode, nm_utils_get_testing() will return
zero (NM_UTILS_TEST_NONE). For unit tests, the test should call
_nm_utils_set_testing() to configure tested functions.
By specifing the @flags attribute, the test can enable/disable
specific behaviors.

https://bugzilla.gnome.org/show_bug.cgi?id=701112
2015-05-19 09:57:46 +02:00
Beniamino Galvani
a1d76a019e core: capture DNS options from resolv.conf 2015-05-13 17:15:35 +02:00
Thomas Haller
63bb33b534 core: remove G_GNUC_WARN_UNUSED_RESULT from ASSERT_VALID_PATH_COMPONENT()
ASSERT_VALID_PATH_COMPONENT() always returns the input argument --
unless it fails an assertion and terminates the program. No need
to require the user to use the return value.
2015-05-01 14:25:58 -05:00
Thomas Haller
967376b840 core: add nm_utils_monotonic_timestamp_as_boottime() function 2015-04-29 07:32:42 +02:00