Commit graph

11904 commits

Author SHA1 Message Date
Thomas Haller
6861cd1f2b libnm: fix compare_property() to handle default values
Before, get_property_for_dbus() would @ignore_defaults.
That is for example wrong for properties of type G_TYPE_STRV.

In this case, if one operand has the property at its default
(NULL) and the other has it to an empty string list, both would
compare equal.

This has the effect that different settings might compare equal.

(cherry picked from commit 7478c4b54a)
2015-06-19 13:06:37 +02:00
Thomas Haller
217c012595 ifcfg-rh: better detect alias files
Alias files have a ':' to separate the base name from their
alias. But we didn't always ensure not to write-out files without
colon, and also initscripts doesn't have that restriction.

We should detect alias files and handle them properly (e.g. by
reloading the base file).

This fixes an error that a `nmcli con load` would have tried to
load the alias file. Also extend load_connection() to support
passing filenames other then the base file.

We only have to handle this in plugin.c. Inside reader.c we always
have the normalized base filename.

Or detection of alias files only looks whether the filename has a ':'
and whether a corresponding base file exists.

(cherry picked from commit 0aed4e2388)
2015-06-19 13:02:24 +02:00
Thomas Haller
14e2e57acd ifcfg-rh: better detect alias files
Alias files have a ':' to separate the base name from their
alias. But we didn't always ensure not to write-out files without
colon, and also initscripts doesn't have that restriction.

We should detect alias files and handle them properly (e.g. by
reloading the base file).

This fixes an error that a `nmcli con load` would have tried to
load the alias file. Also extend load_connection() to support
passing filenames other then the base file.

We only have to handle this in plugin.c. Inside reader.c we always
have the normalized base filename.

Or detection of alias files only looks whether the filename has a ':'
and whether a corresponding base file exists.

(cherry picked from commit 0aed4e2388)
2015-06-19 13:02:00 +02:00
Thomas Haller
da112cc0cc ifcfg-rh: escape colon in generated filename
A colon indicates an alias file. It should be escaped.

(cherry picked from commit 2e87df8408)
2015-06-19 13:02:00 +02:00
Thomas Haller
9feb02d185 ifcfg-rh: refactor utils_should_ignore_file() to return early
(cherry picked from commit 8be9e832b5)
2015-06-19 13:02:00 +02:00
Thomas Haller
144093fa03 ifcfg-rh: also read alias file for dhcp connections
Previously, if the main ifcfg file doesn't define any
static ip addresses, any alias files would be ignored.

We should also allow alias files with (pure) 'dhcp' connections,
just like initscripts do.

Reported-by: Marek Hulan <mhulan@redhat.com>
(cherry picked from commit 4ef8c0c90c)
2015-06-19 13:02:00 +02:00
Thomas Haller
99eb598c34 ifcfg-rh: log warning when loading of connection fails
connection_from_file() used to log a warning about failure,
but only when an @error argument was given.

update_connection() didn't ensure that in several cases,
so we would not log any failure reason when an ifcfg file
failed to read.

This behavior of controlling logging by passing @error (or not)
is unexpected. Instead, refactor the code so that the caller
can do appropriate logging.
Another reason for this refactoring is that PARSE_WARNING() does
not mention the file for which the failure is and uses some extra
indention that looks wrong. IOW, connection_from_file() doesn't
have the context to give the logging line a proper formatting.

(cherry picked from commit 900aa016b1)
2015-06-19 13:02:00 +02:00
Thomas Haller
fd80b02405 ifcfg: refactor utils_get_ifcfg_name()
No need to allocate a temporary "base" variable. Just
search for the last '/' ourselves.
All the special handling that g_path_get_basename() does,
for example handling empty filenames and removing trailing
slashes, is not needed.

Thereby fix not to return empty names such as from "ifcfg-".

(cherry picked from commit 2ef8f6edfe)
2015-06-19 13:02:00 +02:00
Jiří Klimeš
eb07137bec main: fix a compiler warning about function declaration
warning: function declaration isn’t a prototype [-Wstrict-prototypes]

In C function() and function(void) are two different prototypes (as opposed to
C++).
function()     accepts an arbitrary number of arguments
function(void) accepts zero arguments
2015-06-19 12:54:59 +02:00
Thomas Haller
713065b880 libnm/utils: add _nm_utils_strv_find_first() function
(cherry picked from commit ef4e017cfa)
2015-06-19 12:43:03 +02:00
Thomas Haller
832b2bdff4 gitignore: ignore temporary files during build
If you type `git status` a certain times during build,
you see some temporary (untracked) files. Ignore them.

(cherry picked from commit 176b13374a)
2015-06-19 12:43:03 +02:00
Jiří Klimeš
60080377a2 all: fix a compiler warning about function declarations
warning: function declaration isn’t a prototype [-Wstrict-prototypes]

