Commit graph

324 commits

Author SHA1 Message Date
Thomas Haller 1c5d98292a c-list: add c_list_sort()
Add a stable, recursive merge sort for CList.

This could be improved by doing an iterative implementation.
The recursive implementation's stack depth is not an issue,
as it is bound by O(ln(n)). But an iterative implementation
would safe the overhead of O(n*log(n)) function calls and be
potentially faster.
2017-07-25 06:42:14 +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 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 bb009630a1 core: remove NMMultiIndex
It's unused now.
2017-07-05 18:37:38 +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 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
Thomas Haller b55fba8fbd build: fix race creating "libnm-core/tests" directory for "nm-core-tests-enum-types.c"
https://bugzilla.gnome.org/show_bug.cgi?id=783783
2017-06-14 14:04:57 +02:00
Thomas Haller 484d666485 build: fix nm binutils tool when building with LTO
When building with -flto, we need to use linker plugins.
In case of binutils' nm, it means to prefer gcc-nm if
available.

Like for ranlib and ar, prefer gcc-nm.

- replace AC_PATH_TOOL() by AC_CHECK_TOOLS(). That is consistent
  with what we do for ar,ranlib and suggested on bgo#783311.
- instead of using the variable $BINUTILS_NM, replace it by
  $NM, which is more common according to bgo#783311.
- Keep recognizing $BINUTILS_NM environment, which was introduced
  by commit 8bc88bcc7c. This is purely to keep previous build
  scripts working. Originally I named it "$BINUTILS_NM" because
  using $NM in NetworkManager seemed confusing. But well...

https://bugs.gentoo.org/show_bug.cgi?id=620052
https://bugzilla.gnome.org/show_bug.cgi?id=782525
https://bugzilla.gnome.org/show_bug.cgi?id=783311
2017-06-01 12:51:31 +02:00
Lubomir Rintel afebdc795d build: add a missing test artifact to dist
Fixes: ba05819c89
2017-06-01 12:47:43 +02:00
Lubomir Rintel 28505ae92b build: don't drop the test suite log on failure
Fixes: 2198f73b0e
2017-05-31 20:11:11 +02:00
Thomas Haller ba05819c89 ifcfg-rh/tests: add test for reading NETMASK property 2017-05-30 11:10:19 +02:00
Thomas Haller 371b761680 build: sort filenames in Makefile.am alphabetically 2017-05-30 11:10:19 +02:00
Thomas Haller 5a67130e15 build: don't link static libraries multiple times
libnm-core.a should only be linked once in libnm.so. Previously,
it was linked twice, once as part of libnm-utils.a and once
directly in libnm.so.

Fixes: 8df944c7e4
2017-05-19 14:52:03 +02:00
Thomas Haller 733160c862 build: don't install intermediate library libnm/libnm-utils.la
Fixes: 8df944c7e4
2017-05-19 14:13:41 +02:00
Thomas Haller 8df944c7e4 libnm: add testable libnm/nm-libnm-utils.c file
Previously, internal parts of libnm were not testable.
Instead, add "libnm/nm-libnm-utils.c" and "libnm/libnm-utils.la"
to contain code that can be statically linked with a new
test "libnm/tests/test-general".
2017-05-19 12:45:45 +02:00
Thomas Haller 5bfb7c3c89 hostname: split out hostname management from NMSettings
Hostname management is complicated. At least, how it is implemented currently.
For example, NMPolicy also sets the hostname (NMPolicy calls
nm_settings_set_transient_hostname() to have hostnamed set the hostname,
but then falls back to sethostname() in settings_set_hostname_cb()).
Also, NMManager tracks the hostname in NM_MANAGER_HOSTNAME too, and
NMPolicy listens to changes from there -- instead of changes from
NMSettings.

Eventually, NMHostnameManager should contain the hostname parts from NMSettings
and NMPolicy.
2017-05-12 17:29:33 +02:00
Thomas Haller d079846330 shared: add "nm-utils/c-list.h" header
Include the circular, doubly-linked list implementation from
c-util/c-list [1], commit 864051de6e7e1c93c782064fbe3a86b4c17ac466.

[1] https://github.com/c-util/c-list
2017-05-11 18:26:07 +02:00
Thomas Haller 79be44d990 ifcfg: add read/write support for user-data
The user data values are encoded in shell variables named
prefix "NM_USER_". The variable name is an encoded form of the
data key, consisting only of upper-case letters, digits, and underscore.

