Commit Graph

23466 Commits

Author SHA1 Message Date
Beniamino Galvani
db46d9b823 merge: branch 'bg/restore-ip6-addr-link-up-rh1548237'
https://bugzilla.redhat.com/show_bug.cgi?id=1548237
2019-05-08 13:36:52 +02:00
Beniamino Galvani
18d2edfaa1 device: fix intersecting IPv6 configurations
If the link is down we shouldn't drop the link-local address from
configuration as it wasn't removed by user but by kernel.
2019-05-08 13:35:59 +02:00
Beniamino Galvani
d0b16b9283 device: unconditionally reapply IP configuration on link up
Consider the situation in which ipv4.method=auto and there is an
address configured. Also, the DHCP timeout is long and there is no
DHCP server. If the link is brought down temporarily, the prefix route
for the static address is lost and not restored by NM because we
reapply the IP configuration only when the IP state is DONE.

The same can happen also for IPv6, but in that case also static IPv6
addresses are lost.

We should always reapply the IP configuration when the link goes up.
2019-05-08 13:35:59 +02:00
Beniamino Galvani
4735d6764a all: fix typos (milli seconds -> milliseconds) 2019-05-08 13:35:59 +02:00
Thomas Haller
5d851c0f9c libnm,platform: merge branch 'th/various-cleanup-platform-libnm'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/131
2019-05-08 09:51:05 +02:00
Thomas Haller
f2ae994b23 device/trivial: add comment about lifetime of "kind" in tc_commit()
In general, all fields of public NMPlatform* structs must be
plain/simple. Meaning: copying the struct must be possible without
caring about cloning/duplicating memory.
In other words, if there are fields which lifetime is limited,
then these fields cannot be inside the public part NMPlatform*.

That is why

  - "NMPlatformLink.kind", "NMPlatformQdisc.kind", "NMPlatformTfilter.kind"
    are set by platform code to an interned string (g_intern_string())
    that has a static lifetime.

  - the "ingress_qos_map" field is inside the ref-counted struct NMPObjectLnkVlan
    and not NMPlatformLnkVlan. This field requires managing the lifetime
    of the array and NMPlatformLnkVlan cannot provide that.

See also for example NMPClass.cmd_obj_copy() which can deep-copy an object.
But this is only suitable for fields in NMPObject*. The purpose of this
rule is that you always can safely copy a NMPlatform* struct without
worrying about the ownership and lifetime of the fields (the field's
lifetime is unlimited).

This rule and managing of resource lifetime is the main reason for the
NMPlatform*/NMPObject* split. NMPlatform* structs simply have no mechanism
for copying/releasing fields, that is why the NMPObject* counterpart exists
(which is ref-counted and has a copy and destructor function).

This is violated in tc_commit() for the "kind" strings. The lifetime
of these strings is tied to the setting instance.

We cannot intern the strings (because these are arbitrary strings
and interned strings are leaked indefinitely). We also cannot g_strdup()
the strings, because NMPlatform* is not supposed to own strings.

So, just add comments that warn about this ugliness.

The more correct solution would be to move the "kind" fields inside
NMPObjectQdisc and NMPObjectTfilter, but that is a lot of extra effort.
2019-05-07 21:05:12 +02:00
Thomas Haller
9eefe27a1c device: don't rely on nm_platform_link_get_ifindex() returning 0
While nm_platform_link_get_ifindex() is documented to return 0 if the device
is not found, don't rely on it. Instead, check that a valid(!) ifindex was
returned, and only then set the ifindex. Otherwise leave it at zero. There
is of course no difference in practice, but we generally treat invalid ifindexes
as <= 0, so it's not immediately clear what nm_platform_link_get_ifindex()
returns to signal no device.
2019-05-07 20:58:17 +02:00
Thomas Haller
9399297a82 device/trivial: add space between macro name and arguments and vertically align lines
Also calling macros we commonly put a space between the macro name and
the parenthesis.

