Commit Graph

790 Commits

Author SHA1 Message Date
Thomas Haller
4c094adfb7 libnm: streamline functions in nm-connection.c
Functions call each other, like

  nm_connection_get_id()
    nm_connection_get_setting_connection()
      nm_connection_get_setting()

Along the way, each function asserts that the input argument
is of type NMConnection via

    g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);

Avoid such duplicate assertions when we already verifyied the
input argument.

For example, in case of nm_connection_get_id(), don't check just call
nm_connection_get_setting_connection() right away. It already
asserts.

The downside is, that the assertion no longer fails in the function
that immediately called it. But these are assertions after all.
2017-06-07 09:07:18 +02:00
Thomas Haller
abdf9a3673 all: change handling of connection.type for bluetooth NAP and in general
Branch f9b1bc16e9 added bluetooth NAP
support. A NAP connection is of connection.type "bluetooth", but it
also has a "bridge" setting. Also, it is primarily handled by NMDeviceBridge
and NMBridgeDeviceFactory (with help from NMBluezManager).

However, don't let nm_connection_get_connection_type() and
nm_connnection_is_type() lie about what the connection.type is.
The type is "bluetooth" for most purposes -- at least, as far as
the client is concerned (and the public API of libnm). This restores
previous API behavior, where nm_connection_get_connection_type()
and nm_connection_is_type() would be simple accessors to the
"connection.type" property.

Only a few places care about the bridge aspect, and those places need special
treatment. For example NMDeviceBridge needs to be fully aware that it can
handle bluetooth NAP connection. That is nothing new: if you handle a
connection of any type, you must know which fields matter and what they
mean. It's not enough that nm_connection_get_connection_type() for bluetooth
NAP connectins is claiming to be a bridge.

Counter examples, where the original behavior is right:

src/nm-manager.c-        g_set_error (error,
src/nm-manager.c-                     NM_MANAGER_ERROR,
src/nm-manager.c-                     NM_MANAGER_ERROR_FAILED,
src/nm-manager.c-                     "NetworkManager plugin for '%s' unavailable",
src/nm-manager.c:                     nm_connection_get_connection_type (connection));

the correct message is: "no bluetooth plugin available", not "bridge".

src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:   if (   (   nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:           && !nm_connection_get_setting_pppoe (connection))
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME)
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:       || nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME))
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c-        return TRUE;

the correct behavior is for ifcfg-rh plugin to reject bluetooth NAP
connections, not proceed and store it.
2017-06-07 09:07:17 +02:00
Thomas Haller
88c2ccfb4c libnm: avoid assertion with invalid connections in _nm_connection_find_base_type_setting()
Functions should behave gracefully with connections that don't verify.
Especially, as _normalize_connection_type() calls
_nm_connection_find_base_type_setting() precisely with an unknown
connection.type.
2017-06-07 09:07:17 +02:00
Thomas Haller
1d6b717401 libnm: downgrade assertions in _nm_register_setting_impl() to nm_assert()
This is entirely internal API. We have unit tests that execute these
code paths. No need to have these assertions in production code.
2017-06-07 09:07:17 +02:00
Thomas Haller
837a8c1ca5 libnm: distinguish INVALID priority setting from NM_SETTING_PRIORITY_CONNECTION 2017-06-07 09:07:17 +02:00
Thomas Haller
488029d74b libnm: use enum for setting priorities 2017-06-07 09:07:17 +02:00
Thomas Haller
a973eacb3b libnm: add enum for setting priorities
Using plain numbers make it cumbersome to grep for
setting types by priority.

The only downside is, that with the enum values it
is no longer obvious which value has higher or lower
priority.

Also, introduce NM_SETTING_PRIORITY_INVALID. This is what
_nm_setting_type_get_base_type_priority() returns. For the moment
it still has the same numerical value 0 as before. Later, that
shall be distinct from NM_SETTING_PRIORITY_CONNECTION.
2017-06-07 09:07:17 +02:00
Thomas Haller
c7e9f97800 libnm/trivial: rename _nm_register_setting function to _nm_register_setting_impl
Avoid having the function _nm_register_setting() shadowed by a macro
of the same name, but different behavior/arguments.
2017-06-07 09:07:17 +02:00
Beniamino Galvani
7415ad778e libnm-core: fix typo in 802.1x doc comment 2017-06-06 09:28:59 +02:00
Beniamino Galvani
f25e008e2f libnm-core: remove unsupported bond options during normalization
In an ideal world, we should not validate connections containing
options not valid for the current bond mode. However adding such
restriction now means that during an upgrade to the new NM version
some connections that were valid before become invalid, possibly
disrupting connectivity.

