Commit graph

553 commits

Author SHA1 Message Date
Thomas Haller
45c85a0d6b logging: declare default logging macros in "nm-logging.h"
The logging macros _LOGD(), etc. are specific to each
file as they format the message according to their context.

Still, they were cumbersome to define and their implementation
was repeated over and over (slightly different at times).

Move the declaration of these macros to "nm-logging.h".
The source file now only needs to define _NMLOG(), and either
_NMLOG_ENABLED() or _NMLOG_DOMAIN.

This reduces code duplication and encourages a common implementation
and usage of these macros.

(cherry picked from commit ad7cdfc766)
2015-08-20 18:05:43 +02:00
Beniamino Galvani
37877687bb core: avoid ioctls on non existent devices
Performing an ioctl on a non existent device may cause the automatic
load of a kernel module if the device name matches a module
alias. Check if the device actually exists before calling the ioctl.

(cherry picked from commit ab41c13b06)
2015-08-11 18:38:56 +02:00
Thomas Haller
30768c7240 platform: optimize event_notification() not to create full nmp-objects for delete-events
For delete-events, we only need a shallow object with the key fields
set. That sufficies to lookup in the cache and find the object to
delete.

One other issue is that _nmp_vt_cmd_plobj_init_from_nl_link() and
link_extract_type() might call to ethtool for the already deleted
instance. Just avoid that.

https://bugzilla.redhat.com/show_bug.cgi?id=1247156
(cherry picked from commit a4c7176fe9)
2015-08-11 18:38:55 +02:00
Thomas Haller
796f78a04c platform: assert for valid ifname in ethtool_get()
Add an assert (g_return_val_if_reached()) that the interface name is
valid and shorter then 16 bytes. If it happened to be longer, strncpy()
would not have zero terminated the interface name.

(cherry picked from commit 5b123f2539)
2015-08-11 18:38:55 +02:00
Thomas Haller
dfb1c0301a platform/tests: fix assertion for test-link for team device
Seems that team changed to now also raise two change signals.
Relax the assertion that broke tests on Fedora 22.

(cherry picked from commit 1c2883c940)
2015-08-06 18:06:19 +02:00
Thomas Haller
642c38b26b platform: replace addr/route exists() functions by get()
Rename exists() functions to get() and return the cached platform
object.

(cherry picked from commit 6f8fcd2f47)
2015-07-14 13:44:57 +02:00
Lubomir Rintel
a051446492 linux-platform: correct the lifetime conditional
Coverity detected that it was always-true:
src/platform/nm-linux-platform.c:4035: dead_error_line: Execution cannot reach the expression "preferred != 0U" inside this statement: "if (lifetime != 0U || lifet...".

(cherry picked from commit da612acc6a)
2015-07-14 13:19:28 +02:00
Lubomir Rintel
f90e1549ae platform: don't assert there's no parent-parent loops
http://www.spinics.net/lists/netdev/msg314907.html
(cherry picked from commit 4aac263b0d)
2015-07-14 11:52:01 +02:00
Thomas Haller
abebc340cc platform: add optional @metric argument to route_add() function
Allow overwriting the route metric.

(cherry picked from commit 09fdf58f4d)
2015-07-07 16:30:38 +02:00
Lubomir Rintel
c7a1627ea1 platform: avoid assuming a permanent address is an ethernet address
This gets called for all links via link_get_permanent_address(). This could
easily be an infiniband address and we don't want to assert it's not.

(cherry picked from commit 31c8bd6b69)
2015-07-02 23:04:40 +02:00
Thomas Haller
ce0893e532 platform: fix wrong removal of generated enums
Fixes: a130f72d74
(cherry picked from commit 17216ed453)
2015-07-02 16:59:21 +02:00
Thomas Haller
809ddb89f9 platform: mark internal enums to be skipped by glib-mkenums
No need to generate glib type information for these internal
enums.

