Commit Graph

18368 Commits

Author SHA1 Message Date
Thomas Haller
3215508293 policy: fix memleak in lookup_callback() and cancelling
When the operation is cancelled, we must not touch user_data. Note that
NM_POLICY_GET_PRIVATE() theoretically doesn't dereference the pointer
(does it?) but doing pointer arithmetic on a dangling pointer is a very
ugly thing to do.

And of course, the memleak.

Fixes: 5c716c8af8
Fixes: a2cdf63204
2017-05-02 18:24:16 +02:00
Beniamino Galvani
c030bd3049 dhcp: dhclient: fix timeout greater than 60 seconds
The default timeout in dhclient is 60 seconds; if a lease can't be
obtained during such interval, dhclient sends to NM a FAIL event and
then the IP method fails.

Thus, even if user specified a greater dhcp-timeout, NM terminated
DHCP after 60 seconds. Fix this by passing an explicit timeout to
dhclient.

(cherry picked from commit 82ef497cc9)
2017-05-02 15:31:48 +02:00
Beniamino Galvani
82ef497cc9 dhcp: dhclient: fix timeout greater than 60 seconds
The default timeout in dhclient is 60 seconds; if a lease can't be
obtained during such interval, dhclient sends to NM a FAIL event and
then the IP method fails.

Thus, even if user specified a greater dhcp-timeout, NM terminated
DHCP after 60 seconds. Fix this by passing an explicit timeout to
dhclient.
2017-05-02 15:30:53 +02:00
Thomas Haller
d67d12ebe1 libnm: fix comparison of pfm enum against zero
Fixes compiler warning

  comparison of unsigned enum expression < 0 is always false [-Werror,-Wtautological-compare]

Fixes: 6ef59b5b77
2017-04-28 19:28:03 +02:00
Thomas Haller
59805d8c59 ifcfg: merge branch 'th/ifcfg-enum' 2017-04-28 17:21:58 +02:00
Thomas Haller
6ef59b5b77 libnm: make NMSettingWirelessSecurity's PMF property signed
The PMF property is an GEnum, not GFlags. We only have the GObject
property NM_SETTING_WIRELESS_SECURITY_PMF as plain integer type
to allow for future extensions.

But commonly, enums are signed int, while flags are unsigned. Change
the property to be signed for consistency.
2017-04-28 17:20:02 +02:00
Thomas Haller
2c46b65923 ifcfg-rh: use cleanup attribute for error handling in reader
Drop some uses of "goto error". Instead, have the memory owned
by an auto variable and automatically release it via the cleanup
attribute.
2017-04-28 12:42:18 +02:00
Thomas Haller
f16ec61a01 ifcfg-rh: use svGetValueEnum() in reader 2017-04-28 12:31:45 +02:00
Thomas Haller
606497a4e9 ifcfg-rh: use svSetValueEnum() in writer 2017-04-28 12:21:17 +02:00
Thomas Haller
7298798a64 ifcfg-rh: add svGetValueEnum() 2017-04-28 12:21:17 +02:00
Thomas Haller
e81bdf19fa ifcfg-rh: add svSetValueEnum() 2017-04-28 12:21:10 +02:00
Beniamino Galvani
a7fdf09848 wifi: merge branch 'bg/wifi-pmf-bgo748367-pt2'
Per-connection configurable PMF (802.11w) support.

