Commit graph

8977 commits

Author SHA1 Message Date
Thomas Haller
c8fa7b6f57 dnsmasq: use ipv4.dns and ipv4.dns-search with ipv4.method=shared
Configure the dnsmasq DHCP server for shared mode to announce the
configured name resolution settings.
2017-03-03 13:51:05 +01:00
Thomas Haller
9e429ddc0a dnsmasq: reuse string buffer in creating command line arguments in create_dm_cmd_line() 2017-03-03 13:23:01 +01:00
Thomas Haller
24be1fd913 ifcfg/trivial: rename svFileSetName() and svFileSetModified() to mark for testing
The filename of the shvarFile instance should be immutable and stay
unchanged for the entire lifetime of the instance. Similarly, the
modified flag should not be explicitly set.

However, for testing it is still useful to give the unit test a
direct access to those functions.

Rename the setters to make it clear that this is test-only.
2017-03-02 14:10:50 +01:00
Thomas Haller
670e088efe libnm-core: normalize invalid bridge|team slave-port settings
Having a bridge-port/team-port setting for a connection that
has a different slave-type makes no sense. Such a configuration
shall be considered invalid, and be fixed by normalization.

Note that there is already a normalization the other way around,
when you omit the "slave-type" but a "master" and one(!) port-type
setting is present, the slave-type is automatically determined
based on the port-type.

The use of this is of course to modify an existing slave connection
to make it a non-slave. Then the invalid port settings should be
automatically removed.

Previously, ifcfg-rh writer would write the "BRIDGING_OPTS" setting
without a "BRIDGE". The reader would then (correctly) ignore the
bridge-port. Avoid that altogehter, by requiring the connection to
strictly verify.
2017-03-02 12:14:29 +01:00
Thomas Haller
e0252e7a75 ifcfg-rh: require connections to be fully normalized for writing 2017-03-02 12:14:29 +01:00
Thomas Haller
b4594af55e keyfile: updated connection when writing keyfile
Writing a connection to keyfile and read it back should result
in the identical setting. That is, a full round-trip would not
alter any information.

That is however particularly not true for certificate properties, where
the keyfile writes blobs to file and coerces paths.

Thus, whenver writing a keyfile we must read back what we just
wrote and use that instead.
2017-03-02 12:14:29 +01:00
Thomas Haller
e636d28116 keyfile: extend internal API to re-read keyfile connection after writing
Add API to re-read the keyfile after writing it.
Usually, we would expect that whenever we serialize
something to disk, it can be read back exactly the same.

That is however not true for certificates, where we mangle
path and blobs while writing to file.

Anyway, extend the write-API to re-read what we just wrote.

The tests got extended to assert that whatever we write can
be read back the same.

Later, we want to reinject the reread connection into the settings
plugin again.
2017-03-02 12:14:29 +01:00
Thomas Haller
72bfe62a9a all: use stack-allocated uuid at various places
No need to create a UUID on the heap in this case.
2017-03-02 12:14:29 +01:00
Thomas Haller
cf213216fd libnm-core: add ethernet setting for vlan connection
A "vlan" setting can optionally have an ethernet setting.
However, ifcfg-rh reader always adds such a setting, because
well... Anyway, the result is that writing a VLAN setting
without ethernet section will yield a different result
on re-read.

Let's have normalization add the ethernet setting, so that
two we consistently have it present.
2017-03-02 12:14:29 +01:00
Thomas Haller
53018b92e8 ifcfg-rh: fix reading team slave types of vlan type
https://bugzilla.redhat.com/show_bug.cgi?id=1427482
2017-03-02 12:14:29 +01:00
Thomas Haller
5a82494fa6 ifcfg-rh/tests: add test for writing team slave
This shows the current bug, needs to be fixed.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1427482
2017-03-02 12:14:29 +01:00
Thomas Haller
13e9967a3a ifcfg-rh: add internal API to re-read connection after write
Our reader/writer has flaws. We easily write out something that
is re-read differently. That is a problem and should be fixed.

Add API to re-read the connection after writing.

