Commit Graph

10267 Commits

Author SHA1 Message Date
Dan Williams
13a9f2781a vpn: remove useless 'disposed' member from NMVPNConnection 2014-06-06 13:43:43 -05:00
Dan Williams
c9d183f7fc vpn: simplify duplicate service checking 2014-06-06 13:43:43 -05:00
Dan Williams
063411df42 vpn: remove useless 'disposed' member from NMVPNManager
Just make dispose() able to be called again.
2014-06-06 13:43:43 -05:00
Dan Williams
ca7fd98bbe vpn: simplify creation of VPN service objects 2014-06-06 13:43:43 -05:00
Dan Williams
5d1610b347 vpn: optimize un-needed strlen (trivial) 2014-06-06 13:43:43 -05:00
Dan Williams
4b57f6920e vpn: let VPN services quit themselves
Instead of telling a VPN service to quit, leave that up to the service
itself.  Services based on libnm-glib-vpn already have a quit timeout
of 20 seconds.  We also eventually want to D-Bus activate the VPN
services, and at that point we won't have a PID we can send signals
to.
2014-06-06 13:43:43 -05:00
Dan Williams
8b7eaeb07e vpn: simplify service cleanup 2014-06-06 13:43:43 -05:00
Thomas Haller
26a65f4fe4 platform: fix compiler warning about uninitialized usage
CC       nm-linux-platform.lo
    platform/nm-linux-platform.c: In function '_nm_platform_link_get':
    platform/nm-linux-platform.c:161:17: error: 'rtnllink' may be used uninitialized in this function [-Werror=maybe-uninitialized]
       nl_object_put (*object);
                     ^
    platform/nm-linux-platform.c:1923:35: note: 'rtnllink' was declared here
      auto_nl_object struct rtnl_link *rtnllink;
                                       ^
    cc1: all warnings being treated as errors

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:11:36 +02:00
Thomas Haller
a04df905fd platform: fix format specifyer in _lifetime_to_string() for unsigned
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:05:08 +02:00
Thomas Haller
fcc34ef77b platform: merge branch 'th/bgo727382_platform_fix_addr_lifetime'
https://bugzilla.gnome.org/show_bug.cgi?id=727382

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:02:03 +02:00
Thomas Haller
58b318b53a platform: raise address changed signals for lifetime update
When only the lifetime of an address changes, we did not get a platform signal
as libnl does not consider the time fields in nl_object_diff().
Workaround by comparing the timestamps manually.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:38 +02:00
Thomas Haller
441f337412 platform: refactor setting the source of platform addresses to NM_PLATFORM_SOURCE_KERNEL
Moving setting the source of the address to the init_* functions.

This also has the advantage, that the platform internal to_string functions have the proper
source set.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:38 +02:00
Thomas Haller
2ff046e5aa platform: change address_to_string functions to show remaining lifetime/preferred times
Change the to_string functions to convert the lifetime/preferred values
to the time remaining when the function is evaluated. These functions
are used for printing/debugging, so it's more sensible to show the
remaining time.

On the other hand, for debugging, it's better to see the raw values (also).
In addition to the remaining time we keep to print the timestamps+now if the
address is not permanent. So when inspecting the logs it is possible to figure
out the real values.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:38 +02:00
Thomas Haller
e1410b5a88 platform: refactor calculating valid/preferred times when adding address
Replace the calls to subtract_guint32() by _rebase_relative_time_on_now()
and _address_get_lifetime().

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:37 +02:00
Thomas Haller
d90b9ff2c8 platform: fix setting preferred time for address
Before nm_platform_ip4_address_sync() set the preferred time to the same value
as the address lifetime. The result was that the preferred time was
always identical to valid lifetime.

This will lead to the kernel using the address longer then the desired
preferred time (until validity of the address expires).

https://bugzilla.redhat.com/show_bug.cgi?id=1082041
https://bugzilla.redhat.com/show_bug.cgi?id=1083283

Reported-by: Kai Engert <kengert@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:37 +02:00
Thomas Haller
84cfd06d6a core/platform: limit the preferred time to address lifetime
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1082041

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:37 +02:00
Thomas Haller
8310a039d8 platform: fix preferred and valid lifetimes for addresses from netlink/kernel
The kernel tells the address lifetimes in the 'struct ifa_cacheinfo'
attribute. This contains two timestamps (cstamp and tstamp) and two
relative lifetimes (ifa_prefered and ifa_valid).

The timestamps are equal to clock_gettime(CLOCK_MONOTONIC) scale in
1/100th of a second (wrapping every 497 days).

