Commit graph

832 commits

Author SHA1 Message Date
Thomas Haller
b4e8ce876d core: add nm_settings_get() singleton getter for NMSettings 2016-05-24 12:35:57 +02:00
Thomas Haller
c35164a6a3 settings/trivial: rename nm_settings_get_connections() to nm_settings_get_connections_sorted()
nm_settings_get_connections() returns a sorted list. We have many users
of nm_connection_provider_get_connection(), which returns the same result,
but undefined order.

Next NMConnectionProvider will be dropped. Thus, we don't want to
seamlessly replace nm_connection_provider_get_connection() by a sorted
version nm_settings_get_connections().

Rename nm_settings_get_connections() to make clear it is sorted.
2016-05-24 12:35:57 +02:00
Thomas Haller
7c785a064e device/trivial: rename nm_device_set_unmanaged_by_user_config() to nm_device_set_unmanaged_by_user_settings()
After all, it sets NM_UNMANAGED_USER_SETTINGS flag, so the name should
match with the flag.
2016-05-17 12:12:50 +02:00
Thomas Haller
dab2d46aa2 core: fix wrong rebase
Fixes: 25aaaab3b7
2016-05-13 19:28:04 +02:00
Dan Williams
25aaaab3b7 manager: don't unmanage devices without L3 config on shutdown
Use the following logic when quitting, if the device is managed:

  1) if the connection is assumed, leave it up
  2) if the device has no connection (eg, !req) leave it up
  3) if the device only has L2 leave it up

[thaller@redhat.com: original patch reworked by bgalvani@redhat.com and me]

https://bugzilla.redhat.com/show_bug.cgi?id=1311988
https://bugzilla.redhat.com/show_bug.cgi?id=1333983
2016-05-13 19:23:30 +02:00
Beniamino Galvani
81ea812362 manager: disconnect devices before unmanaging them on suspend/sleep
So that dispatcher scripts are run and other applications notified of
the change in connectivity.

https://bugzilla.redhat.com/show_bug.cgi?id=1330694
https://bugzilla.gnome.org/show_bug.cgi?id=748531
2016-05-13 14:40:54 +02:00
Thomas Haller
8bc895d5aa manager: embed NMManagerPrivate data directly into NMManager struct
For a type to be inheritable, its public struct (NMManager) must
be known. As nobody inherits NMManager, we can make it private.

As the struct is private anyway, we can also reuse it for the private
data directly, instead of registering NMManagerPrivate in the manager
class.

There are advantages and disadvantages:

  + simplifies debugging, as the self pointer also contains the
    private data.
  + removes a small overhead of tracking the private data separately
  - is a different way to implement the class, contrary to many
    other classes.
  - inheriting from the class later requires reverting this change
    (but we will never inherit from NMManager).
  - as it is now, nobody uses the priv field directly and we still
    access it via NM_MANAGER_GET_PRIVATE(self). However, the presence
    of the priv field might encourage us to use it directly -- which
    increases above disadvantages.
2016-04-28 14:36:24 +02:00
Thomas Haller
d27a80c4df manager: make NMManager's structs private
They are only useful when we want to derive a class
from NM_TYPE_MANAGER -- which we clearly don't.
2016-04-28 14:20:11 +02:00
Thomas Haller
bb8b9ca6f5 manager: remove unused signal slots from NMManagerClass 2016-04-28 14:20:00 +02:00
Thomas Haller
1e3b2cbb77 sleep-monitor: make sleep-monitor not a singleton
The only user of the sleep-monitor singleton was NMManager anyway.
Also, even if we ever get more users that are interested in the SLEEPING
signal, we would hook them onto NMManager -- because NMManager should
collect, coordinate and possibly forward the SLEEPING signal. In no case,
another object should react on the SLEEPING signal and thus bypassing the
NMManager.
2016-04-28 13:45:49 +02:00
Thomas Haller
07db1217a9 sleep-monitor: merge RESUMING signal into NMSleepMonitor's SLEEPING signal
Having two signals is more complicated and everybody who cares about
one signal also cares about the other.
2016-04-28 13:20:09 +02:00
Thomas Haller
e0c272c153 manager: use _LOGx() macros in nm-manager
They give each logging message a "manager: " prefix.
2016-04-27 18:29:51 +02:00
Thomas Haller
2158d6a5a8 manager: fix wrongly removing DNS configuration on shutdown
When NetworkManager exits, it must preserve the DNS configuration of
devices that are left up.