In C function() and function(void) are two different prototypes (as opposed to
C++).
function()     accepts an arbitrary number of arguments
function(void) accepts zero arguments

(cherry picked from commit 94a393e9ed)
2015-06-19 12:40:54 +02:00
Thomas Haller
c7a343117f platform: merge branch 'th/platform_refact_caching-bgo747981' (early part)
- add new file 'nm-platform-utils.c' and moves some independent utility
  functions there (ethtool, udev).
- some refactoring of platform code, including initialization of
  NMPlatform instance.
- run platform tests in a separate user namespace, which allow
  us to run root-tests as non-root.

https://bugzilla.gnome.org/show_bug.cgi?id=747981

(cherry picked from commit d38c3851f8)
2015-06-19 12:26:39 +02:00
Thomas Haller
072296750c platform: expose nm_platform_signal_change_type_to_string()
(cherry picked from commit d4f828c887)
2015-06-19 12:26:03 +02:00
Thomas Haller
8f6a883c73 platform: refactor support_kernel_extended_ifa_flags to static variable
Whether we have support depends on the kernel, and is not
per NMLinuxPlatform instance.

(cherry picked from commit 2f3fd86dc5)
2015-06-19 12:26:03 +02:00
Thomas Haller
adcd51065b platform: move ethtool_get_link_speed() to nm-platform-utils
(cherry picked from commit 95333d84bc)
2015-06-19 12:26:03 +02:00
Thomas Haller
f9760da1a1 platform: move supports_mii_carrier_detect() to nmp_utils_mii_supports_carrier_detect()
(cherry picked from commit 299af02e40)
2015-06-19 12:26:03 +02:00
Thomas Haller
8ad91fa6d0 platform: move ethtool_*() to nmp_utils_ethtool_*()
(cherry picked from commit ac84b22fc7)
2015-06-19 12:26:03 +02:00
Thomas Haller
ddd9884bcf platform: factor out ethtool_get_wake_on_lan() function
(cherry picked from commit 398819c3ac)
2015-06-19 12:26:03 +02:00
Thomas Haller
345b73fa1b platform: factor out ethtool_get_peer_ifindex() function
(cherry picked from commit ba084b5b90)
2015-06-19 12:26:03 +02:00
Thomas Haller
6c76801190 platform: factor out ethtool_supports_vlans() function
(cherry picked from commit 4be9394864)
2015-06-19 12:26:03 +02:00
Thomas Haller
a72350c4da platform/trivial: move ethtool_supports_carrier_detect() code
(cherry picked from commit 2b8f3331d7)
2015-06-19 12:26:03 +02:00
Thomas Haller
716dd795de platform: move code udev_get_driver() to nmp_utils_udev_get_driver()
(cherry picked from commit 77a3767d1e)
2015-06-19 12:26:02 +02:00
Thomas Haller
cd2d241fb7 platform: add nm-platform-utils.[ch] files
There is no general purpose file for platform utilities.
We only have nm-platform.h, which contains (mostly) functions
that operate on a NMPlatform instance (and that can be mocked
using NMFakePlatform).

Add a new file for independent utility functions. nm-platform-utils.c
should not call into functions having a NMPlatform instance, to
have them independent from platform caching and the platform
singleton.

(cherry picked from commit ce700d94f5)
2015-06-19 12:26:02 +02:00
Thomas Haller
4e0af0aa52 platform: move nm_platform_query_devices() to nm-manager
nm_platform_query_devices() would raise an 'added' signal
for all its links. That is bad style because it could
confuse other listeners for platform signals which don't
expect such artificial change signals.

The public API of NMPlatform already gives NMManager the ability
to 'pull' all the links and iterate them itself.

Before, nm_platform_query_devices() would also initialize udev
devices, so there was a more compelling reason for this function.

(cherry picked from commit d7a312d17a)
2015-06-19 12:26:02 +02:00
Thomas Haller
acb39d4b31 platform: merge setup_devices() function into constructed()
We already populate the netlink cache in constructed(). No need
to wait with udev devices until nm_platform_query_devices(). Just
do it right away.

Add a hack to keep 'lo' default-unmanaged. Now that we load
udev devices earlier, we end up clearing the default-unmanged
flag on 'lo', which has bad consequences.

(cherry picked from commit d6ce01f115)
2015-06-19 12:26:02 +02:00
Lubomir Rintel
cf0a0ed576 tests: use a user ns to fake root
(cherry picked from commit ed01c975d8)
2015-06-19 12:26:02 +02:00
Lubomir Rintel
a030ac36d3 tests: allow running the link test without a writeable sysfs
This fixes the test run in a container/our NETNS/NEWUSER test jail.

