Commit graph

1380 commits

Author SHA1 Message Date
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
Thomas Haller
24be1fd913 ifcfg/trivial: rename svFileSetName() and svFileSetModified() to mark for testing
The filename of the shvarFile instance should be immutable and stay
unchanged for the entire lifetime of the instance. Similarly, the
modified flag should not be explicitly set.

However, for testing it is still useful to give the unit test a
direct access to those functions.

Rename the setters to make it clear that this is test-only.
2017-03-02 14:10:50 +01:00
Thomas Haller
670e088efe libnm-core: normalize invalid bridge|team slave-port settings
Having a bridge-port/team-port setting for a connection that
has a different slave-type makes no sense. Such a configuration
shall be considered invalid, and be fixed by normalization.

Note that there is already a normalization the other way around,
when you omit the "slave-type" but a "master" and one(!) port-type
setting is present, the slave-type is automatically determined
based on the port-type.

The use of this is of course to modify an existing slave connection
to make it a non-slave. Then the invalid port settings should be
automatically removed.

Previously, ifcfg-rh writer would write the "BRIDGING_OPTS" setting
without a "BRIDGE". The reader would then (correctly) ignore the
bridge-port. Avoid that altogehter, by requiring the connection to
strictly verify.
2017-03-02 12:14:29 +01:00
Thomas Haller
e0252e7a75 ifcfg-rh: require connections to be fully normalized for writing 2017-03-02 12:14:29 +01:00
Thomas Haller
b4594af55e keyfile: updated connection when writing keyfile
Writing a connection to keyfile and read it back should result
in the identical setting. That is, a full round-trip would not
alter any information.

That is however particularly not true for certificate properties, where
the keyfile writes blobs to file and coerces paths.

Thus, whenver writing a keyfile we must read back what we just
wrote and use that instead.
2017-03-02 12:14:29 +01:00
Thomas Haller
e636d28116 keyfile: extend internal API to re-read keyfile connection after writing
Add API to re-read the keyfile after writing it.
Usually, we would expect that whenever we serialize
something to disk, it can be read back exactly the same.

That is however not true for certificates, where we mangle
path and blobs while writing to file.

Anyway, extend the write-API to re-read what we just wrote.

The tests got extended to assert that whatever we write can
be read back the same.

Later, we want to reinject the reread connection into the settings
plugin again.
2017-03-02 12:14:29 +01:00
Thomas Haller
cf213216fd libnm-core: add ethernet setting for vlan connection
A "vlan" setting can optionally have an ethernet setting.
However, ifcfg-rh reader always adds such a setting, because
well... Anyway, the result is that writing a VLAN setting
without ethernet section will yield a different result
on re-read.

Let's have normalization add the ethernet setting, so that
two we consistently have it present.
2017-03-02 12:14:29 +01:00
Thomas Haller
53018b92e8 ifcfg-rh: fix reading team slave types of vlan type
https://bugzilla.redhat.com/show_bug.cgi?id=1427482
2017-03-02 12:14:29 +01:00
Thomas Haller
5a82494fa6 ifcfg-rh/tests: add test for writing team slave
This shows the current bug, needs to be fixed.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1427482
2017-03-02 12:14:29 +01:00
Thomas Haller
13e9967a3a ifcfg-rh: add internal API to re-read connection after write
Our reader/writer has flaws. We easily write out something that
is re-read differently. That is a problem and should be fixed.

Add API to re-read the connection after writing.

Extend the tests to check that the re-read value is identical
to what we wrote. In some cases, this does not hold. That is
usually a bug which needs fixing. Note that for certificate
blobs and paths we may intentionally mutate the connection
during writing, so there are valid cases where a connection
is re-read differently.
2017-03-02 12:14:29 +01:00
Thomas Haller
5ef4db18ce ifcfg-rh: change "goto error" pattern to return early and nm_auto* 2017-03-02 12:14:29 +01:00
Lubomir Rintel
9d2dfd9d97 ifcfg: avoid marking newly created connections as Unsaved 2017-02-27 11:17:39 +01:00
Lubomir Rintel
b47340fd3f settings-connection: fix Save()
Avoid using new_settings when they are none. Also, don't shortcut when
the connection hasn't been changed -- let the settings plugin decide if
it needs to rewrite the connection.
2017-02-27 11:16:45 +01:00
Lubomir Rintel
54086127ef ifcfg-rh: don't shortcut writing if the connection stays the same
Some keys, such as MASTER may still be different as they may depend on
other connections. svWriteFile() checks if the resulting file is
different already anyway.
2017-02-27 11:16:45 +01:00
Thomas Haller
71a22df337 settings: refactor autoconnect-blocked-reason to use own enum
Don't reuse NMDeviceStateReason for the autoconnect-blocked-reason. There are
only two cases we care: blocked-due-to-no-secrets, blocked-otherwise.

Encode these values in a new enum type.
2017-02-23 17:00:09 +01:00
Thomas Haller
8406455b4d ifcfg: drop strlen() call from svEscape() 2017-02-21 15:47:43 +01:00
Thomas Haller
c9f6cb9fe4 ifcfg: some refactoring of reader using vGetValueStr()/vGetValue_cp() 2017-02-21 15:43:03 +01:00
Thomas Haller
ccbfda5c08 ifcfg: complete shvar API with svGetValue_cp() and svGetValueStr()
Add svGetValue_cp() and svGetValueStr() for completeness.

Currently, we mostly use svGetValueStr_cp(), which I think is wrong
because for most cases we should instead not ignore empty values -- that
is, svGetValue_cp() would be a better choice.

Also, I think that the non *_cp() API should be preferred in many cases
because it avoids cloning the value in many cases. The API is not
necessarily less favorable either:

    gs_free char *value = NULL;

    value = svGetValue_cp (s, key);
    if (value)
        ...

vs.

    gs_free char *value_to_free = NULL;
    const char *value;

    value = svGetValue (s, key, &value_to_free);
    if (value)
        ...

Add the two missing variants, so that future code can use what fits
best, not following undesired practices because seemingly there is
no alternative.
2017-02-21 15:30:23 +01:00
Thomas Haller
c0c9b3dbcd ifcfg/trivial: rename svGetValueString() to svGetValueStr_cp()
We have

 - svGetValue()
    - returns the original string
    - avoids copying the string unless necessary

 - svGetValueStr_cp() (formerly svGetValueString())
    - returns the original string, unless it is empty ""
    - always clones the string

I think the behavior svGetValueStr*() of coercing "" to NULL is wrongly
used in most places. We should better handle "" like any other value,
not treat it as unset.

That would require another function svGetValue_cp(), which is like svGetValue()
but always copies the string. Rename svGetValueString() so that there is a place
for names like

  - svGetValue_cp()
  - svGetValueStr()

Also rename svSetValueString() to svSetValueStr().
2017-02-21 12:34:36 +01:00
Thomas Haller
d37c77234f ifcfg: set error for failure reading unrecognized connection in connection_from_file_full() 2017-02-21 12:17:30 +01:00
Thomas Haller
9b8e56180f ifcfg: don't g_strstrip() value in read_dcb_bool_array()
Ifcfg reader now properly handles escaping and quoting. We don't
need to stip whitespace, if somebody explicitly configures

  prop=" value"

it is a configuration error.
2017-02-21 12:17:30 +01:00