Commit graph

436 commits

Author SHA1 Message Date
Thomas Haller
d7fe907c32 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.
2015-06-17 11:44:16 +02:00
Thomas Haller
f7fb68755c 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.
2015-06-17 11:44:16 +02:00
Thomas Haller
b74e620f2d platform: expose GUdevDevice instance for platform links 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
076fe578e3 platform: remove redundant NMPlatformLink fields "arp" and "up" 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
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
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
c34598fa23 platform: print more fields in nm_platform_link_to_string() 2015-06-17 10:54:56 +02:00
Thomas Haller
655a0e71d4 platform: expose internal buffer for to_string() functions
I'd like to reuse this buffer for other to-string functions that
are platform related.
2015-06-17 10:54:56 +02:00
Thomas Haller
806109c245 platform/trivial: rename to_string_buffer variable 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
d4f828c887 platform: expose nm_platform_signal_change_type_to_string() 2015-06-05 16:52:50 +02:00
Thomas Haller
d7a312d17a platform: move nm_platform_query_devices() to nm-manager
nm_platform_query_devices() would raise an 'added' signal
for all its links. That is bad style because it could
confuse other listeners for platform signals which don't
expect such artificial change signals.

The public API of NMPlatform already gives NMManager the ability
to 'pull' all the links and iterate them itself.

Before, nm_platform_query_devices() would also initialize udev
devices, so there was a more compelling reason for this function.
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
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
f167346534 platform: fix nm_platform_link_cmp() to consider ifindex 2015-05-13 14:31:05 +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
2abda4bfa5 platform: return link objects from add functions 2015-05-06 16:14:25 -05:00
Dan Williams
1fcc9690d1 platform: remove unused wifi_utils_get_ssid() 2015-05-06 15:23:47 -05: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
Dan Williams
388b7830f3 platform: don't wait for udev before announcing links 2015-05-01 14:25:55 -05:00
Thomas Haller
bdaaf9849b platform: don't accept lowering IPv6 hop-limit from RA (CVE-2015-2924)
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6fd99094de2b83d1d4c8457f2c83483b2828e75a
http://seclists.org/oss-sec/2015/q2/46
https://bugzilla.redhat.com/show_bug.cgi?id=1209902
https://bugzilla.redhat.com/show_bug.cgi?id=1209903
2015-04-29 14:14:20 +02:00
Thomas Haller
90caa93582 platform: add nm_platform_try_get() function 2015-04-22 16:51:11 +02:00
Thomas Haller
04ed48e5a0 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.
2015-04-22 16:51:11 +02:00
Thomas Haller
fe2608c903 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.
2015-04-22 16:50:52 +02:00
Thomas Haller
a50d77d952 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.
2015-04-22 11:26:54 +02:00
Thomas Haller
dc9b25f161 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.
2015-04-22 11:26:54 +02:00
Thomas Haller
c6529a9d74 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".
2015-04-21 17:51:34 +02:00
Thomas Haller
290faa003d platform: add VTable to handle IPv4 and IPv6 routes generically 2015-04-08 14:39:16 +02:00
Dan Williams
25a286e999 platform: add nm_platform_link_get_dev_id()
Some devices (s390 OSA and ipvlan) use the same link layer address
for different interfaces, and dev_id is what differentiates them.
2015-03-27 15:11:34 -05:00
Dan Williams
32e1d6a9a9 platform: update code documentation for nm_platform_link_get_physical_port_id() 2015-03-27 15:11:33 -05:00
Lubomir Rintel
85ee1f4a9c 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"
2015-03-23 15:13:02 +01:00
Thomas Haller
c5d23737fd libnm: move _nm_utils_ascii_str_to_int64() from src/ to libnm-core/ 2015-03-12 18:12:26 +01:00
Thomas Haller
093f6d477b trivial: rename nm_utils_ascii_str_to_int64() to _nm_utils_ascii_str_to_int64() 2015-03-12 18:12:26 +01:00
Lubomir Rintel
874e4a7595 core: split route management code out from platform
Create a NMRouteManager singleton.

Refactor, no functional changes apart from change of log domain from
LOGD_PLATFORM to LOGD_CORE.

Subsequent commit will keep track of the conflicting routes, avoid overwriting
older ones with newer ones and apply the new ones when the old ones go away.
2015-02-27 16:48:27 +01:00
Lubomir Rintel
47167cab4f platform: fix route addition ordering 2015-02-27 16:48:27 +01:00
Lubomir Rintel
6771f836ce ip6-config: remove the link-local address on address flush
If it stays after device dispose a connection is assumed.

https://bugzilla.redhat.com/show_bug.cgi?id=1184997
2015-01-28 17:53:25 +01:00
Lubomir Rintel
db5603e615 platform: Add support for IPv6 tokenized identifiers 2015-01-26 13:05:06 +01:00
Mathieu Trudel-Lapierre
a428de8215 wifi: set wireless powersave for nl80211 devices when activated
Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>

(fixups and WEXT implementation by dcbw)
2015-01-21 14:31:14 -06:00
Thomas Haller
5849c97c03 platform: avoid conflicts when reinstalling the device-route
Since f32075d2fc, we remove the kernel
added IPv4 device route, and re-add it with appropriate metric.

This could potentially replace existing, conflicting routes. Be more
careful and only take any action when we don't have a conflicting
route and when we add the address for the first time.

The motivation for this was libreswan which might install a VPN route
for a subnet that we also have configured on an interface. But the route
conflict could happen easily for other reasons, for example if you
configure a conflicting route manually.

Don't replace the device route if we have any indication that
a conflict could arise.

https://bugzilla.gnome.org/show_bug.cgi?id=723178
2014-12-11 10:07:00 +01:00