Commit Graph

528 Commits

Author SHA1 Message Date
Thomas Haller
ec92ecedae libnm: add NMUtilsStrStrDictKey utility
When having a hash-of-hashes where each hash is indexed by a name,
(such as GKeyFile), you can either implement it as a hash-of-hashes
or define your own version of indexes that pack both levels of names
into one key.

This is an implementation of such a key. Use it as:

  GHashTable *hash = g_hash_table_new_full (_nm_utils_strstrdictkey_hash,
                                            _nm_utils_strstrdictkey_equal,
                                            g_free, _destroy_value);

and create keys via:

  NMUtilsStrStrDictKey *k = _nm_utils_strstrdictkey_create (s1, s2);

For lookup you can use static strings (note that the static string
might increase the size of the binary):

  g_hash_table_contains (hash, _nm_utils_strstrdictkey_static ("outer", "inner"))
2015-07-29 22:34:34 +02:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Thomas Haller
a67c1ec4b5 libnm-core: fix return value in nm_utils_enum_to_str()
Fixes: 8be9814793
2015-07-24 15:48:29 +02:00
Beniamino Galvani
5622461c04 libnm-core: add Wake-on-LAN properties to NMSettingWired 2015-07-24 14:02:59 +02:00
Beniamino Galvani
8be9814793 libnm-core: add enum conversion utilities
Add functions nm_utils_enum_to_str() and nm_utils_enum_from_str()
which can be used to perform conversions between enum values and
strings, passing the GType automatically generated for every enum by
glib-mkenums.
2015-07-24 14:02:59 +02:00
Beniamino Galvani
3a7c641b02 libnm: backport symbols for metered connections support to 1.0.6
Backport to 1.0.6 the following symbols:
 - nm_device_get_metered
 - nm_metered_get_type
 - nm_setting_connection_get_metered
2015-07-22 14:06:31 +02:00
Thomas Haller
7f129b976c libnm-core: don't assert against non-NULL @ip argument to canonicalize_ip()
Remove an assertion in canonicalize_ip() to assert that either a
non-NULL @ip is given, or @null_any is TRUE.

The condition of the assert is not easy to understand without context.
Instead the caller should already handle %NULL properly.

All callers that pass @null_any=FALSE to canonicalize_ip(), already assert
that the argument is not %NULL. With the exception of nm_ip_route_new()
which however checks for a valid @dest early on.
2015-07-22 13:49:17 +02:00
Lubomir Rintel
f14fd048ff libnm-core: 0.0.0.0 is a valid gateway too
It makes sense for point-to point links.

https://bugzilla.redhat.com/show_bug.cgi?id=1244483
2015-07-22 13:49:17 +02:00
Thomas Haller
9342568694 libnm-core: fix nm-setting-ip-config.c:valid_ip() to handle %NULL argument
We call valid_ip() from nm_ip_route_new() to check whether an untrusted string
is a valid ip address. Properly handle %NULL argument.

Fixes: 21c8a6b20e
2015-07-22 13:49:17 +02:00
Thomas Haller
2b55de8560 libnm-core: properly handle %NULL @ip in nm_utils_ipaddr_valid()
A is_valid() function should just accept NULL as input and
return "invalid". It certainly should not crash.

