Commit graph

10807 commits

Author SHA1 Message Date
Beniamino Galvani
2f8917237f device: rework mtu priority handling
If commit_mtu() is called multiple times and dev->get_configured_mtu()
returns @is_user_config=FALSE, only the first call changes the
MTU. So, for example, when the parent MTU of a VLAN changes, we apply
the new MTU only the first time.

Rework the handling of MTU in NMDevice, and store the source of the
configured MTU. When commit_mtu() is called again, we ask the subclass
a MTU to configure and apply it only if the source has higher
priority, or when the parent MTU changed.
2018-06-20 18:50:44 +02:00
Beniamino Galvani
9f8b0697de device: introduce mtu source
Instead of returning a boolean @is_user_config value from
get_configured_mtu(), return an mtu-source enum with possible values
NONE,CONNECTION. This enum will be expanded later; for now there is no
change in behavior.
2018-06-20 18:49:56 +02:00
Beniamino Galvani
d9df1f1d05 device: introduce nm_device_get_configured_mtu_from_connection()
Deduplicate similar code from devices.
2018-06-20 18:30:56 +02:00
Thomas Haller
94200b03fe device: require that device-factories support at least one link-type or setting-type
If a device-factory wouldn't support any link-type or setting-type,
we would not take an additional reference to the @factory instance
(because, the factory is not added to one of the static hash tables).

As such, we would invoke the callback with a factory instance, which
is about to be destroyed immediately afterwards. That would be unusual
for device-plugins, because usually a device-plugin is never destroyed
and essentially leaked at exit.

Just don't get into that situation. All device plugins are internal API,
and they are known to support at least something. Assert for that.
2018-06-20 16:36:26 +02:00
Thomas Haller
4c43d7cad3 device: fix leaking internal device factories
Actually, we anyway leak them, because they are added to static hash tables
which are never released. Anyway, get the ref-count right.
2018-06-20 16:31:18 +02:00
Thomas Haller
dff157b867 device: suppress info logging about internal device plugins
Internal device plugins are compiled-in. In fact, none of the
internal device plugins can currently be disabled via compile
time options. The user would have to patch the sources to
not include a particular device plugin.

Hence, the available device plugins depends exclusively on the
build itself. That is not worth <info> level logging. Especially,
as it was quite verbose, logging 13 lines.
2018-06-20 16:17:03 +02:00
Thomas Haller
3798f98829 device: don't attach unused device-plugin-path to device factory 2018-06-20 16:11:49 +02:00
Thomas Haller
fb63d8d706 platform/tests: fix race in tests
Otherwise, we easily get a failure

    test:ERROR:src/platform/tests/test-cleanup.c:78:test_cleanup_internal: assertion failed (addresses6->len == 2): (1 == 2)

Avoid that by waiting for kernel to add the link-local
address.
2018-06-20 14:46:07 +02:00
Thomas Haller
07a34f2404 platform/tests: fix generating IPv6 link local address in fake-platform 2018-06-20 14:46:07 +02:00
Francesco Giudici
08116409f3 dhcp: look for DUID in both private and global DHCP client lease files
Option to check just in NM private dhcp client specific lease files has
been dropped: either get DUID from specific DHCP plugin or just use the
provided one.

This reverts commit f054c3fcaa.
2018-06-20 10:43:51 +02:00
Francesco Giudici
0a662a3620 dhcp: drop NMDhcpDuidEnforce type
A gboolean is enough: make code easier.
2018-06-20 10:43:51 +02:00
Lubomir Rintel
e27b15c00d all: remove CLOCK_BOOTTIME defintions
It's useless and redundant noise.

The original motivation seems to have been compatibility with ancient
versions uClibc (2011), but given CLOCK_BOOTTIME definition is shipped with
kernel headers, the libc version shall not matter anyway.

Even if it was the case, uClibc has shipped the definition for over
7 years now and been superseded by uClibc-ng that always had the
definition.
2018-06-18 17:21:32 +02:00
Lubomir Rintel
07fd0502f6 wifi: expose LastScan as milliseconds not seconds
This doesn't wrap around in 68 years of uptime and is consistent with
o.fd.NM.Checkpoint.Created.
2018-06-15 16:23:30 +02:00
Thomas Haller
13f860970a systemd: merge branch systemd into master 2018-06-15 15:56:04 +02:00
Thomas Haller
353810ccc1 systemd: update code from upstream (2018-06-15)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=88f375b8c28806633d22ed99f6a5f1194c78ed73

