Commit Graph

21088 Commits

Author SHA1 Message Date
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
Thomas Haller
19f37e0c98 libnm: add nm_setting_ip_config_get_addr_family() util 2017-10-25 14:04:36 +02:00
Thomas Haller
c4f74fcfb6 device: don't configure automatic default-routes if an explicit gateway is set
Since commit 5c299454b4 we can configure
multiple default-routes.

That is especially useful with IPv6 to configure multiple routers.
It will also be useful, once we allow configuring manual default-routes,
like regular static routes.

However the problem is, that the default-route for the manual gateway
and the gateway from DHCP both get the same metric. So it's undefined
which route is used. To avoid that problem, and to restore previous
behavior, don't accept any default-routes if a gateway is set.

Fixes: 5c299454b4
2017-10-25 09:01:55 +02:00
Beniamino Galvani
b16c853bef vpn: consider the never-default connection property
After commit 5c299454b4 ("core: rework tracking of
gateway/default-route in ip-config") NM set a default route for VPNs
only based on the "never-default" option reported by the plugin. It
should also consider the connection setting.

Fixes: 5c299454b4

https://bugzilla.redhat.com/show_bug.cgi?id=1505886
2017-10-25 09:01:25 +02:00
Thomas Haller
43dba57439 device: merge branch 'th/device-mtu-rh1414901'
https://bugzilla.redhat.com/show_bug.cgi?id=1414901
2017-10-24 16:07:49 +02:00
Thomas Haller
d732ac7d31 device: show better logging message when setting MTU fails
Setting the MTU might fail when the underlying device's MTU
is not set.

Detect that case, and log a better warning message.

Unfortunately, it's tricky to detect whether this is a complete
failure, or whether we will later try again to change the MTU.
So, we log a failure, altough later we might fix it. It would
be better not to warn about non-errors.
2017-10-24 16:05:40 +02:00
Thomas Haller
8a6c4fca3d platform: log result also for EEXIST in sysctl_set() 2017-10-24 16:05:40 +02:00
Thomas Haller
54cbb321e5 platform: return platform error code from nm_platform_link_set_mtu() 2017-10-24 16:05:40 +02:00
Thomas Haller
a53f45c15e platform: suppress logging error on failure to set MTU 2017-10-24 16:05:40 +02:00
Thomas Haller
cd271d5cb1 core: add nm_utils_sysctl_ip_conf_is_path() util 2017-10-24 16:05:40 +02:00
Thomas Haller
32b3eb1181 core: merge IPv4 and IPv6 implementation of nm_utils_ip4_property_path()
and nm_utils_ip6_property_path().

Also, rename to nm_utils_sysctl_ip_conf_path().
2017-10-24 16:05:40 +02:00
Thomas Haller
6e01238a40 core: don't use static buffer for nm_utils_ip4_property_path()
and nm_utils_ip6_property_path(). The API with static buffers
looks a bit nicer. But I think they are dangerous, because
we tend to pass the buffer down several layers of the stack, and
it's not immediately clear, that we don't overwrite the static
buffer again (which we probably did not, but it's hard to verify
that there is no bug there).
2017-10-24 16:04:46 +02:00
Thomas Haller
b27a10bde8 platform: merge do_change_link_request() into do_change_link()
There is only one caller left.
2017-10-23 17:53:22 +02:00
Thomas Haller
a37532a694 platform: merge do_change_link_result() into do_change_link()
There is only one caller left.
2017-10-23 17:53:22 +02:00
Thomas Haller
c0c23911da platform: move evaluating the result of set_address to do_change_link_result()
Move all evaluations of the result at one place.
2017-10-23 17:53:22 +02:00
Thomas Haller
42cfcf6f23 platform: downgrade warning about failure to set MTU
Setting the MTU failes under regular conditions, for example when
setting the MTU of a master larger then the MTU of the slaves.

Logging a warning it too alarming.
2017-10-23 17:53:22 +02:00
Thomas Haller
09ee0c9205 device: reset MTU when slave's MTU changes 2017-10-23 17:53:22 +02:00
Thomas Haller
667aed8aeb device: reset MTU when VLAN's parent device changes MTU
Kernel does not allow setting the MTU of a VLAN larger
then the MTU of the underlying device. Hence, we might
initially fail to set a large MTU of the VLAN, but we
have to retry when the MTU of the parent changes.

https://bugzilla.redhat.com/show_bug.cgi?id=1414901
2017-10-23 17:53:22 +02:00
Thomas Haller
05c4497bdd device: set MTU property of device in new _set_mtu() function 2017-10-23 17:53:22 +02:00