The preferred/valid times are re-adjusted everytime when sending the
message and count down as the time goes by. In other words, they are
anchored relatively to the moment of when kernel creates the netlink
message.

As platform is caching the rtnl_addr object, the information of *when* the
lifetimes started counting is not available.

This patch fixes reading these values by hacking the libnl object
when it gets received, so that valid and preferred are instead absolute
expiration timestamps in scale nm_utils_get_monotonic_timestamp_s() --
which NM internally is used for address timestamps.

There are two minor downsides to this hack:
- the valid and preferred properties of a cached rtnl_addr object have
  an unexpected meaning, i.e. they are absolute and in a different time
  scale.
- later when converting rtnl_addr to NMPlatformIPAddress, the base
  timestamp is set to "1", i.e. an NMPlatformIPAddress has no knowledge
  of when the address was created or last modified. The timestamp
  property of NMPlatformIPAddress is solely there to anchor the relative
  timestamps lifetime and preferred. Do not use it for anything
  else.
  Another reason the timestamp property is meaningless is that
  its scale nm_utils_get_monotonic_timestamp_s() starts counting at
  process start. So addresses that existed before would have a negative
  or zero timestamp, which we avoid. This in turn could be solved by either
  allowing negative timestamps or by shifting
  nm_utils_get_monotonic_timestamp_*(). Both is viable, but not
  necessary (ATM), because the age of an address has no other apparent
  use then to anchor the relative timestamps.
  Another implication is, that we potentially could get rid of the
  timestamp completely, and insteat make preferred and lifetime be
  absolute expiries.

This will be fixed properly later, by not caching libnl objects but  instead
native NMPlatform objects. For those we have full control over their properties.

https://bugzilla.gnome.org/show_bug.cgi?id=727382

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:37 +02:00
Thomas Haller
8f8b247e34 core: add nm_utils_get_monotonic_timestamp_ns() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 19:04:05 +02:00
Thomas Haller
bc34ee7779 core: add code comment to nm_utils_get_monotonic_timestamp_*s() functions
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 19:04:05 +02:00
Jiří Klimeš
3ef79ee249 device: don't call strtol() for NULL strings
#1  0x0000003c47239ea2 in __GI_strtol (nptr=nptr@entry=0x0, endptr=endptr@entry=0x0, base=base@entry=10) at ../stdlib/strtol.c:110
 #2  0x000000000043b896 in update_connection (device=<optimized out>, connection=<optimized out>) at devices/nm-device-bridge.c:308
 #3  0x000000000042ed2f in nm_device_generate_connection (device=device@entry=0xfbb260 [NMDeviceBridge]) at devices/nm-device.c:1644
 #4  0x0000000000481613 in get_existing_connection (device=0xfbb260 [NMDeviceBridge], manager=0xfb2000 [NMManager]) at nm-manager.c:1549
 #5  add_device (self=self@entry=0xfb2000 [NMManager], device=device@entry=0xfbb260 [NMDeviceBridge], generate_con=<optimized out>)
     at nm-manager.c:1688
 #6  0x0000000000481f50 in platform_link_added (plink=0x7fffffffdd50, ifindex=695, self=0xfb2000 [NMManager], reason=<optimized out>)
     at nm-manager.c:2023
 #7  platform_link_cb (platform=<optimized out>, ifindex=695, plink=0x7fffffffdd50, change_type=<optimized out>, reason=<optimized out>,
     user_data=<optimized out>) at nm-manager.c:2038
2014-06-06 18:30:45 +02:00
Thomas Haller
ab1a015579 platform/test: fix route tests after reworking source property
Breakage introduced by commit 662ade1e47.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 17:21:33 +02:00
Thomas Haller
6f2b6a6745 core: fix wrong g_return_if_fail() statement when value should be returned in NMManager:assume_connection()
CC       nm-manager.lo
  nm-manager.c: In function 'assume_connection':
  nm-manager.c:1605:345: error: 'return' with no value, in function returning non-void [-Werror=return-type]
    g_return_if_fail (nm_device_get_state (device) >= NM_DEVICE_STATE_DISCONNECTED);

Minor error, introduced by commit f229f4e201.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 16:37:52 +02:00
Dan Winship
9df69b1029 core: fix connection matching with dynamic IPv6 routes
https://bugzilla.gnome.org/show_bug.cgi?id=729203
https://bugzilla.redhat.com/show_bug.cgi?id=1086237
2014-06-06 10:26:19 -04:00
Dan Winship
9f195559d2 core: look at route sources when assuming a connection
When generating an NMConnection to match the current state of a
device, don't add its RA-provided and DHCP-provided routes to the
NMSettingIP4Config/NMSettingIP6Config, since those routes didn't come
from the connection profile before.