Fixes: 9498ea507e
2016-04-20 17:53:58 +02:00
Beniamino Galvani
34964273ee audit: log changed properties when updating a connection
The main purpose of audit logging is to understand who did what to the
system configuration, so it is useful to log also the list of changed
properties when a connection is updated:

 op="connection-update"
 uuid="2f3e48fc-5f47-41d9-9278-d2871378df43"
 name="pppoe1"
 args="pppoe.username,pppoe.password"         <========
 pid=9523
 uid=1001
 result="success"
2016-04-20 17:31:01 +02:00
Dan Williams
2b0e5cd6e6 Revert "core: don't leak ActiveConnection object on AddAndActivate failure"
This reverts commit 8b6a1ac62f.

Original patch was in error; 'active' is already gs_unref_object.
2016-04-19 14:14:25 -05:00
Thomas Haller
3164c026a2 settings: merge "connection-updated" and "connection-updated-by-user" signals
This is mostly interesting of NMPolicy, which no longer needs to
subscribe to two almost identical signals (where the by-user signal
was always invoked together with the plain "updated" signal).
2016-04-14 12:25:41 +02:00
Francesco Giudici
7796c489fd device: minor logging change in platform_link_added()
Show ignored devices in debug level.
2016-04-12 11:24:19 +02:00
Thomas Haller
d0836be0eb core: rename nm_config_run_state* to nm_config_state*
After all, this state is stored persistently to /var/lib/NetworkManager,
and not to volatile storage in /var/run. Hence the name is better.
It's also shorter, so rename it.

The commit is mostly trivial, including update of code comments
and logging messages.

Fixes: 1b43c880ba
2016-04-07 18:52:12 +02:00
Thomas Haller
1b43c880ba config: let NMConfig handle "NetworkManager.state" file (bgo#764474)
Move reading and writing of the state file to NMConfig
("/var/lib/NetworkManager/NetworkManager.state" file).

Originally, I intended to persist more state, thus it made
sense to cleanup handling of the state file and move it all
at one place. Now, it's not clear that will happen anytime soon.

Still, the change is a worthy cleanup, so do it anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=764474
2016-04-07 10:15:01 +02:00
Lubomir Rintel
9498ea507e manager: ensure IP config of device is cleared before removal
If the manager removes the device, the IP config objects must
be cleared. The reason is that NMPolicy registers to the IP config
changed signal and passes these object on to NMDnsManager.

If the INTERNAL_DEVICE_REMOVED signal is emited with IP configuration
object pending, those objects will be leaked.

This partly redoes commit f72816bf10,
which was reverted.

Co-Authored-By: Thomas Haller <thaller@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=764483
2016-04-04 23:10:20 +02:00
Thomas Haller
fe6940b692 manager: refactor error variable in platform_link_added()
Free the error via gs_free_error and create separate instances.
2016-04-04 21:26:51 +02:00
Thomas Haller
ccda474a02 manager: remove unused signal "user-permissions-changed" 2016-04-04 16:45:48 +02:00
Thomas Haller
9cc00d9e26 manager: use defines for signal names 2016-04-04 16:45:48 +02:00
Lubomir Rintel
a6fb37bae2 Revert "manager: don't remove the device before policy learns of ip config change"
This doesn't unexport the connection on disconnect (as opposed to device
removal).

This reverts commit f72816bf10.
2016-04-04 12:52:56 +02:00
Lubomir Rintel
f72816bf10 manager: don't remove the device before policy learns of ip config change
First let the device know it's being removed soon so that it has a
chance to clean up the IP configuration early.

If the manager removes the device fist, the policy never learns of
config removal and doesn't unhook it from the DNS manager resulting in a
IPConfig leak and possible wrong DNS configuration in effect.

Also adjust the route manager to skip over devices without IP
configuration when determining the best connection; it is perhaps
just due to being removed.

