Commit graph

1505 commits

Author SHA1 Message Date
Thomas Haller
cfdb962ebd ifcfg-rh: avoid coverity false positive in write_secrets()
Comparing @secrets_keys indicates to coverity that it might be NULL.
Below, we access @secrets_keys without check, and coverity doesn't realize
that this cannot crash, because secrets_keys_n would be zero too.

Anyway, this way we safe the sorting, in case we only have
one element.
2017-11-15 18:19:12 +01:00
Thomas Haller
0ed49717ab all: support route-attribute "onlink" for IPv4
Kernel doesn't support it for IPv6.

This is especially useful, if you combine static routes
with DHCP. In that case, you might want to get the device-route
to the gateway automatically, but add a static-route for it.
2017-11-13 11:35:44 +01:00
Beniamino Galvani
29a576496e ifcfg-rh: persist the connection type for TeamPort connections
Currently the ifcfg-rh plugin doesn't explicitly store the connection
type for team slaves and is only able to read back ethernet and vlan
connections.

Leave this unchanged for ethernet and vlan slaves, but store the TYPE
variable for other connection types (Wi-Fi and Infiniband) so that we
can properly determine their type when the connection is read.
2017-11-06 16:40:57 +01:00
Thomas Haller
6705c71263 ifcfg-rh: use svSetValueInt64_cond() in write_connection_setting() 2017-11-02 11:41:01 +01:00
Thomas Haller
2730dc60de all: move setting 802-1x.auth-retries to connection.auth-retries
The number of authentication retires is useful also for passwords aside
802-1x settings. For example, src/devices/wifi/nm-device-wifi.c also has
a retry counter and uses a hard-coded value of 3.

Move the setting, so that it can be used in general. Although it is still
not implemented for other settings.

This is an API and ABI break.
2017-11-02 11:41:01 +01:00
Thomas Haller
53dea38834 ifcfg-rh: refactor write_object() to avoid coverity warning
Coverity detects that the "if (blob)" condition must always be true.
Reorder the code, to avoid the warning. It's a bit clearer this way
anyway.
2017-10-31 20:15:04 +01:00
Thomas Haller
1a9d4869ed policy: move nm_settings_connection_can_autoconnect() to policy
Step by step, we move all tracking of autoconnect to NMPolicy.
2017-10-31 19:35:33 +01:00
Thomas Haller
e62e52dfe1 device: handle authentication retries using 802-1x.auth-retries setting
Since commit 4a6fd0e83e (device: honor the
connection.autoconnect-retries for 802.1X) and the related bug bgo#723084,
we reuse the autoconnect-retries setting to control the retry count
for requesting passwords.

I think that is wrong. These are two different settings, we should not
reuse the autoconnect retry counter while the device is still active.

For example, the user might wish to set autoconnect-retries to infinity
(zero). In that case, we would retry indefinitly to request a password.
That could be problematic, if there is a different issue with the
connection, that makes it appear tha the password is wrong.
A full re-activation might succeed, but we would never stop retrying
to authenticate. Instead, we should have two different settings for
retrying to authenticate and to autoconnect.

This is a change in behavior compared to 1.8.
2017-10-31 19:35:33 +01:00
Thomas Haller
89e518db5a libnm,cli,ifcfg-rh: add NMSetting8021x:auth-retries property 2017-10-31 19:35:33 +01:00
Thomas Haller
18f2d272ba settings: add and use nm_settings_connection_autoconnect_retries_try_next() 2017-10-31 19:35:33 +01:00
Thomas Haller
361a199a06 device: move resetting autoconnect retries from subtype to NMDevice 2017-10-31 19:35:28 +01:00
Thomas Haller
447dc874ce config: remove nm_config_data_get_value_cached()
It has almost no callers, and it is a bit of a strange API. Let's
not cache the last accessed value inside NMConfigData. Instead, free
it right after use. It was not reused anyway, it only hangs around
as convenience for the caller.
2017-10-31 19:14:07 +01:00
Thomas Haller
ec9bff293b settings/trivial: rename settings-connection's autoconnect functions
Names like
  - nm_settings_connection_get_autoconnect_retries
  - nm_settings_connection_set_autoconnect_retries
  - nm_settings_connection_reset_autoconnect_retries