Instead, consider invalid options as a normalizable error and remove
them during normalization.

Converting the setting to a "canonical" form without invalid options
is important for the connection matching logic, where such invalid
options can cause false mismatches.
2017-06-05 17:46:10 +02:00
Thomas Haller
ea6648cea1 all: replace uses of inet_aton() and friends
rpmdiff complains about uses of inet_aton, inet_makeaddr, inet_netof,
inet_ntoa under the IPv6 section:

   usr/sbin/NetworkManager on aarch64 i686 x86_64 ppc ppc64 ppc64le s390 s390x uses function inet_aton, which may impact IPv6 support

I think the warning is bogus, but refactor our code to avoid it.

Note that systemd code still uses them, so it don't avoid the rpmdiff
warning. But let's not diverge our systemd import from upstream for this.

- for NMSettingBond:validate_ip() also avoid g_strsplit_set() which
  allocates a full strv. Instead, we can do with one g_strdup().

- for test-resolvconf-capture.c, replace the functions with macros.
  Macros should be avoided usually, but for test asserts they are
  more convenient as they preserved the __FILE__:__LINE__ of where
  the assertion fails.
2017-06-02 14:07:10 +02:00
Lubomir Rintel
c0419257e7 all: reject duplicate keys in JSON
Teamd is not happy about them and would fail anyway. Worse even, if we
json_loads() such a JSON, which is precisely what happens when we inject the
"hwaddr" key, we turn bad JSON into a good one in a lossy matter. Not good.

https://bugzilla.redhat.com/show_bug.cgi?id=1455130
2017-06-01 13:30:21 +02:00
Thomas Haller
b0f9571d3d libnm: add _nm_connection_get_setting_bluetooth_for_nap()
If there is value in such a helper function (there is), then
it should go alongside the other nm_connection_get_setting*()
helpers. NMDevice is already large enough.
2017-06-01 11:28:57 +02:00
Lubomir Rintel
63292b5c41 core/connection: normalize bridge settings into bluetooth NAP connections
For the Bluetooth NAP we need a Bridge link for the BlueZ to assign the BNEP
links for PANU client connections into.

Let's disable STP by default -- it adds extra delay for the Bridge when the
BNEP link is assigned and is likely not useful for a typical client.
2017-05-31 20:17:16 +02:00
Lubomir Rintel
7c5a2be966 core/bluetooth: add NAP type 2017-05-31 20:15:52 +02:00
Lubomir Rintel
2c1a178f5b core: negotiate the best base setting
When the two base settings are present, use one of higher priority.

This will pick the "bridge" setting when both "bridge" and "bluetooth" are
present for a Bluetooth NAP connection.
2017-05-31 20:15:24 +02:00
Lubomir Rintel
7b5712acd2 core: allow two priorities of base settings
We'll need two "base" settings for Bluetooth NAP connections: bridge to set up
the actual link and bluetooth to identify the HCI to register the network
server with.

Let's use two priorities for base setting, with "1" marking one of higher
priority and "2" of lower priority when both are present.
2017-05-31 20:15:01 +02:00
Lubomir Rintel
02e527f644 core/connections: pick base setting from settings the connection actually has
We will need multiple base settings for Bluetooth NAP servers: bluetooth and
bridge. We want to identify the device as "bluetooth" to the user, but leave
the Bridge factory handle it.

The "connection.type" is somewhat redundant -- let's keep it for what the user
sees. And identify the actual base setting to pick the right factory by the
actually present setting.
2017-05-31 20:14:17 +02:00
Lubomir Rintel
c22672b383 libnm-core: fix verify() implementations to allow connection=NULL 2017-05-31 20:05:53 +02:00
Thomas Haller
159cd4836f libnm: fix rejecting NMSettingVlan with id >= 4095
Without it, clients can wrongly create VLan settings with
ID 4095, which triggers assertions in NetworkManager.