https://bugzilla.gnome.org/show_bug.cgi?id=729203
2014-06-06 10:24:44 -04:00
Dan Winship
662ade1e47 platform: improve tracking of route sources
NMIP[46]Route had a "source" field, but it was always set to KERNEL
for routes read from the kernel (even if they were originally added by
NM).

Fix things a bit by translating between our "source" field and the
kernel's "protocol" field.

https://bugzilla.gnome.org/show_bug.cgi?id=729203
2014-06-06 10:24:43 -04:00
Dan Winship
e644745d85 trivial: route-related whitespace/indentation fixes 2014-06-06 10:23:28 -04:00
Dan Winship
722c90343b core: set route metrics earlier
Instead of creating most routes with metric 0 and then fixing them
just before applying them, create the routes with the correct metric
in the first place (so that NMIP4Config and NMIP6Config don't have to
try to guess whether "metric 0" means "unset" or "actually metric 0").
2014-06-06 10:23:28 -04:00
Dan Winship
d3a51b6e4a devices: improve master/slave handling of assumed connections
https://bugzilla.gnome.org/show_bug.cgi?id=729843
https://bugzilla.redhat.com/show_bug.cgi?id=1066706
2014-06-06 10:19:11 -04:00
Dan Winship
08e0cfb484 devices: observe externally-caused master/slave changes (rh #1066706)
If a link's "master" property changes unexpectedly (ie, from outside
NM), update the master and slave NMDevices to reflect it, without
making any changes to them.
2014-06-06 10:14:28 -04:00
Dan Winship
1dbf69cd0a devices: don't allow assuming a slave before its master
The process of activating a slave requires that its master have an
NMActiveConnection. So don't allow generating a connection on a slave
until we have generated the connection on the master.
2014-06-06 10:14:24 -04:00
Dan Winship
950525f5c3 devices: don't allow generated master connections to have no IP config
nm_device_generate_connection() was allowing connections for master
devices to have no IP config, but this didn't really make much sense,
since they would just fail at stage3 in that case anyway.

Now that we get multiple tries at generating a connection on a device,
we can just ignore the device until it has a proper connection.
2014-06-06 10:11:19 -04:00
Dan Winship
f229f4e201 core: re-attempt connection assumption when the device state changes
If the initial attempt to assume a connection on a device fails, and
the device remains un-activated, but then something changes its
configuration externally, try to generate a new connection and assume
that.
2014-06-06 10:11:19 -04:00
Dan Winship
a9a25973cc devices: update generated connections when the underlying IP config changes
If the IP config changes on a device that has assumed a generated
connection, then update the connection's NMSettingIP4Config /
NMSettingIP6Config, under the assumption that the configuration of
that device was in progress but incomplete when NM first observed it.
2014-06-06 10:11:19 -04:00
Dan Winship
14048089a1 settings: add 'nm_generated' flag on NMSettingsConnection
Add 'nm_generated' flag on NMSettingsConnection, and have NMManager
set it on generated connections that it assumes.
2014-06-06 10:11:19 -04:00
Dan Winship
6fd76323e0 core: tweak NMSettingIP[46]Config generation
NMIP4Config and NMIP6Config had methods to update an existing
NMSetting. However, the functions would really only work correctly if
the passed-in setting was empty.

Change them from "update_setting" to "create_setting", and have them
create the NMSetting themselves, and update NMDevice for that.