Also align the parameters. Otherwise it's hard to read for me.
2019-05-07 20:58:17 +02:00
Thomas Haller
04bd404dff platform: merge _add_action(), _add_action_simple() and _add_action_mirred() into _nl_msg_new_tfilter()
There is only one caller, hence it's simpler to see it all in one place.
I prefer this, because then I can read the code top to bottom and
see what's happening, without following helper functions.

Also, this way we can "reuse" the nla_put_failure label and assertion. Previously,
if the assertion was hit we would not rewind the buffer but continue
constructing the message (which is already borked). Not that it matters
too much, because this was on an "failed-assertion" code path.
2019-05-07 20:58:17 +02:00
Thomas Haller
3784a2a2ec platform: assert for out-of-memory in netlink code
These lines can be reached if the allocated buffer is too
small to hold the netlink message. That is actually a bug
that we need to fix. Assert.
2019-05-07 20:58:17 +02:00
Thomas Haller
36d6aa3bcd platform: use bool bitfields in NMPlatformActionMirred structure
Arguably, the structure is used inside a union with another (larger)
struct, hence no memory is saved.

In fact, it may well be slower performance wise to access a boolean bitfield
than a gboolean (int).

Still, boolean fields in structures should be bool:1 bitfields for
consistency.
2019-05-07 20:58:17 +02:00
Thomas Haller
666d58802b libnm: rename "memory" parameter of fq_codel QDisc to "memory_limit"
Kernel calls the netlink attribute TCA_FQ_CODEL_MEMORY_LIMIT. Likewise,
iproute2 calls this "memory_limit".

Rename because TC parameters are inherrently tied to the kernel
implementation and we should use the familiar name.
2019-05-07 20:58:17 +02:00
Thomas Haller
973db2d41b platform: fix handling of default value for TCA_FQ_CODEL_CE_THRESHOLD
iproute2 uses the special value ~0u to indicate not to set
TCA_FQ_CODEL_CE_THRESHOLD in RTM_NEWQDISC. When not explicitly
setting the value, kernel treats the threshold as disabled.

However note that 0xFFFFFFFFu is not an invalid threshold (as far as
kernel is concerned). Thus, we should not use that as value to indicate
that the value is unset. Note that iproute2 uses the special value ~0u
only internally thereby making it impossible to set the threshold to
0xFFFFFFFFu). But kernel does not have this limitation.

Maybe the cleanest way would be to add another field to NMPlatformQDisc:

    guint32 ce_threshold;
    bool ce_threshold_set:1;

