Commit graph

11731 commits

Author SHA1 Message Date
Thomas Haller
b8398b9e79 platform: add NMPRulesManager for syncing routing rules
Routing rules are unlike addresses or routes not tied to an interface.
NetworkManager thinks in terms of connection profiles. That works well
for addresses and routes, as one profile configures addresses and routes
for one device. For example, when activating a profile on a device, the
configuration does not interfere with the addresses/routes of other
devices. That is not the case for routing rules, which are global, netns-wide
entities.

When one connection profile specifies rules, then this per-device configuration
must be merged with the global configuration. And when a device disconnects later,
the rules must be removed.

Add a new NMPRulesManager API to track/untrack routing rules. Devices can
register/add there the routing rules they require. And the sync method will
apply the configuration. This is be implemented on top of NMPlatform's
caching API.
2019-03-13 09:47:37 +01:00
Thomas Haller
5ae2431b0f platform/tests: add tests for handling policy routing rules 2019-03-13 09:03:59 +01:00
Thomas Haller
9992ac1cf8 platform: add routing-rule add/delete netlink functions 2019-03-13 09:03:59 +01:00
Thomas Haller
9934a6a0e3 platform: add support for routing-rule objects and cache them in platform
Add and implement NMPlatformRoutingRule types and let the platform cache
handle rules.

Rules are special in two ways:

- they don't have an ifindex. That makes them different from all other
  currently existing NMPlatform* types, which have an "ifindex" field and
  "implement" NMPlatformObjWithIfindex.

- they have an address family, but contrary to addresses and routes, there
  is only one NMPlatformRoutingRule object to handle both address
  families.

Both of these points require some special considerations.

Kernel treats routing-rules quite similar to routes. That is, kernel
allows to add different rules/routes, as long as they differ in certain
fields. These "fields" make up the identity of the rules/routes. But
in practice, it's not defined which fields contribute to the identity
of these objects. That makes using the netlink API very hard. For
example, when kernel gains support for a new attribute which
NetworkManager does not know yet, then users can add two rules/routes
that look the same to NetworkManager. That can easily result in cache
inconsistencies.

Another problem is, that older kernel versions may not yet support all
fields, which NetworkManager (and newer kernels) considers for identity.
The older kernel will not simply reject netlink messages with these unknown
keys, instead it will proceed adding the route/rule without it. That means,
the added route/rule will have a different identity than what NetworkManager
intended to add.
2019-03-13 09:03:59 +01:00
Thomas Haller
b9ee40b86b platform: separate the refresh-type from the object type
Currently, there is a directy one to one relation between

 - DELAYED_ACTION_TYPE_REFRESH_ALL_*

 - REFRESH_ALL_TYPE_*

 - NMP_OBJECT_TYPE_*

For IP addresses, routes and routing policy rules, when we request
a refresh-all (NLM_F_DUMP), we want to specify the address family.

For addresses and routes that is currently solved by having two
sets of NMPObject types, for each address family one.

I think that is cumbersome because the implementations of both address
families are quite similar. By implementing both families as different
object types, we have a lot of duplicate code and it's hard to see where
the families actually differ. It would be better to have only one NMPObject
type, but then when we "refresh-all" such types, we still want to be able
to dump all (AF_UNSPEC) or only a particular address family (AF_INET, AF_INET6).

Decouple REFRESH_ALL_TYPE_* from NMP_OBJECT_TYPE_* to make that
possible.
2019-03-13 09:03:59 +01:00
Thomas Haller
0a2a861782 platform/trivial: rename enum DELAYED_ACTION_IDX_REFRESH_ALL_* to REFRESH_ALL_TYPE_*
While these numbers are strongly related to DELAYED_ACTION_TYPE_REFRESH_ALL_*,
they differ in their meaning.

These are the refresh-all-types that we support. While some of the delayed-actions
are indeed for refresh-all, they are not the same thing.

Rename the enum.
2019-03-13 09:03:59 +01:00
Thomas Haller
7c5ad2d910 platform: drop unused nm_platform_refresh_all()
The function is unused. It would require redesign to work with
future changes, and since it's unused, just drop it.

The long reasoning is:

    Currently, a refresh-all is tied to an NMPObjectType. However, with
    NMPObjectRoutingRule (for policy-routing-rules) that will no longer
    be the case.

    That is because NMPObjectRoutingRule will be one object type for
    AF_INET and AF_INET6. Contrary to IPv4 addresses and routes, where
    there are two sets of NMPObject types.

    The reason is, that it's preferable to treat IPv4 and IPv6 objects
    similarly, that is: as the same type with an address family property.

    That also follows netlink, which uses RTM_GET* messages for both
    address families, and the address family is expressed inside the
    message.

    But then an API like nm_platform_refresh_all() makes little sense,
    it would require at least an addr_family argument. But since the
    API is unused, just drop it.
