Commit graph

782 commits

Author SHA1 Message Date
Lubomir Rintel
fd314ed7f7 device-factory/trivial: rename get_virtual_iface_name() to get_connection_iface() 2016-02-17 18:43:02 +01:00
Beniamino Galvani
b8c677a0eb manager: fix typo in error message
Fixes: 1762d58a8c
2016-02-16 16:22:50 +01:00
Thomas Haller
87a3df2e57 device: remove default-unmanaged and refactor unmanaged flags
Get rid of NM_UNMANAGED_DEFAULT and refine the interaction between
unmanaged flags, device state and managed property.

Previously, the NM_UNMANAGED_DEFAULT was special in that a device was
still considered managed if it had solely the NM_UNMANAGED_DEFAULT flag
set and its state was managed. Thus, whether the device (state) was managed,
depended on the device state too.

Now, a device is considered managed (or unmanaged) based on the unmanaged
flags and realization state alone. At the same time, the device state
directly corresponds to the managed property of the device. Of course,
while changing the unmanaged flags, that invariant is shortly violated
until the state transistion is complete.

Introduce more unmanaged flags whereas some of them are non-authorative.
For example, the EXTERNAL_DOWN flag has only effect as long as the user
didn't explicitly manage the device (NM_UNMANAGED_USER_EXPLICIT). In other
words, certain flags can render other flags ineffective. Whether the device
is considered managed depends on the flags but also at the explicitly unset flags.
In a way, this is similar to previous where NM_UNMANAGED_DEFAULT was ignored
(if no other flags were present).

Also, previously a device that was NM_UNMANAGED_DEFAULT and in disconnected
state would transition back to unmanaged. No longer do that. Once a device is
managed, it stays managed as long as the flags indicate it should be managed.
However, the user can also modify the unmanaged flags via the D-Bus API.

Also get rid or nm_device_finish_init(). That was previously called
by NMManager after add_device(). As we now realize devices (possibly
multiple times) this should be handled during realization.

https://bugzilla.gnome.org/show_bug.cgi?id=746566
2016-02-15 21:40:02 +01:00
Thomas Haller
2a17dbf48b device/trivial: rename nm_device_set_unmanaged_flags() 2016-02-15 21:33:32 +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
858e4bca45 manager: downgrade assertions to g_critical() in manager's singleton getters 2016-01-27 14:18:38 +01:00
Beniamino Galvani
e3a6ba6756 manager: cleanup active connections upon exit
When connection sharing is enabled, the removal of iptables rules is
delegated to the NMActRequest destructor; but for this to work it is
required that the object is properly dereferenced upon NM termination.

Clean up the active connections which are in DEACTIVATED state when
quitting, so that they are unexported and destroyed.

https://bugzilla.gnome.org/show_bug.cgi?id=692673
2016-01-23 10:01:21 +01:00
Thomas Haller
944065c115 core: check generated virtual interfaceplatform name
https://bugzilla.redhat.com/show_bug.cgi?id=1300755
2016-01-21 18:38:52 +01:00
Beniamino Galvani
a4492f4145 manager: fix a couple of memory leaks
Fixes: 4dbaac4ba2
Fixes: d8e1590c50
2016-01-21 18:23:53 +01:00
Thomas Haller
988ad91976 manager: refactor construction of manager singleton instance
nm_manager_setup() should only call g_object_new() and leave
most of the initialization to the GObject constructor.
2016-01-18 18:12:15 +01:00
Thomas Haller
be9ff2c51a manager: initilize NETWORKING_ENABLED as constructor paramter 2016-01-18 14:22:50 +01:00
Thomas Haller
c8e7957c63 core: add NMLOG macros to nm-manager.c 2016-01-18 14:04:56 +01:00
Thomas Haller
2292cb63bf core: always unrealize software devices when platform link disappears
We possibly need the unrealized device for connections that need
this. nm_device_unrealize() will check if there are still any
available-connections and possibly emit DEVICE_REMOVED signal.

Fixes: 7e5f27a21c
2016-01-17 22:40:04 +01:00
Thomas Haller
7830b79d50 device: minor logging changes to device creation 2016-01-17 22:38:28 +01:00
Thomas Haller
ae7e468630 trivial: fix whitespace 2016-01-17 22:38:28 +01:00
Beniamino Galvani
5996565ca9 manager: retry virtual connections when a device is added or changes
When a new device gets added or when an existing one changes name,
virtual connections that refer to it as parent device may become
ready, so let's try to activate them.

