Commit Graph

21088 Commits

Author SHA1 Message Date
Thomas Haller
c528a89519 contrib/rpm: skip tests for -Q build option
Previously, the --quick option only mattered when creating
the source tarball, to run `make dist` instead of the slower
`make distcheck`.

Extend its meaning to also skip unit tests while building the RPM.
You still can enable them with

  $ ./contrib/fedora/rpm/build_clean.sh -Q -w test
2017-07-25 06:18:36 +02:00
Lubomir Rintel
1ac92ac355 contrib/rpm: provide NetworkManager-devel
The package no longer exists.

Fixes: 03586743f0
2017-07-21 17:30:49 +02:00
Stephen Gallagher
03586743f0 contrib/rpm: fix Requires/Provides on subpackages
NetworkManager-wifi and NetworkManager-glib-devel should require
NetworkManager, not provide it.

https://bugzilla.redhat.com/show_bug.cgi?id=1454505
2017-07-20 20:44:06 +02:00
Beniamino Galvani
7204472de5 connectivity: fix memory leak
Fixes: 9d43869e47
2017-07-19 22:14:05 +02:00
Beniamino Galvani
8469d77e2b core: fix detection of relevant changes in nm_ipX_config_replace()
The @relevant_changes output value must match the result of
!nm_ipX_config_equal(), so route metric and gateway must be taken into
account too.

Fixes: 935411e5c0
Fixes: cfd1851c00

https://bugzilla.redhat.com/show_bug.cgi?id=1471244
2017-07-17 22:18:48 +02:00
Beniamino Galvani
5aa22ed8c9 dns: perform the public-suffix check only for the hostname-derived domain
The DNS manager drops from the search list domains that are public
suffixes to prevent a possible domain hijack when using two-labels
hostnames [1].

This is a problem now that every single-label domain can be a TLD
since this means that such domains can't be used in the search list.

While it's useful to apply such restriction to the domain
automatically derived from the system hostname, it seems wrong to drop
domains specified by users in the configuration or provided by DHCP.

This commit keeps the public-suffix check only for the
hostname-derived domain

[1] https://bugzilla.redhat.com/show_bug.cgi?id=812394

https://bugzilla.redhat.com/show_bug.cgi?id=1404350
2017-07-17 17:01:51 +02:00
Thomas Haller
d61eaf2545 service: don't install dependency for "NetworkManager-wait-online.service" to "network-online.target.wants"
If we install "NetworkManager-wait-online.service" in the
"network-online.target.wants" directory, network-online.target always
pulls in NetworkManager-wait-online.service. As it was, it could only
be disabled by masking the service.

Instead, we should enable NetworkManager-wait-online.sevice via
systemd's preset. That is already done for Fedora 26 and newer.

Note that NetworkManager-wait-online.sevice already has Install.WantedBy.
This way, the dependency is created automatically when enabling the service.

https://bugzilla.redhat.com/show_bug.cgi?id=1455704
2017-07-17 16:04:21 +02:00
Thomas Haller
f42b4960f8 cli: warn when adding connection with a name that already exists
As far as NetworkManager is concerned, the "connection.id" (also called
"con-name" in nmcli) is a pretty name and does not need to be unique.

UI components usually show the "connection.id" instead of the
"connection.uuid" identifier. It is hence likely, that the user
would not intentionally re-use the same name for multiple connection
profiles.

Print a warning to stderr when the user adds such a connection.

This only affects `nmcli connection add` and `nmcli connection import`,
but not `nmcli connection clone` and not interactive edit mode.

https://bugzilla.redhat.com/show_bug.cgi?id=1460796
2017-07-17 14:49:31 +02:00
Thomas Haller
45a58c3811 trivial: fix whitespace 2017-07-17 12:49:58 +02:00
Beniamino Galvani
7a14757595 core: fix route synchronization
Fixes: 667c50f5d9
2017-07-15 09:55:58 +02:00
Thomas Haller
ad5f5c81ef core: shortcut equal operator for identical object reference in NMDedupMultiIndex
And get rid of the unused obj_full_equality_allows_different_class.
It's hard to grasp how to implement different object types that can compare
despite having different klasses. The idea was, that stack allocated
objects (used as lookup needles), are some small lightweight objects,
that still compare equal to the full instance. But it's unused. Drop it.
2017-07-10 21:55:00 +02:00
Thomas Haller
930da031b2 core: fix NMDedupMultiIndex's _dict_idx_entries_hash()
Don't overwrite @h.

Fixes: f9202c2ac1
2017-07-10 21:55:00 +02:00
Thomas Haller
67bc29bed1 core: fix heap overflow accessing NMIP4Config's idx_ip4_routes
and NMIP6Config.