https://bugzilla.gnome.org/show_bug.cgi?id=748367
2017-04-28 09:59:34 +02:00
Beniamino Galvani
acb70d84f9 supplicant: configure PMF for each connection
Now that we have a PMF connection property, get rid of the previous
code to globally enable/disable PMF and use the 'ieee80211w'
configuration option for each configured network when the supplicant
supports it.
2017-04-28 09:46:06 +02:00
Beniamino Galvani
53f3113389 ifcfg-rh: support the wifi.pmf property 2017-04-28 09:46:06 +02:00
Beniamino Galvani
6181f41d8d cli: support for wifi-sec.pmf property 2017-04-28 09:46:06 +02:00
Beniamino Galvani
60a3809815 libnm-core: add pmf property to wireless-security setting
Add a 'pmf' property to enable or disable Protected Management Frames
(802.11w) for the connection.
2017-04-28 09:46:05 +02:00
Thomas Haller
1f40bb13cf shared: cast from/to argument to unsigned for GFlags in _nm_utils_enum_get_values() 2017-04-27 18:01:58 +02:00
Thomas Haller
da5a6534bc cli: fix _values_fcn_gobject_enum() for flag types
For flags, the integer is cast to "unsigned", hence, the min/max
range must be different.

Fixes: f53218ed7c
2017-04-27 17:59:51 +02:00
Thomas Haller
20ef91879c ifcfg-rh/tests: fix test_write_unknown() after change svGetValue() for invalid values
Fixes: daaa741a3d
(cherry picked from commit 43c3501f97)
2017-04-27 17:56:07 +02:00
Thomas Haller
43c3501f97 ifcfg-rh/tests: fix test_write_unknown() after change svGetValue() for invalid values
Fixes: daaa741a3d
2017-04-27 17:52:25 +02:00
Lubomir Rintel
d21b21eba1 ifcfg-rh: preserve the archaic NETMASK key
py-kickstart writes this out and there apparently are users using this.
Let them have one less problem.

Co-Authored-By: Thomas Haller <thaller@redhat.com>

https://bugzilla.redhat.com/show_bug.cgi?id=1445414
(cherry picked from commit dbe0659ba419a77ad5ff2340bfc93c71a1bec61a)
2017-04-27 17:26:26 +02:00
Lubomir Rintel
40b39844fa ifcfg-rh: preserve the archaic BOOTPROTO=static form
py-kickstart writes this out. Okay -- we don't care on read and it makes
sense when there actually are addresses.

https://bugzilla.redhat.com/show_bug.cgi?id=1445414
(cherry picked from commit aa50dfc236b3806c6d7161cdea450655a1268f0d)
2017-04-27 17:26:26 +02:00
Thomas Haller
8d2ceac897 ifcfg-rh: treat a wrongly quoted value like empty string
For example, if you want to test whether a value is present and
reset it to a different value (only if it is present), it would
be reasonable to do

    if (svGetValue (s, key, &tmp)) {
        svSetValue (s, key, "new-value");
        g_free (tmp);
    }

Without this patch, you could not be sure that key is not
set to some inparsable value, which svWriteFile() would then
write out as empty string.

Have invalid values returned by svGetValue() as empty string.
That is how svWriteFile() treats them.

(cherry picked from commit 6470bed5f1ad25e20df14b333f1b083c9b390ece)
2017-04-27 17:26:26 +02:00
Lubomir Rintel
9e668595fe ifcfg-rh: preserve the archaic NETMASK key
py-kickstart writes this out and there apparently are users using this.
Let them have one less problem.

Co-Authored-By: Thomas Haller <thaller@redhat.com>

https://bugzilla.redhat.com/show_bug.cgi?id=1445414
2017-04-27 17:24:23 +02:00
Lubomir Rintel
38fbcdf0e5 ifcfg-rh: preserve the archaic BOOTPROTO=static form
py-kickstart writes this out. Okay -- we don't care on read and it makes
sense when there actually are addresses.

https://bugzilla.redhat.com/show_bug.cgi?id=1445414
2017-04-27 17:24:23 +02:00
Lubomir Rintel
67fab76bf3 ifcfg: use svSetValueInt64() wherever appropriate
With a little help from coccinelle:

  @@
  identifier string;
  expression value, ifcfg, key;
  @@
  (
  - string = g_strdup_printf ("%u", value);
  |
  - string = g_strdup_printf ("%d", value);
  )
  - svSetValueStr (ifcfg, key, string);
  - g_free (string);
  + svSetValueInt64 (ifcfg, key, value);

