Commit graph

1051 commits

Author SHA1 Message Date
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
Thomas Haller
56d77ba568 ifcfg-rh: fix handling error writing route file to disk
Do not return failure based on whether an @error argument
is given.
2017-10-25 14:04:36 +02:00
Thomas Haller
19ebfdba5e ifcfg-rh: don't write to disk in write_route_file_legacy()/write_route6_file()
No change in behavior. Refactor code, to move the places that access
the file system (side effects).
2017-10-25 14:04:36 +02:00
Thomas Haller
6cb46619ed ifcfg-rh: merge new_connection() and update_connection() functions
They are basically the same, with a minor difference where the @filename
argument determines whether to write a new file or do an update.

Also, rename them, to give them a nms_* prefix in the header file.
2017-10-25 14:04:36 +02:00
Thomas Haller
3c3fc089ad settings: return re-read connection from ifcfg-rh writer
As writing a connection to disk might modify it, we re-read
it back and use what we actually found on disk.

For example, if you have a connection with ipv6.method=ignore,
ifcfg-rh writer will not persist the ipv6.route-metric. That
is likely a bug in the writer. Before this patch, changing
the route metric would seemingly succeed, but on the next reload
from this, the changes are lost.

We should fix such bugs. Regardless, it's better to pick up
what we wrote to disk, instead of later.
2017-10-25 14:04:36 +02:00
Thomas Haller
5a82cad5f3 settings: extend commit_changes() to update the settings after writing
During write, it can regularly happen that the connection gets modified.
For example, keyfile never writes blobs as-is, it always writes the
blob to an external file, and replaces the certificate property with
a path.
Other reasons could be just bugs, where the reader and writer are not doing
a proper round trip (these cases should be fixed).

Refactor commit_changes(), to return the re-read connection to
the settings-connection class, and handle replacing the settings
there.

Also, prepare for another change. Sometimes we first call replace_settings()
followed by commit_changes(). It would be better to instead call commit_changes()
first, and only on success proceed with replace_settings(). Hence, commit_changes()
gets a new argument new_connection, that can be used to write another
connection to disk.
2017-10-25 14:04:36 +02:00
Thomas Haller
3ecb57fdc4 settings: get rid of callback arguments for nm_settings_connection_delete() 2017-10-25 14:04:36 +02:00
Thomas Haller
bd66285b1c settings: get rid of callback arguments for nm_settings_connection_commit_changes()
No need to return an error result via a callback function. Just
return the plain error.
2017-10-25 14:04:36 +02:00
Thomas Haller
36f5d440fd settings: refactor virtual delete() function
Don't delegate so much to the virtual function delete().
2017-10-25 14:04:36 +02:00
Thomas Haller
ede1e08ac1 settings: refactor virtual commit_changes() function
Don't delegate so much to the virtual function commit_changes().
Calling the callback is not the task of the virtual function,
because every implementation must do that.

There are some minor changes in behavior for ifnet, where we now
first setup the monitors and reload the parsers, before invoking
the callback.
2017-10-25 14:04:36 +02:00
Thomas Haller
027229a4b0 settings: refactor replace_and_commit()
The virtual function replace_and_commit() had only one implementation: ifcfg-rh.

Refactor the code, to delegate less. That is, the main part of
replace-and-commit is not delegated to a virtual function.
Now, the virtual function is only a pre-check hook, so that
the ifcfg-rh implementation can abort the function.

There are no functional changes.
2017-10-25 14:04:36 +02:00
Thomas Haller
0a8822ce9b ifcfg-rh: use svGetValueInt64() to read DEVTIMEOUT 2017-10-25 14:04:36 +02:00
Thomas Haller
dbd0ffb8e6 ifcfg-rh: use svSetValueInt64_cond() in writer 2017-10-25 14:04:36 +02:00
Thomas Haller
4f4f05edc8 ifnet: avoid registering and leaking multiple file monitors
Also, need to avoid danling pointers in clear_monitor().

This was not really a problem, because we would always call
cancel() before setup(). Still, it's fragile.
2017-10-25 14:04:36 +02:00
Thomas Haller
02deb9cffb ifnet/trivial: whitespace only 2017-10-25 14:04:36 +02:00
Thomas Haller
de4742333a core: add option to pass ownership of file descriptor to nm_utils_fd_get_contents()
In many scenarios, we have no use for the file descriptor
after nm_utils_fd_get_contents(). We just want to read it
and close it.

API wise, it would be nice that the get_contents() function never
closes the passed in fd and it's always responsibility of the caller.