Extend the tests to check that the re-read value is identical
to what we wrote. In some cases, this does not hold. That is
usually a bug which needs fixing. Note that for certificate
blobs and paths we may intentionally mutate the connection
during writing, so there are valid cases where a connection
is re-read differently.
2017-03-02 12:14:29 +01:00
Thomas Haller
5ef4db18ce ifcfg-rh: change "goto error" pattern to return early and nm_auto* 2017-03-02 12:14:29 +01:00
Lubomir Rintel
9d2dfd9d97 ifcfg: avoid marking newly created connections as Unsaved 2017-02-27 11:17:39 +01:00
Lubomir Rintel
b47340fd3f settings-connection: fix Save()
Avoid using new_settings when they are none. Also, don't shortcut when
the connection hasn't been changed -- let the settings plugin decide if
it needs to rewrite the connection.
2017-02-27 11:16:45 +01:00
Lubomir Rintel
54086127ef ifcfg-rh: don't shortcut writing if the connection stays the same
Some keys, such as MASTER may still be different as they may depend on
other connections. svWriteFile() checks if the resulting file is
different already anyway.
2017-02-27 11:16:45 +01:00
Beniamino Galvani
913896721d dns/resolved: consider configuration from unmanaged devices
The DNS configuration for VPN connections is associated to the VPN
device (tun, ppp, etc.) and that device can be unmanaged by NM: don't
ignore such configuration. We do the same for other DNS plugins.

https://bugzilla.gnome.org/show_bug.cgi?id=779087
2017-02-24 21:08:54 +01:00
Thomas Haller
c0d9243e7e session: make systemd-logind and elogind conflicting build options 2017-02-24 13:06:13 +01:00
Sven Eden
360e80b75f session: add elogind support
https://bugzilla.gnome.org/show_bug.cgi?id=779167
https://bugs.gentoo.org/show_bug.cgi?id=607352
2017-02-24 12:49:32 +01:00
Thomas Haller
dcd7a45a5f manager: fix clearing error variable in autoconnect_slaves() 2017-02-24 12:31:20 +01:00
Thomas Haller
405ee7cad0 device: mark uses of device's state-reason with nm_device_state_reason_check()
The state-change of a device has a reason argument, which is mostly for information
only.

There are many places in code that are the source of a state-reason.
Mostly these are calls to:
  - nm_device_state_changed()
  - nm_device_queue_state()
  - nm_device_queue_recheck_available()
  - nm_device_set_unmanaged_by_*()
  - nm_device_master_release_one_slave()
  - nm_device_ip_method_failed()
  - nm_modem_emit_prepare_result()
  - nm_modem_emit_ppp_failed()
  - nm_manager_deactivate_connection()
  - NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_*);

However, there are a few places in code that look at the reason
to decide how to proceed. I think this is a bad pattern, because
cause and effect are decoupled and it gets hard to understand where
a certain reason is set and what consequences that has.

Add a nop-function nm_device_state_reason_check() to mark all uses
of the device state reason that derive decisions from it. That is,
highlight the "effect" part.
2017-02-23 17:07:28 +01:00
Thomas Haller
71a22df337 settings: refactor autoconnect-blocked-reason to use own enum
Don't reuse NMDeviceStateReason for the autoconnect-blocked-reason. There are
only two cases we care: blocked-due-to-no-secrets, blocked-otherwise.

Encode these values in a new enum type.
2017-02-23 17:00:09 +01:00
Thomas Haller
9a64168c87 all: use "static inline" keywords instead of "inline static"
Use a consistent order of "static inline". This seems the prefered
order in general, and we also use it more often already.
2017-02-23 15:28:27 +01:00
Thomas Haller
8e12396b74 modem: remove unused reason argument from nm_modem_device_state_changed()
The reason has pecular meanings during a device state change.
Let's remove the unused reason argument to reduce the noise.
2017-02-23 14:42:36 +01:00
Thomas Haller
434e7b2aa3 modem: cleanup integer types for ppp-stats signal
In practice, guint32 is identical to guint. However, that is not
guaranteed, and we should keep the types separate.
2017-02-23 12:33:41 +01:00
Thomas Haller
20b17910d0 modem: add nm_modem_emit_ppp_failed() function
... instead of emitting the signal by name.
2017-02-23 12:33:41 +01:00
Thomas Haller
0a1fd88d5a modem: add nm_modem_emit_prepare_result() function
... instead of emitting the signal by name. For one,
we get the casting of the NMDeviceStateReason enum right.
Also, emitting by the guint signal-id is faster then
emitting by name.
2017-02-23 12:33:41 +01:00
Thomas Haller
9a8f8e8a89 modem: remove unused variadic argument when emitting NM_MODEM_STATE_CHANGED signal
The signal only has two arguments, no reason.
2017-02-23 12:33:41 +01:00
Thomas Haller
42f60e30ad modem: emit signal NM_MODEM_AUTH_REQUESTED by id not name 2017-02-23 12:20:19 +01:00
Thomas Haller
6c8eac1a4c modem: use defines for signal names 2017-02-23 12:20:13 +01:00
Beniamino Galvani
9dac51d9c0 team: support the ethernet.cloned-mac-address property
The only reliable way of setting a MAC address for the team is through
the "hwaddr" property in the configuration passed to teamd. In order
to rewrite the configuration we need Jansson support; since it is
already a requirement for teamd, let the team plugin depend on it.
2017-02-23 10:07:06 +01:00
Beniamino Galvani
029a0a21ea device: split out cloned MAC decision from nm_device_hw_addr_set_cloned()
In this way, we can query the final cloned address (after special
values as 'random', 'stable', etc. have been evaluated) from
subclasses.
2017-02-23 10:05:48 +01:00
Thomas Haller
5d336aa1ed device: rename reason argument for NMDeviceDummy
And remove assertion for out-argument to be present.