(If we need update_setting later, we can add it, after figuring out
exactly how it's actually supposed to work.)
2014-06-06 09:57:04 -04:00
Jiří Klimeš
dae8391436 cli: switch to the new-style readline typedefs (bgo #731294)
The old Function, CPFunction, CPPFunction and VFunction typedefs are
considered deprecated starting from readline 4.2 (though were not marked
as such): http://lists.gnu.org/archive/html/bug-bash/2000-10/msg00078.html
Compatibility typedefs have been in place up to readline 6.2 but were
removed with the 6.3 release thus causing build to break.
http://lists.gnu.org/archive/html/bug-readline/2014-04/msg00018.html

https://bugzilla.gnome.org/show_bug.cgi?id=731294
2014-06-06 11:34:23 +02:00
Thomas Haller
37aeee5f71 platform: merge branch 'th/bgo706293_platform_tests'
https://bugzilla.gnome.org/show_bug.cgi?id=706293

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:13:26 +02:00
Thomas Haller
48b5ba7cea nmtst: add NMTST_DEBUG=no-expect-message for debugging assert_message tests
Some tests want to assert against the messages logged using g_test_expect_message().
In this mode, nmtst will not log anything itself.

Interpret the option no-expect-message which turns g_test_expect_message()
into a NOP and turns logging on. The use of this is for debugging such
tests, without asserting against the messages but printing them instead.

For tests that are not in the assert_message mode, the option has no
effect.

Example:
  NMTST_DEBUG=debug,no-expect-message make -C src/settings/plugins/keyfile/tests/ check

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:58 +02:00
Thomas Haller
9114794f65 nmtst: turn on g_debug() messages in nmtst_init() when debug logging is enabled
In tests nm-logging will directly write using g_log. Also, non-core components
use g_log() for logging. glib will not print messages with level
G_LOG_LEVEL_INFO or G_LOG_LEVEL_DEBUG unless G_MESSAGES_DEBUG is set.

When the user specifies NMTST_DEBUG turning on 'debug' or
'log-level=DEBUG' it can be reasonably assumed that he wants to see
debug messages. nmtst_init() now sets G_MESSAGES_DEBUG=all.

The user can disable this behaviour, by setting instead G_MESSAGES_DEBUG='',
because nmtst_init() will not reset an existing G_MESSAGES_DEBUG.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:58 +02:00
Thomas Haller
8ce1eb3837 nmtst: add new mode where tests assert against logged messages (assert_messages)
In this mode, nmtst itself will not log anything and not set the logging
level. Also, it will set g_log_set_always_fatal().

This is for tests that want to assert against all logged messages via
g_test_expect_message().

In this mode also setting the logging level via NMTST_DEBUG variable has
no effect. The test is expected to manage the logging level itself and
changing the logging level might interfere with the test.

As a showcase, move keyfile/tests/test-keyfile.c to nmtst.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:58 +02:00
Thomas Haller
ae863a6954 platform/test: allow running root tests as sudo
Call to nmtst_reexec_sudo(), which allows you to specify a program
via environment variable to exec the test.

This is useful to exec the test program with sudo.

  NMTST_DEBUG="no-debug,sudo-cmd=$PWD/tools/test-sudo-wrapper.sh" make -C src/platform/tests/ check

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:58 +02:00
Thomas Haller
e3784fa618 platform/test: always run linux platform tests (will be skipped as non-root)
Always run the linux platform tests, even if called as non-root user.
In such a case, print a message and return 77 (signalizing that the test
was skipped).

Only if we configured with --enable-test=root, we enforce that the
user executes the tests as root.

Co-Authored-By: Pavel Šimerda <psimerda@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:58 +02:00
Thomas Haller
0fde65a14e platform/test: workaround team bug in older kernel version
In older versions of team (e.g. Fedora 17), the master team device
stays up, even if no slaves are IFF_LOWER_UP. Workaround this bug.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:58 +02:00
Thomas Haller
1ff6e1b65e platform/test: fix expecting NM_PLATFORM_SOURCE_KERNEL in platform tests
In this case, the fake platform implementation was wrong in that it did
not set the source property of the route/address objects like linux
platform does. Fix the test and the fake platform.

https://bugzilla.gnome.org/show_bug.cgi?id=706293

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:58 +02:00
Pavel Šimerda
fd41c989d5 platform: fix software device handling when announcing links
The handling for announcing links was broken resulting in
duplicate link-added signals from platform.

Co-Authored-By: Thomas Haller <thaller@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Pavel Šimerda
f008c9fbea platform/test: fix fake platform to emit signals synchronously (analog to Linux platform)
When adding a link, the Linux platform implementation raises the
link-changed signal synchronously. Fix the fake platform to behave identically
and also fix all the tests.

This also fixes the Linux platform tests for the most part because now the
test functions (and fake platform) behave like the Linux system
implementation.

https://bugzilla.gnome.org/show_bug.cgi?id=706293

Co-Authored-By: Thomas Haller <thaller@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Pavel Šimerda
accd10b501 platform/test: disable bonding tests if no bonding module is available
Co-Authored-By: Thomas Haller <thaller@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Thomas Haller
79a99613c2 platform/test: use nm-test-utils.h in test-common
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Thomas Haller
66e2e932b5 platform: add nm_platform_link_get()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Thomas Haller
ed868a388b core: add compatibility wrapper for g_test_skip() to nm-glib-compat.h
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00