Commit graph

1371 commits

Author SHA1 Message Date
luz.paz
f985b6944a docs: misc. typos
Found via `codespell -q 3 --skip="*.po"`

https://github.com/NetworkManager/NetworkManager/pull/203
2018-09-15 09:08:03 +02:00
Thomas Haller
7943b2bb2e platform/netlink: cleanup error number handling
Rename variables for the error number. Commonly the naming
is:

  - errno: the error number from <errno.h> itself
  - errsv: a copy of errno
  - nlerr: a netlink error number
  - err: an error code, but not a errno/errsv and not
      a netlink error number.

(cherry picked from commit f4de941d98)
2018-09-12 11:20:06 +02:00
Thomas Haller
b25e5625ac platform/trivial: adjust coding style in nm-netlink.c
(cherry picked from commit ac73c6f019)
2018-09-12 11:20:05 +02:00
Thomas Haller
62d14e1884 platform/wireguard: rework parsing wireguard links in platform
- previously, parsing wireguard genl data resulted in memory corruption:

  - _wireguard_update_from_allowedips_nla() takes pointers to

      allowedip = &g_array_index (buf->allowedips, NMWireGuardAllowedIP, buf->allowedips->len - 1);

    but resizing the GArray will invalidate this pointer. This happens
    when there are multiple allowed-ips to parse.

  - there was some confusion who owned the allowedips pointers.
    _wireguard_peers_cpy() and _vt_cmd_obj_dispose_lnk_wireguard()
    assumed each peer owned their own chunk, but _wireguard_get_link_properties()
    would not duplicate the memory properly.

- rework memory handling for allowed_ips. Now, the NMPObjectLnkWireGuard
  keeps a pointer _allowed_ips_buf. This buffer contains the instances for
  all peers.
  The parsing of the netlink message is the complicated part, because
  we don't know upfront how many peers/allowed-ips we receive. During
  construction, the tracking of peers/allowed-ips is complicated,
  via a CList/GArray. At the end of that, we prettify the data
  representation and put everything into two buffers. That is more
  efficient and simpler for user afterwards. This moves complexity
  to the way how the object is created, vs. how it is used later.

- ensure that we nm_explicit_bzero() private-key and preshared-key. However,
  that only works to a certain point, because our netlink library does not
  ensure that no data is leaked.

- don't use a "struct sockaddr" union for the peer's endpoint. Instead,
  use a combintation of endpoint_family, endpoint_port, and
  endpoint_addr.

- a lot of refactoring.
2018-09-07 11:24:17 +02:00
Thomas Haller
cb23779e0a platform/trivial: rename local variables for nla_policy/nlattr
We have such variables with similar purpose at various places.
Name them all the same.
2018-09-07 11:24:17 +02:00
Thomas Haller
f18fb7745a platform: fix resusing ext-data from cache in _new_from_nl_link() 2018-09-07 11:24:17 +02:00
Thomas Haller
989bdaec63 platform/trivial: move code in nm-linux-platform.c around
Move NMLinuxPlatformPrivate earlier.

In the past, I moved the declaration of NMLinuxPlatformPrivate
after utility functions which are independent from platform
instance.

However, parsing netlink messages actually requires
NMLinuxPlatformPrivate, because we want to access the "genl"
socket.

So, move the types to the beginning of the file, like we do
for most other source files.
2018-09-07 11:24:17 +02:00
Thomas Haller
f99ee135d1 platform: let _lookup_cached_link() also return cached links that are not in netlink
The _lookup_cached_link() function, should not skip over links which are
currently in the cache, but not in netlink. Instead, let the callers
skip them, as they see fit.

No change in behavior, because the few callers now explicitly check
for this.
2018-09-07 11:24:17 +02:00
Thomas Haller
7042cd5e19 platform: cleanup error paths
- drop "goto error_label" in favor of returning right away.
  At most places, there was no need to do any cleanup or
  the cleanup is handled via nm_auto().

- adjust the return types of wireguard functions to return
  a boolean success/failure, instead of some error code which
  we didn't use.

