Commit graph

25022 commits

Author SHA1 Message Date
Thomas Haller 9b8dcc2665 shared: cleanup NM_NARG() and related macros
- add new helper macros NM_MACRO_CALL(), _NM_MACRO_SELECT_ARG_64(),
  NM_NARG_MAX1(), NM_NARG_MAX2().

- cleanup implementation of NM_NARG() and _NM_UTILS_MACRO_REST() macros
  by reusing helper macros.
2020-01-28 10:42:08 +01:00
Antonio Cardace abcf8d5245 Merge branch 'ac/fix_startup_complete'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/400
2020-01-28 09:05:13 +01:00
Antonio Cardace f583aec806 nm-device: add new pending action to keep the device busy when in between states
Add a 'in-state-change' pending action to be sure the device always has a
pending when transitioning between states (this prevents callbacks to mark
startup as complete while running _set_state_full()).

This is needed as during the 'failed'->'disconnected' the pending action 'activation-*'
for the device is removed resulting in an empty pending_actions list which then
triggers 'check_if_startup_complete()' that will find no pending action and mark
startup as complete even if the device could have been activated with another connection.

https://bugzilla.redhat.com/show_bug.cgi?id=1759956
2020-01-27 12:08:53 +01:00
Beniamino Galvani b9820162f2 dhcp: merge branch 'bg/nettools-dup-options-issue324'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/401
2020-01-25 11:39:26 +01:00
Beniamino Galvani 541db78259 dhcp: don't add server-id option to the parameter request list
The option is mandatory in the replies from server and so we don't
need to ask for it. dhclient doesn't do it either. But especially, it
seems that requesting the option causes some broken server
implementations to send duplicate instances of the option.

So, remove the option from the parameter request list of the internal
nettools and systemd DHCP implementation.
2020-01-25 11:37:44 +01:00
Beniamino Galvani 1cbf9d22a5 n-dhcp4: accept options that are longer than requested
If the server sends a packet with multiple instances of the same
option, they are concatenated during n_dhcp4_incoming_linearize() and
evaluated as a single option as per section 7 of RFC 3396.

However, there are broken server implementations that send
self-contained options in multiple copies. They are reassembled to
form a single instance by the nettools client, which then fails to
parse them because they have a length greater than the expected one.

This problem can be reproduced by starting a server with:

  dnsmasq --bind-interfaces --interface veth1 -d
          --dhcp-range=172.25.1.100,172.25.1.200,1m
	  --dhcp-option=54,172.25.1.1

In this way dnsmasq sends a duplicate option 54 (server-id) when the
client requests it in the 'parameter request list' option, as
dhcp=systemd and dhcp=nettools currently do.

While this is a violation of the RFC by the server, both isc-dhcp and
systemd-networkd client implementations have mechanisms to deal with
this situation. dhclient simply takes the first bytes of the
aggregated option. systemd-networkd doesn't follow RFC 3396 and
doesn't aggregate multiple options; it considers only the last
occurrence of each option.

Change the parsing code to accept options that are longer than
necessary.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/324
2020-01-25 11:31:58 +01:00
Thomas Haller c6745013fb device: minor cleanup NMDevice's _set_state_full() for unrefing activation request 2020-01-20 14:45:14 +01:00
Thomas Haller c2f8400e66 libnm: fix another leak when cleaning up NMClient
We now move the deletion of the context-busy-watcher to and idle handler
on the D-Bus GMainContext.

Note that the idle source does not take an additional reference on the
context. Hence, in certain cases it might happen that the context will
be completely unrefed before the idle handler runs. In that case, we
would leak the object.

Avoid that, by taking an additional reference to the GMainContext.

Note that the alternative would be to unref the context-busy-watcher
via the GSource's GDestroyNotify. That is not done, because then the
busy watcher might be unrefed in a different thread. Instead, we want
that to happen for the right context. The only minor downside of this
is that the user now always pays the price and must iterate the context
to fully clean up. But note that the user anyway must be prepared to
iterate the context after NMClient is gone. And that depends on some
unpredictable events that the user cannot control. That means, either
the user handles this correctly already, or the problem anyway exists
(randomly).

