Commit Graph

13873 Commits

Author SHA1 Message Date
Jiří Klimeš
2dc27a99d7 all: fix additional compiler warningis about function declarations
warning: function declaration isn’t a prototype [-Wstrict-prototypes]

In C function() and function(void) are two different prototypes (as opposed to
C++).
function()     accepts an arbitrary number of arguments
function(void) accepts zero arguments
2015-06-19 13:06:37 +02:00
Jiří Klimeš
b18f328967 merge: activate slaves when master is activated (bgo #735052) (rh #1158529)
When a master connection is activated, check all its slaves and decide whether
they should be activated as well. This is done according to the
connection.autoconnect-slaves property.

https://bugzilla.gnome.org/show_bug.cgi?id=735052
https://bugzilla.redhat.com/show_bug.cgi?id=1158529
2015-06-19 09:58:17 +02:00
Jiří Klimeš
f05d41d358 man: mention that connection.autoconnect-slaves property supports default value 2015-06-19 09:32:58 +02:00
Jiří Klimeš
f4582d812c core: activate slaves when master is activated (bgo #735052) (rh #1158529)
When a master connection is activated, check all its slaves and decide whether
they should be activated as well. This is done according to the
autoconnect-slaves property.

https://bugzilla.gnome.org/show_bug.cgi?id=735052
https://bugzilla.redhat.com/show_bug.cgi?id=1158529
2015-06-19 09:32:58 +02:00
Jiří Klimeš
c3093d9391 cli: add support for connection.autoconnect-slaves property 2015-06-19 09:32:58 +02:00
Jiří Klimeš
2a497eeadc ifcfg-rh: read/write autoconnect-slaves property as AUTOCONNECT_SLAVES
AUTOCONNECT_SLAVES is an NetworkManager extension. initscripts always activate
slaves with the master connection for bond and team, and doesn't activate
automatically slaves for bridge.
NetworkManager behaviour is controlled by this variable. If the variable is
missing the default value from configuration file is used.
2015-06-19 09:32:58 +02:00
Jiří Klimeš
6caafab258 libnm: add autoconnect-slaves property to NMSettingConnection
The property is used for controlling whether slaves should be brought up with
a master connection. If 0, activating the master will not activate slaves.
But if set to 1, activating the master will bring up slaves as well.
The property can have the third state (-1), meaning that the value is default.
That is either a value set in the configuration file for the property, or 0.
2015-06-19 09:32:58 +02:00
Lubomir Rintel
203e48033b vxlan: o.fd.NM.Device.Proxy is a boolean 2015-06-18 22:26:36 +02:00
Lubomir Rintel
2bfbf33720 manager: use proper reason when stealing a connection
The user-requested reason is not really appropriate and blocks autoreconnect.
We added a new reason precisely for that.

Fixes: 4cb97cf66f
2015-06-18 15:45:15 -04:00
Thomas Haller
6849050ad9 default-route-manager: fix syncing routes to consider non-synced routes
We already protected route-metrics that are configured as default-routes
in platform. For most cases, that list is identical to our internal list
of non-synced routes.
But if for some reason that is not the case, we must also protect the
metric of routs that we currently track as "non-synced".
2015-06-18 18:39:12 +02:00
Thomas Haller
8f9dac01ac platform: fix lookup addresses and routes for any ifindex and refactor NMPCacheIdType
After refactoring platform, nm_platform_ipx_route_get_all() and
nm_platform_ipx_address_get_all() was broken for calling with a
non-posititive ifindex (which has the meaning: ignore ifindex).

While fixing that, also refactor the NMPCacheIdType so that it matches
better the supported id-types.

Fixes: 470bcefa5f
2015-06-18 17:19:00 +02:00
Thomas Haller
04caae735f device: delay handling of link-changed platform event
When inside a state-change, we set for example the device up.
This triggers a link-changed event, which then causes further
state-changes of the devices.
A state-change in process of a device is not reentrant, so we must
delay the handling of the link-changed event.
2015-06-18 10:33:30 +02:00
Thomas Haller
8da17c3a19 default-route-manager: disambiguate logging statements 2015-06-17 18:17:49 +02:00
Thomas Haller
5ecfbf18c2 settings: print filename of loaded setting plugins 2015-06-17 17:48:33 +02:00
Thomas Haller
972f61fcd7 macros: add NM_PRINT_FMT_QUOTED() macro 2015-06-17 17:46:54 +02:00
Thomas Haller
3be5e2908c settings: close module if loading of plugins fails 2015-06-17 17:46:54 +02:00
Thomas Haller
fba17e5c84 platform: add g_return_val_if_fail() check to nm_platform_sysctl_set_ip6_hop_limit_safe() 2015-06-17 15:00:10 +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
35dcd8ac33 platform: merge branch 'th/platform_refact_caching-bgo747981'
Refactor caching of NMPlatform and the way how to load objects
via libnl/netlink.

https://bugzilla.gnome.org/show_bug.cgi?id=747981
https://bugzilla.gnome.org/show_bug.cgi?id=747985
https://bugzilla.redhat.com/show_bug.cgi?id=1211133
2015-06-17 11:50:53 +02:00
Thomas Haller
68a4ffb4e2 platform: drop nm_platform_get_error()
For NMPlatform instances we had an error reporting mechanism
which stores the last error reason in a private field. Later we
would check it via nm_platform_get_error().

Remove this. It was not used much, and it is not a great way
to report errors.

One problem is that at the point where the error happens, you don't
know whether anybody cares about an error code. So, you add code to set
the error reason because somebody *might* need it (but in realitiy, almost
no caller cares).
Also, we tested this functionality which is hardly used in non-testing code.
While this was a burden to maintain in the tests, it was likely still buggy
because there were no real use-cases, beside the tests.

Then, sometimes platform functions call each other which might overwrite the
error reason. So, every function must be cautious to preserve/set
the error reason according to it's own meaning. This can involve storing
the error code, calling another function, and restoring it afterwards.
This is harder to get right compared to a "return-error-code" pattern, where
every function manages its error code independently.

It is better to return the error reason whenever due. For that we already
have our common glib patterns

    (1) gboolean fcn (...);
    (2) gboolean fcn (..., GError **error);

In few cases, we need more details then a #gboolean, but don't want
to bother constructing a #GError. Then we should do instead:

    (3) NMPlatformError fcn (...);
2015-06-17 11:44:16 +02:00
Thomas Haller
baec894139 device: drop logging platform error on failure to set permanent MAC address
The platform error is in many cases not meaningful anyway.
2015-06-17 11:44:16 +02:00
Thomas Haller
c1a945b95d platform: signal missing firmware in nm_platform_set_up()
Don't use nm_platform_get_error() anymore.
2015-06-17 11:44:16 +02:00
Thomas Haller
8334171a4e device: don't check for NM_PLATFORM_ERROR_NOT_FOUND in set_nm_ipv6ll()
Unconditionally log a warning if the function fails.
We are about to drop nm_platform_get_error(), it's anyway unclear
why we don't want to log a warning about non-existing interface.
2015-06-17 11:44:16 +02:00
Thomas Haller
d7fe907c32 platform: return NMPlatformError from link-add functions
Later remove nm_platform_get_error() and signal errors via return
error codes.

Also, fix nm_platform_infiniband_partition_add() and
nm_platform_vlan_add() to check the type of the existing link
and fail with WRONG_TYPE otherwise.
2015-06-17 11:44:16 +02:00
Thomas Haller
f7fb68755c platform: rework NMPlatformError codes
- rename "NONE" to "SUCCESS", what it really is.
- change the to-string result not to contain spaces
  and being closer the name of the enum value.
- add new error reasons "UNSPECIFIED" and "BUG".
- remove the code comments around the enum definition.
  They add no further description about why this error
  happens and only paraphrase the name of the enum.
- reserve negative integers for 'errno'. This is neat
  because if we get a system error we can pass on the
  underlying errno as cause.
2015-06-17 11:44:16 +02:00
Thomas Haller
b74e620f2d platform: expose GUdevDevice instance for platform links 2015-06-17 11:44:16 +02:00
Thomas Haller
e7ee2fc139 platform: invoke platform signals with clone of object
Don't expose @obj directly but clone the public fields. A signal
handler might call back into NMPlatform which could invalidate (or modify)
@obj.
2015-06-17 11:44:16 +02:00
Thomas Haller
3359dddd2e Revert "core: add NMRefString"
After hiding the udi field, there are no more users of NMRefString.
Remove the code by explitly reverting the patch so that in case of a future
need, we can find and resurrect NMRefString.

This reverts commit 430658b17a.
2015-06-17 11:44:12 +02:00
Thomas Haller
1b2b988ea9 platform: no longer expose udi field in NMPlatformLink
The @udi field is not a static string, so any user of a NMPlatformLink
instance must make sure not to use the field beyond the lifetime of the
NMPlatformLink instance.
As we pass on the platform link instance during platform changed events,
this is hard to ensure for the subscriber of the signal -- because a
call back into platform could invalidate/modify the object.

Just not expose this field as part of the link instance. The few callers
who actually needed it should instead call nm_platform_get_uid(). With
that, the lifetime of the returned 'const char *' pointer is clearly
defined.
2015-06-17 11:41:43 +02:00
Thomas Haller
2f4301bd26 glib-compat: add g_ptr_array_insert() 2015-06-17 11:41:43 +02:00
Thomas Haller
e16fe9ddd4 platform: stringify nlmsg-event-type in logging 2015-06-17 11:41:43 +02:00
Thomas Haller
5b80be5a2c platform/trivial: rename functions (NMIPConfigSource conversion) 2015-06-17 11:41:43 +02:00
Thomas Haller
37df41a38e platform/trivial: move code (NMIPConfigSource conversion) 2015-06-17 11:41:43 +02:00
Thomas Haller
0e0d3b0775 platform/trivial: rename functions (nm_rtnl_link_parse_info_data) 2015-06-17 11:41:43 +02:00
Thomas Haller
2f0a9bbe9a platform/trivial: move code (nm_rtnl_link_parse_info_data) 2015-06-17 11:41:43 +02:00
Thomas Haller
af70a7fc7c platform/trivial: rename by using _nl_*() prefix for libnl related functions 2015-06-17 11:41:43 +02:00
Thomas Haller
076fe578e3 platform: remove redundant NMPlatformLink fields "arp" and "up" 2015-06-17 11:41:43 +02:00
Thomas Haller
051cf8bbde platform: fetch objects via the event socket
Use the event socket to request object via NLM_F_DUMP.

No longer use 'priv->nlh' socket to fetch objects.
Instead fetch them via the priv->nlh_event socket that also
provides asynchronous events when objects change.

That way, the events are in sync with our explicit requests
and we can directly use the events. Previously, the events were
only used to indicate that a refetch must happen, so that every
event triggered a complete dump of all addresses/routes.

We still use 'priv->nlh' to make synchronous requests such as
adding/changing/deleting objects. That means, after we send a
request, we must make sure that the result manifested itself
at 'nlh_event' socket and the platform cache.
That's why we sometimes still must force a dump to sync changes.
That could be improved by using only one netlink socket so that
we would wait for the ACK of our request.

While not yet perfect, this already significantly reduces the number of
fetches. Additionally, before, whenever requesting a dump of addresses
or routes (which we did much more often, search for "get_kernel_object for type"
log lines), we always dumped IPv4 and IPv6 together. Now only request
the addr-family in question.

https://bugzilla.gnome.org/show_bug.cgi?id=747985
https://bugzilla.redhat.com/show_bug.cgi?id=1211133
2015-06-17 11:41:43 +02:00
Thomas Haller
3377cd7e18 libnm: add _nm_utils_ptrarray_find_first() utility function 2015-06-17 11:41:43 +02:00
Thomas Haller
0a3c1f5774 utils: add nm_utils_is_power_of_two() macro 2015-06-17 11:41:43 +02:00
Thomas Haller
56b07b1a3f platform: register singleton instance early with NM_PLATFORM_REGISTER_SINGLETON
Add a construct-only property NM_PLATFORM_REGISTER_SINGLETON to NMPlatform.
When set to TRUE, the constructor will self-register to nm_platform_setup().

The reason for this is that the _LOG() macro in NMLinuxPlatform logs the
self pointer if the instance is not the singleton instance.

During construction, we already have many log lines due to initialization
of the instance. These lines all end up qualified with the self pointer.
By earlier self-registering, printing the pointer value is omitted.

Yes, this patch is really just to prettify logging.
2015-06-17 11:41:43 +02:00
Thomas Haller
f1f1c3cb73 platform: reorder initialization
First fully construct the GOjbect instance before starting to
populate the cache.
2015-06-17 11:41:42 +02:00
Thomas Haller
a2d793f0e1 platform: add _support_user_ipv6ll_still_undecided() macro 2015-06-17 11:41:42 +02:00
Thomas Haller
bd9dab2a09 platform: add priv pointer to NMLinuxPlatform 2015-06-17 11:41:42 +02:00
Thomas Haller
9a16ce0876 platform: refactor flushing of event socket to _nl_sock_flush_data() 2015-06-17 11:41:42 +02:00
Thomas Haller
977626d942 platform/test: add simple test for NMLinuxPlatform
Just create a NMLinuxPlatform instance and unref it again.
This already connects to netlink and fetches all objects.
2015-06-17 11:41:42 +02:00
Thomas Haller
4fee05c35b platform: remove unused argument preserve_rtprot from rtprot_to_source() 2015-06-17 11:41:42 +02:00
Thomas Haller
2f0d0b96db platform: remove obsolete functions after refactoring platform cache 2015-06-17 11:41:42 +02:00
Thomas Haller
470bcefa5f platform: use new platform caching
Switch platform caching implementation. Instead of caching libnl
objects, cache our own types.

Don't remove yet the now obsolete functions.

Advantage:

* Performance
  - as we now cache our native NMPlatformObject instances, we no longer
    have to convert libnl objects every time we access the platform
    cache.
  - for most cases, access is now O(1) because we can lookup the object
    in a hash table. Note that ip4_address_get_all() still has to
    create a copy of the result (O(n)), but as the caller is about to
    use those elements, he cannot do better then O(n) anyway.

* We cache our own native types and have full control over them. We
  cannot extend the libnl objects, which has many short-commings:
  - _rtnl_addr_hack_lifetimes_rel_to_abs() to convert the timestamps
    to absolute values (and back).
  - hack_empty_master_iff_lower_up() would modify the internal flag,
    but it looses the original value. That means, we can only hack
    the state before putting a link into the cache, but we cannot revert
    that change, when a slave in the cache changes state.
    That was previously solved by always refetching the master when
    a slave changed. Now we can re-evaluate the connected state
    (DELAYED_ACTION_TYPE_MASTER_CONNECTED).
  - we implement functions like equality, to-string as most suitable
    for us. Before we needed hacks like nm_nl_object_diff(),
    nm_nl_cache_search(), route_search_cache().
  - we can extend our objects with exactly those properties we care,
    and possibly additional properties that are not representable in
    the libnl objects.
  - we no longer cache RTM_F_CLONED routes and they get rejected early
    on as we receive them.
  - In the future, maybe it'd be interesting the make platform objects
    immutable (and ref-counted) and expose them directly.

* Previous implementation did not order the refresh of objects but
  called check_cache_items(). Now, those actions are delayed and
  combined in an attempt to reduce the overall number of reloads.
  Realize how expensive a check_cache_items() for addresses and routes
  was: it would iterate all addresses/routes and call refresh_object().
  The latter obtains a full dump of *all* objects again, and ignores
  all but the needle.
  Note that we probably still schedule some delayed actions that
  are not needed.
  Later we can optimize that further (related bug bgo #747985).

While some of these points could also have been implemented with
caching of libnl objects, that would have become hard to maintain.

https://bugzilla.gnome.org/show_bug.cgi?id=747981
2015-06-17 11:41:42 +02:00
Thomas Haller
f268dca0f1 platform: add new platform caching to nm-linux-platform.c
It is not yet used, only add new code beside the existing
implementation. It will be used later.
2015-06-17 11:41:42 +02:00