Commit graph

12006 commits

Author SHA1 Message Date
Thomas Haller
bfe2fd271b core: fix nm_ip_config_intersect() only to remove addresses, routes and gateway
Otherwise we remove the DNS configuration during platform events.

Fixes: 557667df12
(cherry picked from commit 11ccf949a3)
2015-06-22 10:23:14 +02:00
Thomas Haller
43b77d7c32 device: always pickup externally configured default routes for a device
Even more eagerly pickup external default routes from the device.
For assumed devices we already picked up the default route.

(a) For assumed devices we already did not enforce the default route at all.
Instead it was always picked up by from the actualy system
configuration. Note that this is the case for assumed-generated
connections and for assuming existing connections.
That means that when NM assumes a connection at startup, it will never
actively manage the default route on that interface. It will only react
on what is present.

(b) For managed devices that have by configuration no default route, still pick up
the default route. That means, that even a device that is managed and
never-default=yes, can have the default route -- if configured externally.

(c) Only during a commit phase (i.e. when we have new configuraiton to be
applied), we enforce the default route or its absence.

(d) During any IP change event from platform, we again pickup whatever
is present. That means if you remove the default route from a managed
interface, NM will not re-add it until anything triggers (c).

This also means, that during the commit phase, we add default routes as
'synced' to the default-route-manager, but the following event from platform,
will change the route entry immediately to 'non-synced'. That is
expected and correct.

(cherry picked from commit da708059da)
2015-06-22 10:23:14 +02:00
Thomas Haller
ab6548c621 device: better accept external IP changes
When receiving IP changes via platform event, remove all missing
addresses and routes from our internal configurations (such as
wwan, vpn, dhcp).

The effect is that on the next commit, those addresses and routes will
not be re-added as they were explicitly removed by the user.

However on a new DHCP lease or similar events, the addresses will
be added anew.

Another important improvement is that the NMIPxConfig of the active
device reflects when addresses or routes get removed externally. Before
we would continue to expose those entires although they were not
actually configured on the device.

https://bugzilla.gnome.org/show_bug.cgi?id=740443
(cherry picked from commit 557667df12)
2015-06-22 10:23:14 +02:00
Thomas Haller
f6da80f153 device: require a direct route for IPv6 gateway
In the IPv4 case, we check whether we have a direct route to the gateway
also by looking at the configured addresses/subnets. That is correct,
because every IPv4 address also implies a subnet route.

For IPv6, we explicitly add all subnet routes manually (noprefixroute),
hence, we have a direct route exactly if we have it in our list.
Regardless of the configured IPv6 prefixes.

(cherry picked from commit 2c06449085)
2015-06-22 10:23:14 +02:00
Thomas Haller
4001615034 core: add intersect() functions to NMIP?Config
(cherry picked from commit 49d700e862)
2015-06-22 10:23:14 +02:00
Thomas Haller
fd80e62f47 core: refactor subtract() functions in NMIP?Config
Factor out code of the nm_ip4_config_subtract() and
nm_ip6_config_subtract() functions. The code can be reused in the
following commit.

(cherry picked from commit 92d800b2e3)
2015-06-22 10:23:13 +02:00
Thomas Haller
8f01cad71c device: refactor ipx_config_merge_and_apply()
No functional change, but restructure code to make it clearer(?).

(cherry picked from commit 4a83afd530)
2015-06-22 10:23:13 +02:00
Lubomir Rintel
bdf4ea8aa5 trivial: move nm_device_queued_ip_config_change_clear()
Just move it upwards, we'll need it in
nm_device_activate_schedule_ip4_config_result().

