Commit graph

12329 commits

Author SHA1 Message Date
Thomas Haller
87c1b92cc5 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.

(cherry picked from commit d7fe907c32)
2015-06-22 09:54:52 +02:00
Thomas Haller
8fbd2d84e8 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.

(cherry picked from commit f7fb68755c)
2015-06-22 09:54:52 +02:00
Thomas Haller
0def11cf47 platform: expose GUdevDevice instance for platform links
(cherry picked from commit b74e620f2d)
2015-06-22 09:54:52 +02:00
Thomas Haller
eb0b0eb7f3 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.

(cherry picked from commit e7ee2fc139)
2015-06-22 09:54:52 +02:00
Thomas Haller
ae168e53ca 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 d0e2937006.

(cherry picked from commit 3359dddd2e)
2015-06-22 09:54:36 +02:00
Thomas Haller
42a93b79ed 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.

(cherry picked from commit 1b2b988ea9)
2015-06-21 15:32:13 +02:00
Thomas Haller
fb0443def9 glib-compat: add g_ptr_array_insert()
(cherry picked from commit 2f4301bd26)
2015-06-21 15:32:11 +02:00
Thomas Haller
fe803bc567 platform: stringify nlmsg-event-type in logging
(cherry picked from commit e16fe9ddd4)
2015-06-21 15:30:50 +02:00
Thomas Haller
1162eee1be platform/trivial: rename functions (NMIPConfigSource conversion)
(cherry picked from commit 5b80be5a2c)
2015-06-21 15:30:50 +02:00
Thomas Haller
43f799da03 platform/trivial: move code (NMIPConfigSource conversion)
(cherry picked from commit 37df41a38e)
2015-06-21 15:30:50 +02:00
Thomas Haller
db036ef528 platform/trivial: rename functions (nm_rtnl_link_parse_info_data)
(cherry picked from commit 0e0d3b0775)
2015-06-21 15:30:50 +02:00
Thomas Haller
f38f5de4ba platform/trivial: move code (nm_rtnl_link_parse_info_data)
(cherry picked from commit 2f0a9bbe9a)
2015-06-21 15:30:50 +02:00
Thomas Haller
25fb3c822d platform/trivial: rename by using _nl_*() prefix for libnl related functions
(cherry picked from commit af70a7fc7c)
2015-06-21 15:30:49 +02:00
Thomas Haller
d24732b874 platform: remove redundant NMPlatformLink fields "arp" and "up"
(cherry picked from commit 076fe578e3)
2015-06-21 15:30:49 +02:00
Thomas Haller
44dc97d184 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
(cherry picked from commit 051cf8bbde)
2015-06-21 15:30:49 +02:00
Thomas Haller
f1c6d71784 libnm: add _nm_utils_ptrarray_find_first() utility function
(cherry picked from commit 3377cd7e18)
2015-06-21 15:30:49 +02:00
Thomas Haller
5daac57a23 utils: add nm_utils_is_power_of_two() macro
(cherry picked from commit 0a3c1f5774)
2015-06-21 15:30:47 +02:00
Thomas Haller
662194cde3 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.

(cherry picked from commit 56b07b1a3f)
2015-06-21 15:26:18 +02:00
Thomas Haller
25519f798d platform: reorder initialization
First fully construct the GOjbect instance before starting to
populate the cache.

(cherry picked from commit f1f1c3cb73)
2015-06-21 15:23:34 +02:00
Thomas Haller
8d13e08cd3 platform: add _support_user_ipv6ll_still_undecided() macro
(cherry picked from commit a2d793f0e1)
2015-06-21 15:23:34 +02:00
Thomas Haller
521d80dd9d platform: add priv pointer to NMLinuxPlatform
(cherry picked from commit bd9dab2a09)
2015-06-21 15:23:34 +02:00
Thomas Haller
6745030913 platform: refactor flushing of event socket to _nl_sock_flush_data()
(cherry picked from commit 9a16ce0876)
2015-06-21 15:23:34 +02:00
Thomas Haller
eb7b773536 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.

(cherry picked from commit 977626d942)
2015-06-21 15:23:34 +02:00
Thomas Haller
e655d053a1 platform: remove unused argument preserve_rtprot from rtprot_to_source()
(cherry picked from commit 4fee05c35b)
2015-06-21 15:23:34 +02:00
Thomas Haller
f4f78e002d platform: remove obsolete functions after refactoring platform cache
(cherry picked from commit 2f0d0b96db)
2015-06-21 15:23:34 +02:00
Thomas Haller
aa9a596724 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
(cherry picked from commit 470bcefa5f)
2015-06-21 15:23:31 +02:00
Thomas Haller
e784f7d23d 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.

(cherry picked from commit f268dca0f1)
2015-06-21 15:21:56 +02:00
Thomas Haller
d45bb6d461 platform: implement NMPObject and NMPCache
NMPObject is a simple "object" implemenation around NMPlatformObject.
They are ref-counted and have a class-pointer. Several basic functions
like equality, hash, to-string are implemented.

NMPCache is can be used to store the NMPObject. Objects are indexed
via their primary id, but there is also multi-lookup via NMCacheId
and NMMultiIndex.

Part of the implementation is inside "nm-linux-platform.c",
because it depends on utility functions from there.

(cherry picked from commit 53f98e7f9e)
2015-06-21 15:21:56 +02:00
Thomas Haller
9842f292c1 platform: move ObjectType to nmp-object.h
(cherry picked from commit d1e7554a90)
2015-06-21 15:21:56 +02:00
Thomas Haller
d4899efd49 platform: add nmp-object.h file
(cherry picked from commit 359fe9f8c1)
2015-06-21 15:21:56 +02:00
Thomas Haller
9bd4cf340d core: add NMMultiIndex class
A class to do efficient lookup for multiple values based on a key.

