Commit Graph

30 Commits

Author SHA1 Message Date
Thomas Haller
f617d5e8b4 libnm: change nm_wireguard_peer_set_endpoint() API to allow validation
This is an API break since 1.16-rc1.

Similar to previous commit.

(cherry picked from commit 8ae9aa2428)
2019-03-07 22:22:39 +01:00
Thomas Haller
6452d2d0e5 libnm: change nm_wireguard_peer_set_public_key() API to allow validation
This is an API break since 1.16-rc1.

Similar to previous commit.

(cherry picked from commit 7962653918)
2019-03-07 22:22:39 +01:00
Thomas Haller
7682826229 libnm: change nm_wireguard_peer_set_preshared_key() API to allow validation
This is an API break since 1.16-rc1.

The functions like _nm_utils_wireguard_decode_key() are internal API
and not accessible to a libnm user. Maybe this should be public API,
but for now it is not.

That makes it cumbersome for a client to validate the setting. The client
could only reimplement the validation (bad) or go ahead and set invalid
value.

When setting an invalid value, the user can afterwards detect it via
nm_wireguard_peer_is_valid(), but at that point, it's not clear which
exact property is invalid.

First I wanted to keep the API conservative and not promissing too much.
For example, not promising to do any validation when setting the key.
However, libnm indeed validates the key at the time of setting it
instead of doing lazy validation later. This makes sense, so we can
keep this promise and just expose the validation result to the caller.

Another downside of this is that the API just got more complicated.
But it not provides a validation API, that we previously did not have.

(cherry picked from commit d7bc1750c1)
2019-03-07 22:22:39 +01:00
Thomas Haller
395a78618b libnm/tests: add tests for creating wireguard connection profiles 2019-02-22 11:00:11 +01:00
Thomas Haller
a3370af3a8 all: drop unnecessary includes of <errno.h> and <string.h>
"nm-macros-interal.h" already includes <errno.h> and <string.h>.
No need to include it everywhere else too.
2019-02-12 08:50:28 +01:00
Thomas Haller
4d1b8edb73 libnm/tests: compare D-Bus and keyfile serialization in roundtrip-conversion test 2019-01-08 16:16:18 +01:00
Thomas Haller
75e4284781 keyfile: rework handling of GObject properties from keyfile
- previously, writer would use nm_keyfile_plugin_kf_set_integer() for
  G_TYPE_UINT types.
  That means, values larger than G_MAXINT would be stored as negative
  values. On the other hand, the reader would always reject negative
  values.
  Fix that, by parsing the integer ourself.
  Note that we still reject the old (negative) values and there is no
  compatibility for accepting such values. They were not accepted by
  reader in the past and so they are still rejected.
  This affects for example ethernet.mtu setting (arguably, the MTU
  is usually set to small values where the issue was not apparent).
  This is also covered by a test.

- no longer use nm_keyfile_plugin_kf_set_integer().
  nm_keyfile_plugin_kf_set_integer() calls g_key_file_get_integer(), which
  uses g_key_file_parse_integer_as_value(). That one has the odd
  behavior of accepting "<number><whitespace><bogus>" as valid. Note how that
  differs from g_key_file_parse_value_as_double() which rejects trailing data.
  Implement the parsing ourself. There are some changes here:

  - g_key_file_parse_value_as_integer() uses strtol() with base 10.
    We no longer require a certain the base, so '0x' hex values are allowed
    now as well.

  - bogus suffixes are now rejected but were accepted by g_key_file_parse_value_as_integer().
    We however still accept leading and trailing whitespace, as before.

- use nm_g_object_set_property*(). g_object_set() asserts that the value
  is in range. We cannot pass invalid values without checking that they
  are valid.

- emit warnings when values cannot be parsed. Previously they would
  have been silently ignored or fail an assertion during g_object_set().

- don't use "helpers" like nm_keyfile_plugin_kf_set_uint64(). These
  merely call GKeyFile's setters (taking care of aliases). The setters
  of GKeyFile don't do anything miraculously, they merely call
  g_key_file_set_value() with the string that one would expect.
  Convert the numbers/boolean ourselfs. For one, we don't require
  a heap allocation to convert a number to string. Also, there is
  no point in leaving this GKeyFile API, because even if GKeyFile
  day would change, we still must continue to support the present
  format, as that is what users have on disk. So, even if a new
  way would be implemented by GKeyFile, the current way must forever
  be accepted too. Hence, we don't need this abstraction.
2019-01-07 10:41:00 +01:00
Thomas Haller
6d9bea09a7 libnm/tests: add tests for converting profiles to keyfile and back 2019-01-07 10:09:10 +01:00
Thomas Haller
140a5e3316 all: make use of NM_MAKE_STRV() macro 2018-12-01 15:16:48 +01:00
Thomas Haller
837d44ffa4 keyfile: split automatically setting ID/UUID for keyfile
keyfile already supports omitting the "connection.id" and
"connection.uuid". In that case, the ID would be taken from the
keyfile's name, and the UUID was generated by md5 hashing the
full filename.

