Commit graph

11464 commits

Author SHA1 Message Date
Beniamino Galvani
7bd193ef30 device: ensure IP configuration is restored when link goes up
When the link is up and goes down link_changed_cb() schedules
device_link_changed() to be run later. If the function is dispatched
when the link is already up again, it does not detect that the link
was down.

Fix this by storing in the device state that we saw the link down so
that device_link_changed() can properly restore the IP configuration.

https://bugzilla.redhat.com/show_bug.cgi?id=1636715
https://github.com/NetworkManager/NetworkManager/pull/264
2018-12-21 17:54:18 +01:00
Iñigo Martínez
35171b3c3f build: meson: Add trailing commas
Add missing trailing commas that avoids getting noise when another
file/parameter is added and eases reviewing changes[0].

[0] https://gitlab.gnome.org/GNOME/dconf/merge_requests/11#note_291585
2018-12-20 13:50:34 +01:00
Beniamino Galvani
3db4d3aceb device: fix method check in IPvLL code
The check condition was inverted. Anyway, we should receive IPv4LL
events only when the method is LINK_LOCAL so turn this into an
assertion.

Fixes: b16e09a707
2018-12-20 09:49:56 +01:00
Thomas Haller
3102b49f62 core: allow addresses with zero prefix length
There is really no problem here, allow it.

Previously we would assert against a non-zero prefix length.
But I am not sure that all callers really ensured that this
couldn't happen. Anyway, there is no problem we such addresses,
really.

Only we need to make sure that nm_ip4_config_add_dependent_routes()
and nm_ip6_config_add_dependent_routes() don't add prefix routes for
such addresses (which is the case now).
2018-12-19 09:23:08 +01:00
Thomas Haller
9a6a354013 dhcp: fix static-route handling for intenal client and support multiple default routes
Preface: RFC 3442 (The Classless Static Route Option for Dynamic Host
Configuration Protocol (DHCP) version 4) states:

   If the DHCP server returns both a Classless Static Routes option and
   a Router option, the DHCP client MUST ignore the Router option.

   Similarly, if the DHCP server returns both a Classless Static Routes
   option and a Static Routes option, the DHCP client MUST ignore the
   Static Routes option.

Changes:

- sd_dhcp_lease_get_routes() returns the combination of both option 33
(static routes) and 121 (classless static routes). If classless static
routes are provided, the state routes must be ignored.

- we collect the options hash that we expose on D-Bus. For that purpose,
we must not merge both option types as classless static routes. Instead,
we want to expose the values like we received them originally: as two
different options.

- we continue our deviation from RFC 3442, when receiving classless static
routes with option 3 (Router), we only ignore the router if we didn't
already receive a default route via classless static routes.