Applied with:

  spatch --sp-file nm_platform_get.cocci --in-place --smpl-spacing --dir src

Manually fixed up style issues & dropped unused variables.
2017-04-27 17:24:23 +02:00
Thomas Haller
daaa741a3d ifcfg-rh: treat a wrongly quoted value like empty string
For example, if you want to test whether a value is present and
reset it to a different value (only if it is present), it would
be reasonable to do

    if (svGetValue (s, key, &tmp)) {
        svSetValue (s, key, "new-value");
        g_free (tmp);
    }

Without this patch, you could not be sure that key is not
set to some inparsable value, which svWriteFile() would then
write out as empty string.

Have invalid values returned by svGetValue() as empty string.
That is how svWriteFile() treats them.
2017-04-27 17:24:23 +02:00
Lubomir Rintel
39594852ba ifcfg: remove dead code
Unused since 0c6349c62.
2017-04-27 17:24:19 +02:00
Thomas Haller
cfd8cf54df core: make dad_counter argument guint32 type
The dad_counter is hashed into the resulting address. Since we
want the hashing to be independent of the architecture, we always
hash 32 bit of dad_counter. Make the dad_counter argument of
type guint32 for consistency.

In practice this has no effect because:
  - for all our (current!) architectues, guint is the same as
    guint32.
  - all callers of nm_utils_ipv6_addr_set_stable_privacy() keep
    their dad-counter argument as guint8, so they never even pass
    numbers larger then 255.
  - nm_utils_ipv6_addr_set_stable_privacy() limits dad_counter
    further against RFC7217_IDGEN_RETRIES.

(cherry picked from commit 951e5f5bf8)
2017-04-27 17:21:36 +02:00
Thomas Haller
9f7433f869 core: avoid generating reserved IPv6 interface identifiers
https://tools.ietf.org/html/rfc7217 says:

  The resulting Interface Identifier SHOULD be compared against the
  reserved IPv6 Interface Identifiers [RFC5453] [IANA-RESERVED-IID]
  and against those Interface Identifiers already employed in an
  address of the same network interface and the same network
  prefix.  In the event that an unacceptable identifier has been
  generated, this situation SHOULD be handled in the same way as
  the case of duplicate addresses (see Section 6).

In case of conflict, this suggests to create a new address incrementing
the DAD counter, etc. Don't do that. If we generate an address of the
reserved region, just rehash it right away. Note that the actual address
anyway appears random, so this re-hashing is just as good as incrementing
the DAD counter and going through the entire process again.

Note that now we no longer generate certain addresses like we did
previously. But realize that we now merely reject (1 + 16777216 + 128)
addresses out of 2^64. So, the likelyhood of of a user accidentally
generating an address that is suddenly rejected is in the order of
10e-13 (1 / 1,099,503,173,697). Which is not astronomically, but still
extreeeemely unlikely.

Also, the whole process is anyway build on the idea that somebody else
might generate conflicting addresses (DAD). It means, there was always
the extremely tiny chance that the address you generated last time is
suddenly taken by somebody else. So, this change appears to a user
like these reserved addresses are now claimed by another (non existing)
host and a different address gets generated -- business as usual, as
far as SLAAC is concerned.

(cherry picked from commit f15c4961ad)
2017-04-27 17:21:35 +02:00
Thomas Haller
8ac1bf76bd core: move NMIPAddr to nm-core-utils.h
(cherry picked from commit 67da0a28db)
2017-04-27 17:21:33 +02:00
Thomas Haller
951e5f5bf8 core: make dad_counter argument guint32 type
The dad_counter is hashed into the resulting address. Since we
want the hashing to be independent of the architecture, we always
hash 32 bit of dad_counter. Make the dad_counter argument of
type guint32 for consistency.