Previously we tried to activate virtual connections only on startup
and, after commit d8e1590c50 ("manager: retry device creation for
connection that would use a newly created device"), also when a
connection was added/changed, but this doesn't cover the case in which
a parent device appears or changes name at runtime.

https://bugzilla.redhat.com/show_bug.cgi?id=1275875
2016-01-15 09:36:19 +01:00
Lubomir Rintel
8b18c613ab manager: don't reject all internal activations on non-autoconnectable devices
When there's a slave that allows autoconnection and an unrealized master this
would cause the master activation to fail.

For the actual auto-activations the proper check is already done in NMPolicy's
auto_activate_device().
2016-01-13 17:21:31 +01:00
Thomas Haller
2550850f54 device: pass NMPlatformLink instance as const pointer 2016-01-11 14:05:49 +01:00
Thomas Haller
633e105455 device/trivial: rename realize/setup function in NMDevice 2016-01-11 14:05:49 +01:00
Thomas Haller
72e118716e trivial: fix whitespace 2016-01-11 12:22:19 +01:00
Thomas Haller
4706df11fd trivial: fix whitespace 2016-01-08 16:11:56 +01:00
Beniamino Galvani
7976edb723 manager: get rid of unused defines 2016-01-07 22:40:58 +01:00
Beniamino Galvani
44789e3291 core: simplify generation of default connection for new devices
Instead of using a signal for triggering the generation of a default
connection when the device becomes managed, let the manager wait for a
transition to UNAVAILABLE or DISCONNECTED states.

This partially reverts b3b0b46250 ("device: retry creation of
default connection after link is initialized").
2016-01-07 11:52:52 +01:00
Beniamino Galvani
24d8604637 core: use NM_PLATFORM_GET instead of nm_platform_get() in function calls
Replacement was done with command:

spatch --sp-file nm_platform_get.cocci --in-place --smpl-spacing --dir src

where nm_platform_get.cocci contains:

@@
identifier func;
expression list args;
@@
- func (nm_platform_get())
+ func (NM_PLATFORM_GET)

@@
identifier func;
expression list args;
@@
- func (nm_platform_get(), args)
+ func (NM_PLATFORM_GET, args)
2016-01-06 21:25:56 +01:00
Beniamino Galvani
fbd3286955 core,libnm: use nm_clear_g_source() where possible
Replacement was done with commands:

spatch --sp-file nm_clear_g_source.cocci --in-place --smpl-spacing --dir src
spatch --sp-file nm_clear_g_source.cocci --in-place --smpl-spacing --dir libnm

where nm_clear_g_source.cocci contains:

@@
expression e;
@@
- if (e) {
-    g_source_remove (e);
-    e = 0;
- }
+ nm_clear_g_source (&e);
2016-01-06 21:25:55 +01:00
Lubomir Rintel
d830841d63 manager: return values for a non-void function
Fixes: d8e1590c50
2015-12-18 12:10:02 +01:00
Lubomir Rintel
d8e1590c50 manager: retry device creation for connection that would use a newly created device
The VLANs (unrealized) can depend on the devices that are not around yet. We
need to retry their creation when the potential parents appear.
2015-12-18 11:32:34 +01:00
Thomas Haller
4878516281 trivial: fix indention/whitespace 2015-12-17 15:39:24 +01:00
Lubomir Rintel
a8a4eb1418 manager: don't create the virtual devices on all connection changes
Only do so on user initiated changes. Fixes this:

  # ip link add br0 type bridge
  # ip addr add 2001:DB8::666/64 dev br0
  # ip link set br0 up            # A generated connection is assumed
  # ip link del br0               # The device and its address are removed.
                                  # The address removal triggers an update
                                  # of the connection's ipv6 settings,
                                  # which causes the NMDevice to reappear.
  # ip link add br0 type bridge   # The new plink is associated with
                                  # the NMDevice, managed by NM
2015-12-15 13:19:25 +01:00
Lubomir Rintel
96c01f55bc manager: clean up the system_create_virtual_device() error handling
Do the reporting in system_create_virtual_device() only. None of the callers
checked for errors and some of the callees did issue a warning despite also
passing back a GError.

Also, drop the return value. It didn't make much sense and was not used anyway.
2015-12-11 17:03:54 +01:00
Lubomir Rintel
71a684159f manager: if there's an unrealized device that matches new connection, realize it
Fixes this:

  nmcli c add type bridge    # Creates and realizes the device, autoconnects connection
  nmcli c del bridge         # Device unrealizes
  nmcli c add type bridge    # The new connection does not autoconnect, since the
                             # device stays unrealized
2015-12-11 17:03:54 +01:00
Lubomir Rintel
7e5f27a21c manager: let external devices go on removal
If we didn't create them, we shouldn't keep them around unrealized.
2015-12-09 15:41:39 +01:00
Thomas Haller
e967cbd0bf device: during activating device transit to DISCONNECTED state
When activating a device, we must progress the device state to
disconnected state.

This matters when activating a device without carrier. In this
case we would have skipped DISCONNECTED state. Skipping the
device state then leads to other issues like a slave device
never noticing that the master got ready.
2015-12-09 12:42:50 +01:00
Lubomir Rintel
1762d58a8c manager: improve the add_device() error handling a bit
Let it indicate that it didn't succeed adding a device to the global list and
bail out.
2015-12-08 18:11:53 +01:00
Thomas Haller
03f8ba490a core: use define for NMManager's "state-changed" signal name 2015-12-07 19:54:12 +01:00
Thomas Haller
ee4ec4e600 core: use define for NMDevice's "state-changed" signal name 2015-12-07 19:53:14 +01:00
Thomas Haller
546272b216 core: subscribe recheck_assume_connection() early when adding device
It's clearer to (always) subscribe early to the NM_DEVICE_RECHECK_ASSUME signal
instead of during realize. Also, because a device can be realized several times.
Just make sure that recheck_assume_connection() doesn't do anything if it shouldn't
handle the event.
Only downside is some unnecessary work when there is nothing to do.

Also fix the signature of the NM_DEVICE_RECHECK_ASSUME handler recheck_assume_connection().
NM_DEVICE_RECHECK_ASSUME signal returns void. We should not subscribe recheck_assume_connection()
which returns gboolean.
2015-12-04 17:36:16 +01:00
Thomas Haller
3b6602b656 device: expose nm_device_set_autoconnect() function 2015-12-04 15:46:04 +01:00
Thomas Haller
4c9ffa8dba core/trivial: rename functions 2015-12-04 15:46:04 +01:00
Thomas Haller
01a644a05b manager: fix clearing weak-ref in platform_link_added()
We must always clear the weak-ref.

Fixes: 4dbaac4ba2
2015-12-04 14:13:40 +01:00
Dan Williams
f2256af5bc core: allow multiple devices with the same interface name
But, of course, only one realized device can have the same
interface name at a time.

This commit effectively reverts most of:

1b37cd0340
core: allow ActiveConnections to be created without a device

But it's not easy to do a separate revert of that code due to
interdependencies with nm-manager.c.

Creating devices when they are defined by a connection also makes
makes it possible to require the NMDevice to be present when
activating it, which means we can remove a bunch of code from
NMManager that had to handle software devices not existing yet at
the time of the activation request.

But it also means we must be more careful when finding master
interfaces during slave activation, since we cannot simply match
by interface name alone.  Instead we must find the master which
matches both the interface name and can control slaves of the type
which is being activated.
2015-12-04 12:16:41 +01:00
Dan Williams
5da37a129c api/manager: add GetAllDevices() method and AllDevices property
Returns both realized and un-realized devices.
2015-12-04 12:16:41 +01:00
Dan Williams
20906ca7a3 core: ensure platform links are compatible with the NMDevice
Ensure the platform link with the same interface name as the
NMDevice is actually compatible with it before using the link
for initialization of device properties.  If not, remove the
NMDevice and create a new one since there are kernel resources
with a different type.
2015-12-04 12:16:41 +01:00
Dan Williams
4dbaac4ba2 core: create devices first and realize them later
Unrealized devices aren't backed by kernel resources and so won't know
all of their attributes.  That means three things:

1) they must update their attributes when they become realized
2) they must clear those attributes when unrealized
3) they must be looser in checking compatible connections until
they are realized

