Commit graph

11789 commits

Author SHA1 Message Date
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
Thomas Haller
b4a88db19e core: remove G_GNUC_WARN_UNUSED_RESULT from ASSERT_VALID_PATH_COMPONENT()
ASSERT_VALID_PATH_COMPONENT() always returns the input argument --
unless it fails an assertion and terminates the program. No need
to require the user to use the return value.

(cherry picked from commit 63bb33b534)
2015-06-17 15:28:01 +02:00
Dan Williams
251193490a core: change activation failure messages to debug level
Otherwise any user with network control privileges can spam the logs.

(cherry picked from commit 8a5910c25c)
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
Thomas Haller
7c4a657efa platform: fix root-tests after adding link detection without udev
Co-Authored-By: Lubomir Rintel <lkundrak@v3.sk>

Fixes: 388b7830f3
Fixes: 285ee1fda2
(cherry picked from commit b22bf15c1d)
2015-06-17 15:27:52 +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
fab106c912 core: add generic NMDevice function to recheck availability
And use it everywhere.

(cherry picked from commit 3006df940c)
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
72c0379708 build/trivial: reorder and break lines in Makefile.am
(cherry picked from commit 245720819e)
2015-06-17 14:45:46 +02:00
Thomas Haller
dbf8bb85b8 platform: merge branch 'th/platform-div-bgo748131'
https://bugzilla.gnome.org/show_bug.cgi?id=748131

(cherry picked from commit 2316d233e3)
2015-06-17 14:40:02 +02:00
Thomas Haller
594b8e829d platform: add NM_PLATFORM_SIGNAL_NONE enum value
(cherry picked from commit ea5865cf45)
2015-06-17 14:39:35 +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
2f4db91fcc platform: add nm_platform_try_get() function
(cherry picked from commit 90caa93582)
2015-06-17 14:39:35 +02:00
Thomas Haller
e43baa1481 platform: drop nm_platform_free() and register weak-ref
Instead of having a nm_platform_free() function, use NM_DEFINE_SINGLETON_WEAK_REF()
and register a weak reference. That way, users who want to free the platform
instance can just unref it.

(cherry picked from commit 04ed48e5a0)
2015-06-17 14:39:34 +02:00
Thomas Haller
3a437a8e55 platform: drop virtual setup() initalization function
We already have nm_*_platform_setup() that gets specified
via -DSETUP. This SETUP() hook gives us all the flexiblity
we need to customize our singleton, so just do any required
setup there.

Also, it would be easier to add an alternative (hypotetical)
nm_fake_platform_setup_custom() to customize the singleton then to
parametrize the NMPlatform:setup() implementation. So this virtual
function is less flexible and redundant.

(cherry picked from commit fe2608c903)
2015-06-17 14:39:34 +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
b3cbb768a3 platform: merge several platform backports from master into nm-1-0
Backport these patches to have everything in platform up to a
certain point of master.
2015-06-17 14:36:10 +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
Dan Williams
fd40f223bf platform: prevent warning when udev is clueless about a device
udev doesn't know about the device yet when NM creates it internally.

NetworkManager[9275]: <info>  (team0): carrier is OFF
NetworkManager[9275]: <info>  (team0): new Team device (driver: 'team' ifindex: 16)
(NetworkManager:9275): GUdev-CRITICAL **: g_udev_device_get_property: assertion 'G_UDEV_IS_DEVICE (device)' failed
NetworkManager[9275]: <info>  (team0): exported as /org/freedesktop/NetworkManager/Devices/5

(cherry picked from commit 8173f0f9e8)
2015-06-17 13:50:36 +02:00
Thomas Haller
130252f55e platform/trivial: move ethtool code
(cherry picked from commit 2bb44d91d8)
2015-06-17 13:50:36 +02:00
Thomas Haller
710a34c12a platform/trivial: move udev_detect_link_type_from_device()
(cherry picked from commit dffb18cb34)
2015-06-17 13:50:36 +02:00
Thomas Haller
bd7209b04a platform: split link_type_from_udev()
Also change link_extract_type() to accept NULL as @platform
argument.

(cherry picked from commit 34d82d0df1)
2015-06-17 13:50:36 +02:00
Thomas Haller
f5569eb961 platform/trivial: move udev code closer to beginning of nm-linux-platform.c
(cherry picked from commit d695776d48)
2015-06-17 13:50:36 +02:00
Thomas Haller
f59cda06ce platform/trivial: remove unused argument from udev_get_driver()
(cherry picked from commit 7354dc4c58)
2015-06-17 13:50:36 +02:00
Thomas Haller
fd61283fb0 platform/trivial: rename object_type_from_nl_object() to _nlo_get_object_type()
The function names in linux-platform should get better prefixes
indicating whether they are related to libnl or nm objects.

Add a prefix _nlo_ for functions that operate on libnl objects.

(cherry picked from commit 7c5d361c66)
2015-06-17 13:50:36 +02:00
Thomas Haller
fc499ffd14 platform/trivial: move code around so that libnl related stuff is together
Reorder some functions in nm-platform, so that we first have independent
libnl wrappers/utils, then NMPlatform type definition, and then the
rest.

