Commit Graph

360 Commits

Author SHA1 Message Date
Jiří Klimeš
db62fc9d72 platform: fix adding VLAN flags
We need to unset flags first.
2015-10-27 16:23:10 +01:00
Thomas Haller
fd7d57be03 platform/trivial: rename "auto_nmp_obj" macro to "nm_auto_nmpobj"
A define in a header file should have an "NM" prefix. Also,
let's have "nm_auto_" as a prefix for cleanup macros beside
libgsystem's "gs_".
2015-10-20 14:43:54 +02:00
Thomas Haller
8a6afe92c1 platform: fix link-detection for s390 CTC-type devices
Commit 02c6a93343 (rh#1212118)
introduced detection of CTC devices based on the driver name.

That was broken a while ago while refactoring.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1212118
https://bugzilla.redhat.com/show_bug.cgi?id=1272974

Fixes: ddaea22332
2015-10-19 12:24:39 +02:00
Thomas Haller
8968e15eb7 platform: properly handle peer-address for IPv4 addresses
Kernel allows to add the same IPv4 address that only differs by
peer-address (IFL_ADDRESS):

    $ ip link add dummy type dummy
    $ ip address add 1.1.1.1 peer 1.1.1.3/24 dev dummy
    $ ip address add 1.1.1.1 peer 1.1.1.4/24 dev dummy
    RTNETLINK answers: File exists
    $ ip address add 1.1.1.1 peer 1.1.2.3/24 dev dummy
    $ ip address show dev dummy
    2: dummy@NONE: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
        link/ether 52:58:a7:1e:e8:93 brd ff:ff:ff:ff:ff:ff
        inet 1.1.1.1 peer 1.1.1.3/24 scope global dummy
           valid_lft forever preferred_lft forever
        inet 1.1.1.1 peer 1.1.2.3/24 scope global dummy
           valid_lft forever preferred_lft forever

We must also consider peer-address, otherwise platform will treat
two different addresses as one and the same.

https://bugzilla.gnome.org/show_bug.cgi?id=756356
2015-10-14 12:52:07 +02:00
Thomas Haller
f193d98ced platform: refactor order of peer-address argument in ip_address_add() function
The peer-address seems less important then the prefix-length.
Also, nm_platform_ip4_address_delete() has the peer-address
argument as last.

Soon ip4_address_get() also receives a peer-address argument,
so get the order right first.
2015-10-14 12:52:07 +02:00
Thomas Haller
9f1eb190f7 platform: downgrade logging level for "event-notification" messages
We get a lot of these debugging message, although the event is entirely
internal to NMLinuxPlatform and only interesting when debugging a problem
in platform itself.

Downgrade to TRACE level.
2015-10-09 15:38:41 +02:00
Thomas Haller
98e34208bd platform: warn about growing sysctl logging cache and clear it
When debug-logging for platform is enabled, every access to sysctl
is cached (to log the last values).

This cache can grow quite large if the system has a large number of
interfaces (e.g. docker creating veth pairs for each container).

We already used to clear the cache, when we were about to access
sysctl *and* logging was disabled in the meantime.

Now, when logging setup changes, immediately clear the cache.
Having "nm-logging.c" call into platform code is a bit of a hack
and a better design would be to have logging code emit a signal to
which platform would subscribe. But that seems to involve much
more code (especially, as no other users care about such a signal
and because nm-logging is not a GObject).

Also, log a warning when the cache grows large to inform the user
about the cache and what he can do to clear it. The extra effort to
clear the cache when changing logging setup is done so that we do
what we tell the user: changing the logging level, will clear the
cache -- right away, not some time later when the next message is
logged.
2015-10-09 14:56:50 +02:00
Thomas Haller
f4f4e1cf09 platform: cancel delayed action REFRESH_LINK when receiving an update
When we receive an update for a link, cancel a scheduled
REFRESH_LINK delayed-action for that ifindex. At the point when we
scheduled refrehing the link, we only cared about receiving a
notification that was newer then the current state.

We scheduled requesting this new notification to resync the cache.
It is not necessary to actually request a new update, any update we
receive *after* requesting a new update will suffice.

This potentially saves extra round-trips re-requesting the link.
2015-09-18 11:24:21 +02:00
Thomas Haller
2cd6aaa918 platform: refresh links when parent gets removed
When moving a link to another netns, it gets removed from
NMPlatform's view.

Currently kernel does not sent a notification to inform about
that change (see related bug rh#1262908).

Ensure that we reload all linked interfaces which now might
have an invisible parent.
2015-09-18 11:05:37 +02:00
Thomas Haller
eee240ffe8 platform: fix handling refresh-link delayed actions
Due to a bug, we would only handle one REFRESH_LINK delayed action
and ignore the ones queued afterwards.

Fixes: 051cf8bbde
2015-09-18 11:01:21 +02:00
Jiří Klimeš
0f694f1a9a coverity: calm coverity for clock_gettime() return value check
Defect type: CHECKED_RETURN
3. NetworkManager-1.0.6/src/platform/nm-linux-platform.c:1145: check_return: Calling "clock_gettime" without checking return value (as is done elsewhere 6 out of 7 times).
2015-09-18 08:40:08 +02:00
Thomas Haller
7b70a8405e platform/trivial: add code-comment dividers between different sections of the source file 2015-09-04 11:50:49 +02:00
Thomas Haller
6bb26f8680 platform: get rid of old logging macros
The naming of these logging macros is unexpected, as we use such
macros only here in platform.

For these messages we cannot use the default _LOGD() set of macros,
because there is no @platform instance around. So let's introduce an
alternative set of logging macros (_LOG2D(), etc) and use it.
2015-09-04 11:06:26 +02:00
Thomas Haller
d47daeb4d9 platform: use _LOG*() macros instead of duplicated macros
Use the common logging macros _LOGD(), etc. instead of calling
nm_log_*() directly or the non-standard macros debug(), info(), etc.
2015-09-04 11:06:26 +02:00
Thomas Haller
084aec79df platform: refactor setup_socket() to accept explicit platform argument
Also, use _LOGW() in verify_source()
2015-09-04 11:06:26 +02:00
Thomas Haller
ffb931ca5c platform: refactor logging for sysctl functions
Use the standard _LOG*() macros and make the static cache
@sysctl_get_prev_values per instance.
2015-09-04 11:06:26 +02:00
Thomas Haller
a922d5e587 platform: assert to successfully dlopen libnl3 2015-08-27 19:28:52 +02:00
Lubomir Rintel
2f4ba5f2bc platform: remove bogus asserts
You can't really compare a symbol resolved by ld.so to dlsym()'d one. The
former one is likely just an address of trampoline in PLT.
2015-08-27 19:28:44 +02:00
Thomas Haller
790a0713d2 platform: handle parent interfaces in other netns
The parent of a link (IFLA_LINK) can be in another network namespace and
thus invisible to NM.

This requires the netlink attribute IFLA_LINK_NETNSID which is supported
by recent versions of kernel and libnl.

In this case, set the parent field to NM_PLATFORM_LINK_OTHER_NETNS
and properly handle this special case.
2015-08-25 22:33:14 +02:00
Thomas Haller
31902f8f6b platform: minor refactoring in _nl_get_vtable() 2015-08-25 22:25:23 +02:00
Thomas Haller
2189c7c75b platform: return const argument from _nl_get_vtable() 2015-08-25 22:25:23 +02:00
Thomas Haller
19ebe51e2e platform: assert we loaded the right libnl library 2015-08-25 22:25:23 +02:00
Thomas Haller
7f9cb13057 platform: downgrade the warning about cache-sync to info level
It can happen on a regular basis when many events get raised.
It is probalby not avoidable and most likely not an issue, so
downgrade the warning to info level.
2015-08-20 17:50:36 +02:00
Thomas Haller
ad7cdfc766 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.
2015-08-20 11:15:13 +02:00
Thomas Haller
a4c7176fe9 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
2015-08-11 18:31:46 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Thomas Haller
6f8fcd2f47 platform: replace addr/route exists() functions by get()
Rename exists() functions to get() and return the cached platform
object.
2015-07-14 13:36:50 +02:00
Lubomir Rintel
da612acc6a 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...".
2015-07-14 13:02:15 +02:00
Lubomir Rintel
295c9818b0 devices,platform: fix build with gcc
Warnings about missing initializers.
2015-07-01 16:35:52 +02:00
Thomas Haller
5f54a323d1 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
2015-07-01 16:02:10 +02:00
Thomas Haller
42664e8752 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.
2015-07-01 16:00:21 +02:00
Thomas Haller
d9dba6b662 platform: change NMPlatformGetRouteMode enum to NMPlatformGetRouteFlags flags
By having flags instead of an enum/mode, we can encode more combinations
of filtering the result.
2015-07-01 16:00:21 +02:00
Thomas Haller
85bf9ded2e 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.
2015-07-01 16:00:21 +02:00
Thomas Haller
7594e31220 platform: track pref_src field of IPv4 routes 2015-07-01 15:47:28 +02:00
Thomas Haller
d0ed4de104 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.
2015-07-01 15:47:28 +02:00
Thomas Haller
871c4d90c7 platform: fix initializing vlan_id for NMPlatformLink instance from libnl object
If the vlan-information is missing, we must consult the cache.

Fixes: 8a1f4beb65
2015-07-01 15:46:01 +02:00
Lubomir Rintel
8a1f4beb65 linux-platform: don't try to read vlan id from netlink objects without type set
They just don't have the information.
2015-06-26 15:52:10 +02:00
Thomas Haller
c2754ede5c platform: fix inverting guint8 value inet6_addr_gen_mode_inv
Fixes: e8e455817b
2015-06-25 18:49:18 +02:00
Thomas Haller
cd5b260545 platform/coverity: add workarounds to suppress coverify warnings 2015-06-25 18:49:18 +02:00
Thomas Haller
b88c309167 platform: pass object type with platform changed signal 2015-06-24 16:09:57 +02:00
Thomas Haller
7bd3b0b304 platform/trivial: fix name of enum value OBJECT_TYPE_UNKNOWN
Fixes: 518cf76de7
2015-06-24 16:09:57 +02:00
Jiří Klimeš
b77fba3939 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
2015-06-24 14:43:09 +02:00
Thomas Haller
e8e455817b 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().
2015-06-21 12:53:48 +02:00
Thomas Haller
1bfade833a 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
2015-06-19 17:16:39 +02:00
Thomas Haller
518cf76de7 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.
2015-06-19 16:24:20 +02:00
Thomas Haller
55a67ec787 platform: add nm_platform_process_events() function 2015-06-19 15:38:41 +02:00
Thomas Haller
8f9dac01ac 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
2015-06-18 17:19:00 +02:00
Thomas Haller
68a4ffb4e2 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 (...);
2015-06-17 11:44:16 +02:00
Thomas Haller
c1a945b95d platform: signal missing firmware in nm_platform_set_up()
Don't use nm_platform_get_error() anymore.
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