(cherry picked from commit f9dd7f0d84)
2015-06-19 12:26:02 +02:00
Thomas Haller
90eb13a111 core: add option to suppress error logging if nm_utils_modprobe() fails
We don't want error logging for nm_platform_link_add() which
tries to load the bonding module. Later we will run tests as non-root,
where modprobe will fail. Logging an error would break the tests.

(cherry picked from commit 39f2b51abb)
2015-06-19 12:26:02 +02:00
Thomas Haller
baf5f63374 utils: add NM_FLAGS_SET(), NM_FLAGS_UNSET() and NM_FLAGS_ASSIGN() macros
(cherry picked from commit 57958b93b6)
2015-06-19 12:26:02 +02:00
Thomas Haller
1d3c143948 build: rename file "include/nm-utils-internal.h" to "nm-macros-internal.h"
We already have "nm-utils*.h" and "NetworkManagerUtils.h" headers. Rename
"include/nm-utils-internal.h" to "nm-macros-internal.h". I think that
name is better, because this file is header-only, internal, and
repository-wide.

Also, it will never contain non-header-only declarations because
there is no backing object file under "include/".
It will only contain macros and inline functions.

(cherry picked from commit b8b1a01d96)
2015-06-19 12:21:58 +02:00
Thomas Haller
88bdeecf7c utils: move NM_FLAGS_*() macros to header file "include/nm-utils-internal.h"
(cherry picked from commit dce00f0d10)
2015-06-19 12:21:58 +02:00
Jiří Klimeš
b7b47941c0 merge: activate slaves when master is activated (bgo #735052) (rh #1158529)
When a master connection is activated, check all its slaves and decide whether
they should be activated as well. This is done according to the
connection.autoconnect-slaves property.

https://bugzilla.gnome.org/show_bug.cgi?id=735052
https://bugzilla.redhat.com/show_bug.cgi?id=1158529

(cherry-picked from b18f328967)
2015-06-19 12:19:18 +02:00
Jiří Klimeš
94337e58b7 man: mention that connection.autoconnect-slaves property supports default value
(cherry picked from commit f05d41d358)
2015-06-19 12:18:52 +02:00
Jiří Klimeš
5318aec2c2 core: activate slaves when master is activated (bgo #735052) (rh #1158529)
When a master connection is activated, check all its slaves and decide whether
they should be activated as well. This is done according to the
autoconnect-slaves property.

https://bugzilla.gnome.org/show_bug.cgi?id=735052
https://bugzilla.redhat.com/show_bug.cgi?id=1158529
(cherry picked from commit f4582d812c)
2015-06-19 12:18:52 +02:00
Jiří Klimeš
c8826630a3 cli: add support for connection.autoconnect-slaves property
(cherry picked from commit c3093d9391)
2015-06-19 12:18:52 +02:00
Jiří Klimeš
8aa0b5b17d ifcfg-rh: read/write autoconnect-slaves property as AUTOCONNECT_SLAVES
AUTOCONNECT_SLAVES is an NetworkManager extension. initscripts always activate
slaves with the master connection for bond and team, and doesn't activate
automatically slaves for bridge.
NetworkManager behaviour is controlled by this variable. If the variable is
missing the default value from configuration file is used.

(cherry picked from commit 2a497eeadc)
2015-06-19 12:18:52 +02:00
Jiří Klimeš
408b631673 libnm: add autoconnect-slaves property to NMSettingConnection
The property is used for controlling whether slaves should be brought up with
a master connection. If 0, activating the master will not activate slaves.
But if set to 1, activating the master will bring up slaves as well.
The property can have the third state (-1), meaning that the value is default.
That is either a value set in the configuration file for the property, or 0.

(cherry picked from commit 6caafab258)
2015-06-19 12:18:51 +02:00
Jiří Klimeš
2f51ba50df merge branch 'th/connection-defaults-bgo695383'
- support new [connection] section in NetworkManager.conf
- allow configuring a default value for ipvx.route-metric
- allow configuring a default value for ipv6.ip6-privacy
  and read the fallback configuration from sysctl.

https://bugzilla.gnome.org/show_bug.cgi?id=695383
https://bugzilla.gnome.org/show_bug.cgi?id=721200
https://bugzilla.redhat.com/show_bug.cgi?id=1187525

(cherry-picked from commit 18ecf48d7a)
2015-06-19 12:15:12 +02:00
Thomas Haller
1468f4edd2 device: remove reading ipv6 privacy setting from sysctl
Since introduction for support of ip6-privacy (use_tempaddr,
RFC4941) with commit d376270bfe,
the sysctl value from /etc was always read first.

This is problematic, because an explicit setting in the
connection should not be ignored over a global configuration.

Drop that old behavior. It was also problematic, because we did
not read any files under /etc/sysctl.d (except for sysctl.conf).
Also, we did not honor per-interface configurations.

Now we also use as last fallback the value from
/proc/sys/net/ipv6/conf/default/use_tempaddr
That has the advantage of falling back to the system default value
so that NM doesn't need to have it's own default policy
(Related: https://bugzilla.redhat.com/show_bug.cgi?id=1187525).

This is a change in behavior.

(cherry picked from commit f3c61f8141)
2015-06-19 12:10:52 +02:00
Thomas Haller
a6630e4fad device: add global configuration default for ip6-privacy (use_tempaddr, RFC4941)
Support default value for setting 'ipv6.ip6-privacy' in
NetworkManager.conf.

If the global value is unset, preserve old behavior of looking into
/etc/sycctl.conf first. That behavior was introduced with commit
d376270bfe, since we support ip6-privacy
setting.

If the global value is set to "unknown", add a new fallback
that instead reads the runtime value from
  "/proc/sys/net/ipv6/conf/default/use_tempaddr"
This seems more sensible behavior because we fallback to sysctl,
but instead of looking at static files in /etc, read /proc.
But to preserve the old behavior, we only do that when a global
value is configured at all.

https://bugzilla.gnome.org/show_bug.cgi?id=721200
(cherry picked from commit e729dd70ae)
2015-06-19 12:10:52 +02:00
Thomas Haller
905cf30b51 libnm/doc: document behavior of setting ip6-privacy in /etc/sysctl.conf
https://bugzilla.gnome.org/show_bug.cgi?id=721200
(cherry picked from commit e4293788fc)
2015-06-19 12:10:52 +02:00
Thomas Haller
923aa9d727 device: make route-metric configurable per-device
The route-metric can be configured per connection via the
ipv4.route-metric and ipv6.route-metric fields. When the
value is left at -1 (the default), we would determine the
route-metric based on the device type (nm_device_get_priority()).

Extend that scheme by making the default value overwritable in
NetworkManager.conf.

(cherry picked from commit 59a991725a)
2015-06-19 12:10:52 +02:00
Thomas Haller
a64e81703e config: support a [connection] section to NetworkManager.conf to specify connection defaults
Add support for a new section [connection] in NetworkManager.conf.
If the connection leaves an option at "unknown"/"default", we can
support overwriting the value from global configuration.

We also support other sections that are named with "connection"
as a prefix, such as [connection2], [connection-wifi]. This is
to support multiple default values that can be applied depending
on the used device.

I think this has great potential. Only downside is that when
the user looks at a connection value, it will see that it is
unspecified. But the actually used value depends on the device
type and might not be obvious.

https://bugzilla.gnome.org/show_bug.cgi?id=695383
https://bugzilla.redhat.com/show_bug.cgi?id=1164677

(cherry picked from commit dc0193ac02)
2015-06-19 12:10:51 +02:00
Thomas Haller
a76deff2f6 config: publish nm_config_keyfile_get_boolean() utility function
(cherry picked from commit f031b926c4)
2015-06-19 12:10:51 +02:00
Thomas Haller
1429ef7249 device: add device-spec "type:"
Support a device-spec to match by device-type.
This matches on the value as shown by

  nmcli -f GENERAL.TYPE device show

(cherry picked from commit 3fb60edf9f)
2015-06-19 12:10:51 +02:00
Thomas Haller
ddfa354400 device: add nm_device_get_type_description() function
Add a function to get a concise representation of the
device type.

libnm already has nm_device_get_type_description() for that
and it is shown by

  nmcli -f GENERAL.TYPE device show

Reimplement that function for nm-core. Just take care that the
two implementations don't diverge.

(cherry picked from commit e9e9d44468)
2015-06-19 12:10:51 +02:00
Thomas Haller
517e9fa0f0 ibft: avoid logging multiple lines when ibft fails
In case of error, ibft prints an error message to stderr
with two trailing newlines. This causes multiple lines
in our logfile. Replace newlines in the error message
by whitespaces.

(cherry picked from commit 205c109741)
2015-06-19 12:05:50 +02:00
Thomas Haller
060f7a463e build: add compile option to disable building of Wi-Fi plugin
Before, the Wi-Fi plugin was always build. Users who didn't want
to use it would simply drop "libnm-device-plugin-wifi.so".

Add a compile time option to disable needlessly building the plugin.

https://bugzilla.gnome.org/show_bug.cgi?id=743388
(cherry picked from commit 5439fbd77c)
2015-06-19 12:05:50 +02:00
Thomas Haller
9d75928bf3 build,tests: refactoring tests using TAP driver and improve valgrind script 2015-06-19 11:53:53 +02:00