Commit Graph

24195 Commits

Author SHA1 Message Date
Lubomir Rintel
f222dad838 contrib: move scripts from test/ to scripts/
There's no reason to have them separate. Also add the missing executable
bit to btmodem.pl.

https://github.com/NetworkManager/NetworkManager/pull/355
2019-10-09 11:38:22 +02:00
Lubomir Rintel
0ff1cb556c libnm/utils: add SAE security type
https://github.com/NetworkManager/NetworkManager/pull/354
2019-10-09 11:26:14 +02:00
Thomas Haller
597e4b2d1e cli: honor NO_COLOR environment variable to prevent automatic ASCII colors
See-also: https://no-color.org/
2019-10-08 12:18:20 +02:00
Beniamino Galvani
d0db41c1d4 cli: fix crash in 'nmcli connection add'
The connection type can be NULL.

Fixes: e1ec22f74b ('cli: cleanup setting default interface-name')
2019-10-07 13:35:02 +02:00
Thomas Haller
c6d53c5500 dispatcher: avoid "dirname" and "basename" calls in "10-ifcfg-rh-routes.sh" script
The script is run for every dispatcher event. Most of the events are not
actually relevant, and we just need to determine that there is nothing
to do and quit.

Avoid calling "dirname" and "basename".

The supported ifcfg-file has a very specific form. We can just check
(and parse) it in one got regular expression in bash.
2019-10-04 12:38:16 +02:00
Thomas Haller
babd1f314e dispatcher: move return-early checks in "10-ifcfg-rh-routes.sh" first
A shell script is executed line-by-line. Note that for most dispatcher
events, "10-ifcfg-rh-routes.sh" has nothing to do and will just quit.
Move those checks earlier, to avoid bash executing the code that won't
be needed most of the time.
2019-10-04 12:37:50 +02:00
Thomas Haller
5a24ad53ad device: order assert before logging in concheck_cb() 2019-10-03 15:32:32 +02:00
Ilya Shipitsin
e8588d0c6f src/devices/nm-device.c: resolve possible null pointer dereference
found by cppcheck

[src/devices/nm-device.c:3032] -> [src/devices/nm-device.c:3025]: (warning) Either the condition '!handle' is redundant or there is possible null pointer dereference: handle.

https://github.com/NetworkManager/NetworkManager/pull/352
2019-10-03 15:12:34 +02:00
Thomas Haller
adac530d7a libnm: merge branch 'th/libnm-deprecate-sync-api'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/296
2019-10-03 10:49:00 +02:00
Thomas Haller
f45aeba402 libnm: deprecate nm_client_check_connectivity() in 1.22
The previous commit marks all synchronous libnm API as deprecated.
In practice, the macro _NM_DEPRECATED_SYNC_METHOD expands to
nothing, because there is no immediate urgency to force users
to migrate.

However nm_client_check_connectivity() is especially bad: it
makes a synchronous call and then updates the content of the
cache artificially. Usually, NMClient's cache of D-Bus objects
is only updated by "PropertiesChanged" D-Bus signals.
nm_client_check_connectivity() instead will act on the response to
the "CheckConnectivity" D-Bus call -- a response that is picked
out of order from the ordered sequence of messages --  and will
update the cache instead of honoring the usual "PropertiesChanged"
signal.

I think such behavior is fundamentally broken. For a trivial property like
NM_CLIENT_CONNECTIVITY such behavior is odd at best. Note how applying
this approach to other functions (like nm_client_deactivate_connection(),
which would affect a much larger state) would not be feasible.

I also imagine it to be complicate to preserve this behavior when
reworking libnm, as I plan to do.