The alternative would be something like

  NM_USER_1_KEY=my.keys.1
  NM_USER_1_VAL='some value'
  NM_USER_2_KEY=my.other.KEY.42
  NM_USER_2_VAL='other value'

contary to

  NM_USER_MY__KEYS__1='some value'
  NM_USER_MY__OTHER___K_E_Y__42='other value'

The advantage of the former, numbered scheme is that it may be easier to
find the key of a user-data entry. With the current implementation, the
shell script would have to decode the key, like the ifcfg-rh plugin
does.

However, user data keys are opaque identifers for values. Usually, you
are not concerned with a certain name of the key, you already know it.
Hence, you don't need to write a shell script to decode the key name,
instead, you can use it directly:

  if [ -z ${NM_USER_MY__OTHER___K_E_Y__42+x} ]; then
      do_something_with_key "$NM_USER_MY__OTHER___K_E_Y__42"
  fi

Otherwise, you'd first have to search write a shell script to search
for the interesting key -- in this example "$NM_USER_2_KEY", before being
able to access the value "$NM_USER_2_VAL".
2017-05-06 14:12:19 +02:00
Thomas Haller f04bf45e84 ifcfg-rh/tests: compare the written files to a expected result
We have unit tests for writing and re-reading ifcfg file. Those
tests compare whether a file can be successfully read and is
semantically identical.

However, there were no tests that a certain output is written in
a stable format. We aim not to change the output of what we write.
For that, add tests to not only check the semantic of the written
ifcfg file, but their bits and bytes.

Some future changes may well intentionally change the current
output. That will require to update the expected result files
and can be done via

  NMTST_IFCFG_RH_UPDATE_EXPECTED=yes src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh

Note that alias, route, and key files are not checked.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1445414
2017-04-26 12:30:02 +02:00
Thomas Haller 0af2f5c28b core: add NMNetns to bundle platform and route managers
NMPlatform, NMRouteManager and NMDefaultRouteManager are singletons
instances. Users of those are for example NMDevice, which registers
to GObject signals of both NMPlatform and NMRouteManager.

Hence, as NMDevice:dispose() disconnects the signal handlers, it must
ensure that those singleton instances live longer then the NMDevice
instance. That is usually accomplished by having users of singleton
instances own a reference to those instances.
For NMDevice that effectively means that it shall own a reference to
several singletons.

NMPlatform, NMRouteManager, and NMDefaultRouteManager are all
per-namespace. In general it doesn't make sense to have more then
one instances of these per name space. Nnote that currently we don't
support multiple namespaces yet. If we will ever support multiple
namespaces, then a NMDevice would have a reference to all of these
manager instances. Hence, introduce a new class NMNetns which bundles
them together.
2017-04-18 15:49:14 +02:00
Thomas Haller ab47a2d5fe build: fix broken line wraps in Makefile.am 2017-04-07 13:52:12 +02:00
Thomas Haller 9f7380e973 build: add missing build dependency for ifupdown
And reorder _OBJECTS dependencies of settings plugins after their
corresponding _LDADD declartion.

https://mail.gnome.org/archives/networkmanager-list/2017-April/msg00016.html
2017-04-07 12:37:56 +02:00
Thomas Haller b3e2808c32 build: commit pre-generated "settings-docs.c" in git
nmcli has documentation strings embedded. Those strings are extracted
from gtk-doc comments, using pygobject and put in the generated file
"clients/common/settings-docs.c".

This file "clients/common/settings-docs.c" is disted, so from
a source tarball you can build nmcli without enabling introspection.
However, when building from a git-tree, the file is missing and
thus one cannot build --with-nmcli unless also using at least
--enable-introspection to generate "clients/common/settings-docs.c".

That is inconvenient. Especially during cross-compilation, where
one also needs python and pygobject in the foreign architecture (because
the generation of "settings-docs.c" loads the built libnm.so via
pygobject). It is bad because nmcli is an essential part of
NetworkManager, so building --without-nmcli is not a great option.
Previously, the only alternative was to pre-generate a source tarball
on a separate machine and build that. This however complicates efforts
to automatically build git snapshots of NetworkManager.

Fix that by commiting "clients/common/settings-docs.c.in" to git.
When building with --disable-introspection, the pre-generated
file is used instead. This is fine, because the file only depends
on static, checked-in documentation strings that seldomly change.