In practice this has no effect because:
  - for all our (current!) architectues, guint is the same as
    guint32.
  - all callers of nm_utils_ipv6_addr_set_stable_privacy() keep
    their dad-counter argument as guint8, so they never even pass
    numbers larger then 255.
  - nm_utils_ipv6_addr_set_stable_privacy() limits dad_counter
    further against RFC7217_IDGEN_RETRIES.
2017-04-27 16:34:58 +02:00
Thomas Haller
f15c4961ad core: avoid generating reserved IPv6 interface identifiers
https://tools.ietf.org/html/rfc7217 says:

  The resulting Interface Identifier SHOULD be compared against the
  reserved IPv6 Interface Identifiers [RFC5453] [IANA-RESERVED-IID]
  and against those Interface Identifiers already employed in an
  address of the same network interface and the same network
  prefix.  In the event that an unacceptable identifier has been
  generated, this situation SHOULD be handled in the same way as
  the case of duplicate addresses (see Section 6).

In case of conflict, this suggests to create a new address incrementing
the DAD counter, etc. Don't do that. If we generate an address of the
reserved region, just rehash it right away. Note that the actual address
anyway appears random, so this re-hashing is just as good as incrementing
the DAD counter and going through the entire process again.

Note that now we no longer generate certain addresses like we did
previously. But realize that we now merely reject (1 + 16777216 + 128)
addresses out of 2^64. So, the likelyhood of of a user accidentally
generating an address that is suddenly rejected is in the order of
10e-13 (1 / 1,099,503,173,697). Which is not astronomically, but still
extreeeemely unlikely.

Also, the whole process is anyway build on the idea that somebody else
might generate conflicting addresses (DAD). It means, there was always
the extremely tiny chance that the address you generated last time is
suddenly taken by somebody else. So, this change appears to a user
like these reserved addresses are now claimed by another (non existing)
host and a different address gets generated -- business as usual, as
far as SLAAC is concerned.
2017-04-27 16:32:33 +02:00
Thomas Haller
9c37b4ae21 ifcfg-rh/tests: fix out-of-tree build for cexpected file
Fixes: f04bf45e84
(cherry picked from commit 5fc4bfc0e3)
2017-04-27 16:25:51 +02:00
Thomas Haller
67da0a28db core: move NMIPAddr to nm-core-utils.h 2017-04-27 16:25:20 +02:00
Thomas Haller
5fc4bfc0e3 ifcfg-rh/tests: fix out-of-tree build for cexpected file
Fixes: f04bf45e84
2017-04-27 16:25:20 +02:00
Lubomir Rintel
af87569a9b device: disable delegating prefixes to the device when the IPv6 config is removed
Fixes a crash where the default DNS domain to be announced together with the
prefixes to be delegated is updated at the same time the device is being
unrealized.

https://bugzilla.redhat.com/show_bug.cgi?id=1425818
(cherry picked from commit 3e076cf8b1)
2017-04-27 15:43:00 +02:00
Lubomir Rintel
3e076cf8b1 device: disable delegating prefixes to the device when the IPv6 config is removed
Fixes a crash where the default DNS domain to be announced together with the
prefixes to be delegated is updated at the same time the device is being
unrealized.

https://bugzilla.redhat.com/show_bug.cgi?id=1425818
2017-04-27 15:41:19 +02:00
Beniamino Galvani
43182c6e79 libnm-core,shared: fix typo in '(allow-none)' annotation
(cherry picked from commit d19553392b)
2017-04-27 09:03:34 +02:00
Beniamino Galvani
d19553392b libnm-core,shared: fix typo in '(allow-none)' annotation 2017-04-27 09:00:55 +02:00
Thomas Haller
753a2cc4d9 device: fix restricting Generic connection by interface-name
NMDeviceGeneric:check_connection_compatible() doesn't check for a
matching interface name. It relies on the parent implementation to
do that.