https://bugzilla.gnome.org/show_bug.cgi?id=764483
2016-04-04 12:40:40 +02:00
Thomas Haller
a6af426271 manager: fix memleak in error-path of _internal_enable() 2016-04-01 18:55:15 +02:00
Thomas Haller
7871a8fb06 manager: refactor handling GObject properties
Use NM_GOBJECT_PROPERTIES_DEFINE() and _notify() function.
2016-04-01 17:47:45 +02:00
Thomas Haller
5617cd4e61 merge: merge branch 'systemd' into master
After merging https://github.com/systemd/systemd/pull/2898,
use the LLDP defines now from public systemd API.
2016-04-01 15:15:43 +02:00
Lubomir Rintel
ec542df4df manager: don't the already activated devices shouldn't be considered added
The NMSettings shouldn't generate a new default wired connection for
devices that are being deactivated.
2016-04-01 14:35:38 +02:00
Nikolay Martynov
28e9ec499a device: renew dhcp leases on awake for software devices
This makes sure that devices like bond get their dhcp renewed

[thaller@redhat.com: original patch modified to rename
 now-public function update_dynamic_ip_setup()]

https://bugzilla.gnome.org/show_bug.cgi?id=764398
2016-03-31 16:31:34 +02:00
Lubomir Rintel
6b62536ce6 manager: make some error reporting a bit more specific
Make sure there's always the device and connection as well as the reason
when a slave activation fails. The slave connection could in fact be
chosen automatically on "nmcli d connect" and the user might not be
aware activation of which connection was attempted:

  $ nmcli d connect enp0s25
  Error: Device activation failed: Master connection not found or invalid
2016-03-30 13:24:49 +02:00
Dan Williams
8b6a1ac62f core: don't leak ActiveConnection object on AddAndActivate failure 2016-03-29 15:52:23 -05:00
Dan Williams
f2182fbf9b core: don't emit double PropertiesChanged signal for new active connections
When porting to GDBus property change notifications were converted from a
hash table to a GVariantBuilder.  GVariantBuilder doesn't care about
duplicated properties in the dict so each g_object_notify() will add
an additional item with possibly different values:

signal time=1458571005.592811 sender=:1.10 -> destination=(null destination) serial=64451 path=/org/freedesktop/NetworkManager; interface=org.freedesktop.NetworkManager; member=PropertiesChanged
   array [
      dict entry(
         string "ActiveConnections"
         variant             array [
               object path "/org/freedesktop/NetworkManager/ActiveConnection/19"
               object path "/org/freedesktop/NetworkManager/ActiveConnection/18"
               object path "/org/freedesktop/NetworkManager/ActiveConnection/15"
               object path "/org/freedesktop/NetworkManager/ActiveConnection/0"
            ]
      )
      dict entry(
         string "ActiveConnections"
         variant             array [
               object path "/org/freedesktop/NetworkManager/ActiveConnection/24"
               object path "/org/freedesktop/NetworkManager/ActiveConnection/19"
               object path "/org/freedesktop/NetworkManager/ActiveConnection/18"
               object path "/org/freedesktop/NetworkManager/ActiveConnection/15"
               object path "/org/freedesktop/NetworkManager/ActiveConnection/0"
            ]
      )
   ]

Fix that by not emitting notify events for the manager's ActiveConnections
property until the property has actually been updated in active_connection_add().
The unexport also isn't required for VPN connections since it will get
unexported when it's disposed after _internal_activation_failed() gets called.
2016-03-29 15:52:23 -05:00
Thomas Haller
ff06754fe8 core: downgrade warning logging message when creating virtual device
This can regularly happen when a virtual device depends on a parent/master
that is not yet created. We will retry later when the parent is ready, so
logging a warning about it is wrong and confusing.
2016-03-29 15:46:17 +02:00
Thomas Haller
0c5b98b464 core: be strict when parsing connection in AddAndActivateConnection
AddAndActivateConnection is allowed to provide an incomplete connection
that will be completed by NetworkManager. That is, a connection that
does not verify.

But we still want to catch invalid properties or unknown setting types.
Thus, we want to reject invalid partial connections.