2019-03-13 09:03:59 +01:00
Thomas Haller
bbfb8a9b33 platform: suppress unnecessary logging in do_request_all_no_delayed_actions()
When we refresh all links, we clear all flags to refresh a specific
link. However, only log a message if there was anything to clear.
2019-03-13 09:03:59 +01:00
Thomas Haller
2c37a3fb1e platform: add NULL check in inline nmp_object_unref() function
This allows the compiler to see that this function does nothing for %NULL.
That is not so unusual, as we use nm_auto_nmpobj to free objects. Often
the compiler can see that these pointers are %NULL.
2019-03-13 09:03:59 +01:00
Thomas Haller
ac4a1deba0 platform: add NMPlatformObjWithIfindex helper structure for handling NMPObject types
Until now, all implemented NMPObject types have an ifindex field (from
links, addresses, routes, qdisc to tfilter).

The NMPObject structure contains a union of all available types, that
makes it easier to down-case from an NMPObject pointer to the actual
content.

The "object" field of NMPObject of type NMPlatformObject is the lowest
common denominator.

We will add NMPlatformRoutingRules (for policy routing rules). That type
won't have an ifindex field.

Hence, drop the "ifindex" field from NMPlatformObject type. But also add
a new type NMPlatformObjWithIfindex, that can represent all types that
have an ifindex.
2019-03-13 09:03:59 +01:00
Thomas Haller
667aa52f89 platform: move nmp_class_from_type() to header to allow inlining 2019-03-13 09:03:59 +01:00
Thomas Haller
8f3724a6bd platform: drop unnecessary casts from NMP_OBJECT_CAST_*() macros
It's wrong to cast here. The caller must always provide an
NMPObject pointer.
2019-03-13 09:03:59 +01:00
Thomas Haller
7259195a91 platform: unify IPv4 and IPv6 variables for NMPlatformVTableRoute 2019-03-13 09:03:59 +01:00
Lubomir Rintel
2e8f43e379 wwan/device-modem: don't enter available state until registered
Based on Ubuntu's "Modify NMDeviceModem's available logic" patch by
Tony Espy <espy@canonical.com>. The original commit message:

This patch modifies NMDeviceModem's available logic such that the device
is only considered available if the modem_state is
>= NM_MODEM_STATE_REGISTERED.  NMDevice defines 'available' as meaning the
device is in such a state that it can be activated.  This change prevents
NM from trying to activate a modem which is not yet ready to be activated.

Bug-Ubuntu: https://bugs.launchpad.net/bugs/1445080
https://github.com/NetworkManager/NetworkManager/pull/312
2019-03-12 16:02:04 +01:00
Lubomir Rintel
bf0c4e6ac2 all: codespell fixes
Codespel run with the same arguments as described in
commit 58510ed566 ('docs: misc. typos pt2').
2019-03-11 12:01:44 +01:00
Beniamino Galvani
505d2adbc2 device: restore IPv6 addresses when the link comes up
When the link goes down the kernel removes IPv6 addresses from the
interface. In update_ext_ip_config() we detect that addresses were
removed externally and drop them from various internal
configurations. Don't do that if the link is down so that those
addresses will be restored again on link up.
2019-03-09 15:31:46 +01:00
Beniamino Galvani
39b7257208 core: allow ignoring addresses when intersecting ip configs
Add a new argument to nm_ip_config_* helpers to also ignore addresses
similarly to what we already do for routes. This will be used in the
next commit; no change in behavior here.
2019-03-09 15:30:22 +01:00
Beniamino Galvani
056470a4ba device: reset the ipv6 DAD counter when the link comes up
We can detect false DAD failures if the link goes down. Don't try to
prevent them, but just reset the counter if the link goes down.
2019-03-09 15:27:54 +01:00
Beniamino Galvani
72385f363c device: don't try to add IPv6LL address to a down interface
When the interface is down DAD failures becomes irrelevant and we
shouldn't try to add a link-local address even if the configuration
contains other IPv6 addresses.
2019-03-09 15:25:47 +01:00
Beniamino Galvani
d86dd9a0fe core: fix _nm_ip4_config_intersect_helper()
Fixes: 8f07b3ac4f ('ip-config: add @intersect_routes argument to intersect functions')
2019-03-09 15:25:43 +01:00
Lubomir Rintel
90fe78eb7f wwan/ofono: pass the right argument to manager proxy callback
Otherwise it will be dereferencing NULL when invoked.

