Commit graph

1400 commits

Author SHA1 Message Date
Beniamino Galvani
af8aac9b54 ifcfg-rh: omit empty next hop for routes in legacy format
Don't add "via (null)" if the next hop is missing.

https://bugzilla.redhat.com/show_bug.cgi?id=1452648
2017-05-19 17:44:09 +02:00
Lubomir Rintel
99c112a493 ifcfg-rh: save/restore WPS properties 2017-05-15 12:59:55 +02:00
Lubomir Rintel
f87912326c settings-connection: all method to internally supply new secrets
It's sort of a very very lightweight version of get_secrets_done_cb()
that allows as to add secrets to the connection that didn't come from
the agent manager.
2017-05-15 12:59:55 +02:00
Lubomir Rintel
63836f3945 ifcfg-rh: don't skip 802-11-security if there's no WPA-PSK 2017-05-15 12:59:55 +02:00
Thomas Haller
54f5407abf hostname: cache hostname-manager's hostname property
A property preferably only emits a notify-changed signal when
the value actually changes and it caches the value (so that
between property-changed signals the value is guaranteed not to change).

NMSettings and NMManager both already cache the hostname, because
NMHostnameManager didn't guarantee this basic concept.

Implement it and rely on it from NMSettings and NMPolicy.
And remove the copy of the property from NMManager.

Move the call for nm_dispatcher_call_hostname() from NMHostnameManager
to NMManager. Note that NMPolicy also has a call to the dispatcher
when set-transient-hostname returns. This should be cleaned up later.
2017-05-12 17:29:33 +02:00
Thomas Haller
5bfb7c3c89 hostname: split out hostname management from NMSettings
Hostname management is complicated. At least, how it is implemented currently.
For example, NMPolicy also sets the hostname (NMPolicy calls
nm_settings_set_transient_hostname() to have hostnamed set the hostname,
but then falls back to sethostname() in settings_set_hostname_cb()).
Also, NMManager tracks the hostname in NM_MANAGER_HOSTNAME too, and
NMPolicy listens to changes from there -- instead of changes from
NMSettings.

Eventually, NMHostnameManager should contain the hostname parts from NMSettings
and NMPolicy.
2017-05-12 17:29:33 +02:00
Thomas Haller
e827925646 agent-manager: use CList to track requests 2017-05-11 18:26:10 +02:00
Thomas Haller
a844b98259 agent-manager/trivial: move code 2017-05-11 18:26:10 +02:00
Thomas Haller
04dfff7db8 secret-agent: use CList to track requests 2017-05-11 18:26:10 +02:00
Thomas Haller
c12dd0d970 ifcfg-rh: refactor shvar.c to use CList instead of GList 2017-05-11 18:26:10 +02:00
Thomas Haller
79be44d990 ifcfg: add read/write support for user-data
The user data values are encoded in shell variables named
prefix "NM_USER_". The variable name is an encoded form of the
data key, consisting only of upper-case letters, digits, and underscore.

The alternative would be something like

  NM_USER_1_KEY=my.keys.1
  NM_USER_1_VAL='some value'
  NM_USER_2_KEY=my.other.KEY.42
  NM_USER_2_VAL='other value'

contary to

  NM_USER_MY__KEYS__1='some value'
  NM_USER_MY__OTHER___K_E_Y__42='other value'

The advantage of the former, numbered scheme is that it may be easier to
find the key of a user-data entry. With the current implementation, the
shell script would have to decode the key, like the ifcfg-rh plugin
does.

However, user data keys are opaque identifers for values. Usually, you
are not concerned with a certain name of the key, you already know it.
Hence, you don't need to write a shell script to decode the key name,
instead, you can use it directly:

  if [ -z ${NM_USER_MY__OTHER___K_E_Y__42+x} ]; then
      do_something_with_key "$NM_USER_MY__OTHER___K_E_Y__42"
  fi