Also add a check target to notice when the pre-generated file differs
from what we are about to generate during --enable-introspection.
That happens when editing one of the gtk-doc entires. In this case,
`make check` will notify that the pre-generated "settings-docs.c.in"
file needs updating too.

Yes, when changing gtk-doc comments you need to updte the file manually.
At least, the check failure notifies you.
2017-04-05 16:53:06 +02:00
Thomas Haller 022117ff36 cli/tests: add "clients/common/tests/test-general.c" 2017-04-05 16:53:06 +02:00
Thomas Haller d9462879ac build: build intermediate library libnmc.la for nmcli
Used for unit testing in the next commit.

Also add libnmc-base.la, which contains common files for nmcli and
nmtui.
2017-04-05 16:53:06 +02:00
Thomas Haller db300afba1 cli: split out new file "nm-meta-setting-access.h"
"nm-meta-setting-desc.h" contains static type description, vtable and (internal)
accessor functions. Add accessor functions that operate on top of the type description
to "nm-meta-setting-access.h".
2017-04-05 16:53:06 +02:00
Thomas Haller d2af54f9bb build: fix out-of-tree build after moving generated settings-docs.c
Fixes: d720f0955f
2017-03-30 17:52:05 +02:00
Thomas Haller d720f0955f cli: embed gtk-doc directly in property-info structure
Also mark them for translation.
2017-03-30 16:35:52 +02:00
Thomas Haller f5a0b62765 cli: use enum property type for connection.lldp
Change in behavior:

  - the setter would previoulsy allow "enable" case-insensitive.
    Now, it's case sensitive.
2017-03-30 13:09:58 +02:00
Thomas Haller a8730c51c8 libnm: move enum utils to new shared file shared/nm-utils/nm-enum-utils.h
libnm contains the public function nm_utils_enum_from_str() et al.
The function is not flexible enough for nmcli's usecase. So, I would
need another public function like nm_utils_enum_from_str_full() that
has an extended API.

That was already required previously for ifcfg-rh writer, but in that
case I could just add it as internal API as libnm-core is linked statically
with NetworkManager.

I don't want to commit to a public API for an utility function. So move
the code instead to the shared directory, so that nmcli may link
statically against it and use the internal API.
2017-03-30 13:09:58 +02:00
Thomas Haller 23298bfc88 cli: move utils function from common.h to nm-meta-setting-desc.c
These functions are only used by nm-meta-setting-desc.c. Make them internal.
Unfortunately, they are part of "common.h" which cannot be used without
the rest of nmcli. Still todo.
2017-03-30 13:09:58 +02:00
Thomas Haller b5c8622ad3 cli: split nm-meta-setting-desc out of settings
This part contains static functions and variables to describe
settings. It is distinct from the mechanism to use them, or
access them.

Split it out.

It still uses clients/cli/common.h and clients/cli/utils.h
which shall be fixed next.
2017-03-30 13:09:58 +02:00
Thomas Haller d3ad7920de cli: add setting-info structure to settings.c
Will get more use soon.
2017-03-30 13:09:55 +02:00
Thomas Haller 68ab166f38 build: declare build dependencies requiring "nm-core-enum-types.h"
cat <<-EOF > /tmp/glib-mkenums
	#!/bin/bash
	sleep 15 && /usr/bin/glib-mkenums "\$@"
	EOF

	chmod +x /tmp/glib-mkenums

	(export PATH="/tmp:$PATH" &&
	 git clean -fdx &&
	 ./autogen.sh &&
	 make -j20 all-am)
2017-03-29 11:26:04 +02:00
Beniamino Galvani e044071825 ifcfg-rh: also check BONDING_OPTS to determine the connection type
Connections with "TYPE=Ethernet" and "BONDING_OPTS=..." are regarded
by initscripts as bond masters. To maintain the best compatibility, do
the same.

https://bugzilla.redhat.com/show_bug.cgi?id=1434555
2017-03-29 09:47:37 +02:00
Thomas Haller 18663c0960 build: declare build dependency for ifcfg-rh tests 2017-03-28 22:37:19 +02:00
Lubomir Rintel 9d43869e47 core: make connectivity checking per-device
This moves tracking of connectivity to NMDevice and makes the NMManager
negotiate the best of known connectivity states of devices. The NMConnectivity
singleton handles its own configuration and scheduling of the permission
checks, but otherwise greatly simplifies it.

This will be useful to determine correct metrics for multiple default routes
depending on actual internet connectivity.