No longer do this during nm_keyfile_read(), instead let all
callers call nm_keyfile_read_ensure_*() to their liking. This is done
for two reasons:

 - a minor reason is, that one day we want to expose keyfile API
   as public API. That means, we also want to read keyfiles from
   stdin, where there is no filename available. The implementation
   which parses stdio needs to define their own way of auto-generating
   ID and UUID. Note how nm_keyfile_read()'s API no longer takes a
   filename as argument, which would be awkward for the stdin case.

 - Currently, we only support one keyfile directory, which (configurably)
   is "/etc/NetworkManager/system-connections".
   In the future, we want to support multiple keyfile dirctories, like
   "/var/run/NetworkManager/profiles" or "/usr/lib/NetworkManager/profiles".
   Here we want that a file "foo" (which does not specify a UUID) gets the
   same UUID regardless of the directory it is in. That seems better, because
   then the UUID won't change as you move the file between directories.
   Yes, that means, that the same UUID will be provided by multiple
   files, but NetworkManager must already cope with that situation anyway.
   Unfortunately, the UUID generation scheme hashes the full path. That
   means, we must hash the path name of the file "foo" inside the
   original "system-connections" directory.
   Refactor the code so that it accounds for a difference between the
   filename of the keyfile, and the profile_dir used for generating
   the UUID.
2018-10-04 11:03:23 +02:00
Thomas Haller
068d316822 libnm/802-1x: refactor setting certificate from path
NMSetting8021x has various utility functions to set
the certificate:
  - nm_setting_802_1x_set_ca_cert()
  - nm_setting_802_1x_set_client_cert()
  - nm_setting_802_1x_set_private_key()
  - nm_setting_802_1x_set_phase2_ca_cert()
  - nm_setting_802_1x_set_phase2_client_cert()
  - nm_setting_802_1x_set_phase2_private_key()

They support:

 - accepting a plain PKCS11 URI, with scheme set to
   NM_SETTING_802_1X_CK_SCHEME_PKCS11.
 - accepting a filename, with scheme set to
   NM_SETTING_802_1X_CK_SCHEME_BLOB or
   NM_SETTING_802_1X_CK_SCHEME_PATH.

In the latter case, the function tries to load the file and verify it.
In case of the private-key setters, this also involves accepting a
password. Depending on whether the scheme is BLOB or PATH, the function
will either set the certificate to a PATH blob, or take the blob that
was read from file.

The functions seem misdesigned to me, because their behavior is
rather obscure. E.g. they behave fundamentally different, depending
on whether scheme is PKCS11 or BLOB/PATH.

Anyway, improve them:

- refactor the common code into a function _cert_impl_set(). Previously,
  their non-trivial implementations were copy+pasted several times,
  now they all use the same implementation.
- if the function is going to fail, don't touch the setting. Previously,
  the functions would first clear the certificate before trying to
  validate the input. It's more logical, that if a functions is going
  to fail to check for failure first and don't modify the settings.
- not every blob can be represented. For example, if we have a blob
  which starts with "file://", then there is no way to set it, simply
  because we don't support a prefix for blobs (like "data:;base64,").
  This means, if we try to set the certificate to a particular binary,
  we must check that the binary is interpreted with the expected scheme.
  Add this check.
2018-09-04 07:38:30 +02:00
Thomas Haller
dd4a6f307c tests: minor code cleanup in tests
Use nmtst_assert_success(), nm_auto() macros, and minor
cleanups.
2018-08-30 11:17:09 +02:00
Thomas Haller
dba19ebd7d all: avoid useless cast of g_free() to GDestroyNotify 2018-08-22 10:49:34 +02:00
Thomas Haller
df30651b89 libnm, cli, ifcfg-rh: add NMSettingEthtool setting
Note that in NetworkManager API (D-Bus, libnm, and nmcli),
the features are called "feature-xyz". The "feature-" prefix
is used, because NMSettingEthtool possibly will gain support
for options that are not only -K|--offload|--features, for
example -C|--coalesce.

The "xzy" suffix is either how ethtool utility calls the feature
("tso", "rx"). Or, if ethtool utility specifies no alias for that
feature, it's the name from kernel's ETH_SS_FEATURES ("tx-tcp6-segmentation").
If possible, we prefer ethtool utility's naming.

Also note, how the features "feature-sg", "feature-tso", and
"feature-tx" actually refer to multiple underlying kernel features
at once. This too follows what ethtool utility does.

The functionality is not yet implemented server-side.
2018-08-10 10:38:19 +02:00
Beniamino Galvani
a9b4532fa7 libnm-core: add SR-IOV setting
Add a setting containing SR-IOV parameters.
2018-07-11 16:16:22 +02:00
Beniamino Galvani
52e7d6ef46 libnm-core: reject tc configurations with duplicate elements
A configuration with duplicate tc qdiscs and tfilters is not valid;
reject it in verify(). Note that nm_setting_tc_config_add_qdisc() and
nm_setting_tc_config_add_tfilter() can't add duplicate entries and so
the only way to achieve an invalid configuration is setting the
properties directly.

