Commit Graph

280 Commits

Author SHA1 Message Date
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
8715d61437 libnm-core: fail verify() for NMSettingVlan for invalid vlan id
Point in case:

    # ip link add link dummy0 name dummy0.vlan type vlan id 4095
    RTNETLINK answers: Numerical result out of range

This potentially causes existing (invalid) connections to disappear
as they now fail verification.

Instead of adjusting the range of the GObject property
NM_SETTING_VLAN_ID, reject it during vlan. This is a bit more
forgiving to an older client that isn't aware of this new restriction,
so he can first set the value without raising a critical warning.
2016-01-22 12:02:39 +01:00
Beniamino Galvani
9a56fa0b3f core: allow VLAN ids between 1 and 4095
nm_utils_new_vlan_name() should reject the reserved VLAN id 4095, and
the test case should not test reserved values 0 and 4095.

Fixes: 778207f23e
2016-01-22 11:17:44 +01:00
Thomas Haller
778207f23e core: truncate parent ifname when constructing virtual ifname for VLAN
https://bugzilla.redhat.com/show_bug.cgi?id=1300755
2016-01-21 18:49:02 +01:00
Lubomir Rintel
e80346fff7 utils: fix error open() handling
CID 59376 (#2-1 of 2): Argument cannot be negative (NEGATIVE_RETURNS)
negative_returns: urandom is passed to a parameter that cannot be negative.
2016-01-21 16:56:19 +01:00
Thomas Haller
1d15d8c3ef core: add nm_utils_enum2str() 2016-01-18 13:10:18 +01:00
Thomas Haller
b9b65e7d48 utils: save duplicate lookup of path in nm_utils_g_value_set_object_path_array() 2015-12-04 18:28:00 +01:00
Thomas Haller
0b12a4213b utils: assert for valid flags description in nm_utils_flags2str() 2015-12-04 16:58:21 +01:00
Thomas Haller
7d9f819aa1 utils: construct paths array directly in nm_utils_g_value_set_object_path_array()
nm_utils_g_value_set_object_path_array() is used at several places, so that
this optimazation makes some sense.
2015-12-04 12:15:12 +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
Thomas Haller
caa2de563d build: avoid invalid compiler warning
NetworkManagerUtils.c:3308:93: error: comparison of unsigned expression < 0 is always false [-Werror,-Wtautological-compare]
   key_len = (((key_len) > (((guint32) 0xffffffff))) ? (((guint32) 0xffffffff)) : (((key_len) < (0)) ? (0) : (key_len)));
                                                                                    ~~~~~~~~~ ^ ~~~

Fixes: e603c86926
2015-11-10 15:31:49 +01:00
Jiří Klimeš
212b3e6713 core: fix assuming a connection without S390 properties (rh #1276343)
When a connection should be assumed and the generated connection did not
contain a wired setting, the connection did not match due to S390 properties.
Such a connection should be allowed to match to a connection with a wired
setting with default (empty) S390 properties.

This can happen when there is a VLAN profile configured that contains a wired
setting in it and NetworkManager is (re)started.

Example/reproducer:
$ nmcli con add type vlan con-name vlan-test autoconnect no dev em1 id 44
$ nmcli con mod vlan-test eth.mtu 1450   (modify the connection, so that it has a wired setting)
$ nmcli con up vlan-test                 (activate the connection)
$ sudo systemctl restart NetworkManager
$ nmcli device
check that 'vlan-test' connection is active on em1.44 device
(and not the auto-generated em1.44)

https://bugzilla.redhat.com/show_bug.cgi?id=1276343
2015-11-03 08:31:04 +01: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
55d672347f core/trivial: add code comment to nm_utils_get_shared_wifi_permission() 2015-09-18 14:31:31 +02:00
Thomas Haller
1928c2f878 core: relax logging message about disowning singletons
It is not uncommon to see first a "disown" message before "disposing".
That alone does not yet indicate anything wrong or a leak. Remove that
overly alarming part of the logging message.
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
Dan Winship
22e1a97e12 all: drop includes to <glib/gi18n.h> for "nm-default.h"
The localization headers are now included via "nm-default.h".

Also fixes several places, where we wrongly included <glib/gi18n-lib.h>
instead of <glib/gi18n.h>. For example under "clients/" directory.
2015-08-05 15:35:51 +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
4c48f66d3d core: print connection path in nm_utils_log_connection_diff() 2015-07-12 13:56:53 +02:00
Jiří Klimeš
43a50fd5f2 utils: fix error logging in ASSERT_VALID_PATH_COMPONENT() 2015-07-08 16:50:28 +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
7498b670a8 utils: strip whitespace for device spec in nm_match_spec_split()
Via escape sequences, the user still can specify trailing and leading
white spaces: such as "\s \s" will result in 3 spaces.
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
67057079a4 core: fix memleak in nm_utils_get_start_time_for_pid() and parsing start-time
It was leaking @tokens in case of error. Also the error checking of
start-time with strtoull() was erroneous.
2015-06-30 14:19:30 +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
e8e455817b platform: refactor virtual methods for link objects in NMPlatform
Change nm_platform_link_get() to return the cached NMPlatformLink
instance. Now what all our implementations (fake and linux) have such a
cache internal object, let's just expose it directly.
Note that the lifetime of the exposed link object is possibly quite
short. A caller must copy the returned value if he intends to preserve
it for later.
Also add nm_platform_link_get_by_ifname() and modify nm_platform_link_get_by_address()
to return the instance.

Certain functions, such as nm_platform_link_get_name(),
nm_platform_link_get_ifindex(), etc. are solely implemented based
on looking at the returned NMPlatformLink object. No longer implement
them as virtual functions but instead implement them in the base class
(nm-platform.c).
This removes code and eliminates the redundancy of the exposed
NMPlatformLink instance and the nm_platform_link_get_*() accessors.
Thereby also fix a bug in NMFakePlatform that tracked the link address
in a separate "address" field, instead of using "link.addr". That was
a case where the redundancy actually led to a bug in fake platform.

Also remove some stub implementations in NMFakePlatform that just
bail out. Instead allow for a missing virtual functions and perform
the "default" action in the accessor.
An example for that is nm_platform_link_get_permanent_address().
2015-06-21 12:53:48 +02:00
Lubomir Rintel
5e8182279a utils: _get_ip_config_method(): don't assert a connection has IP config
nm_utils_get_shared_wifi_permission() that is called for each AddAndActivate
uses this and triggers an assertion failure for InifnibandConnections which
don't have IPv4 configuration:

NetworkManager[54006]: nm_utils_get_ip_config_method: assertion 's_ip4 != NULL' failed

  #2  0x000055555562b833 in nm_utils_get_ip_config_method (connection=connection@entry=0x5555559c3b60, ip_setting_type=93824996202304) at NetworkManagerUtils.c:1329
  #3  0x000055555562b914 in nm_utils_get_shared_wifi_permission (connection=0x5555559c3b60) at NetworkManagerUtils.c:1105
  #4  0x00005555555fc012 in nm_active_connection_authorize (self=0x5555559b30a0, result_func=0x55555561b980 <_add_and_activate_auth_done>, user_data1=0x555555957210, user_data2=0x555555a055f0)
      at nm-active-connection.c:683
  #5  0x0000555555621b21 in impl_manager_add_and_activate_connection (self=0x555555957210, settings=<optimized out>, device_path=<optimized out>, specific_object_path=0x0, context=0x555555a055f0)
      at nm-manager.c:3495
2015-06-17 13:17:14 +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
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
067202b34e core: use explict NMLogDomain enum instead of int
A while ago (f4f3f4d69b) we added an
enum to represent the logging domain. Use it.
2015-05-12 16:46:48 +02:00
Thomas Haller
ca4361bd53 utils: preserve errno in nm_utils_kill_child_sync() 2015-05-05 16:39:17 +02:00
Thomas Haller
f53fda9fd6 Revert "core: treat ECHILD as child already terminated"
This reverts commit 268da271cc.

This breaks the test, but it is not clear that this is the
right fix. Revert for now, needs still investigation.
2015-05-01 23:14:38 +02:00
Dan Williams
268da271cc core: treat ECHILD as child already terminated
prevents:

NetworkManager[2775]: <error> [1429889302.113450] [NetworkManagerUtils.c:576]
   nm_utils_kill_child_async(): kill child process 'teamd' (3025): failed due
   to unexpected return value -1 by waitpid (No child processes, 10) after
   sending SIGTERM (15)
2015-05-01 14:25:59 -05:00
Thomas Haller
967376b840 core: add nm_utils_monotonic_timestamp_as_boottime() function 2015-04-29 07:32:42 +02:00
Lubomir Rintel
cd2cef9cab utils: match a cloned mac address with a connection that does not specify it
We do the same for the original MAC address.

A device enslaved to a bond it inherits the bond's MAC address. When
NetworkManager tries to assume a connection the generated cloned-mac property
causes a mismatch with the connection that originally brought up the device,
causing the generated connection to be used instead:

  NetworkManager[14190]: <debug> [1424355817.112154] [NetworkManagerUtils.c:1641]
         nm_utils_match_connection(): Connection 'eth2' differs from candidate
         'bond-slave-eth2' in 802-3-ethernet.cloned-mac-address

https://bugzilla.gnome.org/show_bug.cgi?id=744812
2015-04-27 11:33:58 +02:00
Thomas Haller
842ec6163d core: refactor nm_ethernet_address_is_valid() and reject invalid addresses
nm_ethernet_address_is_valid() did not check whether @addr was a valid
address in the first place. It only checked whether the address was not
equal to a few notorious MAC addresses.

At the same time, be more forgiving and accept %NULL as argument.
This fixes an assertion nm_ap_match_in_hash().
2015-04-23 16:38:51 +02:00