Follow-up to commit 437c12fc89.
2017-02-22 21:47:12 +01:00
Thomas Haller
8b7d38c8c5 device: remove out-reason argument from device's set-ip-config
The out-reason is only set to NM_DEVICE_STATE_REASON_CONFIG_FAILED.
And there is only one caller who cares about the reason.

If we one day decide to return a more distinguished error reasons,
we can revert this patch. Until then, drop the code.
2017-02-22 21:43:04 +01:00
Thomas Haller
437c12fc89 device: rename device-state-reason argument to out_failure_reason
This argument is only relevant when the NMActStageReturn argument
indicates NM_ACT_STAGE_RETURN_FAILURE. In all other cases it is ignored.

Rename the argument to make the meaning clearer. The argument is passed
through several layers of code, it isn't obvious that this argument only
matters for the failure case. Also, the distinct name makes it easier
to distinguish from other uses of the "reason" name.

While at it, do some drive-by cleanup:

  - use g_return_*() instead of g_assert() to have a more graceful
    assertion.
  - functions like dhcp4_start() don't need to return a failure reason.
    Most callers don't care, and the caller who does can determine the
    proper reason.
  - allow omitting the out-argument via NM_SET_OUT().
2017-02-22 21:37:47 +01:00
Beniamino Galvani
b42f780e04 core: add support for dummy devices
Add support for creating dummy devices. This commit adds a D-Bus
interface 'org.freedesktop.NetworkManager.Device.Dummy' which is used
primarily for determining the device type but does not carry any
properties.
2017-02-22 21:05:04 +01:00
Thomas Haller
f93fbc76ec device: avoid assertion in nm_device_get_supplicant_timeout() for Wi-Fi connection
... without 802-1x setting.

    NetworkManager[27913]: <trace> [1487689965.7156] device[0x555555bc0060] (wlp3s0): powersave is set to 3
    NetworkManager[27913]: <info>  [1487689965.7156] Config: added 'ssid' value 'xxx'
    NetworkManager[27913]: <info>  [1487689965.7156] Config: added 'scan_ssid' value '1'
    NetworkManager[27913]: <info>  [1487689965.7156] Config: added 'bssid' value 'xxx'
    NetworkManager[27913]: <info>  [1487689965.7157] Config: added 'key_mgmt' value 'WPA-PSK'
    NetworkManager[27913]: <info>  [1487689965.7157] Config: added 'psk' value '<hidden>'
    NetworkManager[27913]: <debug> [1487689965.7157] sup-iface[0x555555be0010,wlp3s0]: assoc[0x555555ebd800]: starting association...
    NetworkManager[27913]: nm_device_get_supplicant_timeout: assertion 's_8021x' failed

    (gdb) bt
    ...
    #3  0x00007ffff4c70419 in g_return_if_fail_warning (log_domain=log_domain@entry=0x55555577610e "NetworkManager", pretty_function=pretty_function@entry=0x5555557725e0 <__func__.44436> "nm_device_get_supplicant_timeout", expression=expression@entry=0x5555557725bb "s_8021x") at gmessages.c:2536
    #4  0x000055555568af3a in nm_device_get_supplicant_timeout (self=0x555555bc0060 [NMDeviceWifi]) at src/devices/nm-device.c:12963
    #5  0x00007fffe88d7f1e in act_stage2_config (device=<optimized out>, reason=0x7fffffffe000) at src/devices/wifi/nm-device-wifi.c:2651
    #6  0x00005555556879f1 in activate_stage2_device_config (self=0x555555bc0060 [NMDeviceWifi]) at src/devices/nm-device.c:4320
    #7  0x000055555566876b in activation_source_handle_cb (self=self@entry=0x555555bc0060 [NMDeviceWifi], family=family@entry=2) at src/devices/nm-device.c:4060
    #8  0x000055555566882e in activation_source_handle_cb4 (user_data=user_data@entry=0x555555bc0060) at src/devices/nm-device.c:3997
    #9  0x00007ffff4c658e7 in g_idle_dispatch (source=0x555555e228c0, callback=0x555555668820 <activation_source_handle_cb4>, user_data=0x555555bc0060) at gmain.c:5545
    #10 0x00007ffff4c68e52 in g_main_dispatch (context=0x555555a214d0) at gmain.c:3203
    #11 0x00007ffff4c68e52 in g_main_context_dispatch (context=context@entry=0x555555a214d0) at gmain.c:3856
    #12 0x00007ffff4c691d0 in g_main_context_iterate (context=0x555555a214d0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3929
    #13 0x00007ffff4c694f2 in g_main_loop_run (loop=0x555555a1a750) at gmain.c:4125
    #14 0x00005555555821fe in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:423