- in the past, NetworkManager treated the default route specially, and
one device could only have one default route. That limitation was
already (partly) lifted by commit 5c299454b4
(core: rework tracking of gateway/default-route in ip-config). However,
from DHCP we still would only accept one default route. Fix that for
internal client. Installing multiple default routes might make sense, as
kernel apparently can skip unreachable routers (as it notes via ICMP
messages) (rh#1634657).

https://bugzilla.redhat.com/show_bug.cgi?id=1634657
2018-12-19 09:23:08 +01:00
Thomas Haller
2f2b489d38 dhcp: request classless-static-route option first according to RFC 3442
In ip4_start(), we iterate over @dhcp4_requests array and add the
options that are to be included. We do so, by calling
sd_dhcp_client_set_request_option().

Note that sd_dhcp_client_set_request_option() only appends the options
to a list, not taking special care about the order in which options are
added.

RFC 3442 (The Classless Static Route Option for Dynamic Host Configuration
Protocol (DHCP) version 4) says:

   DHCP clients that support this option and send a parameter request
   list MAY also request the Static Routes option, for compatibility
   with older servers that don't support Classless Static Routes.  The
   Classless Static Routes option code MUST appear in the parameter
   request list prior to both the Router option code and the Static
   Routes option code, if present.

Compare to RFC 2132 (DHCP Options and BOOTP Vendor Extensions) which says
about the parameter request list:

   The client MAY list the options in order of preference.

Note, with RFC 7844 (Anonymity Profiles for DHCP Clients), the order
should be randomized. But since we don't follow RFC 7844 (yet), let's follow
at least RFC 3442.
2018-12-19 09:23:08 +01:00
Thomas Haller
795facc2ba network: add sd_dhcp_route_get_option() accessor
Since sd_dhcp_lease_get_routes() returns the list of all routes,
the caller may need to differenciate whether the route was option
33 (static-routes) or 121 (classless-static-route).

Add an accessor for the internal field.

systemd-pull-request: #10951
2018-12-19 09:23:08 +01:00
Thomas Haller
b05ebd54b7 dhcp: minor cleanup parsing default route for internal client
Combine same code.
2018-12-19 09:23:08 +01:00
Thomas Haller
3f99d01c1a dhcp: cleanup parsing of DHCP lease for internal client
- check errors when accessing the lease. Some errors, like a failure
  from sd_dhcp_lease_get_address() are fatal.

- while parsing the individual options, don't incrementally build the
  NMPlatformIP4Address instance (and similar). Instead, parse the
  options to individual variales, and only package them as platform
  structure at the point where they are needed. It makes the code simpler,
  because all individual bits (like "r_plen" variable) are only
  initialized and used at one place. That is clearer than incrementally
  building a platform structure, where you have to follow the code to
  see how the structure mutates.

- drop redundant comments that only serve as a visual separator
  for structuring the code. Instead, structure the code.
2018-12-19 09:23:08 +01:00
Thomas Haller
4aa7285dc2 dhcp: let lease_to_ip4_config() allocate option hash
lease_to_ip4_config() can fail, if the lease is broken. As such, a function
that fails should not modifiy an in/out parameter. Avoid that, by not
having the caller pre-allocate the options hash, but instead allocate it
by the lease_to_ip*_config() functions, and return it only on success.
2018-12-19 09:23:08 +01:00
Thomas Haller
d11572ac42 dhcp: fix signedness of loop variable in lease_to_ip4_config()
The loop variable should have the same type as the variable
that holds the number of elements ("num", in this case).
2018-12-19 09:23:08 +01:00
Thomas Haller
a057d8c3fa dhcp: cleanup static option list for internal client
- use proper data types "guint16" and "bool" in static
  option list. It saves a few bytes, but also it's the appropriate
  type. Well, at least, it's the appropriate type for DHCPv6,
  not for DHCPv4 (which is guint8).

- assert against failure of sd_dhcp_client_set_request_option() and
  sd_dhcp6_client_set_request_option().
2018-12-19 09:23:08 +01:00
Thomas Haller
fed16ff1cb dhcp: don't request DHCP6 client-id option with internal client
sd_dhcp6_client_set_request_option() only accepts a white-listed
set of options. Unexpected options are rejected with -EINVAL.
Currently supported are only:

  - SD_DHCP6_OPTION_DNS_SERVERS
  - SD_DHCP6_OPTION_DOMAIN_LIST
  - SD_DHCP6_OPTION_SNTP_SERVERS
  - SD_DHCP6_OPTION_NTP_SERVER
  - SD_DHCP6_OPTION_RAPID_COMMIT

As such, SD_DHCP6_OPTION_CLIENTID is not accepted and requesting it
was silently ignored.

Fixes: d2dd3b2c90
2018-12-19 09:23:08 +01:00
Thomas Haller
22e276a06b dhcp: cleanup error paths in bound4_handle() and bound6_handle()
- return-early on error

- use cleanup attribute
2018-12-19 09:23:08 +01:00
Thomas Haller
a51c09dc12 all: don't use static buffer for nm_utils_inet*_ntop()
While nm_utils_inet*_ntop() accepts a %NULL buffer to fallback
to a static buffer, don't do that.

I find the possibility of using a static buffer here error prone
and something that should be avoided. There is of course the downside,
that in some cases it requires an additional line of code to allocate
the buffer on the stack as auto-variable.
2018-12-19 09:23:08 +01:00
Thomas Haller
a936086d14 device: drop rp_filter handling
After commit b1082aa9a7 (device: disable
rp_filter handling) drop the now unused code.

https://bugzilla.redhat.com/show_bug.cgi?id=1651097
2018-12-19 09:10:31 +01:00
Thomas Haller
8bf6ae1b7f device: add sysctl-ip-conf getter and use it
- add nm_device_sysctl_ip_conf_get() and nm_device_sysctl_ip_conf_get_int_checked().
  These functions don't use nm_device_get_ip_iface(), but resolve the
  ifname from the platform cache.

- in general, resolve the name first with nm_device_get_ip_iface_from_platform().
2018-12-19 09:10:31 +01:00
Thomas Haller
f9077fa74d device: add nm_device_get_ip_iface_from_platform()
We have a cached nm_device_get_ip_iface() property. However, the interface
name is not an identifier for a link because it can change at any time.

Also, we already have the (ip) ifindex as proper identifier for the
platform link. We shouldn't use two redundant identifiers to refer to
a link.

Clearly, sometimes we need an ifname. For example for ethtool ioctl or
sysctl path names. For ethtool API, we resolve the actual name as late
as possible, and for sysctl API we prefer NMP_SYSCTL_PATHID_NETDIR*().
However, that is not always possible, for example for /proc/sys/net/ipv6/conf/
sysctls.

Add a function that resolves the ifname by looking into the cache. This
of course is still racy, but it minimizes the time.

Also, we should less and less rely on the ifname, and resolve it as late
as possible. This patch adds a small wrapper going into that direction.
2018-12-19 09:09:32 +01:00
Thomas Haller
91b5babff2 core/trivial: rename nm_platform_sysctl_set_ip6_hop_limit_safe()
Now that we have other helper function on platfrom for setting
IP configuration sysctls, rename the function to set the hop-limit
to match the pattern.
2018-12-19 09:05:12 +01:00
Thomas Haller
18a99e8652 core: use nm_platform_sysctl_ip_conf_*() wrappers 2018-12-19 09:05:12 +01:00
Thomas Haller
7fa398d596 platform: add nm_platform_sysctl_ip_conf_*() wrappers 2018-12-19 09:05:12 +01:00
Thomas Haller
395374cfbe device/trivial: rename device's sysctl function
These functions call platform's sysctl getter and setters.

Note that the called platform functions are called nm_platform_sysctl_get()
and nm_platform_sysctl_set(). Also, in this case they use the ip-conf path
via nm_utils_sysctl_ip_conf_path().

Also, next we will add API nm_platform_sysctl_ip_conf_get() and
nm_platform_sysctl_ip_conf_set(), which will be wrappers around
nm_platform_sysctl_get() and nm_platform_sysctl_set(), using the ip-conf
paths as well.

Rename the device functions, to be more similar to the existing and future
naming in platform.
2018-12-19 09:03:43 +01:00
Thomas Haller
d27fa36272 device: merge IPv4 and IPv6 variants of nm_device_ipv4_sysctl_set()
For one, next we will drop setting rp_filter, hence there are no
more users of an IPv4 variant and nm_device_ipv4_sysctl_set() would
have to be dropped anyway.

However, instead of doing that, merge the IPv4 and IPv6 variant.

With this, the fallback to the default is now also supported for IPv6
(though unused).

Also, don't access nm_device_get_ip_iface(). The interface name might
not be right, we should only rely on the ifindex. Load the interface
name from platform cache instead.
2018-12-19 08:58:50 +01:00
Thomas Haller
8b9fd01ef3 platform: use struct initializer instead of memset()
I think this is preferred over memset(), because it allows the
compiler to better unstand what is happening.

Also, strictly speaking in the C language, %NULL pointers are not
guaranteed to have an all zero bit pattern. Of course, that is already
required on any architecture where NetworkManager is running.
2018-12-19 08:58:12 +01:00
Thomas Haller
67f02b2a14 platform: assert length of stack allocation in NMP_SYSCTL_PATHID_NETDIR_unsafe()
NMP_SYSCTL_PATHID_NETDIR_unsafe() uses alloca() to allocate the string.
Assert that the "path" argument is reasonably short.

In practice, that is of course the case, because there are only 2 callers
which take care not to pass an untrusted, unbounded path argument.
2018-12-19 08:56:51 +01:00
Aleksander Morgado
6ed21e8342 settings,gsm: deprecate and stop using 'number' property
The 'number' property in GSM settings is a legacy thing that comes
from when ModemManager used user-provided numbers, if any, to connect
3GPP modems.

Since ModemManager 1.0, this property is completely unused for 3GPP
modems, and so it doesn't make sense to use it in the NetworkManager
settings. Ofono does not use it either.

For AT+PPP-based 3GPP modems, the 'number' to call to establish the
data connection is decided by ModemManager itself, e.g. for standard
GSM/UMTS/LTE modems it will connect a given predefined PDP context,
and for other modems like Iridium it will have the number to call
hardcoded in the plugin itself.

https://github.com/NetworkManager/NetworkManager/pull/261
2018-12-19 08:54:50 +01:00
Thomas Haller
f877ba8c04 core: avoid calling platform code with invalid ifindex (5)
https://bugzilla.redhat.com/show_bug.cgi?id=1659790

Fixes: 945c904f95
2018-12-16 20:34:45 +01:00
Aleksander Morgado
90e9695af5 wwan: rework when settings/device are blocked for autoconnection
The reasons to block autoconnection at settings level are not the same
as the ones to block autoconnection at device level.

E.g. if the SIM-PIN is wrong, you may want to block autoconnection
both at settings level (as the PIN configured in settings is wrong)
and at device level (so that no other setting is tried automatically).

For some other reasons, you may want to block autoconnection only at
setting level (e.g. wrong APN).

And for some other reasons you may want to block autoconnection at
device level only (e.g. SIM missing), so that the autoconnection
blocking is removed when the device goes away. This is especially
important with SIM hotplug events processed by ModemManager, as a
device without SIM will be removed from MM when a new SIM is
inserted, so that a completely new object is exposed in MM with the
newly detected SIM.

https://github.com/NetworkManager/NetworkManager/pull/259
2018-12-14 14:25:36 +01:00
Thomas Haller
672852c4d3 dhcp: support generating DHCP client-id/duid for infiniband
https://bugzilla.redhat.com/show_bug.cgi?id=1658057
2018-12-14 13:49:54 +01:00
Thomas Haller
6e48e99be4 core: add nm_utils_detect_arp_type_from_addrlen() helper
and use it in "nm-dhcp-systemd.c".
2018-12-14 09:53:47 +01:00
Beniamino Galvani
0819563e01 ifcfg-rh: fix reading SR-IOV settings
Fixes: d48f389cbf
2018-12-13 18:06:43 +01:00
Aleksander Morgado
87bed48974 devices,bluetooth: fix default CDMA number setting
https://github.com/NetworkManager/NetworkManager/pull/260

Fixes: 215306f5a1
2018-12-13 16:58:05 +01:00
Thomas Haller
b1082aa9a7 device: disable rp_filter handling
Don't let NetworkManager change rp_filter sysctl [1]. By default, various
distributions set rp_filter rather strict. That works badly, in common cases
where the user connects multiple interfaces to the same IP network (for
example, using Wi-Fi and ethernet in your home network). It also confuses
connectivity checking. For that reason, NetworkManager would loosen the
rp_filter setting.

However, that was not configurable and users who really wanted a strict
setting could not prevent NetworkManager from doing it ([2], [3], [4]).

Hence it was decided, that a better solution is for NetworkManager not
to do anything about rp_filter. Instead, distibutions should not enable
it strictly (or at least, only for certain setups where it makes sense
-- if it ever makes sense) ([5], [6]);

Disble this behavior for the moment. In the future, the code will be
removed entirely.

[1] https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1492472
[4] https://bugzilla.redhat.com/show_bug.cgi?id=1593194
[3] https://bugzilla.redhat.com/show_bug.cgi?id=1651097
[5] https://bugzilla.redhat.com/show_bug.cgi?id=1653824
[6] https://github.com/systemd/systemd/pull/10971

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1651097
2018-12-13 14:23:07 +01:00
Beniamino Galvani
a3383726dc settings: apply agent-owned secrets from the new connection on update
When updating a connection passing agent-owned secret, they are lost
from @reread_connection after the settings-plugin persists the
connection. Therefore we need to cache and reapply them separately to
the connection so that they can be saved to secret agents later.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/82
2018-12-13 11:14:21 +01:00
Benjamin Berg
1371414e3d supplicant: Add methods to start/stop a P2P Find operation
The timeout is limited to be in the range of 1-600s. This is arbitrary,
but the point is that a timeout of 0 is not permitted to prevent a
client from making us run a find continuously simply by forgetting to
call the stop method.
2018-12-13 09:20:55 +01:00
Benjamin Berg
c05aa3b309 supplicant: Add API to join/cancel/disconnect a P2P Group 2018-12-13 09:20:55 +01:00
Benjamin Berg
6352213e16 supplicant: Export group path of active group
This can be used to check whether a peer is joined to our group.
2018-12-13 09:20:55 +01:00
Benjamin Berg
f05b7a78c9 supplicant: Track P2P Group information, creation and destruction
Add basic tracking of P2P group information and the creation and
destruction of them.
2018-12-13 09:20:55 +01:00
Benjamin Berg
15b7b36718 supplicant: Allow creating an interface from object path
wpa_supplicant will create a new interface for P2P devices. In this case
we need to fetch the supplicant interface using the object path and then
fetch the interface name via dbus to setup the IP interface of the P2P
device later.
2018-12-13 09:20:55 +01:00
Benjamin Berg
08c28ef96b supplicant: Monitor existance of P2P Peers found 2018-12-13 09:20:55 +01:00
Benjamin Berg
ae22631d66 supplicant: Connect to P2PDevice supplicant interface
The wpa_supplicant interface has a P2PDevice when P2P is supported.
Create a proxy for this and wait for it to be ready before marking the
interface as ready.
2018-12-13 09:20:55 +01:00
Benjamin Berg
e2a99cabda supplicant: Detect P2P and WFD support
Add detection for P2P and WFD support in wpa_supplicant and pass the
information to the NMSupplicantInterface.
2018-12-13 09:20:55 +01:00
Benjamin Berg
55407fd027 supplicant: Handle interface removal
The signal was not handled, potentially creating corner cases where
NetworkManager may not notice an interface removal. Add a handler and
ensure the supplicant interface is brought down when it is removed from
wpa_supplicant for a reason other than NetworkManager requesting it.
2018-12-13 09:20:55 +01:00
Thomas Haller
b16e09a707 core: use streq() instead of strcmp() for comparing ip-config methods
Refactor some code to use nm_streq() and NM_IN_STRSET() instead of
strcmp().

Note that nm_utils_get_ip_config_method() never returns %NULL (not even
with g_return*() assertion failures). nm_streq() is sufficent.
2018-12-13 09:16:32 +01:00
Thomas Haller
589063db3b core: use addr-family argument for nm_utils_get_ip_config_method()
Recently, more and more code was refactored to use an addr_family
integer to distinguish between IPv4 and IPv6.

Refactor nm_utils_get_ip_config_method() and nm_device_get_effective_ip_config_method()
to do that too. If we use different identifiers, we need to translate from one to
another and its inconsistent. Also, accessing a GType is an unnecessary function call,
instead of a plain constant.
2018-12-13 09:16:32 +01:00
Benjamin Berg
adbb9eb246 core: allow devices to modify the meaning of the AUTO IP config method
For P2P wifi we need to do DHCP if we are a peer or provide DHCP if we
are the group owner. This may only be decided while establishing the
connection, making the meaning of the AUTO method dynamic.

This adds a way for the device subclass to override the meaning of AUTO.

Patch cherry picked early from [1].

[1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/24
2018-12-13 09:14:27 +01:00
Beniamino Galvani
1e41495d9a platform: sriov: write new values when we can't read old ones
Fixes: 7df3333879
2018-12-12 14:38:18 +01:00
Beniamino Galvani
e01a7c1154 core: use NMTernary for SR-IOV autoprobe-drivers 2018-12-12 14:38:18 +01:00
Beniamino Galvani
d48f389cbf ifcfg-rh: fix persisting sriov setting
The writer should write all properties of the sriov setting when the
setting exists without additional logic. Likewise, the reader should
instantiate a sriov setting when any sriov key is present and blindly
set properties from keys.

The old code did not always preserve the presence of a sriov setting
after a write/read cycle.

Fixes: c02d1c488f
2018-12-12 14:20:32 +01:00
Beniamino Galvani
529533a50c device: reset SR-IOV VFs on deactivation
If the connection has a sriov setting we configure SR-IOV VFs on
activation. We should also clear resources when the connection
deactivates.
2018-12-12 14:18:53 +01:00