Commit graph

229 commits

Author SHA1 Message Date
Thomas Haller 54ed36e3c0 nmtst: fix compiler warnings and make initialization of macro variables explict
clang warns about uninitialized variables @__cur_setting_name and
@__cur_property_name as used inside @__code. Before calling to @__code,
explicitly initialize the values.

    Making all in tests
    make[4]: Entering directory `./NetworkManager/libnm-core/tests'
      CC       test-general.o
    test-general.c:2730:24: error: variable '__cur_property_name' is uninitialized when used here [-Werror,-Wuninitialized]
                                  NMTST_VARIANT_DROP_PROPERTY (NM_SETTING_CONNECTION_SETTING_NAME,
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../include/nm-test-utils.h:1079:20: note: expanded from macro 'NMTST_VARIANT_DROP_PROPERTY'
                                && !strcmp (__cur_property_name, __property_name)) \
                                            ^~~~~~~~~~~~~~~~~~~
    ../../include/nm-test-utils.h:1023:3: note: expanded from macro 'NMTST_VARIANT_EDITOR'
                    __code; \
                    ^
    test-general.c:2729:2: note: variable '__cur_property_name' is declared here
            NMTST_VARIANT_EDITOR (connection_dict,
            ^
    ../../include/nm-test-utils.h:1015:3: note: expanded from macro 'NMTST_VARIANT_EDITOR'
                    const char *__cur_setting_name, *__cur_property_name; \
                    ^
    [...]

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-22 16:34:18 +02:00
Thomas Haller 1aeb0c6df3 nmtst: move #endif to hide NMTST_VARIANT_* macros if not needed
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-22 16:32:01 +02:00
Dan Winship 58f278fbfb nmtst: add NMTST_VARIANT_EDITOR()
Several test programs create connection hashes and then modify them in
various ways. This becomes much more complicated with GVariants, since
they are immutable. Add NMTST_VARIANT_EDITOR() to simplify the process
of iterating the old variant and building a new, slightly-modified one.
2014-09-18 11:51:09 -04:00
Dan Winship 504c292d73 libnm-core: clean up nm_connection_replace_settings()'s semantics
On failure, nm_connection_replace_settings() would leave the
connection in an undefined state. Fix it so that either (a) the
settings are replaced and the resulting connection is valid and we
return TRUE, or (b) the connection is untouched and we return FALSE
and an error. (And add a test case for this.)
2014-09-04 09:17:37 -04:00
Dan Williams 448254f761 ibft: add settings plugin for reading iBFT configuration (bgo #734009)
Instead of handling iBFT (iSCSI Boot Firmware Table) in the ifcfg-rh plugin,
create a new plugin for it.  This allows all distributions to use iBFT
configuration, and makes both iBFT handling and ifcfg-rh less complicated.

The plugin (like the old ifcfg-rh code) creates read-only connections backed
by the data exported by iscsiadm.  The plugin does not support adding new
connections or modifying existing connections (since the iBFT data is
read-only anyway).  Instead, users should change their iBFT data through
the normal firmware interfaces.

Unmanaged devices can be configured through NetworkManager.conf and the
normal 'keyfile' mechanisms.

(In the future, we'll read this data directly from the kernel's
/sys/firmware/ibft/ethernetX directory instead of iscsiadm, since the
kernel has all the information we need and that's where iscsiadm gets
it from anyway.)

https://bugzilla.gnome.org/show_bug.cgi?id=734009
2014-08-29 18:46:11 -05:00
Thomas Haller fb7b08388e glib-compat: fix compatibility wrapper for g_type_ensure()
The previous implementaiton of the compatibility wrapper failed
with clang when used inside a macro. This seems like a compiler
error not to ignore the deprecation. Workaround by refactoring
the g_type_ensure() wrapper.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-25 22:05:23 +02:00
Thomas Haller 9ea3653f1f core: add compatibility wrapper for g_test_add_data_func_full() to nm-glib-compat.h
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-22 15:24:31 +02:00
Thomas Haller 043ab29ca9 nmtst: add assertion functions for verify() connection
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-22 15:24:30 +02:00
Thomas Haller 80e1b05c31 nmtst: add nmtst_assert_connection_equals() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-22 15:24:30 +02:00
Thomas Haller 0da0293f7e nmtst: add nmtst_connection_normalize() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-22 15:24:30 +02:00
Dan Winship e1ba13a426 libnm-core, libnm, core: make NMConnection an interface
The fact that NMRemoteConnection has to be an NMConnection and
therefore can't be an NMObject means that it needs to reimplement bits
of NMObject functionality (and likewise NMObject needs some special
magic to deal with it). Likewise, we will need a daemon-side
equivalent of NMObject as part of the gdbus port, and we would want
NMSettingsConnection to be able to inherit from this as well.

Solve this problem by making NMConnection into an interface, and
having NMRemoteConnection and NMSettingsConnection implement it. (We
use some hacks to keep the GHashTable of NMSettings objects inside
nm-connection.c rather than having to be implemented by the
implementations.)

Since NMConnection is no longer an instantiable type, this adds
NMSimpleConnection to replace the various non-D-Bus-based uses of
NMConnection throughout the code. nm_connection_new() becomes
nm_simple_connection_new(), nm_connection_new_from_hash() becomes
nm_simple_connection_new_from_hash(), and nm_connection_duplicate()
becomes nm_simple_connection_new_clone().
2014-08-16 10:17:53 -04:00
Dan Winship 32c26a859b libnm-core: move some fake NMConnection methods over to NMSetting
nm_connection_lookup_setting_type() and
nm_connection_lookup_setting_type_by_quark() have nothing to do with
NMConnection. So move them to NMSetting (and rename them to
nm_setting_lookup_type() and nm_setting_lookup_type_by_quark()).
2014-08-16 10:17:53 -04:00
Dan Winship c81fb49aa5 all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).

Fix this by changing the include guards in the non-API-stable parts of
the tree:

  - libnm-glib/nm-ip4-config.h remains   NM_IP4_CONFIG_H
  - libnm/nm-ip4-config.h now uses     __NM_IP4_CONFIG_H__
  - src/nm-ip4-config.h now uses       __NETWORKMANAGER_IP4_CONFIG_H__

And likewise for all other headers.

The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-16 10:17:14 -04:00
Thomas Haller df2711f197 nmtst: fix memory leak in nmtst_create_minimal_connection()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-07 22:26:28 +02:00
Thomas Haller d83f3777ad nmtst: add nmtst_create_minimal_connection() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-07 15:43:43 -04:00
Dan Winship dc1b76432b include: drop nm-settings-flags.h, move NMSecretAgentGetSecretsFlags
For some reason, the flags used by o.fd.NM.SecretAgent.GetSecrets were
defined as both NMSecretAgentGetSecretsFlags in
libnm{,-glib}/nm-secret-agent.h, and then separately as
NMSettingsGetSecretsFlags in include/nm-settings-flags.h.
(NMSettingsGetSecretsFlags also had an additional internal-use-only
value, but that was added later after the duplication already
existed.)

Fix this by moving NMSecretAgentGetSecretsFlags from libnm to
nm-dbus-interface.h, adding the internal-use-only value to it as well,
updating the core code to use that, and then removing
nm-settings-flags.h.
2014-08-01 14:34:39 -04:00
Thomas Haller 65c43a680e utils: add _NM_UTILS_MACRO_FIRST and _NM_UTILS_MACRO_REST macros
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-01 19:06:24 +02:00
Thomas Haller 9f832d99be core: add project-wide header file nm-utils-internal.h
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-01 19:06:24 +02:00
Thomas Haller b461bf54f2 all: add compatibility macros to ignore deprecation warnings for clang
For clang, the defines G_GNUC_BEGIN_IGNORE_DEPRECATIONS and
G_GNUC_END_IGNORE_DEPRECATIONS are not working. Redefine them
for clang in our glib compatibility wrapper.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-01 13:16:59 +02:00
Dan Williams fa809c2636 build: clean nm-version.h
Now that nm-version.h.in lives in libnm-util/, a stale nm-version.h
from include/ messes up the build with errors about NM_VERSION_*.
Clean both old & new nm-version.h on 'make clean' so that we can
switch branches between nm-0-9-8, nm-0-9-10, and git master and
just run 'make clean' and get things to work.
2014-07-31 21:31:20 -05:00
Thomas Haller 2856fcb3de libgsystem: add local copy of gsystem-local-alloc.h
Taken from libgsystem:src/gsystem-local-alloc.c
(commit de2619271ee3ab42971fc770cae110f23e330c30).

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-07-15 22:50:32 +02:00
Dan Winship 2570c5a17c libnm-util, libnm-glib: whitespace fixes
Fix indentation, kill trailing whitespace, split some long lines.
2014-07-15 09:44:55 -04:00
Dan Winship cb7e1893e7 libnm-util, libnm-glib: standardize copyright/license headers
- Remove list of authors from files that had them; these serve no
  purpose except to quickly get out of date (and were only used in
  libnm-util and not libnm-glib anyway).

- Just say "Copyright", not "(C) Copyright" or "Copyright (C)"

- Put copyright statement after the license, not before

- Remove "NetworkManager - Network link manager" from the few files
  that contained it, and "libnm_glib -- Access network status &
  information from glib applications" from the many files that
  contained it.

- Remove vim modeline from nm-device-olpc-mesh.[ch], add emacs modeline
  to files that were missing it.
2014-07-15 09:44:54 -04:00
Dan Winship 7eb0288aa0 libnm-util: move NetworkManager.h, etc, from include/ to here
NetworkManager.h, NetworkManagerVPN.h, and nm-version.h are part of
the libnm-util API, so move them to libnm-util.

include/ still contains headers that are strictly NM-internal (eg,
nm-glib-compat.h).
2014-07-15 09:44:54 -04:00
Thomas Haller 362c4fe188 nmtst: ensure call to nm_utils_get_monotonic_timestamp_s() in nmtst_init()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-07-10 13:27:12 +02:00
Thomas Haller 87c48023f1 libnm-util, libnm-glib: add NM_VERSION_1_0, NM_DEPRECATED_IN_1_0, and NM_DEPRECATED_IN_1_0 macros
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-27 20:39:05 +02:00
Thomas Haller 48b5ba7cea nmtst: add NMTST_DEBUG=no-expect-message for debugging assert_message tests
Some tests want to assert against the messages logged using g_test_expect_message().
In this mode, nmtst will not log anything itself.

Interpret the option no-expect-message which turns g_test_expect_message()
into a NOP and turns logging on. The use of this is for debugging such
tests, without asserting against the messages but printing them instead.

For tests that are not in the assert_message mode, the option has no
effect.

Example:
  NMTST_DEBUG=debug,no-expect-message make -C src/settings/plugins/keyfile/tests/ check

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:58 +02:00
Thomas Haller 9114794f65 nmtst: turn on g_debug() messages in nmtst_init() when debug logging is enabled
In tests nm-logging will directly write using g_log. Also, non-core components
use g_log() for logging. glib will not print messages with level
G_LOG_LEVEL_INFO or G_LOG_LEVEL_DEBUG unless G_MESSAGES_DEBUG is set.

When the user specifies NMTST_DEBUG turning on 'debug' or
'log-level=DEBUG' it can be reasonably assumed that he wants to see
debug messages. nmtst_init() now sets G_MESSAGES_DEBUG=all.

The user can disable this behaviour, by setting instead G_MESSAGES_DEBUG='',
because nmtst_init() will not reset an existing G_MESSAGES_DEBUG.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:58 +02:00
Thomas Haller 8ce1eb3837 nmtst: add new mode where tests assert against logged messages (assert_messages)
In this mode, nmtst itself will not log anything and not set the logging
level. Also, it will set g_log_set_always_fatal().

This is for tests that want to assert against all logged messages via
g_test_expect_message().

In this mode also setting the logging level via NMTST_DEBUG variable has
no effect. The test is expected to manage the logging level itself and
changing the logging level might interfere with the test.

As a showcase, move keyfile/tests/test-keyfile.c to nmtst.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:58 +02:00
Thomas Haller ed868a388b core: add compatibility wrapper for g_test_skip() to nm-glib-compat.h
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Thomas Haller 284ef00d16 nmtst: call nm_utils_init() in nmtst_init()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Thomas Haller 5d3bef5d3f nmtst: add nmtst_spawn_sync()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Thomas Haller 7a7dd9203d nmtst: add nmtst_reexec_sudo() function
Interpret environment variable NMTST_DEBUG which allows
to specify 'sudo-cmd=CMD'. If the test program calls
nmtst_reexec_sudo(), it will `exec CMD "$0" "$@"`.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Thomas Haller 9df3a23d26 nmtst: add nmtst_free()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Thomas Haller 8af001eae4 nmtst: combine files nm-test-helpers.h and nm-test-utils.h
Move the content of nm-test-helpers.h to nm-test-utils.h
which completly replaces the older file.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:56 +02:00
Thomas Haller 0e9cd4f6fc nmtst: add functions nmtst_platform_ip[46]_routes_equal
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:56 +02:00
Thomas Haller be56b26c7d nmtst: add functions nmtst_static_SIZE_NUM() to create a copy of a string returned from an internal buffer
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:56 +02:00
Thomas Haller 5a58afcec9 nmtst: add nmtst_is_debug() and interpret environment NMTST_DEBUG
Also enable "DEBUG" logging conditionally depending on is_debug().

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:56 +02:00
Thomas Haller 64d09e5afe nmtst: add nmtst_initialized()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:56 +02:00
Thomas Haller 86693d2378 nmtst: add parameter to nmtst_init to setup nm-logging
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:56 +02:00
Thomas Haller 17c300b816 nmtst: include missing header file glib-object.h
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:56 +02:00
Thomas Haller d29cd00d2b nmtst: return const address from nmtst_inet6_from_string()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:56 +02:00
Thomas Haller 237ee05887 nmtst: make all test functions "inline static"
'inline' is needed to avoid compiler warnings about unused
functions.
Marking them only as 'inline' was simply wrong and leads to
linker errors when including the header in different translation
units.

By making them "inline static" we also don't need to foward declare the
function prototype to avoid another compiler warning.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:56 +02:00
Thomas Haller a268b825d7 nmtst: move header file to include/ directory
https://bugzilla.gnome.org/show_bug.cgi?id=706293

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:56 +02:00
Dan Williams d043094195 wwan: disable autoconnect if the given SIM PIN was wrong
If the given PIN was wrong, we really don't want to try that PIN
again automatically because it might lock the SIM.  To ensure that
doesn't happen, disable autoconnect so that the user must manually
request reconnection.

(this doesn't fix auto-connect-with-a-wrong-PIN completely, as
autoconnect is reset when resuming from sleep, but it's a start)
2014-05-06 21:51:24 -05:00
Dan Williams 6080425088 wwan: use modem states instead of enabled/connected properties
Determining when the NMDeviceModem is available and when different
connections are available is easier if the modem's state is tracked,
instead of using the separate Enabled and Connected properties.
These properties could not accurately represent the SIM lock state
and prevented NetworkManager from making the modem available for
auto-activation when locked, even if a PIN was available.

In this new scheme, the NMDeviceModem is UNAVAILABLE when the
ModemManager modem state is FAILED, UNKNOWN, or INITIALIZING.  It
transitions to the NM DISCONNECTED state when the modem has finished
initializing and has not failed.

Once the NMDeviceModem is in DISCONNECTED state it can be activated
even if the SIM is locked and a PIN is required; the PIN will be
requested when starting activation, either from the connection itself
or via a secrets request.  This makes auto-activation of WWAN
connections possible.

This also allows us to consolidate code dealing with modem enable/disable
into the base NMModem class using the modem state, and to log more modem
information for debugging purposes.
2014-05-06 21:48:55 -05:00
Dan Winship 42df06e575 platform, devices: add support for vxlan devices
Since vxlan is new-ish, and vxlan IPv6 support in particular has only
been in the kernel since 3.11, we include our own copy of the vxlan
netlink constants rather than depending on the installed headers.
2014-03-06 09:48:15 -05:00
Thomas Haller d3a2219cee replace snprintf by g_snprintf
Use the glib wrapper for snprintf.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-24 21:35:33 +01:00
Dan Winship 64c5395cb1 build: improve our use of glib's version macros to catch more bugs
We were setting GLIB_VERSION_MAX_ALLOWED to 2.34, since we provide
reimplementations of a few 2.34 functions in nm-glib-compat.h. But
this was turning off warnings for the 2.34+ APIs we *didn't* have
compat versions of too.

Fix this by setting MAX_ALLOWED to 2.32 (same as MIN_REQUIRED), and
defining macros to wrap calls to compat-ified functions and disable
deprecation warnings around them.

This points out several places where we were accidentally using 2.34
APIs without noticing, which need to be fixed now.
2014-02-13 11:24:37 -05:00
Dan Winship 9c4d86ee80 libnm-util, libnm-glib: add versioned deprecation/availability macros
Add versioned NM_DEPRECATED_IN_* and NM_AVAILABLE_IN_* macros, and tag
new/deprecated functions accordingly. (All currently-deprecated
functions are assumed to have been deprecated in 0.9.10.)

Add NM_VERSION_MIN_REQUIRED and NM_VERSION_MAX_ALLOWED macros which
can be set to determine which versions will cause warnings.

With the current settings, external consumers of the
libnm-util/libnm-glib APIs will have MIN_REQUIRED and MAX_ALLOWED both
set to NM_VERSION_0_9_8 by default, meaning they will get warnings
about functions added in 0.9.10. NM internally sets
NM_VERSION_MAX_ALLOWED to NM_VERSION_NEXT_STABLE to ensure that it is
always allowed to use all APIs.
2014-02-13 11:24:37 -05:00