(cherry picked from commit a130f72d74)
2015-07-02 16:26:54 +02:00
Thomas Haller
718433307d platform: remove unreachable code in nm_platform_link_get_all()
Linux platform tracks links by ifindex. Hence an ifindex must be unique
and positive. Just assert against it.

(cherry picked from commit 5b208e718a)
2015-07-02 15:04:44 +02:00
Thomas Haller
1cbd3314a0 platform/test: add test to call nm_platform_link_get_all()
(cherry picked from commit 6f5cb596ba)
2015-07-02 15:04:44 +02:00
Thomas Haller
5edba27fe4 platform: add trace-logging to nm_platform_link_get_all()
(cherry picked from commit 987515ea73)
2015-07-02 15:04:44 +02:00
Thomas Haller
41617b9605 platform: replace debug() log macro with _LOGD()
(cherry picked from commit c9aeefb5a1)
2015-07-02 15:04:44 +02:00
Thomas Haller
10c7479507 platform: add logging macros _LOGx() to nm-platform.c
(cherry picked from commit e0630023e5)
2015-07-02 15:04:44 +02:00
Lubomir Rintel
a961ffc6a8 devices,platform: fix build with gcc
Warnings about missing initializers.

(cherry picked from commit 295c9818b0)
2015-07-01 16:36:18 +02:00
Thomas Haller
42ac15c86f route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.

This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).

One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.

We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.

Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.

One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring  addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.

https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
(cherry picked from commit 5f54a323d1)
2015-07-01 16:12:14 +02:00
Thomas Haller
accf3d0f17 platform: properly consider address lifetimes in nm_platform_ip4_address_sync()
When checking whether an address from platform should be deleted, we
compare the address with our list of @known_addresses.
For that we must also check for expired lifetimes, because
@known_addresses might contain expired addresses.

(cherry picked from commit 8336bd2a83)
2015-07-01 16:10:50 +02:00
Thomas Haller
300a7ab4d1 platform: expose routes with "proto kernel" too
Also expose routes with "proto kernel". But add a flag
to nm_platform_ipx_route_get_all() to hide them by default.

(cherry picked from commit 42664e8752)
2015-07-01 16:10:50 +02:00
Thomas Haller
7082f44c2f platform: change NMPlatformGetRouteMode enum to NMPlatformGetRouteFlags flags
By having flags instead of an enum/mode, we can encode more combinations
of filtering the result.

(cherry picked from commit d9dba6b662)
2015-07-01 16:10:50 +02:00
Thomas Haller
44cb5b6b62 platform/trivial: rename enum value NM_IP_CONFIG_SOURCE_RTPROT_KERNEL
This source type was platform internal up to now. Next we will expose it.

(cherry picked from commit 85bf9ded2e)
2015-07-01 16:10:50 +02:00
Thomas Haller
e04d0c6e6b platform: track pref_src field of IPv4 routes
(cherry picked from commit 7594e31220)
2015-07-01 16:10:49 +02:00
Thomas Haller
af0d99cdcc platform: fix setting valid lifetimes when constructing rtnl_addr object
build_rtnl_addr() has two parameters "lifetime" and "preferred". Both
count from *now*.

Fix nmp_object_to_nl() to properly set these timestamps. This bug had
not real consequences, because the only place where we use
nmp_object_to_nl() the arguments are 0.

(cherry picked from commit d0ed4de104)
2015-07-01 16:10:49 +02:00
Thomas Haller
a3c4bf81bb platform: move address lifetime utils function to nm-platform-utils.c
(cherry picked from commit 626a85530e)
2015-07-01 16:10:49 +02:00
Thomas Haller
14ef5f6b32 platform: prettify and line-wrap route_to_string() print statements
(cherry picked from commit 2170804213)
2015-07-01 16:10:37 +02:00
Thomas Haller
e7504376dc platform: fix initializing vlan_id for NMPlatformLink instance from libnl object
If the vlan-information is missing, we must consult the cache.