However, that costs an additional dup() syscall that could
be avoided, if we allow the function to (optionally) close
the file descriptor.
2017-10-19 15:49:58 +02:00
Beniamino Galvani
d29115c138 core: use nm_close()
Use nm_close() in the core to catch any improper use of close().
2017-10-19 15:49:58 +02:00
Thomas Haller
d1a58fbfbf ifcfg-rh: limit reading GATEWAY_PING_TIMEOUT to 600 seconds
libnm-core limits the rande for GATEWAY_PING_TIMEOUT to 0 to 600.
See commit e86f8354a7, "device: restart
ping process when it exits with an error".

The reader must not pass value out of range to g_object_set().
Clamp and warn.
2017-10-18 17:54:53 +02:00
Thomas Haller
3434261811 core,clients: use our own string hashing function nm_str_hash()
Replace the usage of g_str_hash() with our own nm_str_hash().

GLib's g_str_hash() uses djb2 hashing function, just like we
do at the moment. The only difference is, that we use a diffrent
seed value.

Note, that we initialize the hash seed with random data (by calling
getrandom() or reading /dev/urandom). That is a change compared to
before.

This change of the hashing function and accessing the random pool
might be undesired for libnm/libnm-core. Hence, the change is not
done there as it possibly changes behavior for public API. Maybe
we should do that later though.

At this point, there isn't much of a change. This patch becomes
interesting, if we decide to use a different hashing algorithm.
2017-10-18 13:05:00 +02:00
Thomas Haller
cc1ee1d286 all: rework configuring route table support by adding "route-table" setting
We added "ipv4.route-table-sync" and "ipv6.route-table-sync" to not change
behavior for users that configured policy routing outside of NetworkManager,
for example, via a dispatcher script. Users had to explicitly opt-in
for NetworkManager to fully manage all routing tables.

These settings were awkward. Replace them with new settings "ipv4.route-table"
and "ipv6.route-table". Note that this commit breaks API/ABI on the unstable
development branch by removing recently added API.

As before, a connection will have no route-table set by default. This
has the meaning that policy-routing is not enabled and only the main table
will be fully synced. Once the user sets a table, we recognize that and
NetworkManager manages all routing tables.

The new route-table setting has other important uses: analog to
"ipv4.route-metric", it is the default that applies to all routes.
Currently it only works for static routes, not DHCP, SLAAC,
default-route, etc. That will be implemented later.

For static routes, each route still can explicitly set a table, and
overwrite the per-connection setting in "ipv4.route-table" and
"ipv6.route-table".
2017-10-09 22:05:36 +02:00
Thomas Haller
a0aec7efea shared: pass addr_family as first argument to nm_utils_parse_inaddr*()
The addr_family should be the first argument. It mirrors inet_pton()
and is just nicer.

Also, rename the argument from "family" to "addr_family".
2017-10-06 11:08:39 +02:00
Thomas Haller
099be8e4db keyfile: fix reading/writing route metric zero
Zero is a valid route metric and distinct from -1, which means unspecified.
Fix reader and writer.

Fixes: e374923bbe
2017-10-04 11:40:47 +02:00
Thomas Haller
5b0f895e19 libnm,core: add TABLE attribute for routes settings
https://bugzilla.redhat.com/show_bug.cgi?id=1436531
2017-09-26 19:39:36 +02:00
Thomas Haller
c71f26bf92 libnm,cli: add IP setting "route-table-sync" 2017-09-26 19:39:36 +02:00
Beniamino Galvani
7dc1f8b479 ifcfg-rh: trivial: rename write_bonding_setting() to write_bond_setting()
The setting name is NMSettingBond.
2017-09-25 22:36:45 +02:00
Beniamino Galvani
e89ed9b51e ifcfg-rh: write DEVICE only once
The plugin already writes DEVICE in write_connection_setting(), there
is no need to write it again elsewhere.
2017-09-25 22:36:43 +02:00
Thomas Haller
6d675a943b ifcfg-rh: refactor parsing of route options to be strict
The previous parsing was done using regex. One could implement a
complex regex to parse the setting. However, as it was implemented,
the regex would just pick out parts of the line that it expects,
and ignore unknown parts.

Let's be strict about what we parse. The only strong requirement
is that NM can parse everything that was written by NM itself.
Eventually, we could extend the parser to accept everything that
initscripts accept.

Initscripts split the line at $IFS and do filename globbing on the
arguments. That is ugly, because globbing is of coures wrong (we don't
do that). But also, the splitting at $IFS cannot be escaped, hence for
initscripts it is impossible to use '<space><tab><newline>'. We do that
too, as it makes it easy to parse. Later we may want to extend this to
allow a form of escaping/quoting.

Yes, we may now ignore routes that are not defined as we expect them.
2017-09-18 20:14:09 +02:00
Thomas Haller
62f2c4cf20 ifcfg-rh: write lock route attribute with zero value
Only specifying "lock" without a corresponding attribute shall have
the meaning of "$NAME lock 0".
2017-09-18 20:14:09 +02:00