Commit graph

21852 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
Thomas Haller
2063283c3a build/meson: merge branch 'inigomartinez/meson-review'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/23
2018-12-20 13:50:41 +01:00
Iñigo Martínez
282af18e16 build: meson: Remove unnecessary auxiliary variable
The variable containing the list of compiler arguments to be checked
can be removed without any harm to readibility.

The variable has been removed by appending directly to the list of
common compiler arguments, those that are supported.
2018-12-20 13:50:34 +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
Iñigo Martínez
b00e004890 build: meson: Use variables present in pkg-config files
Although some paths related to DBus and PolicyKit are present in
their pkg-config files, those paths might not be writable for the
user. To solve this issue, some build options are present that can
be used to choose a different location.

However, usually these paths are relative to some other variables
such as `prefix`, `datadir`, etc. Using the `define_variable`
option the relative path can be change to point to a directory
under prefix.

These paths are now using relative paths based on the installation
`prefix` and their related options have been removed as they are
unnecessary now. Only `dbus_conf_dir` option has been left because
it must be modified depending on the distribution[0].

[0] contrib/fedora/rpm/NetworkManager.spec
2018-12-20 13:50:34 +01:00
Iñigo Martínez
4b32bbc820 build: meson: Remove polkit_dir option
meson is able to get variables defined in pkg-config files such as
directory paths. PolicyKit defines in its pkg-config file the path to
the directory where `policy` files are present.

This removes the `polkit_dir` option to ease the move to start using
those variables. The `polkit` variable has also been converted to
boolean.

Fedora spec script has also been updated accordingly.
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
abe22689bd dhcp: merge branch 'th/internal-dhcp-routes-rh1634657'
https://bugzilla.redhat.com/show_bug.cgi?id=1634657

https://github.com/NetworkManager/NetworkManager/pull/256
2018-12-19 16:50:41 +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
b9ebaf3a2b libnm: discourage static buffer in nm_utils_inet*_ntop() API
nm_utils_inet[46]_ntop() are public API of libnm, so we cannot change
it. However, discourage the use of the static buffer.
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
898f7a5665 libnm: add internal API nm_utils_inet*_ntop_dup()
In quite some cases we need the string representation on the heap.

While nm_utils_inet*_ntop() accepts NULL as output buffer to fallback
to a static buffer, such usage of a static buffer is discouraged.
So, we actually should always allocate a temporaray buffer on the
stack. But that is cumbersome to write.

Add simple wrappers that makes calling this more convenient.
2018-12-19 09:23:08 +01:00
Thomas Haller
1e4c0dd680 shared/tests: add helper functions to convert IP address to string
We have nm_utils_inet*_ntop(), however:

 - that is partly private API libnm-core, and thus only available in
   components that have access to that. Partly it's public API of
   libnm, but still only available in components that use libnm.

 - relying on the static buffers is discouraged for nm_utils_inet*_ntop().
   For testing, that is fine as we are in a more controlled envionment.
   So, add a test variant that explicitly relies on static buffers.
   That way, it's more convenient to use from tests.

 - these functions can assert more and are more convenient to use from
   tests.
2018-12-19 09:23:08 +01:00
Thomas Haller
e442e3881e core: implement nm_utils_ip4_netmask_to_prefix() via __builtin_ctz()
Taken from systemd's in4_addr_netmask_to_prefixlen().

Yes, this adds the requirement that "int" is 32 bits. But systemd
already has the same requirement in u32ctz(), hence we anyway cannot
build on other architectures. If that is ever necessary, it's easy
to adjust.
2018-12-19 09:23:08 +01:00
Thomas Haller
8586ebb745 core: merge branch 'th/sysctl-and-rp_filter'
https://bugzilla.redhat.com/show_bug.cgi?id=1651097

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/62
2018-12-19 09:14:05 +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
f22492f8fc dhcp: merge branch 'th/dhcp-infiniband-client-id'
https://bugzilla.redhat.com/show_bug.cgi?id=1658057

https://github.com/NetworkManager/NetworkManager/pull/262
2018-12-14 14:14:12 +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
Soapux
e9624c254d meson: correct libaudit not found message
libaudit support is disabled with 'no' instead of 'false'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/63
2018-12-13 23:03:02 +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
Thomas Haller
4d88334d23 wifi: merge branch 'bb/supplicant-wifi-p2p-support'
Partially merge [1].

[1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/24
2018-12-13 09:50:11 +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