Commit Graph

16760 Commits

Author SHA1 Message Date
Thomas Haller
16ad046c87 platform: remove unused nmp_utils_device_exists() util 2016-12-13 11:26:59 +01:00
Thomas Haller
3641178508 platform: lookup ifname for ethtool/mii ioctl immediately before use
The ioctl APIs ethtool/mii require an interface ifname. That is inherrently
racy as interfaces can be renamed. This cannot be fixed, we can only
minimize the time between verifying the ifname and calling ioctl.

We already had problems with that when ethtool would access an interface
by name that didn't exists. See commit ab41c13b06 .
Checking for an existing interface only helps avoiding races when an interface
gets deleted. It does not help against renaming.

Go one step further, and instead of checking whether such an ifname
exists, try to get the ifname based on the ifindex immediately before
we need it.

This brings an additional overhead for each ethtool access.
2016-12-13 11:26:59 +01:00
Thomas Haller
da7b8dd850 wifi: remove check for existing device in wifi_wext_is_wifi()
See also commit ab41c13b06.
2016-12-13 11:26:59 +01:00
Thomas Haller
4bdee37771 all: use O_CLOEXEC for file descriptors 2016-12-13 11:26:59 +01:00
Thomas Haller
e332c27824 platform/tests: add tests for nmp_utils_sysctl_open_netdir() 2016-12-13 11:26:59 +01:00
Thomas Haller
6b132a2bd0 platform/tests: use nmtstp_netns_select_random() util 2016-12-13 11:26:59 +01:00
Thomas Haller
5eb4dfe7ab platform/tests: add nmtstp_netns_select_random() util 2016-12-13 11:26:59 +01:00
Thomas Haller
22be2ae865 core: use nmp_utils_sysctl_open_netdir() for platform master/slave options 2016-12-13 11:26:59 +01:00
Thomas Haller
a9a41edcbd core: use nmp_utils_sysctl_open_netdir() in platform link operations 2016-12-13 11:26:59 +01:00
Thomas Haller
7fc3eace31 core: use nmp_utils_sysctl_open_netdir() to detect link-type 2016-12-13 11:26:59 +01:00
Thomas Haller
d3af925b91 core: use nmp_utils_sysctl_open_netdir() to read tun/tap sysctl 2016-12-13 11:26:59 +01:00
Thomas Haller
89a2169b98 core: use nmp_utils_sysctl_open_netdir() to set infiniband sysctl 2016-12-13 11:26:58 +01:00
Thomas Haller
e933a2ff87 core: use nmp_utils_sysctl_open_netdir() to read infiniband sysctl 2016-12-13 11:26:58 +01:00
Thomas Haller
c85418746c platform: implement sysctl access via relative path to sysctl_open_netdir() 2016-12-13 11:26:58 +01:00
Thomas Haller
d8cefd57fb platform: add optional dirfd argument to sysctl functions
Still unused.
2016-12-13 11:26:58 +01:00
Thomas Haller
1d9bdad1df core: add nm_utils_file_get_contents() and nm_utils_fd_get_contents()
A reimplementation of g_file_get_contents() to overcome two limitations:

 - nm_utils_file_get_contents() accepts a @dirfd argument to open the
   file relative using openat().
 - nm_utils_fd_get_contents() allows to read the content from a file
   filedescriptor.
 - both support a max_length argument, to fail gracefully if we
   get tricked into loading a huge file.
2016-12-13 11:26:58 +01:00
Thomas Haller
76876e896c platform: refactor nmp_utils_sysctl_open_netdir()
- use nm_auto_close cleanup attribute
- optionally, return the found ifname
- don't stat "phy80211". If such an entity can be opened,
  just assume it's a directory.
2016-12-13 11:26:58 +01:00
Kai-Heng Feng
b95556eb78 platform: wifi: use nmp_utils_open_sysctl() to check if device is wifi
Since function nmp_utils_open_sysctl() can avoid race condition, use it
in wifi_utils_is_wifi() to open sysfs and correctly check if it's a wifi
device.

https://bugzilla.gnome.org/show_bug.cgi?id=775613
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
2016-12-13 11:26:58 +01:00
Kai-Heng Feng
713c74f6e4 platform: add a new function nmp_utils_open_sysctl()
A race condition may happen when NetworkManager opens sysfs and udev
renames interface name at the same time. Thomas Haller provides a new
function [1] which can avoid the race condition when opening sysfs.

This patch is a direct copy from [1].