Otherwise, you'd first have to search write a shell script to search
for the interesting key -- in this example "$NM_USER_2_KEY", before being
able to access the value "$NM_USER_2_VAL".
2017-05-06 14:12:19 +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
53f3113389 ifcfg-rh: support the wifi.pmf property 2017-04-28 09:46:06 +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
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
5fc4bfc0e3 ifcfg-rh/tests: fix out-of-tree build for cexpected file
Fixes: f04bf45e84
2017-04-27 16:25:20 +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
Lubomir Rintel
d4d6272fec ifcfg: don't complain if 8021x secrets are empty
The connection is still valid; and it's easily possible to create it. It would
be a shame if it couldn't be read back.
2017-04-10 10:33:24 +02:00
Lubomir Rintel
0812413c9d ifcfg-rh: fix loading the PKCS#11 client certificate
Contrary to the comment above, the reader would skip the client certificate
even if the key is on PKCS#11 token, not just in a PKCS#12 archive.
2017-04-10 10:33:22 +02:00
Lubomir Rintel
2839da06db settings/secret-agent: add initializers
To make coverity a bit happier.
2017-04-03 13:28:26 +02:00
Thomas Haller
a8730c51c8 libnm: move enum utils to new shared file shared/nm-utils/nm-enum-utils.h
libnm contains the public function nm_utils_enum_from_str() et al.
The function is not flexible enough for nmcli's usecase. So, I would
need another public function like nm_utils_enum_from_str_full() that
has an extended API.

That was already required previously for ifcfg-rh writer, but in that
case I could just add it as internal API as libnm-core is linked statically
with NetworkManager.

I don't want to commit to a public API for an utility function. So move
the code instead to the shared directory, so that nmcli may link
statically against it and use the internal API.
2017-03-30 13:09:58 +02:00
Thomas Haller
b5c8622ad3 cli: split nm-meta-setting-desc out of settings
This part contains static functions and variables to describe
settings. It is distinct from the mechanism to use them, or
access them.

Split it out.

It still uses clients/cli/common.h and clients/cli/utils.h
which shall be fixed next.
2017-03-30 13:09:58 +02:00
Beniamino Galvani
e044071825 ifcfg-rh: also check BONDING_OPTS to determine the connection type
Connections with "TYPE=Ethernet" and "BONDING_OPTS=..." are regarded
by initscripts as bond masters. To maintain the best compatibility, do
the same.

https://bugzilla.redhat.com/show_bug.cgi?id=1434555
2017-03-29 09:47:37 +02:00
Francesco Giudici
bdd2e1c2aa policy: try to retrieve hostname from dbus first
As we try to set the hostname through dbus, we should also try to
retrieve current hostname value from dbus first: otherwise we may end
retrieving the "old" hostname via gethostname while the dbus hostnamed
updated is pending.
2017-03-24 15:18:08 +01:00
Lubomir Rintel
8813164b24 keyfile: log the connection context 2017-03-24 12:42:09 +01:00
Lubomir Rintel
eccad6fa90 settings-connection: log the connection context 2017-03-24 12:42:09 +01:00
Lubomir Rintel
ed552c732c logging: log device and connection along with the message 2017-03-24 12:42:09 +01:00
Beniamino Galvani
e832461c0e ifcfg-rh: fix coding style 2017-03-23 17:19:21 +01:00
Thomas Haller
e32839838e udev: drop libgudev in favor of libudev
libgudev is just a wrapper around libudev. We can
use libudev directly and drop the dependency for
libgudev.
2017-03-22 12:41:06 +01:00
Beniamino Galvani
80dfb8cdab core,libnm-core: use same route attribute names of iproute2
Users are probably more familiar with iproute2 route option names than
kernel ones.

Fixes: 54e58eb96b
2017-03-22 12:04:25 +01:00
Yuri Chornoivan
4c6edb22b7 all: fix typos in documentation and comments
https://bugzilla.gnome.org/show_bug.cgi?id=780199