- the change to _wireguard_get_link_properties() is intentional.
  This was wrong previously, because in _wireguard_get_link_properties()
  obj is always a newly created instance, and never has a genl
  family ID set. This will be improved later.
2018-09-07 11:24:17 +02:00
Thomas Haller
9740d3a68c platform/netlink: assert that callbacks don't return positive error code 2018-09-07 11:24:17 +02:00
Thomas Haller
a30dd1eff0 platform/netlink: drop ref-counting for "struct nl_msg"
It was unused.
2018-09-07 11:24:17 +02:00
Thomas Haller
e9cf8b196d platform/trivial: reorder code 2018-09-07 11:24:17 +02:00
Thomas Haller
5fd4ca8a5b platform/netlink: drop nlmsg_alloc_inherit() function
It's only used internally, and it seems not very useful to have.
As it is confusing to have multiple functions for doing something
similar, drop it -- since it's not really used. I also cannot imagine
a good use-case for it.
2018-09-07 11:24:17 +02:00
Thomas Haller
09aaeb83b7 platform: fix printing all-info about NMPObjectLink instances
When we print info about the link, we also want to print
info about the referenced lnk instance, which commonly contains
link-specific data.

For NMP_OBJECT_TO_STRING_PUBLIC this was done correctly, by
calling to-string of public fields on the lnk object.

For NMP_OBJECT_TO_STRING_ALL, we wrongly just delegated to the
public to-string function, this means, for the lnk object we
would not print all fields.

Fix that.
2018-09-07 11:24:17 +02:00
Thomas Haller
085a369446 all: avoid g_memdup()
By using nm_memdup().

Except in shared/nm-utils/nm-compat.c, which may not include
"shared/nm-utils/nm-shared-utils.h".
2018-09-07 11:24:17 +02:00
Thomas Haller
98f28ddf2e platform/netlink: fix nl_errno() to get absolute error number value 2018-09-07 11:24:17 +02:00
Thomas Haller
f3f5d5c900 platform/trivial: add FIXME comment to use new ethtool API to set link settings 2018-09-06 10:30:51 +02:00
Beniamino Galvani
0e367d40f4 platform: fix typo
progess -> progress
2018-09-05 16:13:59 +02:00
Thomas Haller
ff163d9d0d shared: move file-get-contents and file-set-contents helper to shared/
These functions are not specific to "src/". Also, they will be needed
by outside of "src/" soon.
2018-09-04 07:38:30 +02:00
Thomas Haller
6b813b904f core: extend nm_utils_*_get_contents() to zero temporary memory
When reading a file, we may allocate intermediate buffers (realloc()).
Also, reading might fail halfway through the process.

Add a new flag that makes sure that this memory is cleared. The
point is when reading secrets, that we don't accidentally leave
private sensitive material in memory.
2018-09-04 07:38:30 +02:00
Thomas Haller
3b5f8c91fe build: always define NM_MORE_LOGGING define and don't check with #ifdef
Using '#ifdef' is generally error prone. It's better to always define
a define and check for it explicitly. This way, the compiler can issue
a warning if the define does not exist.

Also, note how meson would always define NM_MORE_LOGGING, possibly to
"0". That means, for meson, we unintentionally always enabled more
logging because the define was always present.

Fix that.
2018-08-27 17:49:29 +02:00
Thomas Haller
5cd4e6f3e6 wifi: don't use GBytesArray for NMWifiAP's ssid
GBytes makes more sense, because it's immutable.

Also, since at other places we use GBytes, having
different types is combersome and requires needless
conversions.

Also:

- avoid nm_utils_escape_ssid() instead of _nm_utils_ssid_to_string().
  We use nm_utils_escape_ssid() when we want to log the SSID. However, it
  does not escape newlines, which is bad.

- also no longer use nm_utils_same_ssid(). Since it no longer
  treated trailing NUL special, it is not different from
  g_bytes_equal().

- also, don't use nm_utils_ssid_to_utf8() for logging anymore.
  For logging, _nm_utils_ssid_escape_utf8safe() is better because
  it is loss-less escaping which can be unambigously reverted.