Fixes: 8715d61437
2017-05-30 18:12:57 +02:00
Yuri Chornoivan
0050e8bd34 all: fix typos in documentation, translated strings and comments
https://bugzilla.gnome.org/show_bug.cgi?id=783173
2017-05-28 17:33:37 +02:00
Thomas Haller
8921e5db71 libnm: skip meta enum value NM_WEP_KEY_TYPE_LAST from glib-mkenums 2017-05-23 13:37:10 +02:00
Thomas Haller
a2663803c3 shared: refactor nm_utils_is_power_of_two() to return false for 0
Returning TRUE for zero makes no sense. Obviously, zero is not a power
of two.

Also, the function is used to check whether a number has only one bit
(flag) set, so, an alternative name would be "has-one-bit-set", which
also should return FALSE for zero. All callers didn't really care for
the previous meaning "has-at-most-one-bit-set".

This also avoids the issue of checking (x >= 0), which causes
-Wtype-limits warnings for unsigned types. Which was avoided
by doing (x == 0 || x > 0), which caused -Wlogical-op warning,
which then was avoided (x == 0 || (x > 0 && 1)). Just don't.
2017-05-22 14:01:07 +02:00
Francesco Giudici
7c2ecaa4e0 build: work around GCC -Wlogical-op for "nm_utils_is_power_of_two" macros
We recently added -Wlogical-op in our build process
(commit #41e7fca59762dc928c9d67b555b1409c3477b2b0).
Seems that old versions of gcc (4.8.x) will hit that warning with our
implementation of our "nm_utils_is_power_of_two" and
"test_nm_utils_is_power_of_two_do" macros.
Fool it just adding an always TRUE check.
2017-05-22 12:05:51 +02:00
Thomas Haller
df6d27b33a shared: add nm_utils_str_utf8safe_*() API to sanitize UTF-8 strings
Use C-style backslash escaping to sanitize non-UTF-8 strings.
The functions are compatible with glib's g_strcompress() and
g_strescape().

The difference is only that g_strescape() escapes all non-printable,
non ASCII character as well, while nm_utils_str_utf8safe_escape()
-- depending on the flags -- preserves valid UTF-8 sequence except
backslash.

The flags allow to optionally escape ASCII control characters and
all non-ASCII (valid UTF-8) characters. But the option to preserve
valid UTF-8 (non-ASCII) characters verbatim, is what distinguishes
from g_strescape().
2017-05-19 09:46:08 +02:00
Lubomir Rintel
1194641afe dbus/secret-agent: add a flag indicating WPS PBC is active
The agents may used this to learn that WPS PBC enrollment is active and
suggest that user pushes a button on the router instead of supplying a
network key.
2017-05-15 12:59:55 +02:00
Lubomir Rintel
99c112a493 ifcfg-rh: save/restore WPS properties 2017-05-15 12:59:55 +02:00
Lubomir Rintel
e6f95b50c8 setting-wireless: add wps-method property
This property will be used to decide if it makes sense to attempt a WPS
enrollment on connection activation.
2017-05-15 12:59:55 +02:00
Lubomir Rintel
36b6bbdae3 dbus: add WPS methods to AP flags
Will be used to indicate WPS method discovered to be supported by the
access point.
2017-05-15 12:59:55 +02:00
Thomas Haller
22fd7d2e39 libnm/keyfile: properly read user data from keyfile
Hack keyfile reader support for NMSettingUser.
Writer support already works.
2017-05-06 14:12:19 +02:00
Thomas Haller
1dbbf6fb03 libnm: track invalid user data separately and reject during verify()
nm_setting_user_set_data() rejects invalid keys and values, and
can fail. This API is correct never to fail, like the get_data()
only returns valid user-data.

However, the g_object_set() API allows to set the hash directly but
it cannot report errors for invalid values. This API is used to
initialize the value from D-Bus or keyfile, hence it is wrong
to emit g_critial() assertions for untrusted data.
It would also be wrong to silently drop all invalid date, because
then the user cannot get an error message to understand what happend.

The correct but cumbersome solution is to remember the invalid values
separately, so that verify() can report the setting as invalid.
2017-05-06 14:12:18 +02:00
Thomas Haller
8ef57d0f7e keyfile: fix handling unsupported characters in keys
vpn.data, bond.options, and user.data encode their values directly as
keys in keyfile. However, keys for GKeyFile may not contain characters
like '='.

We need to escape such special characters, otherwise an assertion
is hit on the server:

  $ nmcli connection modify "$VPN_NAME" +vpn.data 'aa[=value'

Another example of encountering the assertion is when setting user-data key
with an invalid character "my.this=key=is=causes=a=crash".
2017-05-06 14:12:18 +02:00
Thomas Haller
095c6f5d53 keyfile: minor refactoring dropping temporary variable in mac_address_parser() 2017-05-06 13:33:28 +02:00
Thomas Haller
cb33e3f3c2 keyfile: fix memleak in read_hash_of_string()
Fixes: 10661abe17
2017-05-06 13:26:19 +02:00
Beniamino Galvani
a4cbfe6f0a all: fix typo 'entires' -> 'entries' 2017-05-05 19:14:19 +02:00
Thomas Haller
d67d12ebe1 libnm: fix comparison of pfm enum against zero
Fixes compiler warning

  comparison of unsigned enum expression < 0 is always false [-Werror,-Wtautological-compare]

Fixes: 6ef59b5b77
2017-04-28 19:28:03 +02:00
Thomas Haller
6ef59b5b77 libnm: make NMSettingWirelessSecurity's PMF property signed
The PMF property is an GEnum, not GFlags. We only have the GObject
property NM_SETTING_WIRELESS_SECURITY_PMF as plain integer type
to allow for future extensions.

But commonly, enums are signed int, while flags are unsigned. Change
the property to be signed for consistency.
2017-04-28 17:20:02 +02:00
Beniamino Galvani
53f3113389 ifcfg-rh: support the wifi.pmf property 2017-04-28 09:46:06 +02:00
Beniamino Galvani
60a3809815 libnm-core: add pmf property to wireless-security setting
Add a 'pmf' property to enable or disable Protected Management Frames
(802.11w) for the connection.
2017-04-28 09:46:05 +02:00
Beniamino Galvani
d19553392b libnm-core,shared: fix typo in '(allow-none)' annotation 2017-04-27 09:00:55 +02:00
Beniamino Galvani
f13fd4524c all: detect SR-IOV device support 2017-04-18 22:48:34 +02:00
Thomas Haller
d58d8d7518 test: fix undefined behavior shifting signed integer in test 2017-04-17 13:19:47 +02:00
Thomas Haller
31d0d0ef83 shared: add NM_PTRARRAY_LEN() utility macro
I used to use g_strv_length ((char **) p) instead, but that feels
ugly because it g_strv_length() is not designed to operate on
arbitrary pointer arrays.
2017-04-12 11:24:03 +02:00
Lubomir Rintel
b35e10f0ed test: set 8021x private key password flags
Fixes: df0dc912cc
2017-04-10 14:07:03 +02:00
Lubomir Rintel
df0dc912cc 8021x: don't request secrets if they are empty and system owned
Empty secrets are fine. In particular, for PKCS#11 it means that protected
authentication path is used (the secrets are obtained on-demand from the
pinpad).
2017-04-10 10:33:23 +02:00
Thomas Haller
9800b1dccc libnm: move public nm_utils_enum_*() functions back to libnm-core
Commit a8730c51c8 moved the enum
utils from libnm-core to shared/nm-utils.

However, three of those functions are part of public API in libnm.
So, when statically linking against "shared/nm-utils/nm-enum-utils.c"
and dynamically linking against libnm.so, those symbols are present
twice and cause a linker failure.

Fix that by moving the public API back to libnm-core.

Fixes: a8730c51c8
2017-04-05 18:38:31 +02:00
Thomas Haller
d1c6d64e6a shared: move _nm_utils_strv_cleanup() to shared utils 2017-04-05 16:53:06 +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