See also commit b799de281b ('libnm: update property in the manager
after connectivity check'), which introduced this behavior to "fix"
bgo#784629.
2019-10-03 10:46:49 +02:00
Thomas Haller
e90684a169 libnm: deprecate synchronous/blocking API in libnm
Note that D-Bus is fundamentally asynchronous. Doing blocking calls
on top of D-Bus is odd, especially for libnm's NMClient. That is because
NMClient essentially is a client-side cache of the objects from the D-Bus
interface. This cache should be filled exclusively by (asynchronous) D-Bus
events (PropertiesChanged). So, making a blocking D-Bus call means to wait
for a response and return it, while queuing all messages that are received
in the meantime.
Basically there are three ways how a synchronous API on NMClient could behave:

 1) the call just calls g_dbus_connection_call_sync(). This means
    that libnm sends a D-Bus request via GDBusConnection, and blockingly
    waits for the response. All D-Bus messages that get received in the
    meantime are queued in the GMainContext that belongs to NMClient.
    That means, none of these D-Bus events are processed until we
    iterate the GMainContext after the call returns. The effect is,
    that NMClient (and all cached objects in there) are unaffected by
    the D-Bus request.
    Most of the synchronous API calls in libnm are of this kind.
    The problem is that the strict ordering of D-Bus events gets
    violated.
    For some API this is not an immediate problem. Take for example
    nm_device_wifi_request_scan(). The call merely blockingly tells
    NetworkManager to start scanning, but since NetworkManager's D-Bus
    API does not directly expose any state that tells whether we are
    currently scanning, this out of order processing of the D-Bus
    request is a small issue.
    The problem is more obvious for nm_client_networking_set_enabled().
    After calling it, NM_CLIENT_NETWORKING_ENABLED is still unaffected
    and unchanged, because the PropertiesChanged signal from D-Bus
    is not yet processed.
    This means, while you make such a blocking call, NMClient's state
    does not change. But usually you perform the synchronous call
    to change some state. In this form, the blocking call is not useful,
    because NMClient only changes the state after iterating the GMainContext,
    and not after the blocking call returns.

 2) like 1), but after making the blocking g_dbus_connection_call_sync(),
    update the NMClient cache artificially. This is what
    nm_manager_check_connectivity() does, to "fix" bgo#784629.
    This also has the problem of out-of-order events, but it kinda
    solves the problem of not changing the state during the blocking
    call. But it does so by hacking the state of the cache. I think
    this is really wrong because the state should only be updated from
    the ordered stream of D-Bus messages (PropertiesChanged signal and
    similar). When libnm decides to modify the state, there may be already
    D-Bus messages queued that affect this very state.

 3) instead of calling g_dbus_connection_call_sync(), use the
    asynchronous g_dbus_connection_call(). If we would use a sepaate
    GMainContext for all D-Bus related calls, we could ensure that
    while we block for the response, we iterate that internal main context.
    This might be nice, because all events are processed in order and
    after the blocking call returns, the NMClient state is up to date.
    The are problems however: current blocking API does not do this,
    so it's a significant change in behavior. Also, it might be
    unexpected to the user that during the blocking call the entire
    content of NMClient's cache might change and all pointers to the
    cache might be invalidated. Also, of course NMClient would invoke
    signals for all the changes that happen.
    Another problem is that this would be more effort to implement
    and it involves a small performance overhead for all D-Bus related
    calls (because we have to serialize all events in an internal
    GMainContext first and then invoke them on the caller's context).
    Also, if the users wants this behavior, they could implement it themself
    by running libnm in their own GMainContext. Note that libnm might
    have bugs to make that really working, but that should be fixed
    instead of adding such synchrnous API behavior.

Read also [1], for why blocking calls are wrong.

[1] https://smcv.pseudorandom.co.uk/2008/11/nonblocking/

So, all possible behaviors for synchronous API have severe behavioural
issues.  Mark all this API as deprecated. Also, this serves the purpose of
identifying blocking D-Bus calls in libnm.

Note that "deprecated" here does not really mean that the API is going
to be removed. We don't break API. The user may:

  - continue to use this API. It's deprecated, awkward and discouraged,
    but if it works, by all means use it.

  - use asynchronous API. That's the only sensible way to use D-Bus.
    If libnm lacks a certain asynchronous counterpart, it should be
    added.

  - use GDBusConnection directly. There really isn't anything wrong
    with D-Bus or GDBusConnection. This deprecated API is just a wrapper
    around g_dbus_connection_call_sync(). You may call it directly
    without feeling dirty.

---

The only other remainging API is the synchronous GInitable call for
NMClient. That is an entirely separate beast and not particularly
wrong (from an API point of view).

Note that synchronous API in NMSecretAgentOld, NMVpnPluginOld and
NMVpnServicePlugin as not deprecated here. These types are not part
of the D-Bus cache and while they have similar issues, it's less severe
because they have less state.
2019-10-03 10:39:48 +02:00
Thomas Haller
3019648b4b checkpatch,gitlab-ci: let checkpatch script compare against latest upstream master
When opening a merge request from a fork of NetworkManager, then the
pipeline runs with the a checkout of the fork. That means, checkpatch
would compare the branch against "master" (or "nm-x-y" stable branches)
of the fork, instead of upstream.

That doesn't seem too useful. Instead, also add upstream NetworkManager
as git remote, fetch the branches, and use the branches from there as
base for checkpatch.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/255
2019-10-02 18:46:36 +02:00
Thomas Haller
10e8f7fdb4 cli: translate overview output of nmcli
Note the "to" in the output:

  $ LANG=de_DE.UTF-8 nmcli
  eth0: verbunden to Wired Connection 1
        "Intel Ethernet"
  ...

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/246
2019-10-02 18:17:21 +02:00
Thomas Haller
3b69f02164 all: unify format of our Copyright source code comments
```bash

readarray -d '' FILES < <(
  git ls-files -z \
    ':(exclude)po' \
    ':(exclude)shared/c-rbtree' \
    ':(exclude)shared/c-list' \
    ':(exclude)shared/c-siphash' \
    ':(exclude)shared/c-stdaux' \
    ':(exclude)shared/n-acd' \
    ':(exclude)shared/n-dhcp4' \
    ':(exclude)src/systemd/src' \
    ':(exclude)shared/systemd/src' \
    ':(exclude)m4' \
    ':(exclude)COPYING*'
  )

sed \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \
  -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \
  -i \
  "${FILES[@]}"

echo ">>> untouched Copyright lines"
git grep Copyright "${FILES[@]}"

echo ">>> Copyright lines with unusual extra"
git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved

sed \
  -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \
  -i \
  "${FILES[@]}"

```

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
2019-10-02 17:03:52 +02:00
Lubomir Rintel
a5ca504b5b bluetooth: don't set the ifindex after the device has been activated
The Bluetooth DUN device's NMModem would signal the reset of ifindex to zero
when it's disconnected and the NMDeviceBt would accordingly update the
bluetooth device's ip ifindex. This is not okay since commit ab4578302d
('device: refactor nm_device_set_ip_ifindex() and set_ip_iface()') which,
although claiming to be a refactoring, made such use of
nm_device_set_ip_ifindex() illegal. Resetting the ifindex is anyway not
necessary, since it's taken care of _cleanup_generic_post().

Let's leave the ifindex alone once the device is activated, in a manner
analogous to what NMDeviceModem.

Fixes: ab4578302d ('device: refactor nm_device_set_ip_ifindex() and set_ip_iface()')
Fixes: 78ca2a70c7 ('device: don't set invalid ip-iface'):
2019-10-02 11:29:53 +02:00
Lubomir Rintel
8d352b5a47 contrib: add a Bluetooth DUN modem emulator
Useful for quickly testing Bluetooth DUN support. Duplicates some
modemu.pl logic, but hey...

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/297
2019-10-02 11:29:53 +02:00
Thomas Haller
b9c4d2bb72 run-nm-test: fix using exec instead of running and exiting
Otherwise, the script tries to run

  dbus-run-session -- exec ...

which fails (because `exec` is a shell command, not a program).
After the failure, the code falls through to run the test under
valgrind.

Fixes: 6a58c55ca4 ('run-nm-test: Just use exec instead of running and exiting')
2019-10-02 09:47:54 +02:00
Thomas Haller
1224bb19a6 clients,libnm,tests: merge branch '3v1n0:gtask-initables' (part 1)
Merge a subset of the patches from !263.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/263
2019-10-02 09:24:06 +02:00
Thomas Haller
819c903543 libnm/secret-agent-old: steal pointer instead of taking additional reference 2019-10-02 09:18:01 +02:00
Thomas Haller
5a91900f8b libnm/trivial: fix whitespace 2019-10-02 09:14:53 +02:00
Marco Trevisan (Treviño)
b93b0c00d6 secret-agent-old: Use GTask for Async initializing
Cleanup the code removing the deprecated GSimpleAsyncResult
2019-10-02 09:12:55 +02:00
Marco Trevisan (Treviño)
b68bb97971 cli: Assert we don't require multiple commands during client initalization
If a new command was requested while a client was in the process of being
created we were just requesting a new client.

This was causing leak, so let's strongly ensure this is not the case.
2019-10-02 09:11:28 +02:00
Thomas Haller
c4c8889256 cli: fix leaking error variable in command_done() 2019-10-02 09:11:28 +02:00
Marco Trevisan (Treviño)
479c269766 cli: Use GTask to perform async requests 2019-10-02 09:11:28 +02:00
Marco Trevisan (Treviño)
36bd0565b7 test-client.py: Close pipes and print logs on timeout failures
If we failed on process wait, we didn't close the pipes and no clear output
of what happened was exposed.

So use a finally stanza to close the pipes and print stdout and stderr
on failure.
2019-10-02 09:11:28 +02:00
Marco Trevisan (Treviño)
6a58c55ca4 run-nm-test: Just use exec instead of running and exiting 2019-10-02 09:11:28 +02:00
Marco Trevisan (Treviño)
073eda68fc run-nm-test: Set NM_TEST_UNDER_VALGRIND accordingly
When a test is going to be run under valgrind we set NM_TEST_UNDER_VALGRIND
so that we can properly check whether this is happening.
2019-10-02 09:11:28 +02:00
Beniamino Galvani
5307b1ed73 wifi: guess metered flag based on Network Cost information element
Network Cost [1] is a vendor-specific information element defined by
Microsoft and used to advertise the cost of Wi-Fi networks to clients.

We can use it together with the ANDROID_METERED mechanism to
automatically set the metered flag on the device.

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/mobilebroadband/network-cost-information-element

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/200
2019-10-01 13:37:50 +02:00
Thomas Haller
44193d3def gitlab-ci: workaround unit test failure for iproute2 bug in "ubuntu:devel"
"ubuntu:devel" ships iproute2 version "5.2.0-1ubuntu1". This has a well known
bug that prevents it from creating IP tunnels during the unit tests.

We already workaround that on Debian. Add the same workaround to match the
Ubuntu package.
2019-10-01 09:55:39 +02:00
Thomas Haller
2cff04ea09 build/meson: merge branch 'inigomartinez:meson-update'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/256
2019-10-01 09:49:41 +02:00
Iñigo Martínez
42a8533d5f meson: Remove devices tests' meson build files
The devices tests' meson build files include only the build of a
single executable file and its execution as a test unit.

This has been moved to the devices' main meson build files so this
files can be removed.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
05c7a77022 meson: Add missing "nm-bt-test" helper program
In 878d4963e a new `nm-bt-test` helper program was added. However,
although `autotools` build steps were included, meson build steps
were not.

This add meson's build steps.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
95abecb24d meson: Make use of gnome.mkenums_simple
There are different enum files created that make use of different
template files. However, `mkenums_simple` method allows the creation
of the same enum files without the need of template files.

The creation of the `nm-core-enum-types` and
`nm-core-tests-enum-types` use now `mkenums_simple` so template
files are now unnecessary.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
23b4dc5f77 meson: Rename variables related to pkg-config variables
Some variables belong to variables in their correspondent pkg-config
file.

These variables have been renamed to `dependency_variable` to
reflect the dependency and variables from pkg-config files they are
related to.

Some of these has also been fixed to use paths relative to
installation prefix.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
2172b885b4 meson: Improve the wwan test build file
The test unit name string is used in different place so it has been
replaced by a variable.

The `nm-service-providers.c` source file is appended by using a
`files` generated object.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
7e1aacaef2 meson: Remove tests related to check_so_symbols
These tests are already working since 19a718bc1 so `FIXME` comments
are not needed anymore.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
f0b7041063 meson: Improve api documentation build file
the `doc_module` variable has been removed. It was created because
its used in the autotools build file but actually `nm_name` variable
can be used easily.

Different objects used in the documentation target have been grouped
together.

The content file `version.xml`, and different build files are now
added properly.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
9d4e1ad5e3 meson: Improve libnm documentation build file
the `doc_module` variable has been removed. It was created because
its used in the autotools build file but actually `libnm_name`
variable can be used easily.

Different objects used in the documentation target have been grouped
together.

The content file `version.xml` is now added properly.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
700f6f6b5f meson: Improve Qt examples
Qt dependencies have been moved to the main build file where the
rest of dependencies are located. This makes it easier to find them.

The included directories has also reviewed and removed the
unnecessary ones.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
da40a6597f meson: Improve nmtui and libnmt-newt build
The dependencies used in the build of the `nmtui` executable and the
`libnmt-newt` library have been reviewed.

The compiler flags used in common by them has also been moved to a
`common_c_flags` variable to avoid any confussion.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
8a5a38f74a meson: Improve nmcli build
The dependencies used in the build of `nmcli` has been reviewed and
removed the unnecessary ones. The used compiler flags has also been
moved to one line.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
f5d74ce179 meson: Improve the client common test build file
The build file in the `client` `common` directory has been improved
by grouping the objects used in properties and by reviewing the
dependencies used by tests built. Finally the indentation has also
been fixed.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
83b760cf98 meson: Improve the client common build file
The build file in the `client` `common` directory has been improved
by grouping the objects used in properties and by reviewing the
dependencies used by libraries built in the file.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
25bb43f4db meson: Ease the use of the libnm-libnm-core-intern library
The dependency for the `libnm-libnm-core-intern` library has been
recovered to ease its use.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
60b2c8683f meson: Make one liner compiler flag 2019-10-01 09:49:33 +02:00
Iñigo Martínez
096748a196 meson: Rename cflags variable
The variable holding the compiler flags, `cflags`, has been renamed
to `c_flags` to be consistent with the rest of build files.

Different objects used in the `test-dispatcher-envp` target
have been grouped together.

The dependency over the `libnm` library has been removed as it is
unnecessary.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
70da6993c8 meson: Improve dispatcher test build file
Different objects used in the `test-dispatcher-envp` target
have been grouped together.

The dependency over the `libnm` library has been removed as it is
unnecessary.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
4e85fdcdb7 meson: Avoid the creation of extra variables
Extra variables are used for sources of targets in the `dispatcher`
build file. These have been moved to the `source` parameter because
using them directly avoiding the creation of extra variablse doesn't
hurt readibility.

The compiler flags `cflags` variable has also been renamed to be
consistent with the rest of build files.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
c5e80a23fe meson: Remove extra new line 2019-10-01 09:49:33 +02:00
Iñigo Martínez
509706b62b meson: Avoid the creation of an extra variable
An extra variable is used for sources of
`libnm-settings-plugin-ifupdown` module. However, it only contains
one source file and using it directly avoiding the creation of the
extra variable doesn't hurt readibility.
2019-10-01 09:49:33 +02:00