2018-08-22 10:49:34 +02:00
Thomas Haller
39efc65096 platform: drop unused virtual function NMPlatformClass.wifi_get_ssid() 2018-08-22 10:49:34 +02:00
Lubomir Rintel
20d905e590 platform: if AF_INET6 is not available, don't warn
These should be logged on DEBUG level:

  <warn>  platform-linux: do-change-link[2]: failure changing link: failure 97 (Address family not supported by protocol)
  <warn>  device (wlo1): failed to enable userspace IPv6LL address handling (unspecified)

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/10
2018-08-20 19:16:38 +02:00
Thomas Haller
da109a291c all/ethtool: add support for all currently supported kernel features
As of upstream kernel v4.18-rc8.

Note that we name the features like they are called in ethtool's
ioctl API ETH_SS_FEATURES.

Except, for features like "tx-gro", which ethtool utility aliases
as "gro". So, for those features where ethtool has a built-in,
alternative name, we prefer the alias.

And again, note that a few aliases of ethtool utility ("sg", "tso", "tx")
actually affect more than one underlying kernel feature.

Note that 3 kernel features which are announced via ETH_SS_FEATURES are
explicitly exluded because kernel marks them as "never_changed":

    #define NETIF_F_NEVER_CHANGE (NETIF_F_VLAN_CHALLENGED | \
                                  NETIF_F_LLTX | NETIF_F_NETNS_LOCAL)
2018-08-10 10:38:19 +02:00
Thomas Haller
c085b6e3a7 platform/ethtool: add code to get/set offload features via ethtool
Also, add two more features "tx-tcp-segmentation" and
"tx-tcp6-segmentation". There are two reasons for that:

 - systemd-networkd supports setting these two features,
   so lets support them too (apparently they are important
   enough for networkd).

 - these two features are already implicitly covered by "tso".
   Like for the "ethtool" program, "tso" is an alias for several
   actual features. By adding two features that are already
   also covered by an alias (which sets multiple kernel names
   at once), we showcase how aliases for the same feature can
   coexist. In particular, note how setting
   "tso on tx-tcp6-segmentation off" will behave as one would
   expect: all 4 tso features covered by the alias are enabled,
   except that particular one.
2018-08-10 10:38:19 +02:00
Thomas Haller
14f963cde3 platform/mii: use SocketHandle also for nmp_utils_mii_supports_carrier_detect()
There is little difference in practice because there is only one caller.
Still re-use the SocketHandle also for mii. If only, to make it clear
that SocketHandle is not only suitable for ethtool, but also mii.
2018-08-10 10:38:19 +02:00
Thomas Haller
bdd9f7482c platform/ethtool: add SocketHandle to reuse socket for ethtool requests
Previously, each call to ethtool_get() would resolve the ifindex and
create a new socket for the ethtool request.

This is partly done, because ethtool only supports making requests by
name. Since interfaces can be renamed, this is inherrently racy. So,
we want to fetch the latest name shortly before making the request.

Some functions like nmp_utils_ethtool_supports_vlans() require multiple
ioctls. And next, we will introduce more ethtool functions, that make an
even larger number of individual requests.

Add a simple SocketHandle struct, to create the socket once and reuse
it for multiple requests. This is still entirely internal API in
"nm-platform-utils.c".
2018-08-10 10:38:19 +02:00
Thomas Haller
29266e0086 platform/ethtool: split functions for ETHTOOL_GSTRINGS
ethtool_get_stringset() will be used later, independently.

Also, don't trust and ensure that the block of strings
returned by ETHTOOL_GSTRINGS are NUL terminated.
2018-08-10 10:38:19 +02:00
Thomas Haller
b7bdde6e0b platform/tests: increase wait timeout in test_cleanup_internal()
Seems this assertion still can fail. Dunno, maybe the timeout was just too
short. Increase it.
2018-08-10 10:38:19 +02:00
Thomas Haller
852abf3d3d all/style: write elvis operator ?: without space
By far most of the time, we write "?:" and not "? :". Adjust
the few places that don't.
2018-08-09 17:06:18 +02:00
Javier Arteaga
edd5cf1a3c platform: rename instances of Wireguard to WireGuard
Respect WireGuard canonical capitalization on identifiers.
As per discussion on:
https://github.com/NetworkManager/NetworkManager/pull/162
2018-08-06 08:34:27 +02:00
Javier Arteaga
6ea0cd1300 platform: put wireguard_family_id in NMPObjectLink
Limit the lifetime of the cached genl family ID to the lifetime of the
interface so we correctly handle module reloads.