that indicates whether the threshold is enable or not.
But note that kernel does:

    static void codel_params_init(struct codel_params *params)
    {
    ...
            params->ce_threshold = CODEL_DISABLED_THRESHOLD;

    static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
                               struct netlink_ext_ack *extack)
    {
    ...
            if (tb[TCA_FQ_CODEL_CE_THRESHOLD]) {
                    u64 val = nla_get_u32(tb[TCA_FQ_CODEL_CE_THRESHOLD]);

                    q->cparams.ce_threshold = (val * NSEC_PER_USEC) >> CODEL_SHIFT;
            }

    static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb)
    {
    ...
            if (q->cparams.ce_threshold != CODEL_DISABLED_THRESHOLD &&
                nla_put_u32(skb, TCA_FQ_CODEL_CE_THRESHOLD,
                            codel_time_to_us(q->cparams.ce_threshold)))
                    goto nla_put_failure;

This means, kernel internally uses the special value 0x83126E97u to indicate
that the threshold is disabled (WTF). That is because

  (((guint64) 0x83126E97u) * NSEC_PER_USEC) >> CODEL_SHIFT == CODEL_DISABLED_THRESHOLD

So in kernel API this value is reserved (and has a special meaning
to indicate that the threshold is disabled). So, instead of adding a
ce_threshold_set flag, use the same value that kernel anyway uses.
2019-05-07 20:58:17 +02:00
Thomas Haller
46a904389b platform: fix handling of fq_codel's memory limit default value
The memory-limit is an unsigned integer. It is ugly (if not wrong) to compare unsigned
values with "-1". When comparing with the default value we must also use an u32 type.
Instead add a define NM_PLATFORM_FQ_CODEL_MEMORY_LIMIT_UNSET.

Note that like iproute2 we treat NM_PLATFORM_FQ_CODEL_MEMORY_LIMIT_UNSET
to indicate to not set TCA_FQ_CODEL_MEMORY_LIMIT in RTM_NEWQDISC. This
special value is entirely internal to NetworkManager (or iproute2) and
kernel will then choose a default memory limit (of 32MB). So setting
NM_PLATFORM_FQ_CODEL_MEMORY_LIMIT_UNSET means to leave it to kernel to
choose a value (which then chooses 32MB).

See kernel's net/sched/sch_fq_codel.c:

    static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
                             struct netlink_ext_ack *extack)
    {
    ...
            q->memory_limit = 32 << 20; /* 32 MBytes */

    static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
                               struct netlink_ext_ack *extack)
    ...
            if (tb[TCA_FQ_CODEL_MEMORY_LIMIT])
                    q->memory_limit = min(1U << 31, nla_get_u32(tb[TCA_FQ_CODEL_MEMORY_LIMIT]));

Note that not having zero as default value is problematic. In fields like
"NMPlatformIP4Route.table_coerced" and "NMPlatformRoutingRule.suppress_prefixlen_inverse"
we avoid this problem by storing a coerced value in the structure so that zero is still
the default. We don't do that here for memory-limit, so the caller must always explicitly
set the value.
2019-05-07 20:58:17 +02:00
Thomas Haller
b658e3da08 platform: fix nm_platform_qdisc_to_string()
When using nm_utils_strbuf_*() API, the buffer gets always moved to the current
end. We must thus remember and return the original start of the buffer.
2019-05-07 20:58:17 +02:00
Thomas Haller
a1099a1fab platform: use u32 netlink type for TCA_FQ_CODEL_ECN
In practice, there is no difference when representing 0 or 1 as signed/unsigned 32
bit integer. But still use the correct type that also kernel uses.

Also, the implicit conversation from uint32 to bool was correct already.
Still, explicitly convert the uint32 value to boolean in _new_from_nl_qdisc().
It's no change in behavior.
2019-05-07 20:58:17 +02:00
Thomas Haller
47d8bee113 platform: use NM_CMP_FIELD_UNSAFE() for comparing bitfield in nm_platform_qdisc_cmp()
"NM_CMP_FIELD (a, b, fq_codel.ecn == TRUE)" is quite a hack as it relies on
the implementation of the macro in a particular way. The problem is, that
NM_CMP_FIELD() uses typeof() which cannot be used with bitfields. So, the
nicer solution is to use NM_CMP_FIELD_UNSAFE() which exists exactly for bitfields
(it's "unsafe", because it evaluates arguments more than once as it avoids
the temporary variable with typeof()).

Same with nm_hash_update_vals() which uses typeof() to avoid evaluating
arguments more than once. But that again does not work with bitfields.
The "proper" way is to use NM_HASH_COMBINE_BOOLS().
2019-05-07 20:58:17 +02:00
Thomas Haller
438855e915 device: fix type of loop variable in tc_commit()
nqdiscs and ntfilters are unsigned integers. The loop variable must agree in
range and signedness.
2019-05-07 20:58:17 +02:00
Thomas Haller
86dc50d476 libnm: use macro and designated initializers for NMVariantAttributeSpec
I think initializing structs should (almost) be always done with designated
initializers, because otherwise it's easy to get the order wrong. The
problem is that otherwise the order of fields gets additional meaning
not only for the memory layout, but also for the code that initialize
the structs.