(cherry picked from commit a772fde00d)
2015-06-22 10:23:13 +02:00
Thomas Haller
e23fda7a07 contrib/rpm: let NetworkManager package own '/etc/NetworkManager/' directory
(cherry picked from commit acef8c6a1b)
2015-06-22 09:56:06 +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
Dan Williams
5ddfc86eb8 trivial: move some code around in nm-device.c
(cherry picked from commit 86abc34e26)
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
6c68d90d81 device: delay handling of link-changed platform event
When inside a state-change, we set for example the device up.
This triggers a link-changed event, which then causes further
state-changes of the devices.
A state-change in process of a device is not reentrant, so we must
delay the handling of the link-changed event.

(cherry picked from commit 04caae735f)
2015-06-22 09:56:05 +02:00
Thomas Haller
6ac7a3c30e settings: print filename of loaded setting plugins
(cherry picked from commit 5ecfbf18c2)
2015-06-22 09:56:05 +02:00
Thomas Haller
a51d2d6149 macros: add NM_PRINT_FMT_QUOTED() macro
(cherry picked from commit 972f61fcd7)
2015-06-22 09:56:05 +02:00
Thomas Haller
e1283824ef settings: close module if loading of plugins fails
(cherry picked from commit 3be5e2908c)
2015-06-22 09:56:05 +02:00
Thomas Haller
1657a91ee6 platform: merge branch 'th/platform_refact_caching-bgo747981'
Refactor caching of NMPlatform and the way how to load objects
via libnl/netlink.

https://bugzilla.gnome.org/show_bug.cgi?id=747981
https://bugzilla.gnome.org/show_bug.cgi?id=747985
https://bugzilla.redhat.com/show_bug.cgi?id=1211133

(cherry picked from commit 35dcd8ac33)
2015-06-22 09:55:55 +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
26b39df884 device: drop logging platform error on failure to set permanent MAC address
The platform error is in many cases not meaningful anyway.

(cherry picked from commit baec894139)
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
Thomas Haller
6d454c8bdf device: don't check for NM_PLATFORM_ERROR_NOT_FOUND in set_nm_ipv6ll()
Unconditionally log a warning if the function fails.
We are about to drop nm_platform_get_error(), it's anyway unclear
why we don't want to log a warning about non-existing interface.

(cherry picked from commit 8334171a4e)
2015-06-22 09:54:52 +02:00
Thomas Haller
87c1b92cc5 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.

(cherry picked from commit d7fe907c32)
2015-06-22 09:54:52 +02:00
Thomas Haller
8fbd2d84e8 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.

(cherry picked from commit f7fb68755c)
2015-06-22 09:54:52 +02:00
Thomas Haller
0def11cf47 platform: expose GUdevDevice instance for platform links
(cherry picked from commit b74e620f2d)
2015-06-22 09:54:52 +02:00
Thomas Haller
eb0b0eb7f3 platform: invoke platform signals with clone of object
Don't expose @obj directly but clone the public fields. A signal
handler might call back into NMPlatform which could invalidate (or modify)
@obj.

(cherry picked from commit e7ee2fc139)
2015-06-22 09:54:52 +02:00
Thomas Haller
ae168e53ca Revert "core: add NMRefString"
After hiding the udi field, there are no more users of NMRefString.
Remove the code by explitly reverting the patch so that in case of a future
need, we can find and resurrect NMRefString.

This reverts commit d0e2937006.

(cherry picked from commit 3359dddd2e)
2015-06-22 09:54:36 +02:00
Thomas Haller
42a93b79ed 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.