The values are opaque pointers (void*). These values can be
associated with keys. The keys are an opaque type NMMultiIndexId
with arbitrary hash/equal functions.

Think of the keys being a set of buckets. A value can be associated with multiple
keys, just like with a regular GHashTable (i.e. it can be in multiple buckets).
But one key can also be associated with multiple values (i.e. one bucket can contain
multiple values). Hence the name "multi".
One bucket can only either contain a value or not. It cannot contain the same
value multiple times.

This is implemented as a hash of hashes with the outer keys being
NMMultiIndexId. The inner hashes are the "buckets".

This class will be used as an efficient lookup index to find all values
that belong to a certain key (bucket). Later we will ask for example
"Which IP4-Addresses are associated with a certain ifindex" and
efficiently retrieve the cached result list.

(cherry picked from commit f99723eda5)
2015-06-21 15:21:56 +02:00
Thomas Haller
d0e2937006 core: add NMRefString
NMRefString is a simple, refcounted, immutable string. Increasing/decreasing
the refcount does not affect const-ness.

It can be used just like a regular 'const char *' pointer. The only
difference is that you need special alloc/free functions.

(cherry picked from commit 430658b17a)
2015-06-21 15:21:54 +02:00
Thomas Haller
a87231abbc glib-compat: add nm_g_hash_table_replace() compat function
The newer version of g_hash_table_replace() is useful, because it
saves an additional hash table lookup.

(cherry picked from commit 2bea70e750)
2015-06-21 15:19:01 +02:00
Thomas Haller
fa7acaef83 platform: add _NM_IP_CONFIG_SOURCE_RTPROT_KERNEL source
Later we will need this flag to distinguish routes from kernel
that have source RTPROT_KERNEL.

This flag is still unused.

(cherry picked from commit 64d918293b)
2015-06-21 15:19:01 +02:00
Thomas Haller
01d20783ed platform: implement dispose() in NMLinuxPlatform
(cherry picked from commit 304abc909a)
2015-06-21 15:19:01 +02:00
Thomas Haller
4ac1889a86 platform: print more fields in nm_platform_link_to_string()
(cherry picked from commit c34598fa23)
2015-06-21 15:19:01 +02:00
Thomas Haller
27c87c75b8 platform: expose internal buffer for to_string() functions
I'd like to reuse this buffer for other to-string functions that
are platform related.

(cherry picked from commit 655a0e71d4)
2015-06-21 15:19:01 +02:00
Thomas Haller
988e8139d0 platform/trivial: rename to_string_buffer variable
(cherry picked from commit 806109c245)
2015-06-21 15:19:01 +02:00
Thomas Haller
79f2c30099 platform: add inet6_token parameter to NMPlatformLink
(cherry picked from commit 32ab8c18f5)
2015-06-21 15:19:01 +02:00
Thomas Haller
0acc868baa platform: add arptype parameter to NMPlatformLink
(cherry picked from commit 3ce4431695)
2015-06-21 15:19:01 +02:00
Thomas Haller
0ee58d136a platform: add inet6_addr_get_mode_inv parameter to NMPlatformLink
(cherry picked from commit 5b2b62ff51)
2015-06-21 15:19:00 +02:00
Thomas Haller
a0cb0b6b08 platform: add addr parameter to NMPlatformLink
(cherry picked from commit 36e77218a0)
2015-06-21 15:19:00 +02:00
Thomas Haller
607b69bbc0 platform: add vlan_id parameter to NMPlatformLink
(cherry picked from commit 3cdde18f52)
2015-06-21 15:19:00 +02:00
Thomas Haller
4e2ef48a21 platform: add flags parameter to NMPlatformLink
(cherry picked from commit b307abc010)
2015-06-21 15:19:00 +02:00
Thomas Haller
980d6f4b78 platform: add scope parameter to NMPlatformIP4Route
Cache the scope as part of the NMPlatformIP4Route and
no longer read it from libnl object when needed. Later
there will be no more libnl objects around, and we need
to scope when deleting an IPv4 route.

(cherry picked from commit 619f660a3e)
2015-06-21 15:18:56 +02:00
Thomas Haller
4e5a11f229 platform: return @now from _rtnl_addr_last_update_time_to_nm()
Will be used later.

(cherry picked from commit 4c49d78f49)
2015-06-21 15:18:15 +02:00
Jiří Klimeš
0380c53c39 core/cli: add missing device state-reason to string conversions
for NM_DEVICE_STATE_REASON_PARENT_CHANGED
and NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED

Fixes: cd3df12c8f
(cherry picked from commit bfd502a9b1)
2015-06-20 11:38:35 +02:00
Thomas Haller
8366b9f60d device: fix wrong assert in NMDeviceFactory
nm_device_factory_manager_find_factory_for_link_type()
easily can see a link-type NM_LINK_TYPE_UNKNOWN because
there are many link types that NetworkManager cannot detect.

Just return NULL early.

Fixes: 71bde20c30
(cherry picked from commit eb2efaa228)
2015-06-20 11:38:17 +02:00
Beniamino Galvani
435dec420f wifi: fix memleak in nm_ap_update_from_properties()
Fixes: 59c8192b22
(cherry picked from commit 3e8d828008)
2015-06-20 11:36:55 +02:00
Dan Williams
5fa0b8a222 wifi: fix recognition of AP RSN capabilities
Stupid C&P error made everything look like WPA1.

Fixes: 59c8192b22
(cherry picked from commit fce2fa57a5)
2015-06-20 11:30:17 +02:00