Fixes: 07570e245a
2017-02-21 16:21:02 +01:00
Thomas Haller
8406455b4d ifcfg: drop strlen() call from svEscape() 2017-02-21 15:47:43 +01:00
Thomas Haller
c9f6cb9fe4 ifcfg: some refactoring of reader using vGetValueStr()/vGetValue_cp() 2017-02-21 15:43:03 +01:00
Thomas Haller
ccbfda5c08 ifcfg: complete shvar API with svGetValue_cp() and svGetValueStr()
Add svGetValue_cp() and svGetValueStr() for completeness.

Currently, we mostly use svGetValueStr_cp(), which I think is wrong
because for most cases we should instead not ignore empty values -- that
is, svGetValue_cp() would be a better choice.

Also, I think that the non *_cp() API should be preferred in many cases
because it avoids cloning the value in many cases. The API is not
necessarily less favorable either:

    gs_free char *value = NULL;

    value = svGetValue_cp (s, key);
    if (value)
        ...

vs.

    gs_free char *value_to_free = NULL;
    const char *value;

    value = svGetValue (s, key, &value_to_free);
    if (value)
        ...

Add the two missing variants, so that future code can use what fits
best, not following undesired practices because seemingly there is
no alternative.
2017-02-21 15:30:23 +01:00
Thomas Haller
c0c9b3dbcd ifcfg/trivial: rename svGetValueString() to svGetValueStr_cp()
We have

 - svGetValue()
    - returns the original string
    - avoids copying the string unless necessary

 - svGetValueStr_cp() (formerly svGetValueString())
    - returns the original string, unless it is empty ""
    - always clones the string

I think the behavior svGetValueStr*() of coercing "" to NULL is wrongly
used in most places. We should better handle "" like any other value,
not treat it as unset.

That would require another function svGetValue_cp(), which is like svGetValue()
but always copies the string. Rename svGetValueString() so that there is a place
for names like

  - svGetValue_cp()
  - svGetValueStr()

Also rename svSetValueString() to svSetValueStr().
2017-02-21 12:34:36 +01:00
Thomas Haller
d37c77234f ifcfg: set error for failure reading unrecognized connection in connection_from_file_full() 2017-02-21 12:17:30 +01:00
Thomas Haller
9b8e56180f ifcfg: don't g_strstrip() value in read_dcb_bool_array()
Ifcfg reader now properly handles escaping and quoting. We don't
need to stip whitespace, if somebody explicitly configures

  prop=" value"

it is a configuration error.
2017-02-21 12:17:30 +01:00
Thomas Haller
b1c8c9cbaf ifcfg: return early on error using cleanup attributes in reader 2017-02-21 12:17:30 +01:00
Thomas Haller
19c9d1bafd ifcfg: add nm_auto_shvar_file_close cleanup macro 2017-02-21 11:46:23 +01:00
Thomas Haller
8588630c26 settings: log changes to NMSettingsConnection's autoconnect_retries 2017-02-21 09:18:53 +01:00
Beniamino Galvani
4a6fd0e83e device: honor the connection.autoconnect-retries for 802.1X
NMDeviceEthernet and NMDeviceMacsec implement their own retry policy
for connection using 802.1X, and consider the credentials wrong when
the authentication fails for 3 times. In such case, they also disable
autoconnection for the device by setting the state reason NO_SECRETS.

This means that it's not possible at the moment to choose how many
times the authentication will be retried since they don't use the
standard reconnection logic.

Change NMDeviceEthernet and NMDeviceMacsec to use the number of
retries from connection.autoconnect-retries instead of a hardcoded
value to decide how many times the authentication must be restarted.
2017-02-21 09:18:53 +01:00
Beniamino Galvani
07570e245a device: add support for 802-1x.auth-timeout
Use the per-connection authentication timeout for 802.1X Ethernet,
MACsec and Wi-Fi connections. In case the value is not defined, fall
back to the global one.
2017-02-21 09:18:53 +01:00
Beniamino Galvani
556a46959f ifcfg-rh: add support for 802-1x.auth-timeout property 2017-02-21 09:18:53 +01:00
Thomas Haller
9952280d40 ifcfg: don't check for empty string after svGetValueString()
svGetValueString() precisely filters out empty strings. No need to
check for that afterwards.
2017-02-21 01:17:41 +01:00