(
  cd "$SYSTEMD_DIR"
  git checkout "$COMMIT"
  git reset --hard
  git clean -fdx
)

git ls-files :/src/systemd/src/ \
             :/shared/nm-utils/siphash24.h \
             :/shared/nm-utils/unaligned.h | \
  xargs -d '\n' rm -f

nm_copy_sd() {
    mkdir -p "./src/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/systemd/$1"
}

nm_copy_sd_shared() {
    mkdir -p "./shared/nm-utils/"
    cp "$SYSTEMD_DIR/$1" "./shared/nm-utils/${1##*/}"
}

nm_copy_sd "src/basic/alloc-util.c"
nm_copy_sd "src/basic/alloc-util.h"
nm_copy_sd "src/basic/async.h"
nm_copy_sd "src/basic/escape.c"
nm_copy_sd "src/basic/escape.h"
nm_copy_sd "src/basic/ether-addr-util.c"
nm_copy_sd "src/basic/ether-addr-util.h"
nm_copy_sd "src/basic/extract-word.c"
nm_copy_sd "src/basic/extract-word.h"
nm_copy_sd "src/basic/fileio.c"
nm_copy_sd "src/basic/fileio.h"
nm_copy_sd "src/basic/fd-util.c"
nm_copy_sd "src/basic/fd-util.h"
nm_copy_sd "src/basic/fs-util.c"
nm_copy_sd "src/basic/fs-util.h"
nm_copy_sd "src/basic/hash-funcs.c"
nm_copy_sd "src/basic/hash-funcs.h"
nm_copy_sd "src/basic/hashmap.c"
nm_copy_sd "src/basic/hashmap.h"
nm_copy_sd "src/basic/hexdecoct.c"
nm_copy_sd "src/basic/hexdecoct.h"
nm_copy_sd "src/basic/hostname-util.c"
nm_copy_sd "src/basic/hostname-util.h"
nm_copy_sd "src/basic/in-addr-util.c"
nm_copy_sd "src/basic/in-addr-util.h"
nm_copy_sd "src/basic/io-util.c"
nm_copy_sd "src/basic/io-util.h"
nm_copy_sd "src/basic/list.h"
nm_copy_sd "src/basic/log.h"
nm_copy_sd "src/basic/macro.h"
nm_copy_sd "src/basic/mempool.h"
nm_copy_sd "src/basic/mempool.c"
nm_copy_sd "src/basic/parse-util.c"
nm_copy_sd "src/basic/parse-util.h"
nm_copy_sd "src/basic/path-util.c"
nm_copy_sd "src/basic/path-util.h"
nm_copy_sd "src/basic/prioq.h"
nm_copy_sd "src/basic/prioq.c"
nm_copy_sd "src/basic/process-util.h"
nm_copy_sd "src/basic/process-util.c"
nm_copy_sd "src/basic/random-util.c"
nm_copy_sd "src/basic/random-util.h"
nm_copy_sd "src/basic/refcnt.h"
nm_copy_sd "src/basic/set.h"
nm_copy_sd "src/basic/signal-util.h"
nm_copy_sd "src/basic/siphash24.h"
nm_copy_sd "src/basic/socket-util.c"
nm_copy_sd "src/basic/socket-util.h"
nm_copy_sd "src/basic/sparse-endian.h"
nm_copy_sd "src/basic/stat-util.c"
nm_copy_sd "src/basic/stat-util.h"
nm_copy_sd "src/basic/stdio-util.h"
nm_copy_sd "src/basic/string-table.c"
nm_copy_sd "src/basic/string-table.h"
nm_copy_sd "src/basic/string-util.c"
nm_copy_sd "src/basic/string-util.h"
nm_copy_sd "src/basic/strv.c"
nm_copy_sd "src/basic/strv.h"
nm_copy_sd "src/basic/time-util.c"
nm_copy_sd "src/basic/time-util.h"
nm_copy_sd "src/basic/umask-util.h"
nm_copy_sd_shared "src/basic/unaligned.h"
nm_copy_sd "src/basic/utf8.c"
nm_copy_sd "src/basic/utf8.h"
nm_copy_sd "src/basic/util.c"
nm_copy_sd "src/basic/util.h"
nm_copy_sd "src/libsystemd-network/arp-util.c"
nm_copy_sd "src/libsystemd-network/arp-util.h"
nm_copy_sd "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-network.c"
nm_copy_sd "src/libsystemd-network/dhcp-option.c"
nm_copy_sd "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd "src/libsystemd-network/lldp-internal.h"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd "src/libsystemd-network/lldp-network.c"
nm_copy_sd "src/libsystemd-network/lldp-network.h"
nm_copy_sd "src/libsystemd-network/network-internal.c"
nm_copy_sd "src/libsystemd-network/network-internal.h"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd "src/libsystemd-network/sd-lldp.c"
nm_copy_sd "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd "src/shared/dns-domain.c"
nm_copy_sd "src/shared/dns-domain.h"
nm_copy_sd "src/systemd/_sd-common.h"
nm_copy_sd "src/systemd/sd-dhcp6-client.h"
nm_copy_sd "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd "src/systemd/sd-dhcp-client.h"
nm_copy_sd "src/systemd/sd-dhcp-lease.h"
nm_copy_sd "src/systemd/sd-event.h"
nm_copy_sd "src/systemd/sd-ndisc.h"
nm_copy_sd "src/systemd/sd-id128.h"
nm_copy_sd "src/systemd/sd-ipv4acd.h"
nm_copy_sd "src/systemd/sd-ipv4ll.h"
nm_copy_sd "src/systemd/sd-lldp.h"
2018-06-15 15:18:28 +02:00
Francesco Giudici
193aae91eb ifcfg: enable writing/reading of speed and duplex when autoneg is enabled 2018-06-15 14:19:50 +02:00
Francesco Giudici
064ea1c58e device: enforce specific speed/duplex modes in link auto-configuration 2018-06-15 14:19:50 +02:00
Francesco Giudici
356addb9e6 platform: allow to force the advertised auto-negotiation link value
This will only work for network devices supporting the BASE-T specification.
2018-06-15 14:19:50 +02:00
Francesco Giudici
45170bad5d platform: move link_duplex_to_string function to platform
Expose it as a regular platform function: change its name
to nm_platform_link_duplex_type_to_string().
2018-06-15 14:19:50 +02:00
Thomas Haller
36e9ec0554 wifi: fix check for valid NMSettingWirelessWakeOnWLan flag 2018-06-15 09:46:26 +02:00
Thomas Haller
8cba4d95df device/wifi: use _LOGD() macros in wake_on_wlan_enable()
_LOGD() is preferred, because it includes a common prefix depending
on the device. This macro requires, that we have a suitable @self
variable in the local scope.
2018-06-15 09:46:26 +02:00
Alfonso Sánchez-Beato
ca3bbede74 core: don't shutdown interfaces if they have wowlan enabled
This is to support the S5 case, where usually the NM process is
stopped. If we are stopping and WoWLAN is set for the interface,
we do not deconfigure it and keep the connection alive so we
can receive packages that will potentially wake up the system.

