Commit graph

23303 commits

Author SHA1 Message Date
Beniamino Galvani
9a410fc312 ifcfg-rh: use PKCS #12 private key also as client cert in reader
Before commit e3ac45c026 the reader set the private key in the
setting using the libnm function, which also set the key as client
certificate if it was in PKCS #12 format.

After the commit, existing connections with a PKCS #12 private key but
without a client certificate became invalid. Restore the old behavior.

Fixes: e3ac45c026 ('ifcfg-rh: don't use 802-1x certifcate setter functions')
2019-05-28 10:51:47 +02:00
Beniamino Galvani
d9b3b2b8ce ifcfg-rh: don't check for 802.1x private key or client cert in reader
Let the setting check it in verify().
2019-05-28 10:42:30 +02:00
Beniamino Galvani
a995244e9b ifcfg-rh: write client certificate even if it is pkcs12
The writer should only persist properties without too much additional
logic, which should be instead embedded in the setting itself.
2019-05-28 10:42:30 +02:00
Beniamino Galvani
3a4a09b669 core: merge branch 'bg/sriov-async'
https://github.com/NetworkManager/NetworkManager/pull/268
2019-05-28 10:35:57 +02:00
Beniamino Galvani
121c58f0c4 core: set number of SR-IOV VFs asynchronously
When changing the number of VFs the kernel can block for very long
time in the write() to sysfs, especially if autoprobe-drivers is
enabled. Turn the nm_platform_link_set_sriov_params() into an
asynchronous function.
2019-05-28 10:35:04 +02:00
Beniamino Galvani
abec66762a platform: add async sysctl set function
Add a function to asynchronously set sysctl values.
2019-05-28 10:34:53 +02:00
Beniamino Galvani
b5009ccd29 platform: print sysctl absolute path when pathid is NULL
@pathid can be NULL, in such case print the absolute path.
2019-05-28 10:34:53 +02:00
Beniamino Galvani
3ed23d405e platform: use 'self' argument name for platform functions
Uniform all functions to use 'self' as first argument.
2019-05-28 10:34:53 +02:00
Beniamino Galvani
d6a51ced40 ifcfg-rh: preserve existence of wired setting
Currently the plugin doesn't preserve the existence of a wired setting
because the writer saves only variables with non-default values and,
especially, the reader always creates the setting.

Fix this; now the writer writes HWADDR even if empty when the setting
is present; the reader creates the setting when at least one property
is found.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/166
https://bugzilla.redhat.com/show_bug.cgi?id=1703960
2019-05-28 09:53:00 +02:00
Thomas Haller
e1b824b871 shared: fix return in nm_value_type_to_variant()/nm_value_type_get_variant_type()
Fixes: 75703a2425 ('shared: add accessor functions for NMValueType')
2019-05-27 13:27:13 +02:00
Thomas Haller
51793569e1 dispatcher: merge branch 'th/dispatcher-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/162
2019-05-27 12:44:25 +02:00
Thomas Haller
7ea76c07e5 dispatcher: log warning when nm-dispatcher quits with requests pending 2019-05-27 12:43:06 +02:00
Thomas Haller
acc335aad4 dispatcher/systemd: order NetworkManager-dispatcher.service Before=NetworkManager.service
During shutdown, systemd should first stop NetworkManager and then
the dispatcher service. Note that dispatcher service is D-Bus activated,
so the two services don't Want/Require each other. But the ordering
still matters.
2019-05-27 12:43:06 +02:00
Thomas Haller
947f979f26 dispatcher/trivial: add FIXME comment about how to fix shutdown of NtworkManager 2019-05-27 12:43:06 +02:00
Thomas Haller
aafeaeab18 dispatcher: log ifname/con_uuid as structured logging for dispatcher requests 2019-05-27 12:43:06 +02:00
Thomas Haller
55be5166f0 dispatcher: cleanup nm_dispatcher_call_cancel()
Remove the call-id from the requests hash before invoking the callback.
This prevents the user to cancel the request from within the callback.
Supporting such a use case is not necessary so prevent it and tighten
the callers up.
2019-05-27 12:42:51 +02:00
Thomas Haller
3dbda5addc dispatcher: use GDBusConnection instead of GDBusProxy in "nm-dispatcher.c"
- drops nm_dispatcher_init(), which was called early in the main loop
  and created a proxy synchronously. Instead, the GDBusConnection is
  always ready.

- reuse the GDBusConnection of NMDBusManager. This means, we won't even
  try from in "initrd" configure-and-quit mode.

- as before, there is no "manager" instance. Instead, the data is stored
  in a global variable. That's ok. What is not OK is how the entire
  shutdown is handled (calling dispatcher blockingly, not waiting for
  requests to complete). That is fixable, but a lot of work. It is
  independent of whether we use a manager object or not.
2019-05-27 12:39:37 +02:00
Thomas Haller
c3e2959a5a dispatcher: replace guint call-id by opaque NMDispatcherCallId
A guint value can wrap, so we would need to check that we don't allocate duplicate
IDs (which we currently don't, and it's likely never to actually hit).

Just expose the (opaque) pointer of the call-id.

We still keep a "request_id", but that is only for logging purpose.
2019-05-27 12:39:37 +02:00
Thomas Haller
c82703d417 dispatcher: add logging macros for per-request messages
This way, we avoid code duplication of how to print the request-id
("(%u) "), but it also will allow up to attach the interface name
and connection name to the call-id, so that we can use it for structured
logging.
2019-05-27 12:39:37 +02:00
Thomas Haller
da345efc08 dispatcher: cleanup constructing parameter in _dispatcher_call()
Don't duplicate this code.
2019-05-27 12:39:37 +02:00
Thomas Haller
f8b0bad2c9 dispatcher: cleanup dispatcher_results_process()
We don't need the two callers both unpack the GVariant and pass a GVariantIter.
Let dispatcher_results_process() do the unpacking.

Also, use some cleanup attributes.
2019-05-27 12:39:37 +02:00
Thomas Haller
f809644866 build: don't link dispatcher with generated nmdbus-dispatcher bindings
We don't need it anymore.

Still, for tests let gdbus-codegen run and generate the sources and
compile them. We want to keep "dispatcher/nm-dispatcher.xml" and ensure
that it is still valid.
2019-05-27 12:39:25 +02:00
Thomas Haller
cdaedecaa7 dispatcher: unown dispatcher D-Bus name on exit 2019-05-27 12:10:26 +02:00
Thomas Haller
a01e760667 dispatcher: drop GDBusInterfaceSkeleton and generate GDBus bindings
Just hook into GDBusConnection directly. No need for this additional
layer that provides nothing. It doesn't even provide extra type-safety,
because you still need to get the arguments of the signal handler right.
That that point, it's as hard as getting the format string for
g_variant_get() right.

It still adds lines of code, because the "Action" method has such a
large argument list.
2019-05-27 12:10:26 +02:00
Thomas Haller
484194fa07 dispatcher: drop Handler GObject
"nm-dispatcher.c" does something rather simple. It is natural that it
has a bit of global data to keep track of that it's doing ("gl").

But this does not lend itself to pack the job of dispatcher into an
object. In fact, the Handler object was little more about packaging
the GDBus interface skeleton and a bit of state.

Global variables are often problematic because they makes unit testing hard.
But first of all, we have no test for this (we should). But it's not said
that you need an "object" to make testing easier. If we want to make
individual bits easier testable, we can just as well pass all required
parameters explicitly instead of accessing global variables. Since we
package global variables neatly in "gl", this is very simple to
refactor. Also, global variables can make code harder to understand. But
the problem is the amount of state that is accessible. This is not
alleviated by packaging the state in a Handler object.

As there is always only one handler instance, this provides very little
benefit.

I will drop the GDBus interface skeleton soon. So this Handler object
will have even less purpose. Drop it.
2019-05-27 12:10:26 +02:00
Thomas Haller
cdea5ca795 dispatcher: keep the GDBusConnection instance in the global variable
It's anyway a singleton that is still referenced by other components.
So unrefing it in the mainloop does not actually release any memory.

However, the GDBusConnection singleton is fundamental for the run of
the program. Keep it accessible in the global variables.

Note that soon I will drop the GDBusInterfaceSkeleton and only operate
on the GDBusConnection. Then it makes more sense to keep it around.

Note that usually we want to keep the amount of global state small.
But this connection is anyway a singleton (that we already implicitly
use). So, it doesn't change the amount of global state nor does it really
have much state (we either have a reference to the singleton or we don't).
2019-05-27 12:09:53 +02:00
Thomas Haller
3a3c807add dispatcher: parse command line arguments in a seprate function
Split command line parsing out of the main() function. For one, it's
an self-contained step, so we can make main() simpler.

Also, we don't need the GOptionEntry on the stack of the main() function
for the remainder of the program.
2019-05-27 12:07:52 +02:00
Thomas Haller
866189a001 dispatcher: don't just exit() but always shutdown before exiting
It's ugly to uncoordinated just call exit(). We should quit the mainloop
and clean up everything we had going.

Note that since Handler has no dispose() function, we also need to hack
a g_signal_handlers_disconnect_by_func(). This will change soon.
2019-05-27 12:07:52 +02:00
Thomas Haller
90e4ba15bc dispatcher: move global variable ever_aquired_name into "gl" struct 2019-05-27 12:07:52 +02:00
Thomas Haller
a454e418d4 dispatcher: unref main loop at exit and remove signal handler sources 2019-05-27 12:07:52 +02:00
Thomas Haller
bccf754347 dispatcher: namespace global variables in a struct "gl" 2019-05-27 12:07:52 +02:00
Thomas Haller
23286b2afa dispatcher: use logging macros instead of g_log() directly
Also cleanup the logging macros.
2019-05-27 12:01:09 +02:00
Thomas Haller
b4d678b314 dispatcher: silence message about non-existing dispatcher directory
Silence messages like

  find-scripts: Failed to open dispatcher directory '/usr/lib/NetworkManager/dispatcher.d': Error opening directory “/usr/lib/NetworkManager/dispatcher.d”: No such file or directory

  find-scripts: Failed to open dispatcher directory '/usr/lib/NetworkManager/dispatcher.d/pre-up.d': Error opening directory “/usr/lib/NetworkManager/dispatcher.d/pre-up.d”: No such file or directory
2019-05-27 12:01:09 +02:00
Thomas Haller
8518a87387 dispatcher: log messages about loading scripts per-request
The messages about loading the scripts are releated to a particular
request. Hence, they should be logged with that context.

Also, we should avoid using g_log() directly. Use our logging macros
instead.
2019-05-27 12:01:09 +02:00
Thomas Haller
58704a37ae dispatcher: don't print debug messages of dispatcher in regular mode
Previously, we would log several messages with level "debug" / g_info().

  _LOG_R_D (request, "start running ordered scripts...");
  _LOG_R_D (request, "new request (%u scripts)", request->scripts->len);
  _LOG_R_D (request, "completed: no scripts");

Note that this effectively logs a message for every event. I think that
is to verbose and not suitable for regular logging.

Only enable these messages if debug logging is enabled. As such, these debug
level messsages now are enabled together with the trace level messages.
2019-05-27 12:01:09 +02:00
Thomas Haller
dd72696af7 dispatcher/trivial: rename logging levels
What we currently print as "info" level is too verbose for regular
operation. It prints two messages for every dispatcher event. That's
already for debugging.

Next that will be downgraded, so rename "debug" to "trace" and "info" to
"debug".

There is only renaming, no change in behavior.
2019-05-27 12:01:09 +02:00
Thomas Haller
17dc6a9da6 shared: add _NM_ENSURE_TYPE_CONST()
The sole purpose of this is more type-safe macros.

An alternative solution would be to define a function instead of a
macro. But if the function is unused (currently!) you get a compiler
warning (on some compilers even when marking the function as "static
inline", if it's in the source file). A workaround for that would be
to mark the function as _nm_unused, or to use a macro instead.

_NM_ENSURE_TYPE_CONST() is to aid the macro solution.
2019-05-27 12:01:09 +02:00
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