Commit Graph

22377 Commits

Author SHA1 Message Date
Thomas Haller
08bc38cb5c platform/wifi: don't use __u32 type in "nm-wifi-utils-nl80211.c"
Also, use unsignd (guint) variable as index. That is fine, because
nla_len() returns a (signed) int.
2019-02-22 10:05:00 +01:00
Thomas Haller
60e4595101 platform: cleanup parsing of RTA_MULTIPATH in _new_from_nl_route()
I think the code before was correct. At the very least because
we only run the while-loop at most once because multipath routes
are not supported.

However, it seems odd that the while loop checks for

    "tlen >= rtnh->rtnh_len"

but later we do

    "tlen -= RTNH_ALIGN (rtnh->rtnh_len)"

Well, arguably, tlen itself is aligned to 4 bytes (as kernel sends
the netlink message that way). So, it was indeed fine.

Still, confusing. Try to check more explicitly for the buffer sizes.
2019-02-22 10:05:00 +01:00
Thomas Haller
1b7e89ad7d platform: use nla_data_as() at some places
nla_data_as() has a static assertion that casting to the pointer is
valid (regarding the alignment of the structure). It also contains
an nm_assert() that the data is in fact large enough.

It's safer, hence prefer it a some places where it makes sense.
2019-02-22 10:04:48 +01:00
Thomas Haller
f7e4310a0f platform: use nm_auto_nlmsg cleanup macro instead of explict nlmsg_free() 2019-02-22 09:58:09 +01:00
Thomas Haller
a41ca7cc89 platform: use nlmsg_append_struct() macro instead of nlmsg_append()
- nlmsg_append_struct() determines the size based on the argument.
  It avoids typing, but more importantly: it avoids typing redundant
  information (which we might get wrong).

- also, declare the structs as const, where possible.
2019-02-22 09:58:09 +01:00
Thomas Haller
98e42a4552 platform: prettify parsing MACSec from netlink 2019-02-22 09:58:09 +01:00
Thomas Haller
dca6d24aab platform: drop READ_STAT64() macro from _new_from_nl_link()
It doesn't make it easier to read. Also, the code comment points
out something rather obvious, as we later use unaligned API to access the
fields.
2019-02-22 09:58:09 +01:00
Thomas Haller
9cc592ae05 platform: don't use memset() to initialize variable in _new_from_nl_route() 2019-02-22 09:58:09 +01:00
Thomas Haller
495cfd9129 platform: sort #include in "nm-linux-platform.h" 2019-02-22 09:58:09 +01:00
Thomas Haller
451073e5bb platform: use nla_get_be64() helper 2019-02-22 09:58:09 +01:00
Thomas Haller
815e0329c0 platform/netlink: cleanup nlmsg_append() and add nlmsg_append_struct() macro 2019-02-22 09:58:09 +01:00
Thomas Haller
020000433b platform/netlink: add nla_data_as() macro
This macro casts the return pointer and asserts that the netlink attribute
is suitably large.
2019-02-22 09:58:09 +01:00
Thomas Haller
5920f187d3 platform/netlink: add more RTM message types in to-string function nl_nlmsghdr_to_str() 2019-02-22 09:58:09 +01:00
Thomas Haller
bc7bf3c861 platform/netlink: add nla_get_be64() helper 2019-02-22 09:58:09 +01:00
Thomas Haller
fac357ac8b platform/netlink: require valid nla argument for nla_get_u64()
nla_get_u64() was unlike all other nla_get_u*() implementations, in that it
would allow for a missing/invalid nla argument, and return 0.

Don't do this. For one, don't behave different than other getters.
Also, there really is no space to report errors. Hence, the caller must
make sure that the attribute is present and suitable -- like for other
nla_get_*() functions.

None of the callers relied on being able to pass NULL attribute.

Also, inline the function and use unaligned_read_ne64(). That is our
preferred way for reading unaligned data, not memcpy().
2019-02-22 09:58:09 +01:00
Thomas Haller
af13eb6cac platform/netlink: add assertions for nla_get_*() functions
These are only nm_assert(), meaning on non-DEBUG builds they
are not enabled.

Callers are supposed to first check that the netlink attribute
is suitable. Hence, we just assert.
2019-02-22 09:58:09 +01:00
Thomas Haller
5044c33ead platform/netlink: use designated initializer in nlmsg_alloc_size() 2019-02-22 09:58:09 +01:00
Thomas Haller
f7df8fda1a platform/netlink: assert for valid policy for string attribute in validate_nla
The policy for strings must indicate a minlen of at least 1.

Everything else is a bug, because the policy contains invalid
data -- and is determined at compile-time.
2019-02-22 09:58:09 +01:00
Thomas Haller
82e31b2816 platform/netlink: cleanup nla_memcpy()
- use size_t arguments for the memory sizes. While sizes from netlink
  API currently are int typed and inherrently limited, use the more
  appropriate data type.

- rename the arguments. The "count" is really the size of the
  destination buffer.