Fixes: 58712c9546 ('ofono: take D-Bus proxy for ConnectionManager asynchronously')

https://github.com/NetworkManager/NetworkManager/pull/313
2019-03-08 13:40:18 +01:00
Thomas Haller
7dd44d6dc8 core: assert for valid NM_DEVICE_DEVICE_TYPE setting 2019-03-07 22:40:13 +01:00
Benjamin Berg
8d9365a973 core,wifi-p2p: Fix Wi-Fi P2P device type
The device type was set to the GType rather than a new value in the
NMDeviceType enum.

Add the corresponding enum entry, fix the device type and set the
routing priority to the same value as generic devices.
2019-03-07 22:17:09 +01:00
Thomas Haller
3990c92fbf wireguard: update TODO list for WireGuard devices 2019-03-07 17:54:25 +01:00
Thomas Haller
e46ba01867 libnm: rename and expose nm_utils_base64secret_decode() in libnm
A NetworkManager client requires an API to validate and decode
a base64 secret -- like it is used by WireGuard. If we don't have
this as part of the API, it's inconvenient. Expose it.

Rename it from _nm_utils_wireguard_decode_key(), to give it a more
general name.

Also, rename _nm_utils_wireguard_normalize_key() to
nm_utils_base64secret_normalize(). But this one we keep as internal
API. The user will care more about validating and decoding the base64
key. To convert the key back to base64, we don't need a public API in
libnm.

This is another ABI change since 1.16-rc1.
2019-03-07 17:54:25 +01:00
Thomas Haller
4e399d82ac platform/wireguard: fix WGPEER_A_LAST_HANDSHAKE_TIME to use int64 typed timespec structure
The netlink API changed for WireGuard. Adjust for that.

https://git.zx2c4.com/WireGuard/commit/?id=c870c7af53f44a37814dfc76ceb8ad88e290fcd8
2019-03-07 17:54:25 +01:00
Thomas Haller
7451a6a649 core: use nm_utils_memeqzero_secret() for printing WireGuard key 2019-03-07 17:54:25 +01:00
Lubomir Rintel
9bcd634cbf utils: obey modprobe blacklist
If the user blacklisted a module we should not override their choice.

https://github.com/NetworkManager/NetworkManager/pull/311
2019-03-07 15:49:40 +01:00
Lubomir Rintel
d551a0893e platform/linux: fix detection of IFA_FLAGS support
The condition got accidentally reversed, which means we're always
undecided and thus wrongly assuming support and never being able to set
any addresses.

This would bother the few that are struck with 3.4 android kernels. Very
few indeed, given this got unnoticed since 1.10.

Fixes: 8670aacc7c ('platform: cleanup detecting kernel support for IFA_FLAGS and IPv6LL')
2019-03-07 10:17:42 +01:00
Marco Trevisan (Treviño)
73005fcf5b nm: Fix syntax on introspection annotations
Various annotations were added using multiple colons, while only one has
to be added or g-ir-introspect will consider them part of the description

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/94
2019-03-07 10:04:41 +01:00
Beniamino Galvani
d2e95856e9 wifi-p2p: fix failed assertion when releasing supplicant interface
Fix the following failed assertion:

  <debug> device[0x11dfec0] (p2p-dev-wlp4s0): P2P: Releasing WPA supplicant interface.
  <debug> supplicant: setting WFD IEs for P2P operation
  (../src/devices/nm-device.c:14769):_set_state_full: runtime check failed: (priv->in_state_changed == FALSE)
  <info>  device (p2p-dev-wlp4s0): state change: unmanaged -> unavailable (reason 'supplicant-failed', sys-iface-state: 'external')
  <debug> device[0x11dfec0] (p2p-dev-wlp4s0): add_pending_action (1): 'waiting-for-supplicant'

supplicant_interfaces_release() can be called during a state change
(for example by device_state_changed()) and so it can't trigger
another state change.

nm_device_wifi_p2p_set_mgmt_iface() now doesn't force an immediate
state change and only schedules a recheck-available. This means that
the device can be in an available state without
priv->mgmt_iface. Adapt the code to deal gracefully with that
situation. In particular, we need to cancel pending timeout sources
(priv->sup_timeout_id) that use the management interface.

Fixes: 27bc2cb22a