Of course all of the discussed "problems" are very specific. In practice, the
users uses the g_main_context_default() instance and anyway will either
keep iterating it or quit the process after the NMClient instance goes
away.
2020-01-16 14:43:29 +01:00
Thomas Haller b1b69c1c7b libnm: merge branch 'th/client-object-manager-dbus-leak'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/398
2020-01-16 12:47:53 +01:00
Thomas Haller b572c0542a libnm: keep context-busy-watcher of NMClient alive for one more idle round
The context-busy-watch has two purposes:

1) it allows the user to watch whether the NMClient still has pending
  GSource'es attached to the GMainContext.
2) thereby, it also keeps the inner GMainContext integrated into the
  caller's (in case of synchronous initialization of NMClient).

Especially for 2), we must not get this wrong. Otherwise, we might
un-integrate the inner GMainContext too early and it will be leaked
indefinitely (because the user has no means to access or iterate it).

To be extra careful, extend the lifetime of the context-busy-watcher
for one more idle invocation. Theoretically, this should not be necessary,
but it's not clear whether something else is still pending.

The downside of that extra safety is that it is probably unnecessary in
practice. And in case where it is necessary, it hides an actual
issue, making it harder to notice and fix it.
2020-01-16 12:44:56 +01:00
Thomas Haller a2fd2ab55d shared: remove nm_dbus_connection_signal_subscribe_object_manager() helper
It seems to complicate things more than helping. Drop it. What we still have
is a wrapper around plain g_dbus_connection_signal_subscribe(). That one is
trivial and helpful. The previous wrapper seems to add more complexity.
2020-01-16 12:42:41 +01:00
Thomas Haller 13c30f987c core/bluetooth: don't use nm_dbus_connection_signal_subscribe_object_manager()
nm_dbus_connection_signal_subscribe_object_manager() wraps the subscription. The problem
is that this requires to pass a destroy notify function for cleaning up. Such a destroy
notify function will result in an idle source when unsubscribing, which keeps the associated
GMainContext alive (until it gets iterated some more). That seems error prone and outright
unsuitable for NMClient.

While the helper may be useful, it cannot be used by NMClient. So, there is only one
user of this function and we don't expect a second one. It seems better to get rid of
this wrapper and implement it directly.
2020-01-16 12:42:41 +01:00
Thomas Haller e280124757 libnm: avoid leaking GMainContext for sync initialization after context-busy-watcher quits
When passing a destroy notify to g_dbus_connection_signal_subscribe(),
that callback gets invoked as an idle handler of the associated
GMainContext. That caused to have yet another source attached to the
context after the NMClient gets destroyed.

Especially with synchronous initialization of NMClient that is bad,
because we may destroy the context-busy-watcher too early. That results
in removing the integration of the inner GMainContext into the caller's
context, and thus we leak the inner context indefinitely.

Avoid that leak by not passing a cleanup function to
g_dbus_connection_signal_subscribe().

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2020-01-16 12:42:41 +01:00
Thomas Haller 1afabd5ffd shared: add nm_source_func_unref_gobject() helper 2020-01-16 12:42:41 +01:00
Thomas Haller 3925ff4833 ifcfg-rh: merge branch 'th/ifcfg-parse-route-file-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/392
2020-01-16 12:41:05 +01:00
Thomas Haller 4fc7c7eec0 ifcfg-rh: avoid creaing route file twice in make_ip4_setting()
Just read the content once. It's wasteful to read the file twice
while parsing.

But what is worse, the file content can change any time we read it.
We make decisions based on what we read, and hence we should only
read the file once in the parsing process to get one consistent result.
2020-01-16 12:40:01 +01:00
Thomas Haller 16ba286e30 ifcfg-rh: expose constructor for shvarFile that doesn't read content from file 2020-01-16 12:40:01 +01:00
Thomas Haller b1fa27f9bd ifcfg-rh: split reading file and parsing from read_route_file() function
Split the parsing of the file content to a separate function.

Next we will load IPv4 files only once, and thus only need to parse
the content without reading it.

Note that the function temporarily modifies the input buffer, but
restores the original content before returning.
2020-01-16 12:40:01 +01:00
Thomas Haller 9f35d9e49e ifcfg-rh: split reading file and parsing in utils_has_route_file_new_syntax() function
We will need both variants, so that the caller can read the file only
once.

