Commit Graph

173 Commits

Author SHA1 Message Date
Thomas Haller
9bf3933855 libnm-util: add non-failing versions of nm_connection_new_from_hash() and replace-settings
Add internal functions _nm_connection_replace_settings() and
_nm_connection_new_from_hash() that cannot fail.

Altough they are not public API, we have to expose them via
libnm-util.ver so that they can be used from libnm-glib.
2016-03-29 11:56:27 +02:00
Thomas Haller
6cd03bf205 libnm-util: refactor hash_to_connection()
No functional change, only move the verify-step out of hash_to_connection().
2016-03-29 11:56:27 +02:00
Thomas Haller
ce6fdc3e5e libnm-util: verify connection also for self-assignment in replace_settings_from_connection()
nm_connection_replace_settings_from_connection() would return whether the
connection verifies at the end of the operation. While that is not very
useful, the API is like that and cannot be changed.

For consistency, also perform the verification step in case of self-assignment.
Self-assigment is anyway a case that probably never happens.
2016-03-26 12:10:53 +01:00
Thomas Haller
ecd42cd915 libnm-util: reword code comment 2016-03-15 18:53:24 +01:00
Thomas Haller
35586da48e libnm-util: add comment for return value of nm_connection_replace_settings_from_connection()
nm_connection_replace_settings_from_connection() can safely be used
to copy an invalid connection. The return value only says, whether
the connection is valid after the fact.
2016-03-15 18:51:49 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller
8c27a370ff libnm-util: allow unknown setting types in nm_connection_get_virtual_iface_name()
Allow calling nm_connection_get_virtual_iface_name() on a non-verified
connection by not asserting asserting against a valid base-setting.

On nma-1-0 branch, nm-applet can crash with:

    #3  0x00007ffff2993a7a in g_assertion_message_expr (domain=0x7ffff51fad86 "libnm-util", file=0x7ffff51fb728 "nm-connection.c", line=320, func=0x7ffff51fc028 "_get_type_setting", expr=<optimized out>) at gtestutils.c:2444
    #4  0x00007ffff51ac52f in _get_type_setting (connection=0xa3c160 [NMRemoteConnection]) at nm-connection.c:320
    #5  0x00007ffff51ac341 in nm_connection_get_virtual_iface_name (connection=0xa3c160 [NMRemoteConnection]) at nm-connection.c:1436
    #6  0x0000000000415bdc in add_virtual_items (type=type@entry=0x43c11d "bridge", all_devices=all_devices@entry=0x7f6580, all_connections=all_connections@entry=0x9354a0, menu=menu@entry=0x922990 [GtkMenu], applet=applet@entry=0x6cc000 [NMApplet]) at applet.c:1640
    #7  0x00000000004176f6 in nma_menu_add_devices (menu=menu@entry=0x922990 [GtkMenu], applet=applet@entry=0x6cc000 [NMApplet]) at applet.c:1713
    #8  0x0000000000418315 in nma_menu_show_cb (menu=0x922990 [GtkMenu], applet=0x6cc000 [NMApplet]) at applet.c:1974

where the connection type is "tun".

Note that libnm accepts invalid connections and exposes them to the
user (albeit issuing a warning). Later on there are many places where
that can lead to further g_return*(), which is ugly indeed.
At least, we should not assert against valid connections (because that
crashes the user) and there is a well known fact that the base setting
will be missing for tun settings. No need to even warn about that in
nm_connection_get_virtual_iface_name() (we already got the warning
during replace_settings).
2015-12-18 14:50:00 +01:00
Dan Winship
22e1a97e12 all: drop includes to <glib/gi18n.h> for "nm-default.h"
The localization headers are now included via "nm-default.h".