Fixes: 8a1f4beb65
(cherry picked from commit 871c4d90c7)
2015-07-01 15:47:08 +02:00
Lubomir Rintel
25b53ff7eb linux-platform: don't try to read vlan id from netlink objects without type set
They just don't have the information.

(cherry picked from commit 8a1f4beb65)
2015-06-26 15:53:02 +02:00
Thomas Haller
85978aff78 platform: fix inverting guint8 value inet6_addr_gen_mode_inv
Fixes: e8e455817b
(cherry picked from commit c2754ede5c)
2015-06-25 20:50:55 +02:00
Thomas Haller
9d0c9733a5 platform/coverity: add workarounds to suppress coverify warnings
(cherry picked from commit cd5b260545)
2015-06-25 20:50:54 +02:00
Thomas Haller
55d2489950 platform/test: minor test fix in "test-nmp-object.c"
(cherry picked from commit 0d8f4bbc45)
2015-06-25 20:50:54 +02:00
Thomas Haller
747af368da platform: pass object type with platform changed signal
(cherry picked from commit b88c309167)
2015-06-24 16:40:11 +02:00
Thomas Haller
2313c6c811 platform/trivial: fix name of enum value OBJECT_TYPE_UNKNOWN
Fixes: 518cf76de7
(cherry picked from commit 7bd3b0b304)
2015-06-24 16:40:11 +02:00
Thomas Haller
28c79aaa33 platform: declare NMPObjectType in nm-types.h
We want to use it outside of NMPlatform, but users should not be required
to include "nmp-object.h".

(cherry picked from commit b6061b3cd5)
2015-06-24 16:40:11 +02:00
Thomas Haller
3845b7706c platform: generate gtype for NMPObjectType enum
(cherry picked from commit 4010d779a7)
2015-06-24 16:40:11 +02:00
Jiří Klimeš
ab9d36c4c4 platform: (trivial) rename @managed to @unmanaged in link_get_unmanaged()
It returns unmanaged state (reads NM_UNMANAGED from udev), so "managed" was
very misleading.

Fixes: 85ee1f4a9c
(cherry picked from commit b77fba3939)
2015-06-24 15:16:47 +02:00
Lubomir Rintel
2d4bd3818f platform: g_hash_table_add doesn't return a value before 2.40
(cherry picked from commit 14bfd55361)
2015-06-22 17:05:11 +02:00
Lubomir Rintel
a8aed11cf0 platform: fix build on 32-bit systems
The decimal literals are signed by default and these are too large to fit in a
signed 32-bit int.

(cherry picked from commit a1868dcfc3)
2015-06-22 13:15:05 +02:00
Lubomir Rintel
af36a41440 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.

(cherry picked from commit 874e4a7595)
2015-06-22 13:15:05 +02:00
Thomas Haller
3c0ceda905 platform: don't assert for valid ifindex in nm_platform_link_get()
It's not uncommon to lookup a platform parameter with invalid
ifindex or ifname. Be more resilient and just return "no link found".

Fixes: e8e455817b
(cherry picked from commit 0a38352470)
2015-06-22 09:56:06 +02:00
Thomas Haller
1fb84b1688 platform: refactor virtual methods for link objects in NMPlatform
Change nm_platform_link_get() to return the cached NMPlatformLink
instance. Now what all our implementations (fake and linux) have such a
cache internal object, let's just expose it directly.
Note that the lifetime of the exposed link object is possibly quite
short. A caller must copy the returned value if he intends to preserve
it for later.
Also add nm_platform_link_get_by_ifname() and modify nm_platform_link_get_by_address()
to return the instance.

Certain functions, such as nm_platform_link_get_name(),
nm_platform_link_get_ifindex(), etc. are solely implemented based
on looking at the returned NMPlatformLink object. No longer implement
them as virtual functions but instead implement them in the base class
(nm-platform.c).
This removes code and eliminates the redundancy of the exposed
NMPlatformLink instance and the nm_platform_link_get_*() accessors.
Thereby also fix a bug in NMFakePlatform that tracked the link address
in a separate "address" field, instead of using "link.addr". That was
a case where the redundancy actually led to a bug in fake platform.