Fixes: 935411e5c0
2017-07-10 21:53:59 +02:00
Thomas Haller
0c23191b01 dhcp/tests: add test parsing dhclient config 2017-07-10 11:44:33 +02:00
Jonathan Kang
3646ed083d dhcp/dhclient: improve "interface" statement parsing
In commit d405cfd908, parsing "interface"
statement is introduced. But it leads to uncommplete parsing of the
"request" entry, if one of the lines in "request" entry is prefixed with
word "interface". For example, the default configuration of openSUSE
distribution:

request subnet-mask, broadcast-address, routers,
	rfc3442-classless-static-routes,
	interface-mtu, host-name, domain-name, domain-search,
	domain-name-servers, nis-domain, nis-servers,
	nds-context, nds-servers, nds-tree-name,
	netbios-name-servers, netbios-dd-server,
	netbios-node-type, netbios-scope, ntp-servers;

Fixes: d405cfd908

https://bugzilla.opensuse.org/show_bug.cgi?id=1047004
https://mail.gnome.org/archives/networkmanager-list/2017-July/msg00015.html
2017-07-10 11:35:12 +02:00
Beniamino Galvani
f395a0c29b cli: don't track device state for VPN connections
Currently nmcli considers the state of the device associated to a
connection to determine the success of an activation; for VPNs the
device is the parent interface on which the VPN is established.

This means that VPNs on bond/bridge/team interfaces are reported as
connected immediately because of the special handling of master
devices state in check_activated().

