Commit graph

1096 commits

Author SHA1 Message Date
Colin Walters
4bd3069b68 tree-wide: cast after g_object_ref() for proposed GLib patch
This fixes the build with related bug https://bugzilla.gnome.org/show_bug.cgi?id=790697

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00005.html
(cherry picked from commit 3f6bef47f3)
2017-12-06 10:44:44 +01:00
Thomas Haller
4334069b10 ifcfg-rh: add and use nm_inotify_helper_clear_watch() helper
(cherry picked from commit a3074ee911)
2017-12-06 09:35:43 +01:00
Thomas Haller
6217a97700 ifcfg-rh: move nm-inotify-helper to ifcfg-rh plugin
The helper is only used by ifcfg-rh. Move it to the plugin.

(cherry picked from commit 8e172eb984)
2017-12-06 09:32:27 +01:00
Thomas Haller
e5f41b763a ifcfg-rh: fix path_watch_stop() not to create inotify-helper
Commonly, we don't monitor files and hence don't need the inotify-helper
instance. We already access and construct the instance lazy, by
accessing the singleton getter only when needed.

However, path_watch_stop() would always access the singleton, hence
always create such an instance. In most cases there is nothing to clean,
and no such instance shall be created.

(cherry picked from commit 31f2a46639)
2017-12-06 09:32:27 +01:00
Thomas Haller
2bff4dd1a6 settings: pass new_connection to commit_changes() and fix ifnet
ifnet shall use the new_connection argument, not NM_CONNECTION(self).
Also, let the caller of the virtual function provide the right new_connection,
not having the virtual function figure that out.

(cherry picked from commit 8a675f3d13)
2017-12-06 09:32:27 +01:00
Thomas Haller
570056af7b settings: unify settings-update API (rename and merge)
(cherry picked from commit 776c5f3893)
2017-12-06 09:32:27 +01:00
Thomas Haller
8b8bb297f7 settings: unify settings-update API (nm_settings_connection_replace_settings())
(cherry picked from commit 9a4225ac96)
2017-12-06 09:32:27 +01:00
Thomas Haller
a703aba62c settings: unify settings-update API (nm_settings_connection_commit_changes())
(cherry picked from commit 1425be0397)
2017-12-06 09:32:27 +01:00
Thomas Haller
00182192f7 settings: add persistent-mode argument for connection-replace
The current behavior of update_unsaved is confusing. Give the argument
an enum with a name that describes better what's happening. Also, it
makes the uses grep-able.

(cherry picked from commit 9531da8b3e)
2017-12-06 09:32:26 +01:00
Thomas Haller
860a4041ef ifcfg-rh: avoid unnecessary string copies in add_one_wep_key()
(cherry picked from commit c3d192b6a3)
2017-12-04 16:01:58 +01:00
Thomas Haller
d94c0e747b ifcfg-rh: use NM_IN_SET() macro in add_one_wep_key()
Evaluate strlen() only once.

(cherry picked from commit 5a857b3922)
2017-12-04 16:01:57 +01:00
Thomas Haller
74c2538bb3 ifcfg-rh: use NM_STRCHAR_ANY() macro in add_one_wep_key()
(cherry picked from commit da6394d572)
2017-12-04 16:01:56 +01:00
Beniamino Galvani
020dcf5bc1 ifcfg-rh: persist the wep key type
The wireless-security setting has a 'wep-key-type' property that is
used to specify the WEP key type and is needed because some keys could
be interpreted both as a passphrase or a hex/ascii key.

The ifcfg-rh plugin currently stores the key type implicitly: if
wep-key-type is 'passphrase' it uses the KEY_PASSPHRASE%d variable, if
it's 'key' the KEY%d variable and when it's 'unknown' it uses either
variables depending on the detected type (preferring 'key' in case
both are compatible).

This means that some connections will be read differently from how
they were written, because once the KEY (or KEY_PASSPHRASE) is read
there is no way to know whether the 'wep-key-type' property was 'key'
(or 'passphrase') or 'unknown'.

Fix this by persisting the key type explicitly in the file. The new
variable is redundant in most cases because the variables used for
keys also determine the key type.

https://bugzilla.redhat.com/show_bug.cgi?id=1518177
(cherry picked from commit c6eb18ee05)
2017-12-04 16:01:54 +01:00
Thomas Haller
e38e1ec659 ifcfg-rh: only open network file once when parsing connection
(cherry picked from commit 9b08f2c61d)
2017-12-01 00:02:34 +01:00
Beniamino Galvani
bd4754da05 ifcfg-rh: use different variables for IPv4 and IPv6 DNS options
Until now the ifcfg-rh plugin merged the values of 'ipv4.dns-options'
and 'ipv6.dns-options' and wrote the result to the RES_OPTIONS
variable. This is wrong because writing a connection and reading it
back gives a different connection compared to the original.