Note that for this work, wpa_supplicant needs to be modified too
so it does not deconfigure the wireless interface either when
stopped. The needed patches for wpa_supplicant can be found in
http://lists.infradead.org/pipermail/hostap/2018-June/038644.html
2018-06-15 09:46:26 +02:00
Simon Fels
ea10016d24 devices: enable wake-on-wlan when device is enabled
Co-authored-by: Alfonso Sanchez-Beato <alfonso.sanchez-beato@canonical.com>
2018-06-15 09:46:26 +02:00
Simon Fels
1621c79e7b platform: add support for wake-on-wlan
Co-authored-by: Alfonso Sanchez-Beato <alfonso.sanchez-beato@canonical.com>
2018-06-15 09:46:26 +02:00
Lubomir Rintel
7af1bc7cf0 ovs: only finish waiting for a link when we actually got one
https://bugzilla.redhat.com/show_bug.cgi?id=1546659
2018-06-15 09:44:04 +02:00
Thomas Haller
6e12e18c15 device: simplify nm_device_hash_check_invalid_keys()
Rather trivial change. Return-early, to completely handle the simpler
case (the success case) first. In the failure case, we only need
extra effort to generate a nice error message.
2018-06-15 09:07:19 +02:00
Thomas Haller
b31bc4fa6c core/trivial: rename local variables to make code clearer 2018-06-15 09:07:19 +02:00
Thomas Haller
79159f61c7 device: check for proxy setting separately in can_reapply_change()
Proxy setting has no property NM_SETTING_IP_CONFIG_ROUTE_TABLE.
It's odd to handle it in the same if-block with IP configs.
2018-06-15 09:07:19 +02:00
Thomas Haller
fe1f5871c8 device: fix crash during reapply
Fixes: bf3b3d444c
2018-06-15 09:07:19 +02:00
Beniamino Galvani
bb20f2eb61 macsec: enable send-sci by default and make the option configurable
It is safer to enable send-sci by default because, at the cost of
8-byte overhead, it makes MACsec work over bridges (note that kernel
also enables it by default). While at it, also make the option
configurable.

