Commit graph

1078 commits

Author SHA1 Message Date
Thomas Haller
b074fd23b4 ifcfg-rh: check integer value for other bridge options 2017-11-23 18:43:49 +01:00
Thomas Haller
ff239c1652 ifcfg-rh: check integer value when reading handle_bridge_option()
We cannot just call g_object_set() with an integer that is out of bound.
Otherwise, glib will warn. We can use nm_g_object_set_property*() to return
an error without asserting.
2017-11-23 18:43:48 +01:00
Thomas Haller
30ce598fb5 ifcfg-rh: fix range and size when parsing integer values in reader 2017-11-23 18:43:48 +01:00
Thomas Haller
12788db4ee ifcfg-rh/trivial: rename get_uint() to get_uint32() 2017-11-23 18:43:48 +01:00
Thomas Haller
3a67b496ca ifcfg-rh: avoid string copies in make_bridge_setting()
Also, don't g_strstrip(value) for BRIDGE_MACADDR.
2017-11-23 18:43:48 +01:00
Beniamino Galvani
fb191fc282 ifcfg-rh: use distinct variables for bridge and wired mac address
Currently both bridge.mac-address and ethernet.cloned-mac-address get
written to the same MACADDR ifcfg-rh variable; the ethernet property
wins if both are present.

When one property is set and the connection is saved (and thus reread)
both properties are populated with the same value. This is wrong
because, even if the properties have the same meaning, the setting
plugin should not read something different from what was written. Also
consider that after the following steps:

 $ nmcli con mod c ethernet.cloned-mac-address 00:11:22:33:44:55
 $ nmcli con mod c ethernet.cloned-mac-address ""

the connection will still have the new mac address set in the
bridge.mac-address property, which is certainly unexpected.

In general, mapping multiple properties to the same variable is
harmful and must be avoided. Therefore, let's use a different variable
for bridge.mac-address. This changes behavior, but not so much:

 - connections that have MACADDR set will behave as before; the only
   difference will be that the MAC will be present in the wired
   setting instead of the bridge one;

 - initscripts compatibility is not relevant because MACADDR for
   bridges was a NM extension;

 - if someone creates a new connection and sets bridge.mac-address NM
   will set the BRIDGE_MACADDR property instead of MACADDR. But this
   shouldn't be a big concern as bridge.mac-address is documented as
   deprecated and should not be used for new connections.

https://bugzilla.redhat.com/show_bug.cgi?id=1516659
2017-11-23 18:43:48 +01:00
Beniamino Galvani
56a02c9baf ifcfg-rh: read wired properties for bridge connections
A bridge connection can have ethernet settings, read them from the
ifcfg file.
2017-11-23 18:43:48 +01:00
Thomas Haller
6b319cd072 ifcfg-rh: avoid duplicate lookup of bond-option in write_bond_setting()
Now that nm_setting_bond_get_option() has a stable order
(alphabetically), we no longer need to sort it.
2017-11-21 13:48:49 +01:00
Thomas Haller
7328976a02 ifcfg-rh/tests: test writing multiple bond options 2017-11-21 13:40:13 +01:00
Beniamino Galvani
9a631a068e ifcfg-rh: sort bond options when writing a connection
Bond options are stored in a hash table and the order in which they
are returned by the API is not guaranteed. Sort them alphabetically so
that a connection will always be written in the same way, even if the
internal implementation of the hash table or the hashing function
changes, as it did in commit a6be2f4aa9 ("all: use nm_str_hash()
instead of g_str_hash()").
2017-11-21 11:27:54 +01:00
Thomas Haller
93adadbdcb all: use nm_direct_hash() instead of g_direct_hash()
We also do this for libnm, where it causes visible changes
in behavior. But if somebody would rely on the hashing implementation
for hash tables, it would be seriously flawed.
2017-11-16 11:49:52 +01:00
Thomas Haller
3ee8de20c4 all: include "nm-utils/nm-hash-utils.h" by default
Next we will use siphash24() instead of the glib version g_direct_hash() or
g_str_hash(). Hence, the "nm-utils/nm-hash-utils.h" header becomes very
fundamental and will be needed basically everywhere.

Instead of requiring the users to include them, let it be included via
"nm-default.h" header.
2017-11-16 11:49:51 +01:00
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
89e518db5a libnm,cli,ifcfg-rh: add NMSetting8021x:auth-retries property 2017-10-31 19:35:33 +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
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
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