The parent device state is not meaningful for VPNs, so don't track it.
2017-07-09 16:10:54 +02:00
Yuri Chornoivan
b535ecc23a po: update Ukrainian (uk) translation (bgo#784529)
https://bugzilla.gnome.org/show_bug.cgi?id=784529
2017-07-07 13:28:50 +02:00
Thomas Haller
22cd73d3aa all: merge branch 'th/dedup-multi-bgo784220'
Refactor platform cache to track objects via a doubly linked
list, with each element indexed via a hash table.

This preserves the order of the objects, which will be needed
for improving the route cache.

Also, the NMPObjects are now immuable, ref-counted and can be
shared. This will allow other parts to reuse the same objects.

NMPIP4Config and NMPIP6Config now uses the same data structure
for tracking their routes. This changes the O(n^2) runtime for
intersect, merge and subtract to O(n).

https://bugzilla.gnome.org/show_bug.cgi?id=784220
2017-07-07 10:21:58 +02:00
Thomas Haller
b2112ff471 platform: refactor NMPObject cast macros using _Generic()
This way, we also accept void pointers, while preserving constness.
2017-07-05 22:17:42 +02:00
Thomas Haller
06598700fe platform: refactor nm_platform_link_get_all() to return GPtrArray
Instead of doing a full clone, return a pointer array (with references
owned). The NMPlatformLink instances are now immutable.
2017-07-05 19:03:46 +02:00
Thomas Haller
ac60b0ce60 platform: move link accessors to NMPlatform base class
and refactor NMFakePlatform to also track links via NMPCache.

For one, now NMFakePlatform also tests NMPCache, increasing the
coverage of what we care about.

Also, all our NMPlatform implementations now use NMPObject and NMPCache.
That means, we can expose those as part of the public API. Which is
great, because callers can keep a reference to the NMPObject object
and make use of generic functions like nmp_object_to_string().
2017-07-05 18:37:39 +02:00
Thomas Haller
71cf60e852 platform: refactor fake platform to use NMPCache for addresses
And move some code from NMLinuxPlatform to NMPlatform, where it belongs.

The advantage is that we reuse (and test!) the NMPCache implementation for
tracking addresses.

Also, we now always expose proper NMPObjects from both linux and fake
platform.

For example,

  obj = NMP_OBJECT_UP_CAST (nm_platform_ip4_address_get (...));

will work as expected. Also, the caller is now by NMPlatform API
allowed to take and keep a reference to the returned objects.
2017-07-05 18:37:39 +02:00
Thomas Haller
8b3b148fda platform/trivial: rename cache-id-type indexes 2017-07-05 18:37:39 +02:00
Thomas Haller
17f02318ad platform: drop separate index for visible objects
Routes and addresses don't implement cmd_obj_is_visible(),
hence they are always visible, and NMP_CACHE_ID_TYPE_OBJECT_TYPE_VISIBLE_ONLY
is identical to NMP_CACHE_ID_TYPE_OBJECT_TYPE.

Only link objects can be alive but invisible. Still, drop the index
for looking up visible links entirely. Let callers do the filtering,
if they care.
2017-07-05 18:37:39 +02:00
Thomas Haller
beb0b9b1ad platform: reduce number of route indexes
Maintaining an index is expensive.Not so much in term of runtime, but
in term of memory.

Drop some indexes, and require the caller to use a more broad index (and
filter out unwanted elements).

Dropped:

 - can no longer lookup visible default-routes by ifindex.
   If you care about default-routes, lookup all and search for the
   desired ifindex. The overall number of default-routes is expected
   to be small.
   We drop NMP_CACHE_ID_TYPE_ROUTES_VISIBLE_BY_IFINDEX_WITH_DEFAULT
   entirely.

 - no longer have a separate index for non-default routes. We
   expect that the most routes are non-default routes. So, don't
   have an index without default-routes, instead let the caller
   just lookup all routes, and reject default-routes themself.
   We keep NMP_CACHE_ID_TYPE_ROUTES_VISIBLE_BY_DEFAULT, but it
   now no longer tracks non-default routes.

This drops 1 out of 6 route indexes, and modifes another one, so
that we expect that there are almost no entires tracked by it.
2017-07-05 18:37:39 +02:00
Thomas Haller
35f52aafc1 platform: drop nm_platform_ip6_route_get_all()
We no longer need a full clone of routes. The only remaining uses
are in test code. Rework it.
2017-07-05 18:37:39 +02:00
Thomas Haller
aeaa1b3b98 platform: refactor nm_dedup_multi_objs_to_ptr_array_head()
by moving the core functionality to "nm-dedup-multi.c".

As the ref-counting mechanism now is part of "nm-dedup-multi.c",
this works better and is reusable outside of platform.
2017-07-05 18:37:39 +02:00
Thomas Haller
cfd1851c00 core: refactor NMIP6Config to use dedup-index for IPv6 routes 2017-07-05 18:37:39 +02:00
Thomas Haller
28340588d9 core: remove NMDedupMultiBox object and track NMDedupMultiObj instances directly
Implement the reference counting of NMPObject as part of
NMDedupMultiObj and get rid of NMDedupMultiBox.

With this change, the NMPObject is aware in which NMDedupMultiIndex
instance it is tracked.

- this saves an additional GSlice allocation for the NMDedupMultiBox.

- it is immediately known, whether an NMPObject is tracked by a
  certain NMDedupMultiIndex or not. This saves an additional hash
  lookup.

- previously, when all idx-types cease to reference an NMDedupMultiObj
  instance, it was removed. Now, a tracked objects stays in the
  NMDedupMultiIndex until it's last reference is deleted. This possibly
  extends the lifetime of the object and we may reuse it better.

- it is no longer possible to add one object to more then one
  NMDedupMultiIndex instance. As we anyway want to have only one
  instance to deduplicate the objects, this is fine.

- the ref-counting implementation is now part of NMDedupMultiObj.
  Previously, NMDedupMultiIndex could also track objects that were
  not ref-counted. Hoever, the object anyway *must* implement the
  NMDedupMultiObj API, so this flexibility is unneeded and was not
  used.

- a downside is, that NMPObject grows by one pointer size, even if
  it isn't tracked in the NMDedupMultiIndex. But we really want to
  put all objects into the index for sharing and deduplication. So
  this downside should be acceptable. Still, code like
  nmp_object_stackinit*() needs to handle a larger object.
2017-07-05 18:37:39 +02:00
Thomas Haller
667c50f5d9 core: avoid cloning platform routes but iterate the cache directly 2017-07-05 18:37:39 +02:00
Thomas Haller
c9cd6d9954 platform: track routes in NMFakePlatform via NMPCache
NMPlatform's cache should be directly accessible to the users,
at least the NMPLookup part and the fact that the cache contains
ref-counted, immutable NMPObjects.

This allows users to inspect the cache with zero overhead. Meaning,
they can obtain an NMDedupMultiHeadEntry and iterate the objects
themself. It also means, the are free to take and keep references
of the NMPObject instances (of course, without modifying them!).

NMFakePlatform will use the very same cache. The fake platform should
only differ when modifying the objects.

Another reason why this makes sense is because NMFakePlatform is for one
a test-stup but also tests behavior of platform itself. Using a separate
internal implementation for the caching is a pointless excecise, because
only the real NMPCache's implementation really matters for production.
So, either NMFakePlatform behaves idential, or it is buggy. Reuse it.

Port fake platform's tracking of routes to NMPCache and move duplicate
code from NMLinuxPlatform to the base class.

This commit only ports IP routes, eventually also addresses and links
should be tracked via the NMPCache instance.
2017-07-05 18:37:39 +02:00
Thomas Haller
16aefdd865 platform: expose index lookup for objects in public API 2017-07-05 18:37:39 +02:00
Thomas Haller
c5af191dbf platform: expose emit-signal function from platform
It will be used by NMFakePlatform too.
2017-07-05 18:37:39 +02:00
Thomas Haller
e160928b9e platform: move the NMPCache from linux platform to NMPlatform
We want to expose the NMPLookup and NMDedupMultiHeadEntry to the users
of NMPlatform, so that they can iterate the cache directly.

That means, NMPCache becames an integral part of NMPlatform's API
and must also be implemented by NMFakePlatform.
2017-07-05 18:37:39 +02:00
Thomas Haller
485551286c platform: add use-udev property for NMPlatform
We want to move the multi_idx from NMLinuxPlatform to NMPlatform,
so that it can be used by NMFakePlatform as well. For that, we need
to know whether NMPlatform will use udev or not. Add a constrctor
property.
2017-07-05 18:37:39 +02:00
Thomas Haller
55e66cc7e6 platform: implement hash function for NMPlatformLnk types 2017-07-05 18:37:39 +02:00
Thomas Haller
d2f856fb95 platform: fix nmp_object_hash() to include object type
NMPlatformLnkMacvtap is a typedef of NMPlatformLnkMacvlan, hence, their
plobj implementation is idential. nmp_object_equal() already correctly
compares the object type, so we should hash it too.
2017-07-05 18:37:39 +02:00
Thomas Haller
bb009630a1 core: remove NMMultiIndex
It's unused now.
2017-07-05 18:37:38 +02:00
Thomas Haller
35502807b5 platform: merge NMP_CACHE_ID_TYPE_ROUTES_BY_DESTINATION* index
In this case, not much is saved, because previously IPv4 and IPv6
routes had completely distinct indexes.
2017-07-05 18:37:38 +02:00
Thomas Haller
6324b779b2 platform: merge NMP_CACHE_ID_TYPE_ROUTES_VISIBLE_*_DEFAULT indexes
Maintaining an index is expensive. We can merge indexes that
are strictly distinct, because one index can just partition the
objects into distinct sets.
2017-07-05 18:37:38 +02:00
Thomas Haller
9440eefb6d platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.

Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:

- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
  the cached items. That is crucial to handle routes properly as kernel
  will replace the first matching route based on network/plen/metric
  properties. See related bug rh#1337855.
  Without tracking the order of routes as they are exposed
  by kernel, we cannot properly maintain the route cache.

- All NMPObject instances are now treated immutable, refcounted
  and get de-duplicated via NMDedupMultiIndex. This allows
  to have a global NMDedupMultiIndex that can be shared with
  NMIP4Config and NMRouteManager. It also allows to share the
  objects themselves.
  Immutable objects are so much nicer. We can get rid of the
  update pre-hook callback, which was required previously because
  we would mutate the object inplace. Now, we can just update
  the cache, and compare obj_old and obj_new after the fact.

- NMMultiIndex was treated as an internal of NMPCache. On the other
  hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
  basically an object that allows to iterate over all related
  objects. That means, we can now lookup objects in the cache
  and give the NMDedupMultiHeadEntry instance to the caller,
  which then can iterate the list on it's own -- without need
  for copying anything.
  Currently, at various places we still create copies of lookup
  results. That can be improved later.

The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.

Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-07-05 18:37:38 +02:00
Thomas Haller
3edf2bff3d platform: fix lookup of all routes unrestricted to an ifindex
Need to use the right NMPCacheIdType when looking up routes
across all ifindexes.

Fixes: 8f9dac01ac
2017-07-05 14:22:10 +02:00
Thomas Haller
0b060d9bc5 platform/trivial: rename variable 2017-07-05 14:22:10 +02:00
Thomas Haller
8822c45453 platform: use NM_SET_OUT() macro 2017-07-05 14:22:10 +02:00
Thomas Haller
935411e5c0 core: refactor NMIP4Config to use dedup-index for IPv4 routes
Eventually, every NMPlatformIP4Route, NMPlatformIP6Route,
NMPlatformIP4Address and NMPlatformIP6Address should be shared
an deduplicated via the global NMDedupMultiIndex instance.

As first proof of concept, refactor NMIP4Config to track
IPv4 routes via the shared multi_idx. There is later potential
for improvement, when we pass (deduplicated) NMPObject instances
around instead of plain NMPlatformIP4Route, which needs still
a lot of comparing and cloning.
2017-07-05 14:22:10 +02:00
Thomas Haller
89385bd968 core: pass NMDedupMultiIndex instance to NMIP4Config and other
NMIP4Config, NMIP6Config, and NMPlatform shall share one
NMDedupMultiIndex instance.

For that, pass an NMDedupMultiIndex instance to NMPlatform and NMNetns.
NMNetns than passes it on to NMDevice, NMDhcpClient, NMIP4Config and NMIP6Config.
So currently NMNetns is the access point to the shared NMDedupMultiIndex
instance, and it gets it from it's NMPlatform instance.

The NMDedupMultiIndex instance is really a singleton, we don't want
multiple instances of it. However, for testing, instead of adding a
singleton instance, pass the instance explicitly around.
2017-07-05 14:22:10 +02:00
Thomas Haller
6d9c3eab38 platform: let NMPObject implement NMDedupIndexObj 2017-07-05 14:22:10 +02:00
Thomas Haller
f9202c2ac1 shared: add NMDedupMultiIndex "nm-dedup-multi.h"
Add the NMDedupMultiIndex cache. It basically tracks
objects as doubly linked list. With the addition that
each object and the list head is indexed by a hash table.
Also, it supports tracking multiple distinct lists,
all indexed by the idx-type instance.
It also deduplicates the tracked objects and shares them.

 - the objects that can be put into the cache must be immutable
   and ref-counted. That is, the cache will deduplicate them
   and share the reference. Also, as these objects are immutable
   and ref-counted, it is safe that users outside the cache
   own them too (as long as they keep them immutable and manage
   their reference properly).

   The deduplication uses obj_id_hash_func() and obj_id_equal_func().
   These functions must cover *every* aspect of the objects when
   comparing equality. For example nm_platform_ip4_route_cmp()
   would be a function that qualifies as obj_id_equal_func().

   The cache creates references to the objects as needed and
   gives them back. This happens via obj_get_ref() and
   obj_put_ref(). Note that obj_get_ref() is free to create
   a new object, for example to convert a stack-allocated object
   to a (ref-counted) heap allocated one.

   The deduplication process creates NMDedupIndexBox instances
   which are the ref-counted entity. In principle, the objects
   themself don't need to be ref-counted as that is handled by
   the boxing instance.

 - The cache doesn't only do deduplication. It is a multi-index,
   meaning, callers add objects using a index handle NMDedupMultiIdxType.
   The NMDedupMultiIdxType instance is the access handle to lookup
   the list and objects inside the cache. Note that the idx-type
   instance may partition the objects in distinct lists.

For all operations there are cross-references and  hash table lookups.
Hence, every operation of this data structure is O(1) and the memory
overhead for an index tracking an object is constant.

The cache preserves ordering (due to linked list) and exposes the list
as public API. This allows users to iterate the list without any
additional copying of elements.
2017-07-05 14:22:10 +02:00
Thomas Haller
343c967e66 clients: make meta data subtypes of NMObjBaseInst
Yes, this wastes 4 times an unused GType instance
in the class structure.
2017-07-05 14:22:10 +02:00
Thomas Haller
b8bc80bcdb all: add base object type in "nm-obj.h"
Platform has it's own, simple implementation of object types:
NMPObject. Extract a base type and move it to "shared/nm-utils/nm-obj.h"
so it can be reused.

The base type is trival, but it allows us to implement other objects
which are compatible with NMPObjects. Currently there is no API for generic
NMObjBaseInst type, so compatible in this case only means, that they
can be used in the same context (see example below).
The only thing that you can do with a NMObjBaseInst is check it's
NMObjBaseClass.

Incidentally, NMObjBaseInst is also made compatible to GTypeInstance.
It means, an NMObjBaseInst is not necessarily a valid GTypeInstance (like NMPObject
is not), but it could be implemented as such.

For example, you could do:

    if (NMP_CLASS_IS_VALID ((NMPClass *) obj->klass)) {
        /* is an NMPObject */
    } else if (G_TYPE_CHECK_INSTANCE_TYPE (obj, NM_TYPE_SOMETHING)) {
        /* it a NMSometing GType */
    } else {
        /* something else? */
    }

The reason why NMPObject is not implemented as proper GTypeInstance is
because it would require us to register a GType (like
g_type_register_fundamental). However, then the NMPClass struct can
no longer be const and immutable memory. But we could.

NMObjBaseInst may or may not be a GTypeInstance. In a sense, it's
a base type of GTypeInstance and all our objects should be based
on it (optionally, they we may make them valid GTypes too).
2017-07-05 14:22:10 +02:00