Commit Graph

748 Commits

Author SHA1 Message Date
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
Dan Williams
29ccb8851c platform: ensure created interface matches requested type
If the caller requested that a bond be created, don't return success
if there was an existing bridge with the same name.
2015-05-06 16:14:25 -05:00
Dan Williams
2abda4bfa5 platform: return link objects from add functions 2015-05-06 16:14:25 -05:00
Dan Williams
baee9080b7 platform: recognize Bluetooth BNEP devices via DEVTYPE
Instead of strcmp()-ing the device name, recognize these devices from their
driver's DEVTYPE.
2015-05-06 16:14:24 -05:00
Dan Williams
1fcc9690d1 platform: remove unused wifi_utils_get_ssid() 2015-05-06 15:23:47 -05:00
Thomas Haller
76ba548959 platform: fix memleak in build_rtnl_addr() using wrong put() method
'struct nl_addr' and 'struct nl_object' have non-compatible put()
functions.
2015-05-05 04:19:00 +02:00
Thomas Haller
7572837375 platform: keep udev-device in udev_device_added() even if there is no netlink object
Throwing away the udev_device instance is wrong. There are two cases:

- the udev-device appears, and the netlink object will never appear
  (or is already gone). In this case, keeping the udev-device is ok
  because we will eventually get a signal from UDev to cleanup the
  device instance.

- the udev-device appears before the netlink object. In this case we
  want to keep the udev instance to have it ready.

Fixes: 388b7830f3
2015-05-04 18:41:15 +02:00
Thomas Haller
3171b543dc platform: intern driver string for NMPlatformLink
Always intern string from udev_get_driver().

We use the result of udev_get_driver() for setting NMPlatformLink.driver.
In all other cases, we already set that value to an interned string,
which simplifies memory handling.

As it was, the lifetime of that string was tied to the lifetime of the
GUdevDevice.

This is not a stelar solution, but we assume that the overall numbers
of different drivers is limited so we don't leak large amounts of
memory.
2015-05-01 14:26:40 -05:00
Thomas Haller
e2c742c77b platform: refactor extraction of type-name for link
link_extract_type() would return the NMLinkType and a
@type_name string. If the type was unknown, this string
was rtnl_link_get_type() (IFLA_INFO_KIND).

Split up this behavior and treat those values independently.
link_extract_type() now only detects the NMLinkType. Most users
don't care about unknown types and can just use nm_link_type_to_string()
to get a string represenation.

Only nm_platform_link_get_type_name() (and NMDeviceGeneric:type_description)
cared about a more descriptive type. For that, modify link_get_type_name()
to return nm_link_type_to_string() if NMLinkType could be detected.
As fallback, return rtnl_link_get_type().

Also, rename the field NMPlatformLink:link_type to "kind". For now this
field is mostly unused. It will be used later when refactoring platform
caching.
2015-05-01 14:26:39 -05:00
Thomas Haller
b538adf123 platform: expose nm_link_type_to_string() function
Given the name nm_link_type_to_string(), we would not expect
to find it in nm-linux-platform.c. It either should be named
nm_platform_link_type_to_string() and be put in a new
nm-platform-utils.c file, or it should be named
nm_utils_link_type_to_string() and be put in NetworkManagerUtils.h.

For now, just leave it here.
2015-05-01 14:25:59 -05:00
Thomas Haller
18d611d5d2 platform: detect TUN/TAP device in link_extract_type() independently of platform cache
link_extract_type() would call tun_get_properties() to determine whether
the link if a TAP or TUN device. The previous implementation would
receive the ifindex, and resolve the ifname via lookup in the platform
cache.
This means, the call on link_extract_type() will only succeed to detect
the TUN/TAP properties, if the libnl object is already in the cache.
Currently that is always the case and there is no problem.

It is desireable, that we can resolve the link type of an object without
consulting the platform cache first.
2015-05-01 14:25:59 -05:00
Dan Williams
2d527b30ff platform: rework link type detection for better fallback (bgo #743209)
See "Revert "wireless: Support of IFLA_INFO_KIND rtnl attribute""
http://www.spinics.net/lists/linux-wireless/msg132219.html

The reverted kernel patch caused rtnl_link_get_type() to return "wlan"
for WiFi devices.  Since NM depends on this function returning
NULL for WiFi devices so that it goes on to check the sysfs DEVTYPE
attribute, the kernel patch caused WiFi devices to show up as Generic
ones instead.  That's wrong, and NM should be able to more easily
handle changes in the kernel drivers from NULL to a more descriptive
rtnl_link_get_type() return, since that's the kernel trend.

What NM should be doing here is to fall back to other detection
schemes if the type is NULL or unrecognized. Make that happen and
clean things up to use a table instead of a giant if(strcmp()) block.

https://bugzilla.gnome.org/show_bug.cgi?id=743209
2015-05-01 14:25:58 -05:00
Dan Williams
b484b03acf platform: refactor link-type to string conversion 2015-05-01 14:25:58 -05:00