This requires that the setup() function be split into two parts, start & finish,
because finish must be run after add_device()

Also, we can simplify whether to pay attention to 'recheck-assume', which
is now dependent on priv->is_nm_owned, because the only case where NM should
*not* listen for the 'recheck-assume' signal is when the device is a
software device created by NM itself.  That logic was previously spread
across the callers of add_device() but is now consolidated into
nm-manager.c::device_realized() and nm-device.c::nm_device_create_and_realize().
2015-12-04 12:16:40 +01:00
Dan Williams
0be66bb1eb core: add class function for device unrealization
When a device is unrealized, its class-specific properties must also be cleared
since the device is no longer valid.
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
9e36ccbe28 device: split new_device_added() out of component_added()
Commit cd3df12c8f reused the
virtual function component_added() to notify the vlan device
about a possibly new parent.

This reuse of the virtual function for another purpose is confusing.
Clean that up by splitting the implementation and add a new
virtual function nm_device_notify_new_device_added() which gets
(only implemented by NMDeviceVlan).
2015-12-04 12:15:12 +01:00
Thomas Haller
510e53ca16 platform: remove NMPlatformReason enum
This enum was unused and meaningless because the platform signals
are emitted as a consequence of netlink messages. It is not clear
whether a netlink message was received due to an external event
or an internal action.
2015-11-27 15:17:44 +01:00
Dan Williams
b023d0754b exported-object: add support for DBus ObjectManager interface
NMExportedObject now derives from GDBusObjectSkeleton, which is what
GDBusObjectManagerServer wants.  The main GDBusConnection and each
private server connection now gets a new GDBusObjectManagerServer,
and exported objects are registered with that instead of individually
exporting each GDBusInterfaceSkeleton.

Previously exported objects were not referenced by the BusManager,
but instead removed from the exports hash via weak references.  The
GDBusObjectManagerServer instead references exported objects, which
can make them live much longer than they did before.

Co-Authored-By: Thomas Haller <thaller@redhat.com>
2015-11-18 15:15:05 +01:00
Dan Williams
f9ee20a7b2 core: explicitly unexport objects when we're done with them
Previously most objects were implicitly unexported when they were
destroyed, but since refcounts may make the object live longer than
intended, we should explicitly unexport them when they should no
longer be present on the bus.

This means we can assume that objects will always be un-exported
already when they are destroyed, *except* when quitting where most
objects will live until exit because NM leaves interfaces up and
running on quit.
2015-11-10 18:12:12 +01:00