https://github.com/NetworkManager/NetworkManager/pull/161
2018-07-13 10:38:42 +02:00
Beniamino Galvani
8720dd3df1 platform: add support for changing VF attributes 2018-07-11 16:16:22 +02:00
Beniamino Galvani
7df3333879 platform: allow setting drivers-autoprobe on SR-IOV PFs
It is possible to tell kernel not to automatically autoprobe drivers
for VFs. This is useful, for example, if the VF must be used by a VM.
2018-07-11 16:16:22 +02:00
Thomas Haller
e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Thomas Haller
4e4b363cc2 platform: reduce logging level for wireguard messages 2018-07-09 11:42:35 +02:00
Thomas Haller
67f50f64d9 platform: fix -Werror=maybe-uninitialized in _new_from_nl_link()
Fixes: 0827d4c2e4
2018-07-09 11:36:43 +02:00
Lubomir Rintel
b200e5d8ed platform/linux: drop an unused variable
Fixes: 2ac5860a06
2018-07-09 11:32:09 +02:00
Lubomir Rintel
79ddef403c merge: branch 'wireguard-platform' of https://github.com/jbeta/NetworkManager
https://github.com/NetworkManager/NetworkManager/pull/143
2018-07-09 11:08:12 +02:00
Beniamino Galvani
09a868a24e platform: add ip6gre/ip6gretap tunnels support
Add platform support for IP6GRE and IP6GRETAP tunnels. The former is a
virtual tunnel interface for GRE over IPv6 and the latter is the L2
variant.

The platform code internally reuses and extends the same structure
used by IPv6 tunnels.
2018-07-02 17:55:14 +02:00
Beniamino Galvani
4c2862b958 platform: add gretap tunnels support
Add platform support for GRETAP tunnels (Virtual L2 tunnel interface
GRE over IPv4) partially reusing the existing GRE code.
2018-07-02 17:55:14 +02:00
Beniamino Galvani
cdad8c6df9 platform: uniform logging for link-add functions
Print all the platform-lnk attributes in a consistent manner.
2018-07-02 17:55:14 +02:00
Beniamino Galvani
4b46c74af7 platform: fix printing macvtap links 2018-07-02 17:55:14 +02:00
Beniamino Galvani
0d5e712f73 platform: fix linux-platform link_*_add() functions signature
They should return a gboolean, not an int.
2018-07-02 17:55:14 +02:00
Beniamino Galvani
2ac5860a06 platform: avoid double log messages
Certain platform operations are logged both in nm-platform.c and
nm-linux-platform.c, resulting in duplicate messages.  Drop log prints
from the latter.
2018-07-02 17:55:14 +02:00
Beniamino Galvani
052d76cf82 platform: fix attribute size in link_gre_add()
Input and output flags are 16 bit.

Fixes: 91bf0efaa7
2018-07-02 17:55:14 +02:00
Javier Arteaga
0827d4c2e4 platform: add support for WireGuard links
Add support for a new wireguard link type to the platform code. For now
this only covers querying existing links via genetlink and parsing them
into platform objects.
2018-07-01 14:52:46 +02:00
Beniamino Galvani
4888ee7e83 platform: change temp variable name in NLA_PUT_TYPE()
__tmp clashes with htole16() on s390x.

Fixes: 4120ad2431

https://github.com/NetworkManager/NetworkManager/pull/151
2018-06-29 10:24:19 +02:00
Javier Arteaga
f92af371e6 platform-linux: add support function for genl
Resolves Generic Netlink family ID by name.
2018-06-28 16:04:43 +01:00