are about the same thing, but they are cumbersome to grep
because they share not a common prefix.

Rename them from SUBJECT_VERB_OBJECT to SUBJECT_OBJECT_VERB,
which sounds odd in English, but seems preferred to me.
Now you can grep for "nm_settings_connection_autoconnect_retries_" to
get all accessors of the retry count, or "nm_settings_connection_autoconnect_"
to get all accessors related to autoconnect in general.
2017-10-31 19:14:07 +01:00
Beniamino Galvani
5f97430e21 ifcfg-rh: remove password-raw keys file after test
Fixes: a83ab252ee
2017-10-31 14:44:39 +01:00
Beniamino Galvani
a83ab252ee ifcfg-rh: add support for 802-1x.password-raw property
When the ifcfg-rh plugin writes a 802-1x setting it currently ignores
the password-raw property and so the password disappears when the
connection is saved. Add support for the property.
2017-10-31 10:19:49 +01:00
Thomas Haller
d0d962d3d1 ifcfg: fix invalid free in parse_route_line()
Cannot free NM_PTRARRAY_EMPTY(). Discovered by coverity.

Fixes: 6d675a943b
2017-10-30 16:35:02 +01:00
Thomas Haller
89a9908abf ifcfg-rh: avoid Unreachable coverity warning in reader
The loops never run more then once.

unreachable: Since the loop increment "iter++;" is unreachable, the loop
body will never execute more than once.
2017-10-30 14:31:29 +01:00
Thomas Haller
287d1aee77 all: avoid coverity warnings about "Missing Initialization"
31. NetworkManager-1.9.2/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c:974:
uninit_use_in_call: Using uninitialized value "contents_rest" when
calling "__strtok_r_1c".

33. NetworkManager-1.9.2/src/nm-core-utils.c:1957:
uninit_use: Using uninitialized value "s".

148. NetworkManager-1.9.2/src/nm-core-utils.c:1924:
uninit_use_in_call: Using uninitialized value "s" when calling
"nm_strstrip_avoid_copy".
2017-10-30 14:13:15 +01:00
Thomas Haller
f3146de41b libnm: avoid unnecessary copies accessing NMIPRoute's attributes
We want to support large number of routes. Reduce the number
of copies, by adding internal accessor functions.

Also, work around a complaint from coverity:

  46. NetworkManager-1.9.2/libnm-core/nm-utils.c:1987:
  dereference: Dereferencing a null pointer "names".
2017-10-30 14:12:41 +01:00
Thomas Haller
4a8a5495a9 all: avoid coverity warnings about "Wrong Check of Return Value"
30. NetworkManager-1.9.2/src/settings/plugins/keyfile/nms-keyfile-writer.c:218:
check_return: Calling "g_mkdir_with_parents" without checking return
value (as is done elsewhere 4 out of 5
 times).

25. NetworkManager-1.9.2/src/platform/nm-linux-platform.c:3969:
check_return: Calling "_nl_send_nlmsg" without checking return value (as
is done elsewhere 4 out of 5 times).

34. NetworkManager-1.9.2/src/nm-core-utils.c:2843:
negative_returns: "fd2" is passed to a parameter that cannot be negative.

26. NetworkManager-1.9.2/src/devices/wwan/nm-modem-broadband.c:897:
check_return: Calling "nm_utils_parse_inaddr_bin" without checking
return value (as is done elsewhere 4 out of 5 times).

3. NetworkManager-1.9.2/src/devices/bluetooth/nm-bluez5-manager.c:386:
check_return: Calling "g_variant_lookup" without checking return value
(as is done elsewhere 79 out of 83 times).

16. NetworkManager-1.9.2/libnm-util/nm-setting.c:405:
check_return: Calling "nm_g_object_set_property" without checking return
value (as is done elsewhere 4 out of 5 times).
2017-10-30 14:10:56 +01:00
Beniamino Galvani
be320e2be7 ifcfg-rh: set team and bond master for any connection type
Now the plugin can only recognize team or bond slaves of type
ethernet, vlan or infiniband.

Instead, check the presence of a team or bond master for all types of
connection to allow arbitrary stacking of interfaces.
2017-10-27 22:52:15 +02:00
Beniamino Galvani
44ffa57c5d ifcfg-rh/trivial: move code 2017-10-27 22:51:50 +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
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
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