[thaller@redhat.com: reworded commit message]
2017-03-17 15:11:20 +01:00
Thomas Haller
90e7c8bf5b core/trivial: rename "nm-generated-assumed" flag to "volatile"
The concept of assumed-connection will change. Currently we mark
connections that are generated and assumed as "nm-generated-assumed".
That has several consequences, one of them being that such a settings
connection gets deleted when the device disconnects.

That is, such a settings connection lingers around as long as it's active,
but once it deactivates it gets automatically deleted. As such, it's
a more volatile concept of an in-memory connection.

The concept of such automatically cleaned up connections is useful beyond
generated-assumed. See the related bug rh#1401515.
2017-03-16 18:27:33 +01:00
Thomas Haller
d2064be787 core/dispatcher: add and use nm_dispatcher_call_hostname() 2017-03-16 18:27:33 +01:00
Thomas Haller
2b72cc2693 core/trivial: give names in src/nm-dispatcher.h header an "NM" prefix
Stuff defined in header files should have an NM prefix, although
this is a project-internal header.

Rename.
2017-03-16 18:27:33 +01:00
Lubomir Rintel
e1ea22ca81 ifcfg-rh: drop an unused variable
nms-ifcfg-rh-reader.c:497:25: error: unused variable 'local_error' [-Werror,-Wunused-variable]
                gs_free_error GError *local_error = NULL;
                                      ^

Fixes: 40e1fd9531
2017-03-10 14:36:37 +01:00
Thomas Haller
831286df30 include: use double-quotes to include our own headers
In practice, this should only matter when there are multiple
header files with the same name. That is something we try
to avoid already, by giving headers a distinct name.

When building NetworkManager itself, we clearly want to use
double-quotes for including our own headers.
But we also want to do that in our public headers. For example:

  ./a.c
    #include <stdio.h>
    #include <nm-1.h>
    void main() {
        printf ("INCLUDED %s/nm-2.h\n", SYMB);
    }

  ./1/nm-1.h
    #include <nm-2.h>

  ./1/nm-2.h
    #define SYMB "1"

  ./2/nm-2.h
    #define SYMB "2"

$ cc -I./2 -I./1 ./a.c
$ ./a.out
INCLUDED 2/nm-2.h

Exceptions to this are
  - headers in "shared/nm-utils" that include <NetworkManager.h>. These
    headers are copied into projects and hence used like headers owned by
    those projects.
  - examples/C
2017-03-09 14:12:35 +01:00
Thomas Haller
10f58f2bd3 ifcg-rh/writer: stack allocate keys in write_ip4_setting()
And make the types of the integer count variables consistent.
2017-03-06 15:20:25 +01:00
Beniamino Galvani
40e1fd9531 ifcfg-rh: support route options
For IPv4 we support both the legacy and the new route file format. In
the legacy format, option are appended to the "ip route" command
arguments:

  203.0.113.0/24 metric 3 via 198.51.100.1 dev eth2 cwnd 14 mtu lock 1500

This is backwards compatible with initscripts. In the new format, a
OPTIONSx= variable is added to represent the options in the same
format understood by iproute2:

 ADDRESS0=203.0.113.0
 NETMASK0=255.255.255.0
 GATEWAY0=198.51.100.1
 METRIC0=3
 OPTIONS0="cwnd 14 mtu lock 1500"

initscripts do not support this variable at the moment (but the
changes needed to support it are trivial).

By default the new format is used, unless the route file is already in
the legacy format.

For IPv6 only the legacy format is supported, as before.
2017-03-06 15:20:25 +01:00
Beniamino Galvani
cdfa625102 keyfile: support route options 2017-03-06 15:20:25 +01:00
Beniamino Galvani
ef491acfde core: split nm_utils_format_con_diff_for_audit()
The function will be called to display in audit logs the changes done
to connections.
2017-03-06 10:29:37 +01:00