Commit graph

287 commits

Author SHA1 Message Date
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
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
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š
60080377a2 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

(cherry picked from commit 94a393e9ed)
2015-06-19 12:40:54 +02:00
Thomas Haller
8f6a883c73 platform: refactor support_kernel_extended_ifa_flags to static variable
Whether we have support depends on the kernel, and is not
per NMLinuxPlatform instance.

(cherry picked from commit 2f3fd86dc5)
2015-06-19 12:26:03 +02:00
Thomas Haller
f9760da1a1 platform: move supports_mii_carrier_detect() to nmp_utils_mii_supports_carrier_detect()
(cherry picked from commit 299af02e40)
2015-06-19 12:26:03 +02:00
Thomas Haller
8ad91fa6d0 platform: move ethtool_*() to nmp_utils_ethtool_*()
(cherry picked from commit ac84b22fc7)
2015-06-19 12:26:03 +02:00
Thomas Haller
ddd9884bcf platform: factor out ethtool_get_wake_on_lan() function
(cherry picked from commit 398819c3ac)
2015-06-19 12:26:03 +02:00
Thomas Haller
345b73fa1b platform: factor out ethtool_get_peer_ifindex() function
(cherry picked from commit ba084b5b90)
2015-06-19 12:26:03 +02:00
Thomas Haller
6c76801190 platform: factor out ethtool_supports_vlans() function
(cherry picked from commit 4be9394864)
2015-06-19 12:26:03 +02:00
Thomas Haller
a72350c4da platform/trivial: move ethtool_supports_carrier_detect() code
(cherry picked from commit 2b8f3331d7)
2015-06-19 12:26:03 +02:00
Thomas Haller
716dd795de platform: move code udev_get_driver() to nmp_utils_udev_get_driver()
(cherry picked from commit 77a3767d1e)
2015-06-19 12:26:02 +02:00
Thomas Haller
acb39d4b31 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.

(cherry picked from commit d6ce01f115)
2015-06-19 12:26:02 +02:00
Thomas Haller
90eb13a111 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.

(cherry picked from commit 39f2b51abb)
2015-06-19 12:26:02 +02:00
Dan Williams
b5f5aa0960 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.

(cherry picked from commit 5cf226463a)
2015-06-17 18:52:43 +02:00
Lubomir Rintel
faf46ad316 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.

(cherry picked from commit 26aeb12749)
2015-06-17 18:47:45 +02:00
Thomas Haller
4609138e3e 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
Fixes: f8a9574f7e
(cherry picked from commit f55a272ade)
2015-06-17 18:42:52 +02:00
Dan Williams
d5e0a6ff86 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.

(cherry picked from commit aba250a7d4)
2015-06-17 16:19:19 +02:00
Dan Williams
c7ce5612ca platform: move driver & firmware version reading into the platform
(cherry picked from commit ddaea22332)
2015-06-17 16:19:19 +02:00
Dan Williams
081aeaf3e6 platform: add nm_platform_link_get_by_address()
(cherry picked from commit fa74ed7ca1)
2015-06-17 16:19:19 +02:00
Dan Williams
f8a9574f7e 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.

(cherry picked from commit 29ccb8851c)
2015-06-17 16:19:19 +02:00
Dan Williams
4b9f506bfd platform: return link objects from add functions
(cherry picked from commit 2abda4bfa5)
2015-06-17 16:19:19 +02:00
Dan Williams
41c92739bd platform: recognize Bluetooth BNEP devices via DEVTYPE
Instead of strcmp()-ing the device name, recognize these devices from their
driver's DEVTYPE.

(cherry picked from commit baee9080b7)
2015-06-17 16:11:55 +02:00
Thomas Haller
ac99f69809 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
(cherry picked from commit 7572837375)
2015-06-17 15:38:05 +02:00
Thomas Haller
7b6ffb1e5f 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.

(cherry picked from commit 3171b543dc)
2015-06-17 15:28:01 +02:00
Thomas Haller
efec4b42e2 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.

