Commit Graph

18706 Commits

Author SHA1 Message Date
Thomas Haller
ba13c02e48 ifcfg-rh: merge branch 'th/ifcfg-reread-add' 2017-10-27 10:28:55 +02:00
Thomas Haller
8a1d483ca8 ifcfg-rh: reread from disk when adding new connection 2017-10-27 10:28:41 +02:00
Thomas Haller
304bf5563f ifcfg-rh: refactor nm_settings_plugin_add_connection() to return on error early 2017-10-27 10:28:41 +02:00
Thomas Haller
74eeb90d96 ifcfg-rh: don't check can_write_conection before writing
nms_ifcfg_rh_writer_write_connection() also calls nms_ifcfg_rh_writer_can_write_connection()
as first check. No need to duplicate the check.
2017-10-27 10:28:41 +02:00
Thomas Haller
4af4e92646 ifcfg-rh: split function to write connection to disk 2017-10-27 10:28:41 +02:00
Beniamino Galvani
7ed57f2286 ifcfg-rh: write wired setting for bridge connections
Write the wired setting of bridge connections, otherwise properties
such as ethernet.cloned-mac-address won't be saved.
2017-10-26 22:37:15 +02:00
Thomas Haller
53aa340476 nmcli: fix wrongly adding a generic setting when constructing connection
nmc_read_connection_properties() iterates over the input arguments, and
completes the connection.

Initially, the type is not yet known, in that case, we should not wrongly
assume that this is a generic connection. Later, when the type is specified,
con_settings() will return the correct settings.

Previously, this would wrongly add a [generic] section:

  $ nmcli connection add type ethernet ifname eth1 con-name ethie autoconnect no ipv4.method auto ethernet.cloned-mac-address random

With the fix, it still works to specify the type later:

  $ nmcli connection add ifname eth1 con-name ethie autoconnect no ipv4.method auto type ethernet

but it doesn't work, to specify the type after type-specific options:

  $ nmcli connection add ifname eth1 con-name ethie autoconnect no ipv4.method auto ethernet.cloned-mac-address random type ethernet
  Error: invalid or not allowed setting 'ethernet': 'ethernet' not among [connection, ipv4, ipv6, proxy].

The patch doesn't change the latter limitation.

Fixes: c5324ed285
2017-10-26 19:07:24 +02:00
Beniamino Galvani
ef52122469 shared: fix compilation on 32-bit archictectures
shared/nm-utils/nm-hash-utils.c:110:3: error: right shift count >= width of type [-Werror]
   h = h ^ ((guint) (((uintptr_t) ptr) >> 32)) ^ ((guint) ((uintptr_t) ptr));
   ^

Even if the branch is not reached on 32-bit architectures, the
compiler still emits a warning for the 32-bit right shift.

Fixes: ee76b0979f
2017-10-26 15:13:40 +02:00
Thomas Haller
095a419e70 libnm: merge branch 'th/connection-diff-empty' 2017-10-26 15:08:30 +02:00
Thomas Haller
975eeda611 libnm: fix the return value of nm_setting_diff() if a results hash was given
Previously, nm_setting_diff() would return !(*results), that means,
if the caller passed in a hash table (empty or not), the return value
would always be FALSE, indicating a difference.

That is not documented, and makes no sense.

The return value, should solely indicate whether some difference was
found. The only convenience is, if nm_setting_diff() created a hash
table internally and no difference was found, it would destroy
it again, without returning it to the caller.
2017-10-26 14:27:45 +02:00
Thomas Haller
6f94b16507 libnm: fix nm_connection_diff() for settings without properties
NMSettingGeneric has no properties at all. Hence, nm_connection_diff() would report that
a connection A with a generic setting and a connection B without a generic setting are
equal.