Fixes: 21c8a6b20e
2015-07-22 13:49:17 +02:00
Dan Williams
4e47d36d73 libnm-core: fix GOI annotations after 019943bb
Fixes: 019943bb
2015-07-17 17:31:17 -05:00
Jiří Klimeš
2af10ef444 docs: fix a copy/paste error in description of VLAN flags 2015-07-17 09:20:29 +02:00
David Shea
568b4ad31f libnm: handle illegal characters in nm_utils_ssid_to_utf8() (rh #1243078)
g_convert_with_fallback() will fail if the SSID contains characters that
are not legal in the source encoding, which, if $LANG is not set, will
be ASCII. If this happens, replace all non-ASCII and non-printable
characters with '?'. It is possible that nm_utils_ssid_to_utf8() will
now return an empty string (e.g., the source string is actually
big-endian UTF-16 and g_strcanon() stops on the first byte), but it will
not return NULL.

https://bugzilla.redhat.com/show_bug.cgi?id=1243078
2015-07-16 14:22:03 +02:00
Thomas Haller
61eed191a9 libnm-core: don't assert in nm_connection_get_uuid() for valid connection
We want to call nm_connection_get_uuid() also on connections that don't verify.
Otherwise it is chumbersome to check first for verified connection.
2015-07-12 13:56:52 +02:00
Thomas Haller
904e961464 all: remove #if GLIB_CHECK_VERSION conditionals around g_type_init()
g_type_init() is now provided by nm-glib-compat.h as nm_g_type_init().
2015-07-12 13:56:52 +02:00
Thomas Haller
7a3ab5c02f test: initialize tests with nmtst_init() 2015-07-12 13:56:52 +02:00
Jiří Klimeš
640eb8f284 supplicant: allow with_system_ca_path to be a file name (rh #1236548)
NetworkManager uses wpa_supplicant, which in turn calls OpenSSL for verifying
certificates. wpa_supplicant calls
SSL_CTX_load_verify_locations(ctx, CAfile, CApath)
using its ca_cert and ca_path options as CAfile and CApath parameters.

We have a configure time option with_system_ca_path to override ca_path.
However, it doesn't work when a system (like Fedora) only uses bundled PEM
certificates instead of a directory with hashed certificates ([1], [2]).

So this commit allows setting --with_system_ca_path to a file name (the
trusted certificate bundle). Then the name is used to populate wpa_supplicant's
ca_cert instead of ca_path.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1053882
[2] https://www.happyassassin.net/2015/01/12/a-note-about-ssltls-trusted-certificate-stores-and-platforms/

https://bugzilla.redhat.com/show_bug.cgi?id=1236548
2015-07-08 17:07:02 +02:00
Thomas Haller
47551df352 libnm/keyfile: fix compile warning about uninitialized variable
Fixes: 71323122c6
2015-07-02 16:53:35 +02:00
Thomas Haller
ed632207cd libnm: add @deep_copy argument to _nm_utils_strv_to_slist() and _nm_utils_slist_to_strv() 2015-07-02 15:50:04 +02:00
Thomas Haller
93e4a8d102 libnm: expose strv utils function in internal header nm-core-internal.h 2015-07-02 15:50:04 +02:00
Thomas Haller
7fbfaf567d libnm: consider ordering for _nm_keyfile_equals()
GKeyFile considers the order of the files, so add a possibility
to check whether to keyfiles are equal -- also with respect to
the order of the elements.
2015-07-02 15:50:03 +02:00
Thomas Haller
e1b0195c67 libnm-keyfile/test: fix missing assertion in test 2015-07-02 15:50:03 +02:00
Thomas Haller
71323122c6 libnm: add keyfile utility functions 2015-07-02 15:50:03 +02:00
Thomas Haller
885d187d23 libnm: add _nm_utils_strv_cleanup() function 2015-07-02 15:50:03 +02:00
Thomas Haller
aa7a53bc67 libnm-keyfile: ensure g_key_file_get_groups() sets the length argument
Under certain cases, if g_key_file_get_groups() fails, it might not set the
out argument @length. Play it safe and initialize it.
2015-07-02 15:50:03 +02:00
Thomas Haller
650fec81e2 libnm: add _nm_utils_ptrarray_find_binary_search() helper 2015-07-01 16:02:09 +02:00
Beniamino Galvani
e86f8354a7 device: restart ping process when it exits with an error
When ping is launched to check the connectivity to the gateway it may
return earlier than the given timeout in case of error. When this
happens we need to respawn it until the timeout is reached.

While at it, increase maximum timeout value to 600 seconds.

https://bugzilla.redhat.com/show_bug.cgi?id=1128581
2015-07-01 13:42:41 +02:00
Thomas Haller
f5cc6da8cf libnm: backport autoconnect-slaves symbols to libnm_1_0_4
https://bugzilla.gnome.org/show_bug.cgi?id=751535
2015-06-26 16:28:33 +02:00
Jiří Klimeš
2dc27a99d7 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
2015-06-19 13:06:37 +02:00
Jiří Klimeš
2a497eeadc ifcfg-rh: read/write autoconnect-slaves property as AUTOCONNECT_SLAVES
AUTOCONNECT_SLAVES is an NetworkManager extension. initscripts always activate
slaves with the master connection for bond and team, and doesn't activate
automatically slaves for bridge.
NetworkManager behaviour is controlled by this variable. If the variable is
missing the default value from configuration file is used.
2015-06-19 09:32:58 +02:00
Jiří Klimeš
6caafab258 libnm: add autoconnect-slaves property to NMSettingConnection
The property is used for controlling whether slaves should be brought up with
a master connection. If 0, activating the master will not activate slaves.
But if set to 1, activating the master will bring up slaves as well.
The property can have the third state (-1), meaning that the value is default.
That is either a value set in the configuration file for the property, or 0.
2015-06-19 09:32:58 +02:00
Thomas Haller
2f4301bd26 glib-compat: add g_ptr_array_insert() 2015-06-17 11:41:43 +02:00
Thomas Haller
3377cd7e18 libnm: add _nm_utils_ptrarray_find_first() utility function 2015-06-17 11:41:43 +02:00
Thomas Haller
0a3c1f5774 utils: add nm_utils_is_power_of_two() macro 2015-06-17 11:41:43 +02:00
Thomas Haller
ef4e017cfa libnm/utils: add _nm_utils_strv_find_first() function 2015-06-11 19:58:51 +02:00
Jiří Klimeš
94a393e9ed all: fix a compiler warning 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
2015-06-10 10:01:49 +02:00
Beniamino Galvani
7e5e624daf ifcfg-rh: add support for CONNECTION_METERED 2015-06-09 18:18:45 +02:00
Beniamino Galvani
6f647fe689 libnm-core: add 'metered' property to NMSettingConnection
Add a 'metered' enum property to NMSettingConnection with possible
values: unknown,yes,no. The value indicates the presence of limitations
in the amount of traffic flowing through the connection.
2015-06-09 18:11:25 +02:00
Beniamino Galvani
bbbf522941 core,libnm: add 'metered' property to NMDevice 2015-06-09 18:11:25 +02:00
Thomas Haller
f3c61f8141 device: remove reading ipv6 privacy setting from sysctl
Since introduction for support of ip6-privacy (use_tempaddr,
RFC4941) with commit d376270bfe,
the sysctl value from /etc was always read first.

This is problematic, because an explicit setting in the
connection should not be ignored over a global configuration.

Drop that old behavior. It was also problematic, because we did
not read any files under /etc/sysctl.d (except for sysctl.conf).
Also, we did not honor per-interface configurations.

Now we also use as last fallback the value from
/proc/sys/net/ipv6/conf/default/use_tempaddr
That has the advantage of falling back to the system default value
so that NM doesn't need to have it's own default policy
(Related: https://bugzilla.redhat.com/show_bug.cgi?id=1187525).

This is a change in behavior.
2015-06-05 12:38:30 +02:00
Thomas Haller
e729dd70ae device: add global configuration default for ip6-privacy (use_tempaddr, RFC4941)
Support default value for setting 'ipv6.ip6-privacy' in
NetworkManager.conf.

If the global value is unset, preserve old behavior of looking into
/etc/sycctl.conf first. That behavior was introduced with commit
d376270bfe, since we support ip6-privacy
setting.

If the global value is set to "unknown", add a new fallback
that instead reads the runtime value from
  "/proc/sys/net/ipv6/conf/default/use_tempaddr"
This seems more sensible behavior because we fallback to sysctl,
but instead of looking at static files in /etc, read /proc.
But to preserve the old behavior, we only do that when a global
value is configured at all.

https://bugzilla.gnome.org/show_bug.cgi?id=721200
2015-06-05 12:38:30 +02:00
Thomas Haller
e4293788fc libnm/doc: document behavior of setting ip6-privacy in /etc/sysctl.conf
https://bugzilla.gnome.org/show_bug.cgi?id=721200
2015-06-05 12:38:30 +02:00
Thomas Haller
d5e948e482 libnm/test: test compare_property() to handle default values
Add a test case to check whether compare/diff works correctly.
2015-06-05 12:26:48 +02:00
Thomas Haller
a8dd1b5358 libnm: make dns-options support an "undefined" default value
We want to distinguish between "no-options/empty" and "unset/default".
The latter can be interpreted by NM to use a default set of options.
2015-06-05 12:26:48 +02:00
Thomas Haller
7478c4b54a libnm: fix compare_property() to handle default values
Before, get_property_for_dbus() would @ignore_defaults.
That is for example wrong for properties of type G_TYPE_STRV.

In this case, if one operand has the property at its default
(NULL) and the other has it to an empty string list, both would
compare equal.

This has the effect that different settings might compare equal.
2015-06-05 12:26:48 +02:00
Lubomir Rintel
ccb0ca4493 libnm-core,libnm-util: avoid calling a constructor
It yields completely unpredictable results on Ubuntu 12.04 (the global variable
successfully comparing to NULL despite demonstrably not NULL). Possibly a
toolchain bug.
2015-06-02 12:30:03 +02:00
Lubomir Rintel
eb2b8c2798 build: use compat version of g_clear_pointer()
Ubuntu 12.04 has an ancient version of glib, which we nevertheless support.
2015-06-02 12:30:03 +02:00
Thomas Haller
b8b1a01d96 build: rename file "include/nm-utils-internal.h" to "nm-macros-internal.h"
We already have "nm-utils*.h" and "NetworkManagerUtils.h" headers. Rename
"include/nm-utils-internal.h" to "nm-macros-internal.h". I think that
name is better, because this file is header-only, internal, and
repository-wide.

Also, it will never contain non-header-only declarations because
there is no backing object file under "include/".
It will only contain macros and inline functions.
2015-06-01 14:47:08 +02:00
Lubomir Rintel
c47c06470a builds: only enable TAP driver for glib >= 2.37.6
No TAP support for previous versions and --tap argument is silently ignored,
confusing the TAP driver.
2015-05-28 12:51:24 +02:00
Lubomir Rintel
6463ce5dd9 tests: use the TAP formatter
The test results in standard format are easily integrated into CI systems.
2015-05-26 13:51:45 +02:00