Commit graph

12596 commits

Author SHA1 Message Date
Beniamino Galvani
336bfcabc4 manager: skip activation of a virtual device if master is missing
Don't realize a virtual device if the master is missing because in
such case the autoactivation can't start and a stale link will be
created.
2020-01-29 16:43:19 +01:00
Thomas Haller
89c8a47047 core: fix device detection due to bug in NM_DEVICE_DEFINE_LINK_TYPES()
Fixes: 86787e0278 ('core: improve implementation of NM_DEVICE_DEFINE_LINK_TYPES() macro')
2020-01-28 14:38:47 +01:00
Thomas Haller
07b66da4a1 core: cleanup setting IP address in NMDeviceIPTunnel 2020-01-28 11:43:22 +01:00
Thomas Haller
8f3b43f009 all: use nm_utils_ipaddr_is_valid() instead of nm_utils_ipaddr_valid()
We should use the same "is-valid" function everywhere.

Since nm_utils_ipaddr_valid() is part of libnm, it does not qualify.

Use nm_utils_ipaddr_is_valid() instead.
2020-01-28 11:17:41 +01:00
Thomas Haller
0f9664f417 shared: use static array indices in function parameter declarations of _nm_utils_inet[46]_ntop()
This should give the compiler more possibilities to warn about wrong
use of the API.

In practice, my current compiler wouldn't flag any issues. However,
some compilers (or compile options) might.
2020-01-28 11:17:41 +01:00
Thomas Haller
cd0863a339 all: use _nm_utils_inet4_ntop() instead of nm_utils_inet4_ntop()
and _nm_utils_inet6_ntop() instead of nm_utils_inet6_ntop().

nm_utils_inet4_ntop()/nm_utils_inet6_ntop() are public API of libnm.
For one, that means they are only available in code that links with
libnm/libnm-core. But such basic helpers should be available everywhere.

Also, they accept NULL as destination buffers. We keep that behavior
for potential libnm users, but internally we never want to use the
static buffers. This patch needs to take care that there are no callers
of _nm_utils_inet[46]_ntop() that pass NULL buffers.

Also, _nm_utils_inet[46]_ntop() are inline functions and the compiler
can get rid of them.

We should consistently use the same variant of the helper. The only
downside is that the "good" name is already taken. The leading
underscore is rather ugly and inconsistent.

Also, with our internal variants we can use "static array indices in
function parameter declarations" next. Thereby the compiler helps
to ensure that the provided buffers are of the right size.
2020-01-28 11:17:41 +01:00
Thomas Haller
06d6de95d6 platform: use IN6_IS_ADDR_UNSPECIFIED() to check for set IPv6 address in _nl_msg_new_link_set_linkinfo() 2020-01-28 11:17:41 +01:00
Thomas Haller
86787e0278 core: improve implementation of NM_DEVICE_DEFINE_LINK_TYPES() macro
I think it's technically not correct to rely on the "sentinal" field
being immediately after the previous field, due to alignment. Implement
the macro differently.
2020-01-28 10:42:08 +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
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
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
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
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
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
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
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
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
Thomas Haller
5af17d80f3 session-monitor: don't use GIOChannel to watch plain file descriptor 2020-01-13 15:46:04 +01:00
Thomas Haller
cc1822d783 lndp: don't use GIOChannel to watch plain file descriptor for socket 2020-01-13 15:46:04 +01:00
Thomas Haller
7848c165a1 platform: don't use GIOChannel to watch plain file descriptor for netlink socket 2020-01-13 15:46:04 +01:00
Thomas Haller
e832c478b0 acd: don't use GIOChannel to watch plain file descriptor for event fd 2020-01-13 15:46:04 +01:00
Thomas Haller
4b46e3a5fa dhcp/nettools: don't use GIOChannel to watch plain file descriptor for event fd 2020-01-13 15:46:04 +01:00
Thomas Haller
e4ab27722a bluez: don't use GIOChannel to watch plain file descriptor for rfcomm 2020-01-13 15:46:04 +01:00
Thomas Haller
c15411d7c9 bluez: don't use GIOChannel to watch plain file descriptor
Also, don't track the GSource via the guint ID but the full
GSource pointer.
2020-01-13 15:46:04 +01:00
Thomas Haller
e90c1de868 all: use nm_g_unix_fd_source_new() instead of g_unix_fd_source_new()
Its source-func argument has the right signature. Otherwise, this is an
easy to make mistake.
2020-01-13 15:46:04 +01:00
Thomas Haller
4972ba0957 platform: use NM_MAKE_STRV() in NMLinuxPlatform:constucted() 2020-01-13 15:46:04 +01:00
Thomas Haller
a90397b963 core: set MAC address for IP tunnels when creating device
There is however a serious issue currently: when NetworkManager creates
virtual devices, it starts from an unrealized NMDevice, creates the
netdev device, realizes the device, and transitions through states
UNMANAGED and DISCONNECTED. Thereby, the state of NMDevice gets cleared
again. That means, if the profile has "connection.stable-id=${RANDOM}"
and "ethernet.cloned-mac-address=stable", then we will first set a
random MAC address when creating the device. Then, the NMDevice
transitions through UNMANAGED state, forgets the MAC address it
generated and creates a new MAC address in stage 1. This should be
fixed by better handling unrealized devices. It also affects all
software devices that set the MAC address upon creation of the
interfaces (as they all should).
2020-01-09 10:42:32 +01:00
Thomas Haller
81d83b9e00 platform: support setting MAC address during nm_platform_link_gre_add()
We should set the MAC address of devices early on, and not later.
2020-01-09 10:42:32 +01:00
Thomas Haller
cb4093fc8f platform: drop NMPlatformLnkMacvtap typedef
In several cases, the layer 2 and layer 3 type are very similar, also from
kernel's point of view. For example, "gre"/"gretap" and "ip6tnl"/"ip6gre"/"ip6gretap"
and "macvlan"/"macvtap".

While it makes sense that these have different NMLinkType types
(NM_LINK_TYPE_MACV{LAN,TAP}) and different NMPObject types
(NMPObjectLnkMacv{lan,tap}), it makes less sense that they have
different NMPlatformLnk* structs.

Remove the NMPlatformLnkMacvtap typedef. A typedef does not make things simpler,
but is rather confusing. Because several API that we would usually have, does
not exist for the typedef (e.g. there is no nm_platform_lnk_macvtap_to_string()).

Note that we also don't have such a typedef for NMPlatformLnkIp6Tnl
and NMPlatformLnkGre, which has the same ambiguity between the link type
and the struct with the data.
2020-01-09 10:42:32 +01:00
Thomas Haller
f30ae56608 platform: implement link_macvlan_add via nm_platform_link_add() 2020-01-09 10:42:32 +01:00
Thomas Haller
1ffdca6331 platform: implement link_macsec_add via nm_platform_link_add() 2020-01-09 10:42:32 +01:00
Thomas Haller
14b5627633 platform: implement link_ipip_add via nm_platform_link_add() 2020-01-09 10:42:32 +01:00
Thomas Haller
16fd8ddf95 platform: implement link_ip6gre_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
bfd74974dc platform: implement link_ip6tnl_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
8b417300ca platform: implement link_6lowpan_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
d3963e4ac7 platform: implement link_vxlan_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
62b9d8ee33 platform: implement link_vlan_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
4029f9cd2e platform: implement link_sit_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00