They are not. For empty settings, let nm_setting_diff() return also empty difference
hash.
2017-10-26 14:23:46 +02:00
Thomas Haller
ecf85fd50f ifcfg-rh/tests: test nm_connection_diff() not showing difference for empty generic setting 2017-10-26 14:16:02 +02:00
Beniamino Galvani
33cb2f3723 settings: keep connection alive in delete_auth_cb()
Before commit 3ecb57fdc4 ("settings: get rid of callback arguments
for nm_settings_connection_delete()") audit logging was done in the
callback, which was run by nm_settings_connection_delete() with a
reference to the connection to keep it alive. Now we have to keep an
extra reference to ensure it doesn't go away.

Fixes: 3ecb57fdc4
2017-10-26 08:54:53 +02:00
Murilo Opsfelder Araujo
301cf7151b contrib/fedora: Update required packages
Add dhclient and iptables packages to build dependencies to satisfy
rpmbuild complaints:

```
error: Failed build dependencies:
	dhclient is needed by NetworkManager-1:1.9.2-18653.43dba57439.fc28.x86_64
	iptables is needed by NetworkManager-1:1.9.2-18653.43dba57439.fc28.x86_64
ERROR: rpmbuild FAILED
```

https://github.com/NetworkManager/NetworkManager/pull/33
2017-10-25 18:08:34 +02:00
Beniamino Galvani
429a1becbb release: bump version to 1.9.3 (development) 2017-10-25 15:40:00 +02:00
Thomas Haller
fda635f5e9 ifcfg-rh: merge branch 'th/ifcfg-rule-write-rh1384799'
https://bugzilla.redhat.com/show_bug.cgi?id=1384799
2017-10-25 14:06:52 +02:00
Thomas Haller
7028818a83 ifcfg-rh/trivial: add code comment about re-reading connection in writer 2017-10-25 14:04:36 +02:00
Thomas Haller
669e693169 ifcfg-rh: don't allow policy routing mixed with an existing rule file
Eventually, we want to fully implement policy routing and
handle rules as well. When that happens, we will use the
route-table setting to tell NetworkManager to handle the
rule file as well.

Since we currently don't yet support that, we should reject
configuring a non-zero routing table combined with a rule file,
because later we will change behavior in that case.
2017-10-25 14:04:36 +02:00
Thomas Haller
3d82124f5f ifcfg-rh: don't let complex routes (rule files) prevent writing connection
... if the connection has no static routes, there is no reason to
reject writing to these files, we don't touch the route file.
2017-10-25 14:04:36 +02:00
Thomas Haller
65fc6f14c5 ifcfg-rh: don't limit reading static routes and addresses to 256
We should support an arbitrary number of routes and addresses.
Arguably, our accessors for shvarFile are O(n), hence with
large ifcfg files, we will have a performance problem. The
fix for that would be to index the files.
2017-10-25 14:04:36 +02:00
Thomas Haller
717e4f8d25 settings: drop redundant can_commit() virtual functions
The only implementation of can_commit() was ifcfg-rh, which
bails out with complex routes.

Note that the only caller of can_commit() (update_auth_cb()),
immidiately afterwards called nm_settings_connection_commit_changes(),
which, a few layers down in nms_ifcfg_rh_writer_write_connection()
as first thing errors out in presence of complex routes.

The check was redundant.

In general, a can_commit() function before a commit_changes() makes
no sense, because commit_changes() can just fail with error.
2017-10-25 14:04:36 +02:00
Thomas Haller
18048ab20c ifcfg-rh/tests: rename test function connection_from_file_test()
Test functions shall have a nmtst_ prefix. Then they don't need
a code comment that they are for testing only.
2017-10-25 14:04:36 +02:00
Thomas Haller
48d23b3ab7 ifcfg-rh: write blobs only do disk after determining what to write 2017-10-25 14:04:36 +02:00
Thomas Haller
dfc6c5ab37 ifcfg-rh: write ip4 alias files after the main fail
write_ip4_aliases() does not collect internal in-memory state, instead
it writes state to disk and deletes extraneous alias files.

It should be done after we completed our pre-run checks to generated
the data we want to write.
2017-10-25 14:04:36 +02:00
Thomas Haller
74b6de6933 ifcfg-rh: rework writing secrets and write them all at once later
Instead of having set_secret() for each call open the file,
mangle it, and write it back, collect all secrets and process
them at the end once.

Also, previously set_secrets() ignored failures to write a secret and
added the secret in plain to the ifcfg file. Let's not do that.

Also, purge all other entires form the secrets file. Not only
the once that we explicitly touch.
2017-10-25 14:04:36 +02:00
Thomas Haller
9b04a41f8f ifcfg-rh: replace svUnsetValuesWithPrefix() by svUnsetAll(USER) 2017-10-25 14:04:36 +02:00
Thomas Haller
2e07a0f92e ifcfg-rh: use svUnsetAll() to clear IPv4 address properties 2017-10-25 14:04:36 +02:00
Thomas Haller
720db2ae60 ifcfg-rh: write route file outside of write_ipx_setting()
Eventually, we should generate all configuration in-memory
first, and only after validating everything write to disk.
That avoids that we start touching files, and later encounter
a fatal error that let's us abort writing the connection.

Also, previously, we would not purge the route file if
write_ip6_setting() returns early for slave types.
2017-10-25 14:04:36 +02:00
Thomas Haller
53c69b1d6e ifcfg-rh: rework writing route file in sv format
- we now safe all routes we have, not limited to 256.

- we use svUnsetAll() to delete the existing keys. This is
  faster then probing them one-by-one, and not limited to
  256 keys (which we were checking before).
  Note that we always try to load an existing file and
  drop the unneeded keys. We do that, so that unrelated
  entries and comments don't get the deleted. Also, so
  that the order of the variables is not changed.
2017-10-25 14:04:36 +02:00
Thomas Haller
042fdd25d8 ifcfg-rh: add svUnsetAll() function 2017-10-25 14:04:36 +02:00
Thomas Haller
95a76f7263 ifcfg-rh: don't fail creating shvarFile instance
When calling svOpenFileInternal() with @create, we don't care about
potential errors reading the file. We shouldn't return NULL in such
case, but always create a shvarFile instance.
2017-10-25 14:04:36 +02:00
Thomas Haller
8687081534 ifcfg-rh: merge IPv4 and IPv6 implementations of write_route_file() 2017-10-25 14:04:36 +02:00
Thomas Haller
56d77ba568 ifcfg-rh: fix handling error writing route file to disk
Do not return failure based on whether an @error argument
is given.
2017-10-25 14:04:36 +02:00
Thomas Haller
19ebfdba5e ifcfg-rh: don't write to disk in write_route_file_legacy()/write_route6_file()
No change in behavior. Refactor code, to move the places that access
the file system (side effects).
2017-10-25 14:04:36 +02:00
Thomas Haller
6cb46619ed ifcfg-rh: merge new_connection() and update_connection() functions
They are basically the same, with a minor difference where the @filename
argument determines whether to write a new file or do an update.

Also, rename them, to give them a nms_* prefix in the header file.
2017-10-25 14:04:36 +02:00
Thomas Haller
3c3fc089ad settings: return re-read connection from ifcfg-rh writer
As writing a connection to disk might modify it, we re-read
it back and use what we actually found on disk.

For example, if you have a connection with ipv6.method=ignore,
ifcfg-rh writer will not persist the ipv6.route-metric. That
is likely a bug in the writer. Before this patch, changing
the route metric would seemingly succeed, but on the next reload
from this, the changes are lost.

We should fix such bugs. Regardless, it's better to pick up
what we wrote to disk, instead of later.
2017-10-25 14:04:36 +02:00
Thomas Haller
713ad38fe5 settings: first persist connection to disk before replacing settings
Previously, we would first call replace_settings(), followed by
commit_changes(). There are two problems with that:

  - commit_changes() might fail easily, for example if the settings
    plugin cannot handle the connection. In that case, we fail the operation,
    but still we already replaced the settings in memory. We should
    first write to disk, and only when that succeeded, replace our
    settings.
    Also, note that replace_settings() cannot really fail at that
    point, because we already validate the setting previously
    (everything else would be a bug).

  - commit_changes() might modify the connection while writing it.
    We re-read it and replace the settings. If we already replaced
    it before, we replcace the settings twice -- needlessly.
2017-10-25 14:04:36 +02:00
Thomas Haller
5a82cad5f3 settings: extend commit_changes() to update the settings after writing
During write, it can regularly happen that the connection gets modified.
For example, keyfile never writes blobs as-is, it always writes the
blob to an external file, and replaces the certificate property with
a path.
Other reasons could be just bugs, where the reader and writer are not doing
a proper round trip (these cases should be fixed).

Refactor commit_changes(), to return the re-read connection to
the settings-connection class, and handle replacing the settings
there.

Also, prepare for another change. Sometimes we first call replace_settings()
followed by commit_changes(). It would be better to instead call commit_changes()
first, and only on success proceed with replace_settings(). Hence, commit_changes()
gets a new argument new_connection, that can be used to write another
connection to disk.
2017-10-25 14:04:36 +02:00
Thomas Haller
edc7503569 settings: split nm_settings_connection_replace_settings() function
Extract two function "replace_prepare" and "replace", so that
they can be used independently.
2017-10-25 14:04:36 +02:00
Thomas Haller
3ecb57fdc4 settings: get rid of callback arguments for nm_settings_connection_delete() 2017-10-25 14:04:36 +02:00
Thomas Haller
bd66285b1c settings: get rid of callback arguments for nm_settings_connection_commit_changes()
No need to return an error result via a callback function. Just
return the plain error.
2017-10-25 14:04:36 +02:00
Thomas Haller
7d7bc99ff0 settings: fix leaking info in update_auth_cb() 2017-10-25 14:04:36 +02:00
Thomas Haller
7a660ea66f settings: inline nm_settings_connection_replace_and_commit()
nm_settings_connection_replace_and_commit() only has one caller:
update_auth_cb().

Inline the function.
2017-10-25 14:04:36 +02:00
Thomas Haller
36f5d440fd settings: refactor virtual delete() function
Don't delegate so much to the virtual function delete().
2017-10-25 14:04:36 +02:00
Thomas Haller
ede1e08ac1 settings: refactor virtual commit_changes() function
Don't delegate so much to the virtual function commit_changes().
Calling the callback is not the task of the virtual function,
because every implementation must do that.

There are some minor changes in behavior for ifnet, where we now
first setup the monitors and reload the parsers, before invoking
the callback.
2017-10-25 14:04:36 +02:00
Thomas Haller
027229a4b0 settings: refactor replace_and_commit()
The virtual function replace_and_commit() had only one implementation: ifcfg-rh.

Refactor the code, to delegate less. That is, the main part of
replace-and-commit is not delegated to a virtual function.
Now, the virtual function is only a pre-check hook, so that
the ifcfg-rh implementation can abort the function.

There are no functional changes.
2017-10-25 14:04:36 +02:00
Thomas Haller
0a8822ce9b ifcfg-rh: use svGetValueInt64() to read DEVTIMEOUT 2017-10-25 14:04:36 +02:00
Thomas Haller
dbd0ffb8e6 ifcfg-rh: use svSetValueInt64_cond() in writer 2017-10-25 14:04:36 +02:00
Thomas Haller
4f4f05edc8 ifnet: avoid registering and leaking multiple file monitors
Also, need to avoid danling pointers in clear_monitor().

This was not really a problem, because we would always call
cancel() before setup(). Still, it's fragile.
2017-10-25 14:04:36 +02:00
Thomas Haller
02deb9cffb ifnet/trivial: whitespace only 2017-10-25 14:04:36 +02:00