[1] https://mail.gnome.org/archives/networkmanager-list/2016-December/msg00004.html

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
2016-12-13 11:26:58 +01:00
Thomas Haller
99e1e4d6a1 shared: add NM_AUTO_PROTECT_ERRNO
Similar to systemd's PROTECT_ERRNO. The difference it, that it doesn't
treat the auto-variable as internal, so it is allowed to use it. E.g.

    if (!(fd = open (...)) {
        NM_AUTO_PROTECT_ERRNO (errno_saved);
        printf ("error: %s", g_strerror (errno_saved));
        return FALSE;
    }
2016-12-13 11:26:58 +01:00
Thomas Haller
215c50922d logging: preserve errno in logging functions
It would be nice that our logging functions are guaranteed to
preserve errno. We are currently not very consistent about handling
errno, let's improve on that.
2016-12-13 11:26:58 +01:00
Thomas Haller
ccf766f659 platform: preserve errno in nm_auto_pop_netns 2016-12-13 11:26:58 +01:00
Thomas Haller
ed299cc860 device/wwan: use nm_auto_close instead of gs_fd_close 2016-12-13 11:26:58 +01:00
Thomas Haller
312cea870d shared: add nm_auto_close and nm_auto_fclose
We already have gs_fd_close, which however doesn't preserve
errno and only checks for fd != -1. Add our own define.

Downside is, we have to include stdio.h and errno.h,
which effectively ends up to be included *everywhere*.
2016-12-13 11:26:58 +01:00
Thomas Haller
7744fdd00f platform: rename _assert_netns_current() to a ASSERT_NETNS_CURRENT()
This assert, although being a regular function has more the character
of a macro as it only contains asserts itself.
2016-12-13 11:26:58 +01:00
Beniamino Galvani
597f327b20 dns: merge branch 'bg/dns-dbus-bgo603321'
https://bugzilla.gnome.org/show_bug.cgi?id=603321
2016-12-12 22:27:39 +01:00
Thomas Haller
3206b72964 dns: split collecting resolv-conf data out of update_dns()
update_dns() is rather complicated. The part where we collect
resolv-conf data can be moved out. That is nice, because
_collect_resolv_conf_data() has no side-effects (except logging)
and it's only purpose is to return the out-arguments.
2016-12-12 22:06:24 +01:00
Thomas Haller
916a0e7cad dns: use cleanup attributes for update_dns()'s strv arrays 2016-12-12 22:06:24 +01:00
Beniamino Galvani
8af465d579 examples: add DNS example with python and GObject introspection 2016-12-12 22:06:24 +01:00
Beniamino Galvani
20bf5ce359 cli: add DNS information to overview output
Example:

   $ nmcli
   [...]
   DNS configuration:
   	servers: 10.0.0.1
   	domains: foobar.com
   	interface: tun0
   	type: vpn

   	servers: 192.168.10.1
   	domains: home
   	interface: ens3

   	servers: fd01🔡:21
   	interface: ens3
2016-12-12 22:06:24 +01:00
Beniamino Galvani
a8d6005256 libnm: implement support for DNS manager properties 2016-12-12 22:06:24 +01:00
Beniamino Galvani
e3c67177ac dns: export current configuration through D-Bus
It is useful to let clients retrieve the current DNS configuration,
which can be displayed to users or used (together with dns=none) to
implement custom DNS configuration logic through external tools.
2016-12-12 22:06:23 +01:00
Beniamino Galvani
14105ece56 dns: export DNS manager D-Bus object
Extend the D-Bus API and introduce a new NMDnsManager interface that
contains all the information related to DNS configuration.

At the moment the new DnsManager object only contains basic properties
describing the current DNS mode and resolv.conf manager.
2016-12-12 21:49:15 +01:00
Beniamino Galvani
5307e07e3b dns: don't print empty configurations
Previously we printed the DNS configuration for all devices including
unmanaged and unconfigured ones:

  dns-mgr: config:      100 best    v4 ens3             : 192.168.10.1
  dns-mgr: config:      100 default v6 ens3             : fd01🔡:3681:c4ff:fec0:fe94
  dns-mgr: config:      100 default v4 lo               :
  dns-mgr: config:      100 default v6 lo               :
  dns-mgr: config:      100 default v4 ens9             :
  dns-mgr: config:      100 default v6 ens9             :

Instead, print only devices that have name servers set.
2016-12-12 21:41:23 +01:00
Beniamino Galvani
8c4e824997 exported-object: don't assert the presence of PropertiesChanged signal
For new interfaces we don't define a PropertiesChanged signal as we
rely on GDBus to generate one on the standard
org.freedesktop.DBus.Properties interface.
2016-12-12 21:41:23 +01:00
Thomas Haller
a2402acfed build: fix dependency of NetworkManager.ver for libnm-ppp-plugin
Fixes: 025235e00f
2016-12-12 21:38:26 +01:00
Beniamino Galvani
a3b61303f8 cli: implement 'networking' subcommand using nmc_do_cmd()
It simplifies the code and doesn't require that NM is running to
display the help.
2016-12-09 17:57:49 +01:00
Francesco Giudici
c5fe886a36 trivial: fix indentation 2016-12-09 07:26:04 +01:00
Thomas Haller
994f1ca96e device: fix activation_source_schedule() for rescheduling the same function
Fixes: 78ca961c0f
2016-12-08 13:26:04 +01:00
Thomas Haller
92ea1bdb06 proxy: stricter validate the proxy pac script in NMSettingProxy 2016-12-06 22:01:41 +01:00
Beniamino Galvani
d7c4807737 ppp: merge branch 'bg/ppp-manager-split-bgo773482-squashed'
https://bugzilla.gnome.org/show_bug.cgi?id=773482
2016-12-06 14:51:14 +01:00
Beniamino Galvani
bdc61c4e95 contrib/rpm: split PPP support into a separate package
This allows to remove from the main package the PPP dependency.
2016-12-06 11:08:11 +01:00
Beniamino Galvani
025235e00f ppp: split ppp manager into a plugin
Moving the PPP manager to a separate plugin that is loaded when needed
has the advantage of slightly reducing memory footprint and makes it
possible to install the PPP support only where needed.

https://bugzilla.gnome.org/show_bug.cgi?id=773482
2016-12-06 11:08:11 +01:00
Beniamino Galvani
2e21d78494 core: factor out plugin validation
The new function will be used to validate other plugins we load.
2016-12-06 11:08:11 +01:00
Beniamino Galvani
7ae6e980e4 core: move plugin path reading function to nm-core-utils.c
Even if it's called only from one place, it can be considered an
utility function.
2016-12-06 11:08:11 +01:00
Lubomir Rintel
a96c819f6f contrib/travis: the test outputs are now logged more sanely
Adjust the travis script accordingly.
2016-12-05 13:54:35 +01:00
Lubomir Rintel
a0aea99bd7 contrib/rpm: mark the config packages noarch 2016-12-05 13:24:51 +01:00
Beniamino Galvani
207a747064 core: merge branch 'bg/ip-order-rh1394500'
https://bugzilla.redhat.com/show_bug.cgi?id=1394500
2016-12-05 10:59:20 +01:00
Beniamino Galvani
2f68a50041 platform: fix the order of addition of primary and secondary IPv4 addresses
nm_platform_ip4_address_sync() tries to apply the new configuration
with the minimum effort and doesn't delete addresses if they are
already present on the interface. This can break the ordering, as an
existing address would be promoted by kernel to primary, even if it
was last in our configuration.

Add some logic to ensure the correct order of addresses is always
enforced. This fixes situations like:

 # nmcli connection add type ethernet ifname eth0 con-name t \
                        ipv4.method manual \
                        ipv4.addresses "1.1.1.1/24,1.1.1.2/24,1.1.1.5/24"
 # nmcli connection up t

  => addresses are applied in the right order:
     inet 1.1.1.1/24 brd 1.1.1.255 scope global eth0
     inet 1.1.1.2/24 brd 1.1.1.255 scope global secondary eth0
     inet 1.1.1.5/24 brd 1.1.1.255 scope global secondary eth0

 # nmcli connection mod t ipv4.addresses "1.1.1.5/24,1.1.1.2/24,1.1.1.1/24"
 # nmcli device reapply eth0

  => order is wrong:
     inet 1.1.1.2/24 brd 1.1.1.255 scope global eth0
     inet 1.1.1.5/24 brd 1.1.1.255 scope global secondary eth0
     inet 1.1.1.1/24 brd 1.1.1.255 scope global secondary eth0

Co-Authored-By: Thomas Haller <thaller@redhat.com>
2016-12-05 10:56:51 +01:00
Beniamino Galvani
0a0bca9c7f ip6-config: sort addresses only when reading the property value
Don't change the address order from configuration, but instead sort
addresses just before returning them to clients.
2016-12-05 10:56:51 +01:00