The parent implementation calls nm_manager_get_connection_iface().
That fails for NM_SETTING_GENERIC_SETTING_NAME, because that one has
no factory. Maybe this imbalance of having no factory for the Generic device
is wrong, but usually factories only match a distinct set of device
types, while the generic factory would handle them all (as last resort).

Without this, activating a generic connection might activate the
wrong interface.

(cherry picked from commit 3876b10a47)
2017-04-26 21:09:19 +02:00
Thomas Haller
3876b10a47 device: fix restricting Generic connection by interface-name
NMDeviceGeneric:check_connection_compatible() doesn't check for a
matching interface name. It relies on the parent implementation to
do that.

The parent implementation calls nm_manager_get_connection_iface().
That fails for NM_SETTING_GENERIC_SETTING_NAME, because that one has
no factory. Maybe this imbalance of having no factory for the Generic device
is wrong, but usually factories only match a distinct set of device
types, while the generic factory would handle them all (as last resort).

Without this, activating a generic connection might activate the
wrong interface.
2017-04-26 19:08:55 +02:00
Thomas Haller
d19a11e137 ifcfg-rh/tests: compare the written files to a expected result
We have unit tests for writing and re-reading ifcfg file. Those
tests compare whether a file can be successfully read and is
semantically identical.

However, there were no tests that a certain output is written in
a stable format. We aim not to change the output of what we write.
For that, add tests to not only check the semantic of the written
ifcfg file, but their bits and bytes.

Some future changes may well intentionally change the current
output. That will require to update the expected result files
and can be done via

  NMTST_IFCFG_RH_UPDATE_EXPECTED=yes src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh

Note that alias, route, and key files are not checked.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1445414
(cherry picked from commit f04bf45e84)
2017-04-26 12:31:37 +02:00
Thomas Haller
27025f08c3 ifcfg-rh/tests: remove unused macro _writer_update_connection_FIXME()
Fixes: 670e088efe
(cherry picked from commit e1e5d0d867)
2017-04-26 12:31:36 +02:00
Thomas Haller
f04bf45e84 ifcfg-rh/tests: compare the written files to a expected result
We have unit tests for writing and re-reading ifcfg file. Those
tests compare whether a file can be successfully read and is
semantically identical.

However, there were no tests that a certain output is written in
a stable format. We aim not to change the output of what we write.
For that, add tests to not only check the semantic of the written
ifcfg file, but their bits and bytes.

Some future changes may well intentionally change the current
output. That will require to update the expected result files
and can be done via

  NMTST_IFCFG_RH_UPDATE_EXPECTED=yes src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh

Note that alias, route, and key files are not checked.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1445414
2017-04-26 12:30:02 +02:00
Thomas Haller
e1e5d0d867 ifcfg-rh/tests: remove unused macro _writer_update_connection_FIXME()
Fixes: 670e088efe
2017-04-25 20:14:34 +02:00
Thomas Haller
7daf92afb8 cli: merge branch 'th/cli-l10n' 2017-04-23 23:52:36 +02:00
Thomas Haller
8b3c35a13e po: make update-po 2017-04-23 23:51:32 +02:00
Thomas Haller
83a6f36207 cli: don't mark field names for translation
Before refactoring nmcli recently, field names were marked for translation.
Note that for the property names, marking them had no effect as only
plain strings can be marked with N_().

Note how --fields are also an input argument. The input should be
independent of the locale and not translated. Likewise, when printing
the header names, they should not be translated to match the --fields
option.

    $ LANG=de_DE.utf8 nmcli --fields GENERAL.DEVICE device show enp0s25
    GENERAL.GERÄT:                          enp0s25

Drop the translation marks.
2017-04-23 23:45:02 +02:00
Thomas Haller
7aab314cef cli: fix marking settings docs for translation
Text for translation cannot contain defines (or variables). We must
generate the description docs with plain N_() values.
2017-04-23 23:45:02 +02:00