https://github.com/NetworkManager/NetworkManager/pull/302
2019-03-06 08:03:54 +01:00
Thomas Haller
626beaf83e wireguard: implement direct "peer-routes" for WireGuard allowed-ips ranges 2019-03-05 09:53:21 +01:00
Thomas Haller
d5e93ae613 wireguard: add "mtu" setting for WireGuard profiles
This adds new API for 1.16.0 and is an ABI break since 1.16-rc1.
2019-03-05 09:53:21 +01:00
Thomas Haller
096247e60b device: expose nm_device_ip_config_new() as internal API 2019-03-05 09:53:21 +01:00
Thomas Haller
5e71f01605 device: merge stage3 and stage4 ip-config function for IPv4 and IPv6 2019-03-05 09:53:21 +01:00
Thomas Haller
03b708f7f7 device/trivial: rename wwan_ip_config to dev2_ip_config
dev2_ip_config (formerly wwan_ip_config) is only set by nm_device_set_dev2_ip_config()
(formerly nm_device_set_wwan_ip_config()), which is only called by NMDeviceModem.

For NMDeviceWireGuard we will also inject additional configuration
in the parent class. Rename and give it a wider purpose. The new name
merely indicates that this IP configuration is injected by a subclass
of NMDevice.
2019-03-05 09:53:21 +01:00
Thomas Haller
99abcf0105 device: merge IPv4 and IPv6 variant of nm_device_set_wwan_ip_config() 2019-03-05 09:53:21 +01:00
Thomas Haller
ee63e008d1 device: avoid setting an empty dev_ip_config_4 for activate_schedule_ip_config_result()
An empty NMIP4Config instance should have the same effect as %NULL.
Don't create it.
2019-03-05 09:53:21 +01:00
Thomas Haller
2f88523eef device/trivial: rename dev_ip4_config field
So that it follows the naming pattern of similar fields,
that exist in a variant for IPv4 and IPv6.
2019-03-05 09:53:21 +01:00
Thomas Haller
515e003eff device: unify IPv4 and IPv6 handling of IP state of device 2019-03-05 09:53:21 +01:00
Thomas Haller
ca14df5619 device/trivial: rename ip-state fields in NMDevicePrivate
Now they follow the naming pattern of ending in "_4" / "_6".
We will merge them and alias them to an "_x" array, like done
for similar fields.
2019-03-05 09:53:21 +01:00
Thomas Haller
2076550d8f device/trivial: rename IpState to NMDeviceIPState
It will be moved to a header file.
2019-03-05 09:53:21 +01:00
Thomas Haller
1585eaf473 device: unify IPv4 and IPv6 device methods for IP configs
It is preferable to treat IPv4 and IPv6 in a similar manner.
This moves the places where we differ down the call-stack.

It also make it clearer how IPv6 behaves differently. I think this
is a bug, but leave it for now.

+         /* If IP had previously failed, move it back to IP_CONF since we
+          * clearly now have configuration.
+          */
+         if (priv->ip6_state == IP_FAIL)
+              _set_ip_state (self, AF_INET6, IP_CONF);
2019-03-05 09:53:21 +01:00
Thomas Haller
2be022ad68 core: use nm_connection_get_setting_ip_config() helper 2019-03-05 09:53:21 +01:00
Thomas Haller
be107c75c9 core: accept %NULL as source argument for nm_utils_ipx_address_clear_host_address()
Just for convenience.
2019-03-05 09:53:21 +01:00
Beniamino Galvani
93bbe43695 manager: ignore ovs-system master when assuming connections
This change allows NM to assume after a restart a device that has been
enslaved externally to an ovs bridge.

https://bugzilla.redhat.com/show_bug.cgi?id=1676551
2019-03-04 10:47:00 +01:00
Thomas Haller
6580f2931d ifcfg-rh: avoid duplicate cache lookup in is_wifi_device() 2019-03-04 10:10:47 +01:00
Beniamino Galvani
560a35dd43 supplicant: fix setting pmf when the supplicant doesn't advertise support
wpa_supplicant only advertises pmf support since commit [1], which is
after 2.6. When using a version without that commit (for example,
plain 2.6), we would unconditionally set the global Pmf property to 1
(optional) and then skip setting the per-network property. The result
was that pmf was enabled without the possibility to disable it by
user. The correct behavior is instead to disable pmf on such versions.

[1] https://w1.fi/cgit/hostap/commit/?id=3cdb4ac074f76accf24a51d143db545afad2c90b

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/129
2019-02-26 18:31:24 +01:00
Beniamino Galvani
cab17ff8e0 supplicant: clarify ready_count usage 2019-02-26 18:31:24 +01:00
Thomas Haller
8f6a8d0517 libnm,core: fix device TYPE for Wi-Fi P2P devices
Don't use "wifip2p" for the type description.

    $ nmcli device
    DEVICE             TYPE      STATE         CONNECTION
    wlan0              wifi      connected     x
    p2p-dev-wlan0      wifip2p   disconnected  --

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/87
2019-02-26 09:13:03 +01:00