(cherry picked from commit 1b2b988ea9)
2015-06-21 15:32:13 +02:00
Thomas Haller
fb0443def9 glib-compat: add g_ptr_array_insert()
(cherry picked from commit 2f4301bd26)
2015-06-21 15:32:11 +02:00
Thomas Haller
fe803bc567 platform: stringify nlmsg-event-type in logging
(cherry picked from commit e16fe9ddd4)
2015-06-21 15:30:50 +02:00
Thomas Haller
1162eee1be platform/trivial: rename functions (NMIPConfigSource conversion)
(cherry picked from commit 5b80be5a2c)
2015-06-21 15:30:50 +02:00
Thomas Haller
43f799da03 platform/trivial: move code (NMIPConfigSource conversion)
(cherry picked from commit 37df41a38e)
2015-06-21 15:30:50 +02:00
Thomas Haller
db036ef528 platform/trivial: rename functions (nm_rtnl_link_parse_info_data)
(cherry picked from commit 0e0d3b0775)
2015-06-21 15:30:50 +02:00
Thomas Haller
f38f5de4ba platform/trivial: move code (nm_rtnl_link_parse_info_data)
(cherry picked from commit 2f0a9bbe9a)
2015-06-21 15:30:50 +02:00
Thomas Haller
25fb3c822d platform/trivial: rename by using _nl_*() prefix for libnl related functions
(cherry picked from commit af70a7fc7c)
2015-06-21 15:30:49 +02:00
Thomas Haller
d24732b874 platform: remove redundant NMPlatformLink fields "arp" and "up"
(cherry picked from commit 076fe578e3)
2015-06-21 15:30:49 +02:00
Thomas Haller
44dc97d184 platform: fetch objects via the event socket
Use the event socket to request object via NLM_F_DUMP.

No longer use 'priv->nlh' socket to fetch objects.
Instead fetch them via the priv->nlh_event socket that also
provides asynchronous events when objects change.

That way, the events are in sync with our explicit requests
and we can directly use the events. Previously, the events were
only used to indicate that a refetch must happen, so that every
event triggered a complete dump of all addresses/routes.

We still use 'priv->nlh' to make synchronous requests such as
adding/changing/deleting objects. That means, after we send a
request, we must make sure that the result manifested itself
at 'nlh_event' socket and the platform cache.
That's why we sometimes still must force a dump to sync changes.
That could be improved by using only one netlink socket so that
we would wait for the ACK of our request.

While not yet perfect, this already significantly reduces the number of
fetches. Additionally, before, whenever requesting a dump of addresses
or routes (which we did much more often, search for "get_kernel_object for type"
log lines), we always dumped IPv4 and IPv6 together. Now only request
the addr-family in question.

https://bugzilla.gnome.org/show_bug.cgi?id=747985
https://bugzilla.redhat.com/show_bug.cgi?id=1211133
(cherry picked from commit 051cf8bbde)
2015-06-21 15:30:49 +02:00
Thomas Haller
f1c6d71784 libnm: add _nm_utils_ptrarray_find_first() utility function
(cherry picked from commit 3377cd7e18)
2015-06-21 15:30:49 +02:00
Thomas Haller
5daac57a23 utils: add nm_utils_is_power_of_two() macro
(cherry picked from commit 0a3c1f5774)
2015-06-21 15:30:47 +02:00
Thomas Haller
662194cde3 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.

(cherry picked from commit 56b07b1a3f)
2015-06-21 15:26:18 +02:00
Thomas Haller
25519f798d platform: reorder initialization
First fully construct the GOjbect instance before starting to
populate the cache.

(cherry picked from commit f1f1c3cb73)
2015-06-21 15:23:34 +02:00
Thomas Haller
8d13e08cd3 platform: add _support_user_ipv6ll_still_undecided() macro
(cherry picked from commit a2d793f0e1)
2015-06-21 15:23:34 +02:00
Thomas Haller
521d80dd9d platform: add priv pointer to NMLinuxPlatform
(cherry picked from commit bd9dab2a09)
2015-06-21 15:23:34 +02:00
Thomas Haller
6745030913 platform: refactor flushing of event socket to _nl_sock_flush_data()
(cherry picked from commit 9a16ce0876)
2015-06-21 15:23:34 +02:00
Thomas Haller
eb7b773536 platform/test: add simple test for NMLinuxPlatform
Just create a NMLinuxPlatform instance and unref it again.
This already connects to netlink and fetches all objects.

(cherry picked from commit 977626d942)
2015-06-21 15:23:34 +02:00