Also fixes several places, where we wrongly included <glib/gi18n-lib.h>
instead of <glib/gi18n.h>. For example under "clients/" directory.
2015-08-05 15:35:51 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +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
027ab3efaa libnm-util: only unref and don't destroy hash in nm_connection_to_hash()
The returned hash from nm_connection_to_hash() used to destroy the
nested hashes, instead of only unrefing them.
2015-02-09 11:51:05 +01:00
Dan Winship
53f5e9afa4 libnm*: fix library gettext usage
Libraries need to include <gi18n-lib.h>, not <gi18n.h>, so that _()
will get defined to "dgettext (GETTEXT_DOMAIN, string)" rather than
"gettext (string)" (which will use the program's default domain, which
works fine for programs in the NetworkManager tree, but not for
external users). Likewise, we need to call bindtextdomain() so that
gettext can find the translations if the library is installed in a
different prefix from the program using it (and
bind_textdomain_codeset(), so it will know the translations are in
UTF-8 even if the locale isn't).

(The fact that no one noticed this was broken before is because the
libraries didn't really start returning useful translated strings much
until 0.9.10, and none of the out-of-tree clients have been updated to
actually show those strings to users yet.)
2014-11-13 17:18:42 -05:00
Dan Winship
3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Thomas Haller
0fe0e62d68 libnm-util: properly disconnect "notify" signal for settings in NMConnection
When removing/replacing a NMSetting in an NMConnection, we have
to disconnect setting_changed_cb() from the "notify" signal.

Backport commit dfba4ce1e1 from
libnm-core.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-22 15:26:34 +02:00
Thomas Haller
2fdaa29f08 libnm-util: fix leak in _nm_connection_verify()
Regression introduced by commit 2570c5a17c.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-07-15 21:57:34 +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
Thomas Haller
29d538239f libnm-util: normalize IP settings in connection
This is the same behaviour as nm_utils_normalize_connection(),
which will soon be removed in favor of nm_connection_normalize().

This takes care, that normal connections always have an IP4 and IP6 setting,
and that slave connections never have it.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-30 18:35:46 +02:00
Thomas Haller
2deaa5397a libnm-util: normalize virtual_iface_name in NMSettings
Some type-specific NMSetting implementations (bond, bridge, team, vlan)
have their own 'interface-name' property. This property will be
deprecated in favour of 'interface-name' in NMSettingConnection.

Change verify() and normalize() to check that the redundant
values match and repair/normalize the properties.

Force the virtual interface name of the type-specific setting to be
equal to NMSettingConnection:interface_name. This way, the depreacted
field stays valid and backward compatible.

NMSettingInfiniband is special, because it does not have a backing
property for the interface name, although it implements
get_virtual_iface_name(). To account for this, some special handling
is needed in order not to change the behaviour of get_virtual_iface_name().

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-30 18:35:46 +02:00
Thomas Haller
de5656a570 libnm-util: add function nm_connection_normalize
This function behaves like verify(), but it also performs some
normalization/fixing of inconsistent connections.

Contrary to verify(), this function might modify the settings.
This will be mainly used, to repair connections from older versions
and to fix deprecated options.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-30 18:35:46 +02:00
Thomas Haller
28169725d7 libnm-util: add function nm_connection_get_interface_name()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-30 18:35:16 +02:00
Dan Winship
aa1dce6da2 all: remove remaining GParamSpec name/blurb strings
Remove all remaining GParamSpec name and blurb strings (and fix
indentation while we're there), and add G_PARAM_STATIC_STRINGS to all
paramspecs that were lacking it.
2014-06-19 17:45:03 -04:00
Dan Winship
8487a4490c libnm-util, libnm-glib: be consistent about "Wi-Fi", "Ethernet", "InfiniBand" in docs
We made the UIs consistent last year, but missed the documentation.
Fix the docs to also consistently use "Wi-Fi" rather than "WiFi",
"Wifi", "wifi", or "WiFI"; "Ethernet" rather than "ethernet"; and
"InfiniBand" rather than "Infiniband".
2014-06-19 17:45:01 -04:00
Jiří Klimeš
28bd3cab28 core: add 'type' and 'id' property for NMActiveConnection (rh #1061822)
https://bugzilla.redhat.com/show_bug.cgi?id=1061822
2014-03-05 16:17:13 +01:00
Dan Winship
95be722e54 libnm-util, libnm-glib: add some missing "Since: 0.9.10" tags
Based on diffing libnm-util.ver and libnm-glib.ver with their 0.9.8
versions.
2014-02-13 11:24:37 -05:00
Dan Winship
f7b1b28202 libnm-util, libnm-glib: add device/connection describing functions
Add functions to describe and disambiguate devices and connections for
display to the user. Originally from libnm-gtk.
2014-01-27 15:39:51 -05:00
Thomas Haller
ff6315cbab libnm-util: only emit one CHANGED signal when adding several settings
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-15 17:01:53 +01:00
Thomas Haller
123bf9eea4 libnm-util: raise CHANGED signal in nm_connection_update_secrets only on change
This changes behaviour of nm_connection_update_secrets() in that it will
now return %TRUE, if there are no secrets to be cleared. Seems more
correct, to return success if there is nothing to do.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-15 17:01:53 +01:00
Thomas Haller
0f38213129 libnm-util: raise CHANGED signal in nm_connection_clear_secrets only on change
Often, nm_connection_clear_secrets does have no consequences, because
there is nothing to be cleared. Only raise a signal, if something
actually changed.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-15 17:01:53 +01:00
Thomas Haller
b7f6169dbd libnm-util: minor refactoring in nm_connection_compare()
Evaluate a cheaper comparison first, to fail early

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-17 17:18:14 -06:00
Dan Williams
5f15409684 libnm-util: add INFERRABLE flag and remove CANDIDATE
INFERRABLE means the opposite of CANDIDATE; a property which NetworkManager
can read ("infer") from the system or the kernel when generating
connections.  CANDIDATE isn't a great name and thus dies.
2013-12-05 16:07:24 -06:00
Thomas Haller
03943e2854 trivial: make nm_connection_dump more forgiving when passing NULL
nm_connection_dump is mainly used for printf debugging, so
no need about being overly critical about not accepting NULL.
Just don't dump anything.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-07 19:30:38 +01:00
Jiří Klimeš
8ec031fb0e core: again allow calling AddAndActivateConnection() without a connection
When settings are NULL or empty in impl_manager_add_and_activate_connection(),
the connection is created and completed by nm_utils_complete_generic() or
nm_device_complete_connection().

Also, do not assert in nm_connection_is_type(). Returning FALSE there is
sufficient.

Related commit a878cd8145
2013-11-01 14:07:04 +01:00
Jiří Klimeš
abe4f4daf5 libnm-util: do not assert valid connection type in nm_connection_is_type()
That is not useful, simply return FALSE.
2013-11-01 12:38:25 +01:00
Dan Williams
77e50740a8 libnm-util: add Data Center Bridging (DCB) setting
Includes various fixes & cleanups from Thomas Haller.
2013-10-31 13:28:42 -05:00
Yuri Chornoivan
61de24ba35 Fix typos
https://bugzilla.gnome.org/show_bug.cgi?id=710505
2013-10-19 11:49:18 -04:00
Pavel Šimerda
2a4a359eb1 libnm-util: add NM_SETTING_COMPARE_FLAG_CANDIDATE flag
Acked-by: Dan Winship <danw@gnome.org>
Acked-by: Thomas Haller <thaller@redhat.com>
2013-08-22 22:06:47 +02:00
Jiri Pirko
64cdb1a7f0 libnm-util: add setting for team port
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
2013-08-15 10:54:14 -05:00
Jiri Pirko
3dcb7935a5 libnm-util: add team device setting
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
2013-08-15 10:53:03 -05:00
Dan Williams
cd5d92705d settings: track whether connection is saved to disk or not
Use the new NMConnection 'changed' signal to mark connections
as dirty/unsaved, and reset that when they get flushed to disk.
Previously, the 'Updated' signal was emitted only when the
connection was changed and flushed to disk, but now we have
more granular needs, and the signal is emitted whenever the
connection actually *is* changed, regardless of whether its
flushed to disk or not.
2013-05-28 12:26:55 -05:00
Dan Williams
f6064e7b74 libnm-util: implement connection changed signal
Emitted whenever settings are added or removed from the connection,
and whenever any property of any setting in the connection is changed.
2013-05-28 12:26:55 -05:00
Dan Williams
1d8ab72a60 libnm-util: fix hashing of secrets broken by 4d326182
4d326182 changed connection hashing slightly such that now base type settings
are always returned even if they are empty. Unfortunately a bunch of code in
the settings hashed connections with the ONLY_SECRETS flag and then checked
whether the returned hash was NULL or not to determine whether there were
any secrets, and then called nm_connection_update_secrets() with the hash.

nm_connection_update_secrets() would fail in the case where a setting
name was given, but the passed-in secrets hash did not contain any secrets
for the requested setting.  Instead, the function should return success
to match the semantics of passing in an entire connection hash which may
not have any secrets either.
2013-05-20 13:56:48 -05:00
Dan Winship
8b823d7c6a libnm-util: add NMSettingGeneric
Add NMSettingGeneric, a dummy L2 NMSetting for creating NMConnections
for devices that are not specifically recognized.
2013-05-07 12:46:56 -04:00
Dan Winship
6cb786f569 libnm-util: move setting priority functions to nm-setting.c
None of these take an NMConnection; they logically belong in
NMSetting.
2013-05-03 08:39:06 -04:00
Jiří Klimeš
841c259119 libnm-util: make nm_connection_replace_settings_from_connection() safer
When 'connection' and 'new_connection' arguments are the same object make the
function no-op and simply return true. Otherwise 'connection's settings are
removed, making it invalid.

Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
2013-04-22 10:15:53 -05:00
Martin Pitt
57a9fb3c89 Use %NULL macro in doc strings
Mass-converted "NULL" to "%NULL" in docstrings with

  find -name '*.c'| xargs sed -i '/^ \*.*[^%]NULL/ s/NULL\b/%NULL/g'
2013-04-19 10:08:17 -04:00
Martin Pitt
6226fb9b59 libnm-util: Fix transfer annotations of nm_{connection,setting}_need_secrets()
The various need_secrets() implementation do allocate a fresh GPtrArray, but
add static strings to them without dup'ing. Thus callers must _not_ free the
array elements, only the array itself. Adjust documentation and annotations
accordingly.

Also adjust the corresponding comment in the goi-list-connections.py example.

https://bugzilla.gnome.org/show_bug.cgi?id=698175
2013-04-19 09:43:56 -04:00
Dan Williams
bafd0d557d libnm-util: add nm_connection_replace_settings_from_connection() (bgo #696387)
Convenience function to replace settings in one conneciton with settings
from another, without having to go through the nm_connection_to_hash()
steps, which are just inefficient and kinda pointless.
2013-04-17 12:23:34 -05:00
Dan Winship
5fec30d98e Revert :carrier-detect properties and associated code
Ignoring carrier is generally something you want at the machine level
(eg, for a server), not at the connection level.
2013-04-03 10:23:49 -04:00
Dan Williams
a492d29ceb libnm-util: convert remaining NMConnection users to GHashTableIter 2013-04-01 17:18:54 -05:00