This behavior existed since when DNS options were introduced, but it
became more evident now that we reread the connection after write,
because after doing a:

 $ nmcli connection modify ethie ipv4.dns-options ndots:2

the connection has both ipv4.dns-options and ipv6.dns-options set. In
order to delete the option, an user has to delete it from both
settings:

 $ nmcli connection modify ethie ipv4.dns-options "" ipv6.dns-options ""

To improve this let's use different variables for IPv4 and IPv6. To
keep backwards compatibility IPv4 still uses RES_OPTIONS, while IPv6
uses a new IPV6_RES_OPTIONS variable.

https://bugzilla.redhat.com/show_bug.cgi?id=1517794
(cherry picked from commit 8379785560)
2017-12-01 00:02:32 +01:00
Thomas Haller
11eb191302 ifcfg-rh: replace usage of _nm_utils_strsplit_set() with nm_utils_strsplit_set()
(cherry picked from commit a81ad3474d)
2017-11-29 19:15:30 +01:00
Thomas Haller
a961a65cea ifcfg-rh: avoid copy of value for "HWADDR_BLACKLIST"
(cherry picked from commit d3520813e8)
2017-11-29 19:15:30 +01:00
Thomas Haller
bf7661189e c-list: re-import latest version of c-list.h from upstream
Most notably, it renames
  c_list_unlink_init() -> c_list_unlink()
  c_list_unlink() -> c_list_unlink_stale()

  $ sed -e 's/\<c_list_unlink\>/c_list_unlink_old/g' \
        -e 's/\<c_list_unlink_init\>/c_list_unlink/g' \
        -e 's/\<c_list_unlink_old\>/c_list_unlink_stale/g' \
        $(git grep -l c_list_unlink -- ':(exclude)shared/nm-utils/c-list.h') \
        -i

(cherry picked from commit b6efac9ec2)
2017-11-28 12:04:15 +01:00
Thomas Haller
f000c76be4 core: replace "dup()" by "fcntl(fd, F_DUPFD_CLOEXEC, 0)"
(cherry picked from commit 1e572ebf87)
2017-11-27 14:03:51 +01:00
Beniamino Galvani
a792a7f9c3 ifcfg-rh: close file descriptor only when necessary
If the file was read-only, we already closed it.

This fixes the following valgrind warnings:

 Warning: invalid file descriptor -1 in syscall close()

(cherry picked from commit 174da8f922)
2017-11-27 10:19:29 +01:00
Thomas Haller
539a2835b2 ifcfg-rh: check integer value for other bridge options
(cherry picked from commit b074fd23b4)
2017-11-24 08:29:27 +01:00
Thomas Haller
c42913f5b1 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.

(cherry picked from commit ff239c1652)
2017-11-24 08:29:24 +01:00
Thomas Haller
3d6d54676d ifcfg-rh: fix range and size when parsing integer values in reader
(cherry picked from commit 30ce598fb5)
2017-11-24 08:29:21 +01:00
Thomas Haller
0219368a77 ifcfg-rh/trivial: rename get_uint() to get_uint32()
(cherry picked from commit 12788db4ee)
2017-11-24 08:29:19 +01:00
Thomas Haller
f147f490dd ifcfg-rh: avoid string copies in make_bridge_setting()
Also, don't g_strstrip(value) for BRIDGE_MACADDR.

(cherry picked from commit 3a67b496ca)
2017-11-24 08:29:18 +01:00
Beniamino Galvani
1d5f060098 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
(cherry picked from commit fb191fc282)
2017-11-24 08:28:47 +01:00
Beniamino Galvani
3a623c2d1f ifcfg-rh: read wired properties for bridge connections
A bridge connection can have ethernet settings, read them from the
ifcfg file.

(cherry picked from commit 56a02c9baf)
2017-11-24 08:28:43 +01:00
Thomas Haller
628d292be7 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.

(cherry picked from commit 6b319cd072)
2017-11-21 14:15:26 +01:00
Thomas Haller
fae12cf956 ifcfg-rh/tests: test writing multiple bond options
(cherry picked from commit 7328976a02)
2017-11-21 14:14:25 +01:00
Beniamino Galvani
7225fdc5ae 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()").

(cherry picked from commit 9a631a068e)
2017-11-21 11:29:32 +01:00
Thomas Haller
2dcf08402c 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.

(cherry picked from commit cfdb962ebd)
2017-11-15 18:19:54 +01:00
Thomas Haller
4b890dead5 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.

(cherry picked from commit 0ed49717ab)
2017-11-13 14:43:07 +01:00
Beniamino Galvani
293710434d 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.

(cherry picked from commit 29a576496e)
2017-11-06 16:46:22 +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