https://github.com/NetworkManager/NetworkManager/pull/95
(cherry picked from commit 2576e3a8e8)
2018-06-23 11:52:24 +02:00
Thomas Haller
b7426e91db build: use default NM_BUILD_* defines for tests
Use two common defines NM_BUILD_SRCDIR and NM_BUILD_BUILDDIR
for specifying the location of srcdir and builddir.

Note that this is only relevant for tests, as they expect
a certain layout of the directories, to find files that concern
them.
2018-05-31 15:59:38 +02:00
Beniamino Galvani
1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Francesco Giudici
31d9a9de14 libnm-core: team: add support to runner "random"
https://bugzilla.redhat.com/show_bug.cgi?id=1538699
2018-02-05 15:24:36 +01:00
Thomas Haller
25ade39752 tests: use NMTST_EXPECT*() macros
Tests are commonly created via copy&paste. Hence, it's
better to express a certain concept explicitly via a function
or macro. This way, the implementation of the concept can be
adjusted at one place, without requiring to change all the callers.

Also, the macro is shorter, and brevity is better for tests
so it's easier to understand what the test does. Without being
bothered by noise from the redundant information.

Also, the macro knows better which message to expect. For example,
messages inside "src" are prepended by nm-logging.c with a level
and a timestamp. The expect macro is aware of that and tests for it

  #define NMTST_EXPECT_NM_ERROR(msg)      NMTST_EXPECT_NM (G_LOG_LEVEL_MESSAGE, "*<error> [*] "msg)

This again allows the caller to ignore this prefix, but still assert
more strictly.
2018-01-08 12:38:54 +01:00
Pavel Šimerda
4650a4e1a1 tests: fix warnings about unused functions
https://github.com/NetworkManager/NetworkManager/pull/48
2017-12-30 12:02:31 +01:00
Lubomir Rintel
dbef7e684f libnm-core/tests: test NMSettingTCConfig traffic filter support 2017-12-11 11:02:04 +01:00
Lubomir Rintel
883e565b7d libnm-core/tests: test NMSettingTCConfig action support 2017-12-11 11:02:04 +01:00
Lubomir Rintel
0ab77ebd1d libnm-core/tests: test NMSettingTCConfig qdisc support
...so that we have an excuse when it breaks.
2017-12-11 10:52:22 +01:00
Thomas Haller
b1c65d32fe Revert "Makefile: rework team compilation flags"
I don't think we should do this.

- renamining/dropping configure options is still an annoyance,
  because it requires to different ./configure options depending
  on the version. The rename from --enable-teamctl to --enable-team
  might be theoretically nice, but more annoying then helpful.

- There is no strict dependency between --enable-team and
  --enable-json-validation. At most, one could argue that
  when enabling the team plugin (--enable-teamctl), then
  libnm must also be build with --enable-json-validation.
  But in fact, the team plugin will happily work with a
  libnm that doesn't link against libjansson.
  That is --enable-teamctl --disable-json-validation will work
  in practice just fine.
  On the other hand, libnm is a client library to create connection
  profiles, fully supporting team profiles also makes sense if the
  actual plugin is not installed (or build). Thus, --disable-teamctl
  --enable-json-validation certainly makes sense.

At this point, one might ask whether libnm is even still complete without
libjansson. Maybe libnm should *require* --enable-json-validation.
But that is not what the patch was doing, and it would also need
some careful consideration before doing so.

This reverts commit 9d5cd7eae8.
2017-12-08 09:07:30 +01:00
Thomas Haller
af6f62be8d libnm/tests: fix memleak in test 2017-12-08 08:51:21 +01:00
Francesco Giudici
9d5cd7eae8 Makefile: rework team compilation flags
Rename the team functionality enablement from 'teamdctl' to 'team'.
Force jansson lib requirement for team functionality: NetworkManager
requires the teamd daemon to manage team. As teamd depends upon jansson
lib, adding jansson requirement for teaming support in NetworkManager
seems reasonable.
Remove the jansson_validation flag, as the only generic json function in
nmcli (not related to team) was the one to check if a string was in json
format. Anyway, that function is used for team checks only. So, move
also json validation functions under the WITH_TEAM flag.
2017-12-08 00:46:27 +01:00
Francesco Giudici
b5f0d61d03 libnm-core: add test cases for NMSettingTeamPort 2017-12-08 00:46:27 +01:00
Francesco Giudici
1248969342 libnm-core: add test cases for NMSettingTeam 2017-12-08 00:46:27 +01:00
Lubomir Rintel
9bb30f86ec libnm-core: merge the settings tests into a single one
Thomas likes this more and who am I to argue.
2017-12-08 00:46:27 +01:00