https://bugzilla.redhat.com/show_bug.cgi?id=1588041
2018-06-14 15:13:11 +02:00
Lubomir Rintel
650b5fd99e wwan: ensure the route parameters are set on IPv6 only configuration 2018-06-13 16:56:51 +02:00
Lubomir Rintel
267948f2b7 wwan: set the route parameters at the beginning of ip4 config
We set the metric to the routes as we receive them from the PPP plugin. We
ought to let the modem know before it starts IPv4 configuration, not right
before the commit.

https://bugzilla.redhat.com/show_bug.cgi?id=1585611
2018-06-13 16:45:24 +02:00
Lubomir Rintel
74c2a0aca4 device: drop an unused variable
src/devices/nm-device.c:7764:25: error: unused variable 'stable_hwaddr' [-Werror,-Wunused-variable]
        gs_unref_bytes GBytes *stable_hwaddr = NULL;
                               ^
2018-06-13 15:56:27 +02:00
Lubomir Rintel
c00e17578f wifi: expose the LastScan property
This is the time when the last Wi-Fi scan finished. It will help clients
decide whether the AP list is fresh enough.
2018-06-13 14:44:06 +02:00
Thomas Haller
988cecb6d3 device: log generated ipv4.dhcp-client-id in <debug> mode 2018-06-12 14:45:40 +02:00
Thomas Haller
67ffd17b6c device: unify logging of ipv6.dhcp-duid by giving common prefix
For better or worse, the logging done for ipv4.dhcp-client-id
is prefixed with ipv4.dhcp-client-id. Let ipv6.dhcp-duid follow
that pattern.

Also, generate_duid_from_machine_id() would log at two places,
it should use the same logging prefix.

Also, it logs the value of "duid" variable. Ensure, that "duid"
is not %NULL at that point.