Also remove some stub implementations in NMFakePlatform that just
bail out. Instead allow for a missing virtual functions and perform
the "default" action in the accessor.
An example for that is nm_platform_link_get_permanent_address().

(cherry picked from commit e8e455817b)
2015-06-22 09:56:06 +02:00
Thomas Haller
c01a9d059c nmp-object: check for non-empty ifname in _vt_cmd_obj_is_visible_link()
(cherry picked from commit ae824f582b)
2015-06-22 09:56:05 +02:00
Thomas Haller
42d17463e5 platform: fix ip4_check_reinstall_device_route() implementation
We must check if a conflicting route/address is configured on
*any* interface, not only on the target ifindex.

This at least restores the previous behavior. Note that this whole
check_reinstall_device_route() still has problems and it might
be better to move it all to NMRouteManager.

Fixes: 470bcefa5f
(cherry picked from commit 1bfade833a)
2015-06-22 09:56:05 +02:00
Thomas Haller
74381b3bf5 platform/trivial: rename ObjectType to NMPObjectType
After doing all the refactoring, rename the ObjectType enum to NMPObjectType.
I didn't do this earlier to avoid problems with rebasing. But since I will
backport the platform changes to nm-1-0, this is the right time to get
the name right.

(cherry picked from commit 518cf76de7)
2015-06-22 09:56:05 +02:00
Thomas Haller
6835e80aea platform: add nm_platform_process_events() function
(cherry picked from commit 55a67ec787)
2015-06-22 09:56:05 +02:00
Jiří Klimeš
e585c4d4f3 all: fix additional compiler warningis 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 2dc27a99d7)
2015-06-22 09:56:05 +02:00
Thomas Haller
bc9a673d1e platform: fix lookup addresses and routes for any ifindex and refactor NMPCacheIdType
After refactoring platform, nm_platform_ipx_route_get_all() and
nm_platform_ipx_address_get_all() was broken for calling with a
non-posititive ifindex (which has the meaning: ignore ifindex).

While fixing that, also refactor the NMPCacheIdType so that it matches
better the supported id-types.

Fixes: 470bcefa5f
(cherry picked from commit 8f9dac01ac)
2015-06-22 09:56:05 +02:00
Thomas Haller
dd49380d42 platform: drop nm_platform_get_error()
For NMPlatform instances we had an error reporting mechanism
which stores the last error reason in a private field. Later we
would check it via nm_platform_get_error().

Remove this. It was not used much, and it is not a great way
to report errors.

One problem is that at the point where the error happens, you don't
know whether anybody cares about an error code. So, you add code to set
the error reason because somebody *might* need it (but in realitiy, almost
no caller cares).
Also, we tested this functionality which is hardly used in non-testing code.
While this was a burden to maintain in the tests, it was likely still buggy
because there were no real use-cases, beside the tests.

Then, sometimes platform functions call each other which might overwrite the
error reason. So, every function must be cautious to preserve/set
the error reason according to it's own meaning. This can involve storing
the error code, calling another function, and restoring it afterwards.
This is harder to get right compared to a "return-error-code" pattern, where
every function manages its error code independently.

It is better to return the error reason whenever due. For that we already
have our common glib patterns

    (1) gboolean fcn (...);
    (2) gboolean fcn (..., GError **error);

In few cases, we need more details then a #gboolean, but don't want
to bother constructing a #GError. Then we should do instead:

    (3) NMPlatformError fcn (...);

(cherry picked from commit 68a4ffb4e2)
2015-06-22 09:54:52 +02:00
Thomas Haller
6a9cd7c113 platform: signal missing firmware in nm_platform_set_up()
Don't use nm_platform_get_error() anymore.

(cherry picked from commit c1a945b95d)
2015-06-22 09:54:52 +02:00