1. 21 May, 2019 40 commits
    • Lubomir Rintel's avatar
      po: update-po · 9944b071
      Lubomir Rintel authored
    • Beniamino Galvani's avatar
      team: don't kill teamd for external devices · a641211c
      Beniamino Galvani authored
      The teamd instance must not be killed if the device was externally
      (cherry picked from commit 008a4b42)
      (cherry picked from commit bd113fe7)
    • Thomas Haller's avatar
      device/trivial: add comment about lifetime of "kind" in tc_commit() · 38e9c4cb
      Thomas Haller authored
      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.
      (cherry picked from commit f2ae994b)
    • Thomas Haller's avatar
      device: don't rely on nm_platform_link_get_ifindex() returning 0 · 7cb1a277
      Thomas Haller authored
      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.
      (cherry picked from commit 9eefe27a)
    • Thomas Haller's avatar
      device/trivial: add space between macro name and arguments and vertically align lines · b81231c4
      Thomas Haller authored
      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.
      (cherry picked from commit 9399297a)
    • Thomas Haller's avatar
      platform: merge _add_action(), _add_action_simple() and _add_action_mirred()... · cea79df5
      Thomas Haller authored
      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.
      (cherry picked from commit 04bd404d)
    • Thomas Haller's avatar
      platform: assert for out-of-memory in netlink code · af4f8ba4
      Thomas Haller authored
      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.
      (cherry picked from commit 3784a2a2)
    • Thomas Haller's avatar
      platform: use bool bitfields in NMPlatformActionMirred structure · 3bf538a3
      Thomas Haller authored
      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
      (cherry picked from commit 36d6aa3b)
    • Thomas Haller's avatar
      libnm: rename "memory" parameter of fq_codel QDisc to "memory_limit" · 1749dcb8
      Thomas Haller authored
      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.
      (cherry picked from commit 666d5880)
    • Thomas Haller's avatar
      platform: fix handling of default value for TCA_FQ_CODEL_CE_THRESHOLD · b252e20e
      Thomas Haller authored
      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,
                          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.
      (cherry picked from commit 973db2d4)
    • Thomas Haller's avatar
      platform: fix handling of fq_codel's memory limit default value · a9d64925
      Thomas Haller authored
      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.
      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.
      (cherry picked from commit 46a90438)
    • Thomas Haller's avatar
      platform: fix nm_platform_qdisc_to_string() · b3f2ab16
      Thomas Haller authored
      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.
      (cherry picked from commit b658e3da)
    • Thomas Haller's avatar
      platform: use u32 netlink type for TCA_FQ_CODEL_ECN · ce8c727d
      Thomas Haller authored
      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.
      (cherry picked from commit a1099a1f)
    • Thomas Haller's avatar
      platform: use NM_CMP_FIELD_UNSAFE() for comparing bitfield in nm_platform_qdisc_cmp() · 6c2ffcd2
      Thomas Haller authored
      "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().
      (cherry picked from commit 47d8bee1)
    • Thomas Haller's avatar
      device: fix type of loop variable in tc_commit() · 8b1f68ec
      Thomas Haller authored
      nqdiscs and ntfilters are unsigned integers. The loop variable must agree in
      range and signedness.
      (cherry picked from commit 438855e9)
    • Thomas Haller's avatar
      libnm: use macro and designated initializers for NMVariantAttributeSpec · ecc62e01
      Thomas Haller authored
      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
      (cherry picked from commit 86dc50d4)
    • Thomas Haller's avatar
      libnm: mark NMVariantAttributeSpec pointers as const · 21551899
      Thomas Haller authored
      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
      (cherry picked from commit 4e3955e6)
    • Thomas Haller's avatar
      libnm: cleanup _nm_utils_parse_tc_handle() · d3666ab9
      Thomas Haller authored
      - 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
        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.
      (cherry picked from commit cc9f0716)
    • Thomas Haller's avatar
      libnm/tests: add test for _nm_utils_parse_tc_handle() · 7beb584e
      Thomas Haller authored
      (cherry picked from commit fac95d00)
    • Thomas Haller's avatar
      shared: use nm_str_skip_leading_spaces() in _nm_utils_ascii_str_to_int64() · 6c1683f9
      Thomas Haller authored
      (cherry picked from commit 9d2623cc)
    • Lubomir Rintel's avatar
      tc/tfilter: add mirred action · 6af549ba
      Lubomir Rintel authored
      (cherry picked from commit 90029214)
    • Lubomir Rintel's avatar
      tc/qdisc: add support for fq_codel attributes · eb4a220a
      Lubomir Rintel authored
      (cherry picked from commit 1efe982e)
    • Thomas Haller's avatar
      core: fix file permissions for "/var/lib/NetworkManager/secret_key" · 613af1de
      Thomas Haller authored
      Ooherwise, the file has wrong permissions:
        # ls -la /var/lib/NetworkManager/secret_key
        ----r-xr-x. 1 root root 50 May 14 13:52 /var/lib/NetworkManager/secret_key
      Luckily, /var/lib/NetworkManager should be already
        # ls -lad /var/lib/NetworkManager
        drwx------. 2 root root 8192 May 14 13:57 /var/lib/NetworkManager
      which mitigates this a bit.
      Fixes: dbcb1d6d ('core: let nm_utils_secret_key_read() handle failures internally')
      (cherry picked from commit dc3a2f9b)
      (cherry picked from commit 2d46247c)
    • Thomas Haller's avatar
      settings/d-bus: fix boolean return value of "LoadConnections" · fe616116
      Thomas Haller authored
      The boolean value is intended to indicate success. It would indicated
      failure due to a bug.
      Fixes: 297d4985 ('core/dbus: rework D-Bus implementation to use lower layer GDBusConnection API'):
      (cherry picked from commit 22e830f0)
      (cherry picked from commit e73a5058)
    • Thomas Haller's avatar
      settings: avoid assertion for LoadConnections D-Bus method with relative paths · 6849f005
      Thomas Haller authored
        $ busctl call org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/Settings org.freedesktop.NetworkManager.Settings LoadConnections as 1 relative/filename
      triggers a g_critical() assertion in nm_utils_file_is_in_path():
        #3  0x00007ffff7a19e7d in g_return_if_fail_warning
            (log_domain=log_domain@entry=0x55555586c333 "NetworkManager", pretty_function=pretty_function@entry=0x55555586c0a0 <__FUNCTION__.38585> "nm_utils_file_is_in_path", expression=expression@entry=0x55555586c010 "abs_filename && abs_filename[0] == '/'") at ../glib/gmessages.c:2767
        #4  0x00005555555f1128 in nm_utils_file_is_in_path (abs_filename=abs_filename@entry=0x555555b56670 "dfd", abs_path=<optimized out>) at src/NetworkManagerUtils.c:1077
        #5  0x00005555555a4779 in load_connection (config=<optimized out>, filename=0x555555b56670 "dfd") at src/settings/plugins/keyfile/nms-keyfile-plugin.c:522
        #6  0x00005555557ce291 in nm_settings_plugin_load_connection (self=0x5555559fd400 [NMSKeyfilePlugin], filename=0x555555b56670 "dfd") at src/settings/nm-settings-plugin.c:70
        #7  0x000055555559ccdf in impl_settings_load_connections
            (obj=<optimized out>, interface_info=<optimized out>, method_info=<optimized out>, connection=<optimized out>, sender=<optimized out>, invocation=0x7fffe0015ed0 [GDBusMethodInvocation], parameters=<optimized out>) at src/settings/nm-settings.c:1439
        #8  0x00005555555a9bf9 in dbus_vtable_method_call
            (connection=0x5555559b91b0 [GDBusConnection], sender=sender@entry=0x555555b5c360 ":1.32283", object_path=object_path@entry=0x7fffe0019070 "/org/freedesktop/NetworkManager/Settings", interface_name=<optimized out>, interface_name@entry=0x7fffe002aa70 "org.freedesktop.NetworkManager.Settings", method_name=<optimized out>,
            method_name@entry=0x7fffe00276b0 "LoadConnections", parameters=parameters@entry=0x555555c4a690, invocation=0x7fffe0015ed0 [GDBusMethodInvocation], user_data=0x5555559a1a00)
            at src/nm-dbus-manager.c:947
        #9  0x00007ffff7c506c4 in call_in_idle_cb (user_data=user_data@entry=0x7fffe0015ed0) at ../gio/gdbusconnection.c:4874
        #10 0x00007ffff7a0e8eb in g_idle_dispatch (source=source@entry=0x7fffe00208a0, callback=0x7ffff7c50590 <call_in_idle_cb>, user_data=0x7fffe0015ed0) at ../glib/gmain.c:5627
        #11 0x00007ffff7a11fd0 in g_main_dispatch (context=0x555555994d00) at ../glib/gmain.c:3189
        #12 0x00007ffff7a11fd0 in g_main_context_dispatch (context=context@entry=0x555555994d00) at ../glib/gmain.c:3854
        #13 0x00007ffff7a12368 in g_main_context_iterate (context=0x555555994d00, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:3927
        #14 0x00007ffff7a126b3 in g_main_loop_run (loop=0x555555995e60) at ../glib/gmain.c:4123
        #15 0x000055555558a741 in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:444
      Filter out relative filenames early.
      (cherry picked from commit a1b102ea)
      (cherry picked from commit c21171e0)
    • Beniamino Galvani's avatar
      device: fix intersecting IPv6 configurations · 82fea31a
      Beniamino Galvani authored
      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.
      (cherry picked from commit 18d2edfa)
      (cherry picked from commit 6f691445)
    • Beniamino Galvani's avatar
      device: unconditionally reapply IP configuration on link up · 249c802e
      Beniamino Galvani authored
      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.
      (cherry picked from commit d0b16b92)
      (cherry picked from commit 4482ca64)
    • Beniamino Galvani's avatar
      all: fix typos (milli seconds -> milliseconds) · e124df08
      Beniamino Galvani authored
      (cherry picked from commit 4735d676)
      (cherry picked from commit f6b9366e)
    • Beniamino Galvani's avatar
      manager: unmanage software devices when networking gets disabled · 073cfea1
      Beniamino Galvani authored
      If a user disables networking, we consider that as an indication that
      also software devices must be disconnected. OTOH, we don't want to
      destroy them for external events as a system suspend.
      (cherry picked from commit 32ee51ee)
      (cherry picked from commit da8462df)
    • Beniamino Galvani's avatar
      manager: clear unmanaged-sleeping flag on software devices on resume · 3c0416f1
      Beniamino Galvani authored
      When networking is disabled at NM startup we unmanage all devices
      (including software ones) due to SLEEPING. After networking gets
      enabled again we must clear the unmanaged-sleeping flag on software
      (cherry picked from commit 656753b7)
      (cherry picked from commit bb555ff6)
    • Beniamino Galvani's avatar
      settings: fix failed assertion · e579a62a
      Beniamino Galvani authored
      Fix the following assertion failure:
        g_object_ref: assertion 'G_IS_OBJECT (object)' failed.
      nm_settings_add_connection() can return a NULL connection.
      Fixes: f034f17f ('settings: keep the added connection alive for a bit longer')
      (cherry picked from commit 48ce3628)
      (cherry picked from commit d80818e6)
    • Beniamino Galvani's avatar
      device: fix reapply of MTU · 499add9c
      Beniamino Galvani authored
      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: 2f891723 ('device: rework mtu priority handling')
      (cherry picked from commit 4ed72fa6)
      (cherry picked from commit e738479b)
    • Beniamino Galvani's avatar
      cli: hide certificate blobs unless --show-secrets is passed · 1ef8bcc3
      Beniamino Galvani authored
      This restores the behavior before commit 99711579.
      Fixes: 99711579 ('cli: add property type for 802-1x certificate properties (pt2)').
      (cherry picked from commit c91aad49)
      (cherry picked from commit 8c75120d)
    • Beniamino Galvani's avatar
      cli: complete 802.1x certificate file names · e8333c66
      Beniamino Galvani authored
      (cherry picked from commit ec4a12ec)
      (cherry picked from commit 3d3fac55)
    • Beniamino Galvani's avatar
      cli: allow completing filenames · 4a150fa1
      Beniamino Galvani authored
      Allow the completion function to indicate that the word should be
      completed as a filename by the shell.
      (cherry picked from commit eb724293)
      (cherry picked from commit 09f9831f)
    • Beniamino Galvani's avatar
      cli: remove bluetooth completion code · 4cd6a09f
      Beniamino Galvani authored
      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
      (cherry picked from commit 78b9448b)
      (cherry picked from commit a9728a61)
    • Beniamino Galvani's avatar
      cli: parse escape sequences when reading an 802.1x private key · 97ebf40b
      Beniamino Galvani authored
      In this way it become possible to specify a filename that includes one
      of the delimiters.
      (cherry picked from commit eac15501)
      (cherry picked from commit 0f03773b)
    • Beniamino Galvani's avatar
      cli: fix setting private key password · 0b32e185
      Beniamino Galvani authored
      Fixes: fe390556 ('cli: add property type for 802-1x certificate properties (pt3)')
      (cherry picked from commit ee963875)
      (cherry picked from commit d8badb28)
    • Thomas Haller's avatar
    • Francesco Giudici's avatar
      dhcp/internal: make default dhcp-client-id based on systemd DUID-EN · 191054f4
      Francesco Giudici authored
      For RHEL-7 we want to stick to the legacy behavior of the internal
      dhcp client: the default dhcp-client-id is based on systemd DUID-EN.
      This reverts commit cfd696cc.