Note that also utils_has_route_file_new_syntax_content() will
restore the original contents and not modify the input (from point
of view of the caller). In practice it will momentarily modify the
content.
2020-01-16 12:40:01 +01:00
Thomas Haller da4a3dd24c ifcfg-rh: don't use GRegex in utils_has_route_file_new_syntax()
It's simple enough to iterate the file content line by line
and search for a suitable prefix.
2020-01-16 12:40:01 +01:00
Thomas Haller 5aee49aaae ifcfg-rh/tests: add test for utils_has_route_file_new_syntax() 2020-01-16 12:40:01 +01:00
Thomas Haller d944761f83 shared/tests: add nmtst_file_set_contents_size() helper 2020-01-16 12:40:01 +01:00
Thomas Haller f69746c9f9 clients: avoid compiler warning about redefining NDEBUG for qrcodegen
[1/5] Compiling C object 'clients/common/913ef36@@nmc-base@sta/nm-client-utils.c.o'.
  ../clients/common/nm-client-utils.c:528: warning: "NDEBUG" redefined
    528 | #define NDEBUG
        |
  <command-line>: note: this is the location of the previous definition
2020-01-15 22:25:21 +01:00
Thomas Haller a6b6f33f01 build: fix linking of "src/devices/wifi/tests/test-devices-wifi"
On ppc64le, the linking fails due to unresolved symbols.

Fixes: 7d8da6c9c1 ('build: build intermediate library with core wifi for device-plugin and tests')
2020-01-15 17:43:07 +01:00
Carmen Bianca Bakker 85aadf8e15 po: update Esperanto (eo) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/395
2020-01-15 15:28:24 +01:00
Thomas Haller 21d4a26188 core: remove code for unused NM_WIFI_P2P_PEER_GROUPS property 2020-01-15 13:54:45 +01:00
Thomas Haller e00d36f5dd core: drop "Groups" property from WifiP2PPeer D-Bus API
This property is currently most likely not used. Also, because libnm doesn't
expose it and the only known user of this API (gnome-network-displays) doesn't
use it.

In the future we may want to expand on the Groups API. E.g. exposing groups as
separate D-Bus objects, in which case a better property type would be "ao" and
not "as". For now, that is unclear nor requested.

Remove the property for now.
2020-01-15 13:54:45 +01:00
Thomas Haller 05f66697e4 libnm: ignore "Groups" property of WifiP2PPeer
Groups currently are not exposed on D-Bus as separate objects.
Also, we might want to expose the property as "ao" instead of "as".
This API needs more thought.

There are likely no users that rely on this property. So, we will
drop it from server side, until it will be requested and newly designed.

Regardless, NMClient needs to gracefully ignore the property.
Despite we will remove it from 1.24 API, libnm should ignore the
property on previous versions. Mark it accordingly.
2020-01-15 13:53:57 +01:00
Thomas Haller e978eca644 libnm: fix exposing nm_wifi_p2p_peer_get_name() from D-Bus property
Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2020-01-15 13:37:20 +01:00
Thomas Haller 109a6fd557 introspection: belatedly add Wi-Fi P2P peer "Name" property to D-Bus introspection file
Fixes: 00e64d1332 ('core/devices: Add P2P Wifi device and peer tracking')
2020-01-15 13:32:33 +01:00
Thomas Haller 51b39ceb33 libnm: fix wrong assertion in nm_client_add_and_activate_connection2_finish()
Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2020-01-15 12:32:02 +01:00
Benjamin Berg e8cc69c37e libnm: fix interface and object path for P2P StartFind/StopFind calls
The change to use a GDBusConnection (7871105ff9) introduced a bug by
using the wrong hardcoded path and the wrong interface. Correct this
mistake again.