- return how many bytes we wanted to write (like g_strlcpy()).
  That makes more sense than how many bytes we actually wrote
  because previously, we could not detect truncation.
  Anyway, none of the callers cared about the return-value either
  way.
2019-02-22 09:58:09 +01:00
Thomas Haller
b080146cc6 platform/netlink: cleanup nla_strlcpy()
- let nla_strlcpy() return how many bytes we would like to have
  copied. That way, the caller could detect string truncation.
  In practice, no caller cared about that.

- the code before would also fill the entire buffer with zeros first,
  like strncpy(). We still do that. However, only copy the bytes up
  to the first NUL byte. The previous version would have copied
  "a\0b\0" (with srclen 4) as "a\0b". Strip all bytes after the
  first NUL character from src. That seems more correct here.

- accept nla argument as %NULL.
2019-02-22 09:58:09 +01:00
Thomas Haller
6c24846929 platform/trivial: coding style fixes/whitespace 2019-02-22 09:58:09 +01:00
Thomas Haller
6f8208c0d4 platform/netlink: cleanup nla_parse*() code by using safer macros
- drop explicit MAX sizes like

      static const struct nla_policy policy[IFLA_INET6_MAX+1] = {

  The compiler will deduce that.

  It saves redundant information (which is possibly wrong). Also,
  the max define might be larger than we actually need it, so we
  just waste a few bytes of static memory and do unnecesary steps
  during validation.

  Also, the compiler will catch bugs, if the array size of policy/tb
  is too short for what we access later (-Warray-bounds).

- avoid redundant size specifiers like:

      static const struct nla_policy policy[IFLA_INET6_MAX+1] = {
      ...
      struct nlattr *tb[IFLA_INET6_MAX+1];
      ...
      err = nla_parse_nested (tb, IFLA_INET6_MAX, attr, policy);

- use the nla_parse*_arr() macros that determine the maxtype
  based on the argument types.

- move declaration of "static const struct nla_policy policy" variable
  to the beginning, before auto variables.

- drop unneeded temporay error variables.
2019-02-22 09:58:09 +01:00
Thomas Haller
cf22d28c2e platform/netlink: add nla_parse* macros that safely determine the max-type
The common idiom is to stack allocate the tb array. Hence,
the maxtype is redundant. Add macros that autodetect the
maxtype based on the C type infomation.

Also, there is a static assertion that the size of the policy
(if provided) matches.
2019-02-22 09:58:09 +01:00
Thomas Haller
6245569c6d platform/netlink: cleanup unnecessary "goto out" from nla_parse() 2019-02-22 09:58:09 +01:00
Thomas Haller
d8727f6aa9 platform/netlink: fix return value of nla_get_s8() 2019-02-22 09:58:09 +01:00
Thomas Haller
7f1865cad9 platform/wifi: fix size check for parsing netlink attribute NL80211_BSS_BSSID 2019-02-22 09:58:09 +01:00
Thomas Haller
a4cff10ceb platform: fix error handling for creating nlmsg in do_request_all_no_delayed_actions()
In practice, we don't fail to create the nlmsg, because in glib
malloc() cannot fail and we always create large enough buffers.

Anyway, handle the error correctly, and reduce the in-progress
counter again.
2019-02-22 09:58:09 +01:00
Thomas Haller
106e4ebc13 platform/netlink: fix _genl_parse_getfamily() for checking error code from genlmsg_parse()
Errors are negative numbers.

This had no effect however, because currently genlmsg_parse() won't ever return
positive values.
2019-02-22 09:58:09 +01:00
Thomas Haller
98e6abb5a0 shared: add nm_ip_addr_set_from_untrusted() helper
Will be used later. The point is to set an IP address from
unvalidated/untrusted input (that is, the data length might
not match the address-family).

Will be used later when parsing netlink attributes.
2019-02-22 09:58:09 +01:00
Thomas Haller
0fdfe89f45 shared: add nm_hash_update_valp() helper macro
Add a macro for hashing that takes a pointer and the size is
automatically determined by sizeof(*p).
2019-02-22 09:58:09 +01:00
Thomas Haller
014d6a2c78 shared/tests: add test for unaligned reads 2019-02-22 09:58:09 +01:00
Thomas Haller
fefb965cfe libnm: fix leak in nm_client_add_and_activate_connection{2,_async}()
Detected via valgrind:

  $ ./tools/run-nm-test.sh -m -v libnm/tests/test-nm-client -p /libnm/active-connections

Fixes: fbb038af5e
2019-02-22 08:14:01 +01:00
Thomas Haller
b7d4ad8547 wifi-p2p: drop WiFi-P2P "group-owner" property from D-Bus API and libnm
It's not yet implemented server-side.

Until it is clear that we need this property and until it is implemented,
drop it again from public API.

See-also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/80#note_118004
2019-02-21 15:34:55 +01:00
Thomas Haller
5106d7290b cli/tests: fix tests after adding polkit action for Wi-Fi scans
Fixes: 243af16c5b
2019-02-21 15:33:28 +01:00
Jonathan Kang
243af16c5b Add polkit action for Wi-Fi scans
Previously, Wi-Fi scans uses polkit action
"org.freedesktop.NetworkManager.network-control". This is introduced
in commit 5e3e19d0. But in a system with restrict polkit rules, for
example "org.freedesktop.NetworkManager.network-control" was set as
auth_admin. When you open the network panel of GNOME Control Center, a
polkit dialog will keep showing up asking for admin password, as GNOME
Control Center scans the Wi-Fi list every 15 seconds.

Fix that by adding a new polkit action
"org.freedesktop.NetworkManager.wifi.scan" so that distributions can
add specific rule to allow Wi-Fi scans.

[thaller@redhat.com: fix macro in "shared/nm-common-macros.h"]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/68
2019-02-21 13:49:17 +01:00
Thomas Haller
696cf38f45 supplicant: avoid G_VARIANT_BUILDER_INIT() from glib 2.50
G_VARIANT_BUILDER_INIT() was only added in glib 2.50, hence we cannot use
it.

Maybe nm-glib.h should provide a compat macro, but the macro relies
on the magic number GVSB_MAGIC_PARTIAL, which is private to glib.
It's not clear that we can savely provide such a compat implementation
for older glib variants.

Fixes: 642f15f2f6
2019-02-21 13:27:34 +01:00
Thomas Haller
d10024684f cli: fix generated documentation
Fixes: 8ed7aef26d
2019-02-21 10:19:11 +01:00
Thomas Haller
229b4fdd81 wifi-p2p: merge branch 'benzea/WFDIEs'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/125

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/84
2019-02-21 10:11:25 +01:00
Benjamin Berg
8fd5505ed5 device: Set WFD IEs when connecting to P2P device
Set the WFD IEs before trying to connect to a P2P device. Reset the
value when cancelling or when disconnecting.
2019-02-21 10:10:20 +01:00
Benjamin Berg
642f15f2f6 supplicant: Add API to set WFD IEs
This API allows setting the global WFDIEs property of wpa_supplicant.
Ideally it would be better if this property was per-device, but this is
a limitation of wpa_supplicant.
2019-02-21 10:10:20 +01:00
Benjamin Berg
3d12dbc0a7 Remove WFD IEs property from P2P device
While this can be considered a property of the P2P device, the API will
require setting it through the settings when activating a connection. As
such, having a (read only) property on the device is not very useful, so
remove it again.
2019-02-21 10:10:20 +01:00
Benjamin Berg
8ed7aef26d core/setting-wifi-p2p: Add WFD IEs property to P2P settings
This is a protocol specific extension to Wi-Fi frames which need to be
set in certain conditions. The P2P device will use this to update the
corresponding wpa_supplicant property.
2019-02-21 10:10:20 +01:00
Benjamin Berg
181326bac7 core/setting-wifi-p2p: Use correct constant for wps-method property
The equivalent constant from the wireless settings was used. Simply
switch to use the P2P specific define.
2019-02-21 10:10:20 +01:00
Beniamino Galvani
b5efcf08f4 all: move nm_utils_bin2hexstr_full() to shared
reuse++
2019-02-21 09:36:17 +01:00
Thomas Haller
d2144019d8 keyfile: merge branch 'th/keyfile-cleanup'
https://github.com/NetworkManager/NetworkManager/pull/297
2019-02-21 09:19:00 +01:00
Thomas Haller
045d1d350f keyfile: cleanup _internal_write_connection()
- use gs_free instead of explicit free().

- use nm_streq*() instead of strcmp().

- move deletion of existing file after we successfully wrote
  the new file.

- add parameter existing_path_readonly, to avoid to overwrite or
  delete the existing path (if it exists). This is still mostly unused,
  but will be necessary when we have read-only directories.
2019-02-21 09:17:58 +01:00
Thomas Haller
f324091557 keyfile: use nm_utils_file_is_in_path() for detecting required rename 2019-02-21 09:17:58 +01:00
Thomas Haller
6c07faa013 shared/nm-glib: add our own g_steal_pointer() macro to shadow the one from glib
g_steal_pointer() as provided by glib improved significantly. Nowadays it
casts the return type via the non-standard typeof() operator.

But this useful feature is only enabled with

    GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58

which NetworkManager does not set.

This macro is hardly rocket science. Always provide our own
implementation, that always does the casting (we rely on gcc/clang
to support typeof() already at many places).
2019-02-21 07:22:36 +01:00
Thomas Haller
a13b2397de ifcfg-rh: don't rely on g_steal_pointer() returning a void pointer
Next, we will update g_steal_pointer() to cast the return type
to the type of the argument. Hence, this automatic conversion
from setting (sub) classes to NMSetting no longer works.

Add an explict cast.
2019-02-21 07:22:36 +01:00
Beniamino Galvani
787a18c467 systemd: merge branch systemd into master 2019-02-20 19:18:52 +01:00