This possibly rejects invalid requests from clients that were accepted
before. Thus this change has the potential to break misbehaving clients.
2016-03-29 11:55:24 +02:00
Lubomir Rintel
b26159b149 manager: allow delaying the device activation when the parent is not real
Don't try to realize our device when the parent device is not real.
Instead, enqueue the activation and wait until it is active before
realizing our device and progressing the device to DISCONNECTED so that
it can get connected.
2016-03-26 11:31:21 +01:00
Lubomir Rintel
da226ae137 manager: separate the traversal to disconected to a separate routine
Will be useful when we'll be able to defer the realization of the
device.
2016-03-26 11:31:20 +01:00
Lubomir Rintel
6219759490 device: _get_available_connections() with _get_best_connection()
We'll need to share the best conneciton logic and it's the only caller
of nm_device_get_available_connections(). Let's just move it all to
NMDevice and provide the best connection from there instead.
2016-03-26 11:29:41 +01:00
Thomas Haller
2eab5ed347 utils: inject platform into nm_utils_complete_generic() 2016-03-15 12:56:58 +01:00
Beniamino Galvani
e80fc0566a manager: fix assumption of child connections with autoconnect=no
During startup, when a link is detected (enp0s25 in the example below)
we try to create also virtual devices (ipip1) on it through
system_create_virtual_device(), however this realizes only devices for
connections which can autoactivate.

To support the assumption of child devices with autoconnect=no, we
should take in consideration in retry_connections_for_parent_device()
only connections for which the link does not exist, and let existing
links be handled by platform_link_added(), which also realizes them.

Reproducer:
 $ nmcli c add type ip-tunnel ifname ipip1 con-name ipip1+ autoconnect no \
               mode ipip remote 172.25.16.1 dev enp0s25 ip4 1.2.3.4/31
 $ nmcli c up ipip1+
 $ systemctl restart NetworkManager

Result:
 * before: ipip1+ is not assumed, ipip1 is not present in 'nmcli d' output
 * after:  ipip1+ is assumed, ipip1 detected
2016-03-09 09:48:44 +01:00
Thomas Haller
b36d721525 all: drop str_if_set() in favor of the "?:" operator
str_if_set() was added to replace the non-standard gcc extension "?:".
However, "?:" is supported by clang as well and we already use it at
several places.

Also, str_if_set() did not follow our naming scheme and renaming to
nm_str_if_set() would be ugly. So just drop it.
2016-03-08 17:57:20 +01:00
Thomas Haller
cd4f84b738 all: don't include error->code in log messages
GError codes are only unique per domain, so logging the code without
also indicating the domain is not helpful. And anyway, if the error
messages are not distinctive enough to tell the whole story then we
should fix the error messages.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller
01b9b4104c all: clean-up usage of GError
Functions that take a GError** MUST fill it in on error. There is no
need to check whether error is NULL if the function it was passed to
had a failing return value.

Likewise, a proper GError must have a non-NULL message, so there's no
need to double-check that either.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Beniamino Galvani
8f706197fe manager: use logging helpers 2016-03-02 12:16:23 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- 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
2016-02-19 17:53:25 +01:00
Lubomir Rintel
3f669444ce manager: don't proceed with activation when there's no master device
Since the device-for-all merge it's a sin (trips an assert) to create an
activation request with NULL device.

If we get here, it's probably that the master device exists, but is not ready
for activation (it's in UNMANAGED state in the process of being created).
2016-02-17 19:04:05 +01:00
Thomas Haller
e93abf0552 device: optimize nm_manager_get_connection_iface() 2016-02-17 18:43:45 +01:00
Thomas Haller
ca0dbefb02 manager: reused the factory looked up in nm_manager_get_connection_iface()
Only lookup the factory once and pass it down to find_parent_device_for_connection().
2016-02-17 18:43:44 +01:00
Lubomir Rintel
f9ec713641 device: move the interface name check from manager
We not only want to check the device name when creating a virtual device, but
also when determining if the connection can actually be activated there.

Otherwise the device names will mix up if there's more connections that use
virtual devices of the same type.
2016-02-17 18:43:44 +01:00
Lubomir Rintel
adc9895ebe manager: export nm_manager_get_connection_iface()
We'll need the actual device name that should be used for a connection
activated on a given device when checking the connection availability.
2016-02-17 18:43:44 +01:00