Fixes: 7871105ff9 ('libnm: implement nm_device_wifi_p2p_start_find()/nm_device_wifi_p2p_stop_find() by using GDBusConnection directly')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/399
2020-01-15 11:55:57 +01:00
Thomas Haller 7766e24cdc license: add Iñigo to RELICENSE.md
https://mail.gnome.org/archives/networkmanager-list/2020-January/msg00014.html
2020-01-14 17:30:44 +01:00
Thomas Haller d7d66f0963 license: add Dan, Dan, Lubomir and Franceso to RELICENSE.md
Dan Williams:      https://mail.gnome.org/archives/networkmanager-list/2020-January/msg00013.html
Dan Winship:       https://mail.gnome.org/archives/networkmanager-list/2020-January/msg00012.html
Francesco Giudici: https://mail.gnome.org/archives/networkmanager-list/2020-January/msg00015.html
Lubomir Rintel:    https://mail.gnome.org/archives/networkmanager-list/2020-January/msg00018.html
2020-01-14 17:25:11 +01:00
Thomas Haller 694e22f88d license: add list for legal entities to track their relation of contributors
And add "Red Hat, Inc." there. The actual consent is not yet determined.
2020-01-14 17:13:37 +01:00
Thomas Haller 6d9f1725db license: relicense "shared/nm-std-aux/nm-dbus-compat.h" under LGPL-2.1+
"nm-dbus-compat.h" was GPL licensed. That is a problem, because we use it from
libnm (which is LGPL).

The history of this file in NetworkManager source tree:

  $ git shortlog -n -s e055bdbbc3 -- shared/nm-std-aux/nm-dbus-compat.h include/nm-dbus-compat.h shared/nm-dbus-compat.h
       5    Thomas Haller
       1    Dan Winship
       1    Lubomir Rintel

Note that commit dd0e198955 ('include: add nm-dbus-compat.h')
introduced this file from dbus sources ([1]). Hence, originally
the file is (like all of dbus sources) dual-licensed under GPL-2.0+
and Academic Free License 2.1 (AFL-2.1). That makes it problematic to
change the license of this file to LGPL also because of the old history
of the file.

Instead, drop everything from the header except the bits that we
actually use. I claim the remainder is trivial and only contains
defines for documented D-Bus API. I don't think that the remainder
is copyrightable and hence get rid of the copy-right notice and the
GPL license.

[1] 39ea37b587/dbus/dbus-shared.h
2020-01-14 16:54:43 +01:00
Thomas Haller d60cb4d5de initrd: merge branch 'lr/a-pair-of-ibft-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/393
2020-01-14 16:44:51 +01:00
Thomas Haller 9f95b797f1 initrd/cmdline: minor style cleanups 2020-01-14 16:43:26 +01:00
Lubomir Rintel 39e1e723de initrd/cmdline: obey rd.iscsi.ibft
Do process the connections from the iBFT block if the rd.iscsi.ibft or
rd.iscsi.ibft=1 argument is present.

This is supposed to fix what was originally reported by Kairui Song
<kasong@redhat.com> here: https://github.com/dracutdevs/dracut/pull/697
2020-01-14 16:43:26 +01:00
Lubomir Rintel 59ead70952 initrd/ibft-reader: don't set con.interface-name in iBFT connections
If an argument in form ip=eth0:ibft is specified, we'd first create a
wired connection with con.interface-name and then proceed completing it
from the iBFT block. At that point we also add the MAC address, so the
interface-name is no longer necessary..

Worse even, for VLAN connections, it results in an attempt to create
a VLAN with the same name as the parent wired device. Ooops.

Let's just drop it. MAC address is guarranteed to be there and does the
right thing for both plain wired devices as well as VLANs.
2020-01-14 16:43:26 +01:00
Thomas Haller de818bf610 n-dhcp4: fix integer context in n_dhcp4_client_probe_transition_nak() on 32 bit
Fixes: 218782a9a3 ('n-dhcp4: restart the transaction after a NAK')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/339
2020-01-14 16:25:49 +01:00
Thomas Haller c6f9002b13 platform: merge branch 'th/ifa-broadcast'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/391
2020-01-14 16:10:50 +01:00
Thomas Haller 7910333527 platform: generate IFA_BROADCAST address based on the peer IFA_ADDRESS
This is also what iproute2 does ([1]) when creating a default broadcast address
with `ip addr add 192.168.1.5/24 brd + dev eth0`.

