Commit Graph

360 Commits

Author SHA1 Message Date
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
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
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
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
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
Thomas Haller
53f98e7f9e 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.
2015-06-17 11:23:51 +02:00
Thomas Haller
d1e7554a90 platform: move ObjectType to nmp-object.h 2015-06-17 11:23:51 +02:00
Thomas Haller
64d918293b 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.
2015-06-17 10:54:56 +02:00
Thomas Haller
304abc909a platform: implement dispose() in NMLinuxPlatform 2015-06-17 10:54:56 +02:00
Thomas Haller
32ab8c18f5 platform: add inet6_token parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
3ce4431695 platform: add arptype parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
5b2b62ff51 platform: add inet6_addr_get_mode_inv parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
36e77218a0 platform: add addr parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
3cdde18f52 platform: add vlan_id parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
b307abc010 platform: add flags parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
619f660a3e 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.
2015-06-17 10:53:55 +02:00
Thomas Haller
4c49d78f49 platform: return @now from _rtnl_addr_last_update_time_to_nm()
Will be used later.
2015-06-12 16:30:34 +02:00
Jiří Klimeš
94a393e9ed all: fix a compiler warning 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-10 10:01:49 +02:00
Thomas Haller
2f3fd86dc5 platform: refactor support_kernel_extended_ifa_flags to static variable
Whether we have support depends on the kernel, and is not
per NMLinuxPlatform instance.
2015-06-05 16:52:50 +02:00
Thomas Haller
299af02e40 platform: move supports_mii_carrier_detect() to nmp_utils_mii_supports_carrier_detect() 2015-06-05 16:52:50 +02:00
Thomas Haller
ac84b22fc7 platform: move ethtool_*() to nmp_utils_ethtool_*() 2015-06-05 16:52:50 +02:00
Thomas Haller
398819c3ac platform: factor out ethtool_get_wake_on_lan() function 2015-06-05 16:52:50 +02:00
Thomas Haller
ba084b5b90 platform: factor out ethtool_get_peer_ifindex() function 2015-06-05 16:52:50 +02:00
Thomas Haller
4be9394864 platform: factor out ethtool_supports_vlans() function 2015-06-05 16:52:50 +02:00
Thomas Haller
2b8f3331d7 platform/trivial: move ethtool_supports_carrier_detect() code 2015-06-05 16:52:50 +02:00
Thomas Haller
77a3767d1e platform: move code udev_get_driver() to nmp_utils_udev_get_driver() 2015-06-05 16:52:50 +02:00
Thomas Haller
d6ce01f115 platform: merge setup_devices() function into constructed()
We already populate the netlink cache in constructed(). No need
to wait with udev devices until nm_platform_query_devices(). Just
do it right away.

Add a hack to keep 'lo' default-unmanaged. Now that we load
udev devices earlier, we end up clearing the default-unmanged
flag on 'lo', which has bad consequences.
2015-06-05 16:52:49 +02:00
Thomas Haller
39f2b51abb core: add option to suppress error logging if nm_utils_modprobe() fails
We don't want error logging for nm_platform_link_add() which
tries to load the bonding module. Later we will run tests as non-root,
where modprobe will fail. Logging an error would break the tests.
2015-06-05 16:52:49 +02:00
Lubomir Rintel
ef295ddeef platform-linux: allow netlink messages from non-privileged user namespaces
Just check they're from kernel.
2015-06-01 17:30:20 +00:00
Dan Williams
5cf226463a platform: move InfiniBand property reading into the platform and prefer netlink
Add a netlink implementation for reading InfiniBand properties, but fall back to
sysfs when that isn't supported by the kernel.
2015-05-19 09:25:16 -05:00
Thomas Haller
0c258402c7 platform: fix memleak in link_delete()
Turns out, the valgrind suppression was hiding a memleak
2015-05-13 14:24:06 +02:00
Lubomir Rintel
26aeb12749 linux-platforms: don't enumerate devices via udev if udevd is not running
We'd be able to do so for already existing devices, but not for devices that
are added afterwards, since gudev is hardwired not to listen for events from
kernel.
2015-05-11 19:28:13 +02:00
Thomas Haller
f55a272ade platform: fix compiler warning about non-initialized pointer
When compiling with -fexceptions (as we build our RPM), we must
initialize all variables with a cleanup attribute.

Fixes: 29ccb8851c
2015-05-07 11:10:36 +02:00
Dan Williams
aba250a7d4 core: move permanent and initial MAC address reading to NMDevice and NMPlatform
Ethernet, WiFi, and VLAN used the same implementation for initial address.

Ethernet and WiFi used the same implementation (and duplicated code) for
permanent MAC address, plus they both used ethtool in what should be
generic code, which is better done in the platform.
2015-05-06 16:14:25 -05:00
Dan Williams
ddaea22332 platform: move driver & firmware version reading into the platform 2015-05-06 16:14:25 -05:00
Dan Williams
fa74ed7ca1 platform: add nm_platform_link_get_by_address() 2015-05-06 16:14:25 -05:00