(cherry picked from commit e2c742c77b)
2015-06-17 15:28:01 +02:00
Thomas Haller
3d1ab669e3 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.

(cherry picked from commit b538adf123)
2015-06-17 15:28:01 +02:00
Thomas Haller
bae47558ba 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.

(cherry picked from commit 18d611d5d2)
2015-06-17 15:28:01 +02:00
Dan Williams
19cdd7d9a1 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
(cherry picked from commit 2d527b30ff)
2015-06-17 15:28:01 +02:00
Dan Williams
0ab54aeb47 platform: refactor link-type to string conversion
(cherry picked from commit b484b03acf)
2015-06-17 15:28:01 +02:00
Dan Williams
285ee1fda2 platform: don't wait for udev before announcing links
(cherry picked from commit 388b7830f3)
2015-06-17 14:54:02 +02:00
Dan Williams
e43bd9228c platform: don't use udev for link type determination
This allows us to always announce links when the kernel advertises
them, instead of waiting for udev.

(cherry picked from commit 2599dadc28)
2015-06-17 14:54:02 +02:00
Thomas Haller
093b29a618 logging: define _LOGT() macro to check valid arguments
With NM_MORE_LOGGING disabled, we still want the compiler to evaluate
the argument list. By wrapping it in "if(FALSE)", we get compile time
checks, but the logging statement will be optimized out.

(cherry picked from commit cb6bafb9af)
2015-06-17 14:45:46 +02:00
Thomas Haller
0a8511582d platform: refactor detection of support_user_ipv6ll
Move detection of @support_user_ipv6ll to a separate function
_support_user_ipv6ll_detect() and call it immediately after the
places where we receive libnl objects from kernel, i.e.
get_kernel_object(), event_notification(), and cache_repopulate_all().

Also, whether we have support depends on the kernel and is per-system,
not per-platform-instance. Make @_support_user_ipv6ll a global variable.
This way, we don't need to pass around a NMLinuxPlatform instance.

(cherry picked from commit f15a27f9c1)
2015-06-17 14:39:35 +02:00
Thomas Haller
a989eadec0 platform: don't assert against success of nl_msg_parse()
(cherry picked from commit a319aea9f4)
2015-06-17 14:39:35 +02:00
Thomas Haller
fa666781e5 platform: use new _LOG() logging macros in nm-linux-platform.c
(cherry picked from commit 0c03db4e8e)
2015-06-17 14:39:35 +02:00
Thomas Haller
3ded80d143 platform: add _LOG() logging macros to linux platform
(cherry picked from commit 7db9306aa3)
2015-06-17 14:39:35 +02:00
Thomas Haller
c61901d24c platform: pass singleton instance to nm_platform_setup()
We have two hooks to modify setup of the platform singleton:
nm_linux_platform_setup() and the virtual setup() function.

On the other hand, nm_platform_setup() limits us by accepting
only a GType, instead of a prepeared platform instance.
Make the nm_platform_setup() method more flexible, so that we can
later drop the setup() hook.

(cherry picked from commit a50d77d952)
2015-06-17 14:37:32 +02:00
Thomas Haller
2cbcb6df51 platform: initialize NMLinuxPlatform in constructed() method
setup() can be used to initialize a NMPlatform instance that is
registered as singleton via nm_platform_setup(). It should not
be used to initialize the object.

Prior to c6529a9d74, this change was
not possible because constructed() will call back into nm_platform_*()
functions, without having the singleton instance setup.

(cherry picked from commit dc9b25f161)
2015-06-17 14:37:32 +02:00
Thomas Haller
704e9dbdc2 platform: pass @platform instance to build_rtnl_addr()
(cherry picked from commit bdb2f94519)
2015-06-17 14:32:30 +02:00
Thomas Haller
3a30ccacc7 platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.

While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.

With this change, NMPlatform instances can be used individually, not
only as a singleton instance.

Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.

Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.

Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.

This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".

(cherry picked from commit c6529a9d74)
2015-06-17 14:32:30 +02:00