Also, kernel does in fib_add_ifaddr() ([2]):
```
        __be32 addr = ifa->ifa_local;
        __be32 prefix = ifa->ifa_address & mask;

        ...

        /* Add broadcast address, if it is explicitly assigned. */
        if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF))
                fib_magic(RTM_NEWROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32,
                          prim, 0);

        if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags & IFA_F_SECONDARY) &&
            (prefix != addr || ifa->ifa_prefixlen < 32)) {
                if (!(ifa->ifa_flags & IFA_F_NOPREFIXROUTE))
                        fib_magic(RTM_NEWROUTE,
                                  dev->flags & IFF_LOOPBACK ? RTN_LOCAL : RTN_UNICAST,
                                  prefix, ifa->ifa_prefixlen, prim,
                                  ifa->ifa_rt_priority);

                /* Add network specific broadcasts, when it takes a sense */
                if (ifa->ifa_prefixlen < 31) {
                        fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix, 32,
                                  prim, 0);
                        fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix | ~mask,
                                  32, prim, 0);
                }
        }
```

Which means by default kernel already adds those special broadcast routes which
are identical to what we configure with IFA_BROADCAST. However, kernel too bases
them on the peer (IFA_ADDRESS).

[1] https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/ip/ipaddress.c?id=d5391e186f04214315a5a80797c78e50ad9f5271#n2380
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/fib_frontend.c?id=bef1d88263ff769f15aa0e1515cdcede84e61d15#n1109
2020-01-14 16:09:24 +01:00
Thomas Haller 71d5550547 platform: track IFA_BROADCAST address in NMPlatformIP4Address
- track the broadcast address in NMPlatformIP4Address. For addresses
  that we receive from kernel and that we cache in NMPlatform, this
  allows us to show the additional information. For example, we
  can see it in debug logging.

- when setting the address, we still mostly generate our default
  broadcast address. This is done in the only relevant caller
  nm_platform_ip4_address_sync(). Basically, we merely moved setting
  the broadcast address to the caller.
  That is, because no callers explicitly set the "use_ip4_broadcast_address"
  flag (yet). However, in the future some caller might want to set an explicit
  broadcast address.

In practice, we currently don't support configuring special broadcast
addresses in NetworkManager. Instead, we always add the default one with
"address|~netmask" (for plen < 31).

Note that a main point of IFA_BROADCAST is to add a broadcast route to
the local table. Also note that kernel anyway will add such a
"address|~netmask" route, that is regardless whether IFA_BROADCAST is
set or not. Hence, setting it or not makes very little difference for
normal broadcast addresses -- because kernel tends to add this route either
way. It would make a difference if NetworkManager configured an unusual
IFA_BROADCAST address or an address for prefixes >= 31 (in which cases
kernel wouldn't add them automatically). But we don't do that at the
moment.

So, while what NM does has little effect in practice, it still seems
more correct to add the broadcast address, only so that you see it in
`ip addr show`.
2020-01-14 16:09:24 +01:00
Beniamino Galvani e6a9d5b99c merge: branch 'bg/vrf'
Add support for virtual routing and forwarding (VRF) interfaces.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/375
2020-01-14 10:31:41 +01:00
Beniamino Galvani 667568d1b2 core,libnm: add VRF support
Add VRF support to the daemon. When the device we are activating is a
VRF or a VRF's slave, put routes in the table specified by the VRF
connection.

Also, introduce a VRF device type in libnm.
2020-01-14 09:51:56 +01:00
Beniamino Galvani 7c73c6a038 platform: add VRF support
Add support for creating and parsing VRF links.
2020-01-14 09:49:01 +01:00
Beniamino Galvani 89d387f782 ifcfg-rh: add support for VRF slaves
Even if the ifcfg-rh plugin doesn't support VRF connections, it must
be able to read and write other connection types that have a VRF
master.
2020-01-14 09:49:01 +01:00
Beniamino Galvani f4ced16791 libnm-core,cli: add VRF setting
Add new VRF setting and connection types to libnm-core and support
them in nmcli.
2020-01-14 09:49:01 +01:00
Thomas Haller 56e91b11a2 all: merge branch 'th/unix-fd-source'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/378
2020-01-13 15:49:27 +01:00