The per-device connection checks is not yet exposed on the D-Bus, since they
probably should be per-address-family as well.
2017-03-28 15:26:47 +02:00
Thomas Haller 4ec7dd987e libnm: add NMSettingUser
This only adds new API for a NMSettingUser. The setting class
is still entirely unused.

The point is getting the new API into 1.8.0 release of libnm.
It's easier to backport the use of the API to a stable branch
then backporting public API.

https://bugzilla.gnome.org/show_bug.cgi?id=776276
https://bugzilla.redhat.com/show_bug.cgi?id=1421429
2017-03-28 14:58:21 +02:00
Lubomir Rintel 7750a384a5 libnm-util/vapi: add missing dependencies
Works by dumb luck for in-tree build, because the .deps files that are
meant for the distribution happen to be the builddir. The out-of-tree
builds would generate an empty file.
2017-03-24 11:38:49 +01:00
Lubomir Rintel ec17f82960 build: yet another missing dependency 2017-03-24 11:38:49 +01:00
Thomas Haller 8b9dfa013d build: fix building clients/cli/settings-docs.c (4)
We also dist libnm/nm-property-docs.xml, so depending on
whether we build from git or source tarball, the file
is in $(srcdir) or $(builddir).

Fixes: d7ad13591b
2017-03-24 10:48:56 +01:00
Thomas Haller 5581d91973 build: fix building clients/cli/settings-docs.c (3)
Fixes: d7ad13591b
2017-03-24 10:31:15 +01:00
Thomas Haller 431493827b build: fix building clients/cli/settings-docs.c (2)
Fixes: d7ad13591b
2017-03-23 23:23:47 +01:00
Thomas Haller 3468a54ec1 build: fix building clients/cli/settings-docs.c
Fixes: d7ad13591b
2017-03-23 20:57:28 +01:00
Thomas Haller 0fefcbfb2d build: don't link against libm.so
There are very few places where we actually use floating point
or #include <math.h>.

Drop that library, although we very likely still get it as indirect
dependency (e.g. on my system it is still dragged in by libsystemd.so,
libudev.so and libnl-3.so).
2017-03-23 19:06:02 +01:00
Thomas Haller d628ada05a build: remove currently unneeded include of shared/nm-setting-metadata.h from nmcli
One day, I wish we would have more setting metadata in shared via
"shared/nm-setting-metadata.h", ready for nmcli and nmtui to use
(by statically linking against the internal API).

Anyway, it is still unused, so drop the files from the SOURCES of
nmcli.
2017-03-23 18:58:47 +01:00
Thomas Haller d7ad13591b build: fix out-of-tree build for including "clients/cli/settings-docs.c"
"$(srcdir)/clients/cli/settings.c" includes "$(builddir)/clients/cli/settings-docs.c",
hence, we need "-I$(builddir)/clients/cli".

This basically reverts commit bbce089840,
but adds dependencies so that the build directory exists.
2017-03-23 18:50:34 +01:00
Lubomir Rintel bbce089840 cli/build: drop $builddir/cli/ from the include path
The sources should reach files in the $builddir using #include "".
Besides, it is not guarranteed to be around:

    CC       shared/clients_cli_nmcli-nm-setting-metadata.o
  cc1: error: ./clients/cli: No such file or directory [-Werror=missing-include-dirs]
  cc1: all warnings being treated as errors
  Makefile:12971: recipe for target 'shared/clients_cli_nmcli-nm-setting-metadata.o' failed
2017-03-23 17:41:04 +01:00
Lubomir Rintel 96571ec621 build: ensure libnm-core is around before mkenums puts files there
It's not sufficient to make nm-core-enum-types.[ch] depend on the
dirstamp, because they also depend on their own stamps that are to be
placed in libnm-core.

  $ make libnm-core/nm-core-enum-types.h.stamp
    GEN      libnm-core/nm-core-enum-types.h
  /bin/sh: libnm-core/nm-core-enum-types.h.tmp: No such file or directory
  ../../Makefile.glib:107: recipe for target 'libnm-core/nm-core-enum-types.h.stamp' failed
  make: *** [libnm-core/nm-core-enum-types.h.stamp] Error 1
2017-03-23 17:41:04 +01:00
Thomas Haller e32839838e udev: drop libgudev in favor of libudev
libgudev is just a wrapper around libudev. We can
use libudev directly and drop the dependency for
libgudev.
2017-03-22 12:41:06 +01:00