(cherry picked from commit 850af91f22)
2015-06-17 13:50:36 +02:00
Thomas Haller
7518d9a1ce platform/trivial: add OBJECT_TYPE_MAX enum value
(cherry picked from commit ee64b8585b)
2015-06-17 13:50:36 +02:00
Thomas Haller
87b49c088e platform/test: clear host part of routes in fake platform
Adding a route with host part non zero is rejected by kernel.
But NMLinuxPlatform works around it -- so must fake platform.

(cherry picked from commit cdd3e1c302)
2015-06-17 13:50:36 +02:00
Thomas Haller
1bbf159cd0 platform/test: fake platform must use nm-logging for reporting errors
Just like linux platform does.

(cherry picked from commit 21b129084f)
2015-06-17 13:50:36 +02:00
Lubomir Rintel
caa3628976 platform: merge branch 'lr/udev-unmanaged-fd731014'
https://bugzilla.gnome.org/show_bug.cgi?id=731014

(cherry picked from commit ca9679334c)
2015-06-17 13:40:02 +02:00
Lubomir Rintel
b9a6de480c Revert "core: make veth devices default-unmanaged for now"
This reverts commit ebeaeaed4d.

No need to hardwire these as unmanaged anymore, an udev rule will take care of
it.

(cherry picked from commit 498d45e85f)
2015-06-17 13:39:42 +02:00
Lubomir Rintel
cf1166f27f data: move OLPC MESH udev rules away from callouts
No idea why was it there in the first place.

This also fixes a bug that the rules file was conditionally included in dist
depending on presence of udev dir at configure time.

(cherry picked from commit ceea3c6782)
2015-06-17 13:39:42 +02:00
Lubomir Rintel
5c187b9b1c data: add udev rules to make emulated ethernet devices default unmanaged
There are some out-of-tree drivers that create devices masquerading as
ethernets which are supposed to use their own management tools. Avoid touching
them.

The rules should be run after 80-net-setup-link.rules, so that the
ID_NET_DRIVER is set.

(cherry picked from commit 7ba30cfd26)
2015-06-17 13:39:42 +02:00
Lubomir Rintel
117e62040d platform: give the platform an opportunity to override default-unmanaged
Some out of tree drivers add Ethernet devices that are supposed to be managed
by other their tooling, e.g. VirtualBox or VMWare.

Rather than hardcoding their drivers (at least VirtualBox doesn't even set a
"driver" property in sysfs) or hardcoding a logic that identifies such devices
let's just add a possibility to blacklist them in udev. This makes it possible
for whoever who ships such a driver to ship rules that prevent NetworkManager
from managing the device itself.

Furthermore it makes it possible for the user with special needs leverage the
flexibility of udev rules to override the defaults. In the end the user can
decide to let NetworkManager manage default-unmanaged interfaces such as VEth
or turn on default-unmanaged for devices on a particular bus.

An udev rule for VirtualBox would look like this:

  SUBSYSTEM=="net", ENV{INTERFACE}=="vboxnet[0-9]*", ENV{NM_UNMANAGED}="1"

(cherry picked from commit 85ee1f4a9c)
2015-06-17 13:39:42 +02:00
Lubomir Rintel
3300e10c69 platform: don't wait for udev device initializaton if there's no udev
There's no udev running in containers, it only starts if /sys is writable. If a
hardware device is added to the container's namespace NM would not announce it.

This also removes the software link special case -- the software links will now
wait for udev initialization (in case udev is there) as well. There's no reason
to treat them differently anymore. This makes it possible to use udev properties
of the software links.

https://bugzilla.gnome.org/show_bug.cgi?id=740526
(cherry picked from commit 4a05869557)
2015-06-17 13:39:41 +02:00
Lubomir Rintel
8be448cc9d contrib: ensure udev rules from RPM package are applied
We install udev rules and need to ensure that correct ones are in effect when
the package is installed, updated or removed.

(cherry picked from commit b3667afa22)
2015-06-17 13:39:41 +02:00
Thomas Haller
efb507cf12 merge: backport test fixes and moving of nm_utils_ascii_str_to_int64()
Backport improvements to NMFakePlatform, which is useful anyway.

Also backport the moving of nm_utils_ascii_str_to_int64()
to reduce conflicts for future backports.
2015-06-17 13:31:52 +02:00
Thomas Haller
ba285e319e libnm: move _nm_utils_ascii_str_to_int64() from src/ to libnm-core/
(cherry picked from commit c5d23737fd)
2015-06-17 13:30:39 +02:00
Thomas Haller
a4d11bae29 trivial: rename nm_utils_ascii_str_to_int64() to _nm_utils_ascii_str_to_int64()
(cherry picked from commit 093f6d477b)
2015-06-17 13:30:38 +02:00
Lubomir Rintel
0916861c5c fake-platform: normalize ipv6 route metric before deletion
(cherry picked from commit 72cefd5162)
2015-06-17 13:30:38 +02:00
Lubomir Rintel
63611cb46f fake-platform: reject adding routes without the gateway on the same interface
This mimics Linux behavior.

(cherry picked from commit 4d097829f0)
2015-06-17 13:30:38 +02:00