Add a macro NM_VARIANT_ATTRIBUTE_SPEC_DEFINE() that replaces the other
(duplicate) macros. This macro also gets it right to mark the struct as
const.
2019-05-07 20:58:17 +02:00
Thomas Haller
4e3955e6dd libnm: mark NMVariantAttributeSpec pointers as const
This actually allows the compiler/linker to mark the memory as read-only and any
modification will cause a segmentation fault.

I would also think that it allows the compiler to put the structure directly
beside the outer constant array (in which this pointer is embedded). That is good
locality-wise.
2019-05-07 20:58:17 +02:00
Thomas Haller
cc9f071676 libnm: cleanup _nm_utils_parse_tc_handle()
- g_ascii_strtoll() accepts leading spaces, but it leaves
  the end pointer at the first space after the digit. That means,
  we accepted "1: 0" but not "1 :0". We should either consistently
  accept spaces around the digits/colon or reject it.

- g_ascii_strtoll() accepts "\v" as a space (just like `man 3 isspace`
  comments that "\v" is a space in C and POSIX locale.
  For some reasons (unknown to me) g_ascii_isspace() does not treat
  "\v" as space. And neither does NM_ASCII_SPACES and
  nm_str_skip_leading_spaces().
  We should be consistent about what we consider spaces and what not.
  It's already odd to accept '\n' as spaces here, but well, lets do
  it for the sake of consistency (so that it matches with our
  understanding of ASCII spaces, albeit not POSIX's).

- don't use bogus error domains in "g_set_error (error, 1, 0, ..."
  That is a bug and we have NM_UTILS_ERROR exactly for error instances
  with unspecified domain and code.

- as before, accept a trailing ":" with omitted minor number.

- reject all unexpected characters. strtoll() accepts '+' / '-'
  and a "0x" prefix of the numbers (and leading POSIX spaces). Be
  strict here and only accepts NM_ASCII_SPACES, ':', and hexdigits.
  In particular, don't accept the "0x" prefix.

This parsing would be significantly simpler to implement, if we could
just strdup() the string, split the string at the colon delimiter and
use _nm_utils_ascii_str_to_int64() which gets leading/trailing spaces
right. But let's save the "overhead" of an additional alloc.
2019-05-07 20:58:17 +02:00
Thomas Haller
fac95d0062 libnm/tests: add test for _nm_utils_parse_tc_handle() 2019-05-07 20:58:17 +02:00
Thomas Haller
9d2623cceb shared: use nm_str_skip_leading_spaces() in _nm_utils_ascii_str_to_int64() 2019-05-07 20:58:17 +02:00
Lubomir Rintel
143f518ca0 modem/broadband: set the gsm.device-id in complete_connection()
This is the preferred way of associating the connection with a
particualr modem.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/138
2019-05-07 18:19:44 +02:00
Thomas Haller
7a5bf59e5f core: merge branch 'th/cache-state-keyfiles'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/134
2019-05-07 16:42:15 +02:00
Thomas Haller
8a78493de1 settings: cache keyfile databases for "timestamps" and "seen-bssids"
Only read the keyfile databases once and cache them for the remainder of
the program.

- this avoids the overhead of opening the file over and over again.

- it also avoids the data changing without us expecting it. The state
  files are internal and we don't support changing it outside of
  NetworkManager. So in the base case we read the same data over
  and over. In the worst case, we read different data but are not
  interested in handling the changes.

- only write the file when the content changes or before exiting
  (normally).

- better log what is happening.

- our state files tend to grow as we don't garbage collect old entries.
  Keeping this all in memory might be problematic. However, the right
  solution for this is that we come up with some form of garbage
  collection so that the state files are reaonsably small to begin with.
2019-05-07 16:41:21 +02:00
Thomas Haller
b0693863c1 shared: add NMKeyFileDB API
It will be used for "/var/lib/NetworkManager/seen-bssids" and
"/var/lib/NetworkManager/timestamps" which currently is implemented
in NMSettingConnection.
2019-05-07 16:41:21 +02:00
Thomas Haller
8c2fda7ca0 shared: add "shared/nm-glib-aux/nm-keyfile-aux.h" 2019-05-07 16:41:21 +02:00
Thomas Haller
8decdf2225 shared: add nm_log_level_from_syslog() helper to convert from syslog levels 2019-05-07 16:41:21 +02:00
Thomas Haller
4aba7d4696 core: use NM_SETTINGS_GET for singlton instead of nm_settings_get()
We have it, so use it. Also, we use a similar macro for other singletons.
2019-05-07 16:04:49 +02:00
Thomas Haller
4a078d5065 platform: merge branch 'th/ethtool-retry'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/133
2019-05-07 09:44:08 +02:00
Thomas Haller
856322562e platform/ethtool,mii: retry ioctl when interface name was renamed for ehttool/mii
ethtool/mii API is based on the ifname. As an interface can be renamed,
this API is inherently racy. We would prefer to use the ifindex instead.
The ifindex of a device cannot change (altough it can repeat, which opens a
different race *sigh*).

Anyway, we were already trying to minimize the race be resolving the
name from ifindex immediately before the call to ethtool/mii.

Do better than that. Now resolve the name before and after the call. If
the name changed in the meantime, we have an indication that a race
might have happend (but we cannot be sure).

Note that this can not catch every possible kind of rename race. If you are very
unlucky a swapping of names cannot be detected.

For getters this is relatively straight forward. Just retry when we
have an indication to fall victim to a race (up to a few times). Yes, we
still cannot be 100% sure, but this should be very reliable in practice.

For setters (that modify the device) we also retry. We do so under the
assumption that setting the same options multiple times has no bad effect.
Note that for setters the race of swapping interface names is particularly
bad. If we hit a very unlucky race condition, we might set the setting on
the wrong interface and there is nothing we can do about it. The retry only
ensures that eventually we will set it on the right interface.

Note that this involves one more if_indextoname() call for each operation (in
the common case when there is no renaming race). In cases where we make
multiple ioctl calls, we cache and reuse the information though. So, for such
calls the overhead is even smaller.
2019-05-07 09:41:19 +02:00
Thomas Haller
945620624a shared: add nm_malloc_maybe_a(), nm_malloc0_maybe_a() and nm_memdup_maybe_a() utils 2019-05-07 09:38:44 +02:00
Beniamino Galvani
4ed72fa658 device: fix reapply of MTU
When we set the MTU on the link we remember its previous source
(ip-config, parent-device or connection profile) and don't change it
again afterwards to avoid interfering with user's manual changes. The
only exceptions when we change it again are (1) if the parent device
MTU changes and (2) if the new MTU has higher priority than the one
previously set.

To allow a live reapply of the MTU property we also need to clear the
saved source, or the checks described above will prevent setting the
new value.

Fixes: 2f8917237f ('device: rework mtu priority handling')

https://bugzilla.redhat.com/show_bug.cgi?id=1702657
2019-05-06 10:19:19 +02:00
Beniamino Galvani
9ecbca4798 cli: merge branch 'bg/rh1702199'
Don't print blob certificates unless the '--show-secrets' option is
passed to nmcli; plus other related changes.

https://bugzilla.redhat.com/show_bug.cgi?id=1702199
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/122
2019-05-06 10:15:14 +02:00
Beniamino Galvani
c91aad4969 cli: hide certificate blobs unless --show-secrets is passed
This restores the behavior before commit 99711579ed.

Fixes: 99711579ed ('cli: add property type for 802-1x certificate properties (pt2)').
2019-05-06 10:10:00 +02:00
Beniamino Galvani
ec4a12ecdb cli: complete 802.1x certificate file names 2019-05-06 10:10:00 +02:00
Beniamino Galvani
eb724293c2 cli: allow completing filenames
Allow the completion function to indicate that the word should be
completed as a filename by the shell.
2019-05-06 10:10:00 +02:00
Beniamino Galvani
78b9448b69 cli: remove bluetooth completion code
The 'bt-type' property alias accepts values provided by
gen_func_bt_type(); instead the 'bluetooth.type' property can only be
set to [dun, panu, nap] and therefore it doesn't need special
handling.
2019-05-06 10:10:00 +02:00
Beniamino Galvani
eac15501b2 cli: parse escape sequences when reading an 802.1x private key
In this way it become possible to specify a filename that includes one
of the delimiters.
2019-05-06 10:10:00 +02:00
Beniamino Galvani
ee96387578 cli: fix setting private key password
Fixes: fe390556ab ('cli: add property type for 802-1x certificate properties (pt3)')
2019-05-06 10:10:00 +02:00
Beniamino Galvani
48ce3628c5 settings: fix failed assertion
Fix the following assertion failure:

  g_object_ref: assertion 'G_IS_OBJECT (object)' failed.

nm_settings_add_connection() can return a NULL connection.

Fixes: f034f17ff6 ('settings: keep the added connection alive for a bit longer')
2019-05-06 10:09:10 +02:00
Rodrigo Lledó
79d7991eaf po: update Spanish (es) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/135
2019-05-04 08:46:08 +02:00
Lubomir Rintel
0777a26fc1 release: bump version to 1.19.2-dev 2019-05-03 11:04:34 +02:00
Lubomir Rintel
e33a995db1 build: fix an out-of-tree build
make[3]: Entering directory 'NetworkManager/_build/sub'
    CC       clients/cli/nmcli-common.o
  cc1: error: ./clients/common: No such file or directory [-Werror=missing-include-dirs]
  cc1: all warnings being treated as errors

The only generated header in $builddir/clients/common is settings-docs.h
and only libnmc.la needs it. Include the directory on the command line
only when we know it exists.
2019-05-03 11:04:34 +02:00
Lubomir Rintel
54663b89dc NEWS: update 2019-05-03 11:04:34 +02:00
Thomas Haller
56d748eb84 device/wireguard: fix memleak for NMDeviceWireGuard
Fixes: 2148d09482 ('core/wireguard: add support for WireGuard peers')
2019-05-03 11:03:08 +02:00
Thomas Haller
d5a2b70909 platform/tests: workaround routing-rules test failure due to suppress_prefixlen on older kernels
On Ubuntu 14.04 kernel (4.4.0-146-generic, x86_64) this easily causes
test failures:

    make -j 8 src/platform/tests/test-route-linux \
    && while true; do \
        NMTST_SEED_RANDOM= ./tools/run-nm-test.sh src/platform/tests/test-route-linux -p /route/rule \
        || break; \
    done

outputs:

    ...
    /route/rule/1:
    nmtst: initialize nmtst_get_rand() with NMTST_SEED_RAND=22892021
    OK
    /route/rule/2: >>> failing...
    >>> no fuzzy match between: [routing-rule,0x205ab30,1,+alive,+visible; [6] 0: from all suppress_prefixlen 8 none]
    >>>                    and: [routing-rule,0x205c0c0,1,+alive,+visible; [6] 0: from all suppress_prefixlen -1579099242 none]
    **
    test:ERROR:src/platform/tests/test-route.c:1695:test_rule: code should not be reached
2019-05-02 09:28:31 +02:00
Rodrigo Lledó
0a0a8706f8 po: update Spanish (es) translation
Changing "Token" translation from "identificador" to "testigo" as discussed
in the GNOME Spanish Translation Team's mailing list.

Special thanks to Daniel Mustieles our coordinator.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/130
2019-05-01 13:59:19 +02:00
Yuri Chornoivan
4e1b1232d9 po: update Ukrainian (uk) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/128
2019-05-01 13:56:30 +02:00