Commit Graph

23466 Commits

Author SHA1 Message Date
Rafael Fontenelle
8f1b542bd7 po: update Brazilian Portuguese (pt_BR) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/165/commits
2019-05-27 11:03:53 +02:00
Tom Gundersen
e43b1791a3 Merge commit 'e23b3c9c3ac86b065eef002fa5c4321cc4a87df2' as 'shared/n-dhcp4'
Imported n-dhcp4 code with command:

  git subtree add --prefix shared/n-dhcp4/ git@github.com:nettools/n-dhcp4.git master --squash

To update the library use:

  git subtree pull --prefix shared/n-dhcp4/ git@github.com:nettools/n-dhcp4.git master --squash
2019-05-25 02:02:04 +02:00
Thomas Haller
3f760601d4 libnm/team: merge branch 'th/libnm-team'
https://bugzilla.redhat.com/show_bug.cgi?id=1691619

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/146
2019-05-23 18:10:54 +02:00
Thomas Haller
30455ab1b5 libnm/keyfile: don't parse JSON config in keyfile reader twice
Commit d6ec009afd ('team: normalize invalid configuration during
load') let's keyfile reader ignore JSON configs that cannot be parsed.

Keep doing that, but don't parse the JSON twice for that.

Just set the JSON, and if the setting afterwards does not verify, reset
it to NULL. We also get a better error message and in most cases we
don't need to parse twice.
2019-05-23 18:09:49 +02:00
Thomas Haller
74d0a5bf9a nmcli: don't validate team config in nmcli
nm_connection_verify() can already validate team settings just fine.
No need to duplicate this.
2019-05-23 18:09:49 +02:00
Thomas Haller
f229102ddf libnm: support strict parsing of team link watcher from GVariant 2019-05-23 18:09:49 +02:00
Thomas Haller
cfcc4ff7e3 libnm: implement team's _link_watcher_from_variant() reusing meta data
- re-use the existing meta-data. That is, don't duplicate the
dbus-names, the types, or the default value. Instead, parse the
settings according to these flags.

- notice and return if there are any suspicious/wrong keys in the
variant. For strict parsing, we should not silently ignore them.

- previously, the code used g_variant_lookup() to search for the
expected keys. As the number of keys that we look up is fixed, this
still had O(n). But if we want to detect and reject invalid keys,
we cannot use g_variant_lookup() but need to iterate the entire variant
once.
2019-05-23 18:09:49 +02:00
Thomas Haller
396818c35d libnm: implement team's _link_watcher_to_variant() reusing meta data 2019-05-23 18:09:49 +02:00
Thomas Haller
7f2d655a46 libnm: split creation/conversion of team link watcher from variant 2019-05-23 18:09:49 +02:00
Thomas Haller
c7e349d1ab libnm: move team link-watchers to/from variant to "nm-team-setting.c" 2019-05-23 18:09:49 +02:00
Thomas Haller
13f6f3a410 libnm: rework team handling of JSON config
Completely refactor the team/JSON handling in libnm's NMSettingTeam and
NMSettingTeamPort.

- team handling was added as rh#1398925. The goal is to have a more
  convenient way to set properties than constructing JSON. This requires
  libnm to implement the hard task of parsing JSON (and exposing well-understood
  properties) and generating JSON (based on these "artificial" properties).
  But not only libnm. In particular nmcli and the D-Bus API must make this
  "simpler" API accessible.

- since NMSettingTeam and NMSettingTeamPort are conceptually the same,
  add "libnm-core/nm-team-utils.h" and NMTeamSetting that tries to
  handle the similar code side-by-sdie.
  The setting classes now just delegate for everything to NMTeamSetting.

- Previously, there was a very fuzzy understanding of the provided
  JSON config. Tighten that up, when setting a JSON config it
  regenerates/parses all other properties and tries to make the
  best of it. When modifying any abstraction property, the entire
  JSON config gets regenerated. In particular, don't try to merge
  existing JSON config with the new fields. If the user uses the
  abstraction API, then the entire JSON gets replaced.

  For example note that nm_setting_team_add_link_watcher() would not
  be reflected in the JSON config (a bug). That only accidentally worked
  because client would serializing the changed link watcher to
  GVariant/D-Bus, then NetworkManager would set it via g_object_set(),
  which would renerate the JSON, and finally persist it to disk. But
  as far as libnm is concerned, nm_setting_team_add_link_watcher() would
  bring the settings instance in an inconsistent state where JSON and
  the link watcher property disagree. Setting any property must
  immediately update both the JSON and the abstraction API.

- when constucting a team setting from D-Bus, we would previously parse
  both "config" and abstraction properties. That is wrong. Since our
  settings plugins only support JSON, all information must be present
  in the JSON config anyway. So, when "config" is present, only the JSON
  must be parsed. In the best case, the other information is redudant and
  contributes nothing. In the worse case, they information differs
  (which might happen if the client version differs from the server
  version). As the settings plugin only supports JSON, it's wrong to
  consider redundant, differing information from D-Bus.

- we now only convert string to JSON or back when needed. Previously,
  setting a property resulted in parsing several JSON multiple times
  (per property). All operations should now scale well and be reasonably
  efficient.

- also the property-changed signals are now handled correctly. Since
  NMTeamSetting knows the current state of all attributes, it can emit
  the exact property changed signals for what changed.

- we no longer use libjansson to generate the JSON. JSON is supposed
  to be a machine readable exchange format, hence a major goal is
  to be easily handled by applications. While parsing JSON is not so
  trivial, writing a well-known set of values to JSON is.
  The advantage is that when you build libnm without libjansson support,
  then we still can convert the artificial properties to JSON.

- Requiring libjansson in libnm is a burden, because most of the time
  it is not needed (as most users don't create team configurations). With
  this change we only require it to parse the team settings (no longer to
  write them). It should be reasonably simple to use a more minimalistic
  JSON parser that is sufficient for us, so that we can get rid of the
  libjansson dependency (for libnm). This also avoids the pain that we have
  due to the symbol collision of libjansson and libjson-glib.

https://bugzilla.redhat.com/show_bug.cgi?id=1691619
2019-05-23 18:09:49 +02:00
Thomas Haller
539dfbcc42 libnm: add "libnm-core/nm-team-utils.h" 2019-05-23 18:09:49 +02:00
Thomas Haller
0cc68e1c4f libnm: add init_from_dbus() virtual function to NMSetting 2019-05-23 18:09:49 +02:00
Thomas Haller
d31622a63e ifcfg-rh: don't check for errors reading team settings in ifcfg-rh
We have nm_setting_verify() for a purpose.

The checks that ifcfg-rh reader does are either

  - redundant (and thus unnecessary)

  - wrong (and thus we cannot read valid settings)

  - should belong to libnm's nm_setting_verify().

NMSettingTeam/NMSettingTeamPort are already very libraral and don't do
almost any strict validation. Previously, ifcfg reader would be even more
liberal. If there is totally invalid data in the profile, reading the profile
should fail.
2019-05-23 18:09:49 +02:00
Thomas Haller
966e0db8d7 libnm: don't duplicate NMTeamLinkWatcher and make ref thread-safe
NMTeamLinkWatcher are immutable and ref-counted.

As such, there is little reason to ever duplicate them. Just increase
the ref-count.

For this change to be safe in all cicumstances, make ref/unref of the
link watcher thread-safe. After all, NMTeamLinkWatcher is public API,
and while libnm generally is not thead-safe, the cost of this is small.
2019-05-23 18:09:49 +02:00
Thomas Haller
e923668d74 libnm: rework NMTeamLinkWatcher structure and embed strings
Don't rely on the same memory layout for the NMTeamLinkWatcher union to
hold data for the watcher types. It looks wrong and is error prone.

Also, as we no longer require the full union, we can allocate a smaller
structure for ethtool. And while at it, we can embed the strings
directly instead of allocating them separately.

The point is to have a more efficient representation (memory wise).
2019-05-23 18:09:49 +02:00
Thomas Haller
b6156e9099 libnm: add internal cmp() function for NMTeamLinkWatcher types
Add internal nm_team_link_watcher_cmp() function.

We can implement nm_team_link_watcher_equal() based on that.

This was we can sort link watchers so that nm_team_link_watchers_equal()
with ignore_order is O(n*log(n)) instead of O(n^2).

In general, as basic API cmp() functions are as much effort to implement
as equal(), but they can also be used for sorting.

In nm_team_link_watcher_cmp(), only compare the fields that are set
according to the link watcher type.
2019-05-23 18:09:49 +02:00
Thomas Haller
e28bd1289b libnm: mark NMTeamLinkWatcher arguments as const in API
NMTeamLinkWatcher is immutable, meaning there is no way to change an
existing instance (aside increasing/decreasing the ref-count).

Hence, all API is implicitly const.

Still, mark the arguments as const.
2019-05-23 18:09:49 +02:00
Thomas Haller
35c92cf582 libnm/tests: mark team tests as skipped without JSON validation
We should not just disable tests with an #if.

Instead, mark them as skipped. This way, we still compile them, and we
even run them (showing a message why they are skipped).
2019-05-23 18:09:49 +02:00
Thomas Haller
a178fbac26 libnm/tests: add tests for modifying team setting 2019-05-23 18:09:49 +02:00
Thomas Haller
49dbdae00a libnm/tests: check for identical team config in _team_config_equal_check() 2019-05-23 18:09:49 +02:00
Thomas Haller
9b0dee8e9c libnm/tests: cleanup tests 2019-05-23 18:09:49 +02:00
Thomas Haller
b927287c7d shared/utils: add nmtst_assert_setting_dbus_roundtrip() util 2019-05-23 18:09:49 +02:00
Thomas Haller
892440c4ab shared/tests: add nmtst_assert_setting_is_equal() util 2019-05-23 18:09:49 +02:00
Thomas Haller
ae7f32e03b shared/tests: add nmtst_variant_from_string() util 2019-05-23 18:09:49 +02:00
Thomas Haller
5d3b033072 shared: add nm_utils_gvariant_vardict_filter*() helpers
Usually, such an operation does not make much sense. It's also not good
performance wise.

But for unit testing this becomes very interesting.
2019-05-23 18:09:49 +02:00
Thomas Haller
848a80598e shared: add JSON helper functions for NMValueType 2019-05-23 18:09:49 +02:00
Thomas Haller
75703a2425 shared: add accessor functions for NMValueType
"nm-value-type.h" is a header-only file, as it contains only small
accessors that should be inlined.

As such, the implementation of these functions is guarded by "#ifdef
NM_VALUE_TYPE_DEFINE_FUNCTIONS", so that one can use this header (and
NMValueType enum) with less overhead (at compile time).
2019-05-23 18:09:49 +02:00
Thomas Haller
e64fdeeaf6 shared: add "shared/nm-glib-aux/nm-value-type.h"
Glib has GValue which used for boxing value.

Add NMValueType enum, which has a similar purpose, but it's much more
limited.

- contrary to GValue, the type must be tracked separately from the
  user-data. That is, the "user-data" is only a pointer of appropriate
  type, and the knowledge of the actual NMValueType is kept separately.
  This will be used to have a static list of meta-data that knows the
  value types, but keeping the values independent of this type
  information. With GValue this would not be possible.

- the use case is much more limited. Just support basic integers,
  boolean and strings. Nothing fancy.

Note that we already do something similar at muliple places. See for
example NMVariantAttributeSpec and nm_utils_team_link_watcher_to_string().
These could/should instead use NMValueType.
2019-05-23 18:09:49 +02:00
Thomas Haller
efccc2a53c shared: add nm_json_aux_gstr_append_*() helper 2019-05-23 18:09:49 +02:00
Thomas Haller
50dbcda015 shared: add nm_jansson_json_as_*() helpers to "shared/nm-glib-aux/nm-jansson.h" 2019-05-23 18:09:49 +02:00
Thomas Haller
f84e623732 shared: add "shared/nm-glib-aux/nm-json-aux.h"
This will be a set of JSON related utilities, that are independent of
libjansson.
2019-05-23 18:09:49 +02:00
Thomas Haller
f5482013ac shared: add NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY() macro as part of NM_GOBJECT_PROPERTIES_DEFINE()
This will be needed independently from NM_GOBJECT_PROPERTIES_DEFINE().
2019-05-23 18:09:49 +02:00
Thomas Haller
dadd38c484 shared: add nm_utils_strv_make_deep_copied_n() helper 2019-05-23 18:09:49 +02:00
Thomas Haller
79ef1abcca shared: add nm_strcmp0()
g_strcmp0() is not inlineable, so we first need to call to glib, only to
call to libc.
2019-05-23 18:09:49 +02:00
Thomas Haller
9e544d527a shared: fix invalid assertion in nm_utils_team_link_watcher_from_string()
Fixes: a473ab431a ('cli: refactor team-link-watcher to/from strings')
2019-05-23 18:09:49 +02:00
Thomas Haller
61b1d1e963 libnm: fix parsing "nsna_ping" team link watcher from GVariant
Fixes: ba4ce843fa ('libnm-core: add backend for GVariant de/serialization of link_watchers.')
2019-05-23 18:09:49 +02:00
Thomas Haller
4b8a9cc51b ifcfg: use proper define for D-Bus interface name in "nms-ifcfg-rh-plugin.c"
No difference in practice, as both defines define the same name.
2019-05-23 11:07:26 +02:00
Thomas Haller
f01866060b build: merge branch 'th/build-link-static-libraries-later'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/149
2019-05-22 20:05:24 +02:00
Thomas Haller
e7056d4efd build: don't statically link static libraries with other static libraries (6) 2019-05-22 20:04:08 +02:00
Thomas Haller
15e224fd59 build: don't statically link static libraries with other static libraries (5) 2019-05-22 20:04:08 +02:00
Thomas Haller
0a510ed1cf build: don't statically link static libraries with other static libraries (4) 2019-05-22 20:04:08 +02:00
Thomas Haller
53168b0d2c build: drop trivial variables from Makefile.am
It just hides what we link. Link against GLIB explicitly
instead of indirectly via another variable.
2019-05-22 20:04:08 +02:00
Thomas Haller
c808191846 build: don't statically link static libraries with other static libraries (3) 2019-05-22 20:04:08 +02:00
Thomas Haller
b5850cb4d4 build: don't statically link static libraries with other static libraries (2) 2019-05-22 20:04:08 +02:00
Thomas Haller
1a24f3ae8d build: don't statically link static libraries with other static libraries (1)
When we link static libraries together, there must be no duplicate
symbols.

Since we have a lot of static/intermediate libraries, getting this right
is complicated and sometimes leads to ugly solutions.

As a new rule: don't let static libraries link with other static
libraries. Only binaries and libnm/libnm.la should explicitly link
with all the static libraries that they require.

There are exceptions: "src/libNetworkManager.la" and "libnm/liblibnm.la".
These are static, internal libraries, but they are basically *everything*
that ends up in "src/NetworkManager" and "libnm/libnm.la", respecitively.
Hence, these static libraries also link against other static libraries.
Another exception to this rule is "src/libNetworkManagerTest.la", for
similar reasons.
2019-05-22 20:04:08 +02:00
Thomas Haller
d8eb9e7515 build: link src/NetworkManager explicitly with glib
We compile src/main.c as part of src/NetworkManager. Explicitly link with
glib, because that is required by the source code. Apparently, it also
works without this, but still do it for correctness.
2019-05-22 20:04:08 +02:00
Thomas Haller
105d0d56d3 build: link libnm/liblibnm.la with udev library
libnm/liblibnm.la compiles "libnm/nm-device.c" and "libnm/nm-client.c",
both include libudev.h.

Let's explicitly link this library with libudev.
2019-05-22 20:04:08 +02:00
Thomas Haller
aff1d66b81 Revert "libnm: don't assert for success of g_dbus_error_register_error()"
Now that unit tests no longer dynamically link against libnm/libnm.la,
and statically against the same code, we can enable this assertion
again.

This reverts commit 7a0e347b38.
2019-05-22 20:04:08 +02:00
Thomas Haller
6b7264e4aa build/meson: introduce libnm/liblibnm.la as static library for libnm/libnm.la
Same as done for autotools.
2019-05-22 20:04:08 +02:00