Also, fix leak of nm_dhcp_utils_duid_to_string() value during logging.
2018-06-12 14:45:40 +02:00
Thomas Haller
374d147421 device: refactor generate_duid_from_machine_id() to have a straight forward code path
Previously, there were two blocks

  if (NM_IN_SET (duid, "ll", "llt")
     preprocess_hwaddr()
  else if (NM_IN_SET (duid, "stable-ll", "stable-llt", "stable-uuid"))
     preprecess_stable_id()

  if (nm_streq (duid, "ll")
     generate_ll()
  else if (nm_streq (duid, "llt"))
     generate_llt()
  else if (nm_streq (duid, "stable-ll")
     generate_stable_ll()
  ...

That is, the latter block depends on the execution of the previous
block, while the previous block is guarded by a particular condition,
slighlty different than the condition in the later block.

It is confusing to follow. Instead, check for our cases one by one, and
when we determined a particular DUID type, process it within the same block
of code. Now the code consists of individual blocks, that all end with a "goto
out*". That means, it's easier to understand the flow of the code.

Also, don't initialize duid_error variable and separate between
"out_error" and "out_good". This allows that the compiler gives
a warning if we missed ot initialize duid_error.
2018-06-12 14:45:40 +02:00
Thomas Haller
6d06a0e1b0 device: handle failure in generate_duid_from_machine_id() in dhcp6_get_duid()
dhcp6_get_duid() already handles failure to generate the DUID in a
sensible manner. No reason to duplicate the error handling in
generate_duid_from_machine_id().

Especially, because generate_duid_from_machine_id() used to cache the
random DUID in memory and reuse it from then on. There is no reason to do
that, /etc/machine-id must be available to NetworkManager. We still
handle such a grave error gracefully by generating a random DUID.
2018-06-12 14:45:40 +02:00
Thomas Haller
8bb1aed2ad device: fix enforcing ipv6.dhcp-duid for binary DUID 2018-06-12 13:30:36 +02:00
Thomas Haller
5df4c17ba1 device: handle failure to generate ipv4.dhcp-client-id by fallback to random client-id
First of all, generating the client-id is not expected to fail. If it fails,
something is already very wrong. Maybe, a failure to generate a client-id
should result in failing the activation. However, let's not go full
measure in this question.

Instead:
- ensure that we log a warning and a reason why the client-id could not
  be generated.
- fallback to a random client id. Clearly, we were unable to generate
  the requested client-id, hence, we should fallback to a default value
  which does not make the host easily identifyable. Of course, that means
  that the generated DHCP client-id is not at all stable. But note that
  something is already very wrong, so when handling the error we should do
  something conservative (that is, protecting the users privacy).

This is also what happens for a failure to generate the ipv6.dhcp-duid.
2018-06-12 13:30:36 +02:00
Thomas Haller
d9488417e7 device: obtain current MAC address from platform for generating ipv4.dhcp-client-id=mac
In practice, there should be no difference between peeking into
the platform cache, or using the cached value from nm_device_get_hw_address().

Prefer the hardware address from the platform, because:
- we also pass the current MAC address to nm_dhcp_manager_start_ip4().
  For not particularly strong reason, it uses the MAC address obtained
  from platform. At the least, it makes sense that we use the same
  addresses for the client-id as well.
- ipv6.dhcp-duid also gets the address from platform. Again,
  no strong reason either way, but they should behave similar
  in this regard.
2018-06-12 10:23:40 +02:00
Lubomir Rintel
d815130468 ifcfg-rh: add nm-ifup and nm-ifdown scripts
They're intended to be used via update-alternatives(8) as compatibility
shims for Red Hat systems without the legacy network control scripts.

While they're not strictly parts of the settings plugin, they're best
just installed along with it, since they're supposed to be available on
systems that use the ifcfg files.
2018-06-11 15:09:42 +02:00
Lubomir Rintel
87f5ff6927 settings-connection: expose Filename property on D-Bus
This allows implementing some convenience features in nmcli -- listing
the backing store for the connection in "nmcli c show", and using the
filename for specifying connection in "nmcli c up/down".

Eventually, paired with ReloadConnections(), this could be used to
implement something similar to what "systemctl edit" does for units
(though we'd need to pick another command name as we aready use
"nmcli c edit" for something different).
2018-06-11 15:06:49 +02:00
Thomas Haller
152560e294 policy: log connection UUID for auto-activation
The connection.id (NAME) is not necessarily unique.
To avoid confusion, log the UUID as well.
2018-06-11 09:44:05 +02:00
Francesco Giudici
f913ed4d0c ifcfg: introduce DHCPV6_DUID to map ipv6.dhcp-duid property 2018-06-09 22:20:39 +02:00
Francesco Giudici
e9321713a9 ifcfg: make_ip6_setting cleanup & optimization 2/2
get rid of svGetValueStr_cp() in favor of svGetValueStr() in the
make_ip6_setting() function
2018-06-09 22:20:39 +02:00
Francesco Giudici
fa478d8f22 ifcfg: make_ip6_setting cleanup & optimization 1/2
get rid of the useless "str_value" variable.
2018-06-09 22:20:39 +02:00
Francesco Giudici
f054c3fcaa dhcp: allow to skip DUID search from DHCP client global configuration
When the used client is dhclient we were used to search for DUID not
only in the specific lease files generated by NetworkManager, but also
in the global lease file generated outside NetworkManager.
Keep this capability but allow to just search in the NM lease files if
a value different from the default one is specified in dhcp-duid.
2018-06-09 22:20:39 +02:00
Francesco Giudici
0d841e7471 dhcp: remove fallback DUID-UUID generation from dhcp code
This commit centralizes the DUID generation in nm-device.c.
As a consequence, a DUID is always provided when starting a
DHCPv6 client. The DHCP client can override the passed DUID
with the value contained in the client-specific lease file.
2018-06-09 22:20:39 +02:00
Francesco Giudici
7a0b6b17bb libnm-core: add ipv6.dhcp-duid property
allow to specify the DUID to be used int the DHCPv6 client identifier
option: the dhcp-duid property accepts either a hex string or the
special values "lease", "llt", "ll", "stable-llt", "stable-ll" and
"stable-uuid".

"lease": give priority to the DUID available in the lease file if any,
         otherwise fallback to a global default dependant on the dhcp
         client used. This is the default and reflects how the DUID
         was managed previously.
"ll": enforce generation and use of LL type DUID based on the current
      hardware address.
"llt": enforce generation and use of LLT type DUID based on the current
       hardware address and a stable time field.
"stable-ll": enforce generation and use of LL type DUID based on a
             link layer address derived from the stable id.
"stable-llt": enforce generation and use of LLT type DUID based on
              a link layer address and a timestamp both derived from the
              stable id.
"stable-uuid": enforce generation and use of a UUID type DUID based on a
               uuid generated from the stable id.
2018-06-08 18:23:31 +02:00