Commit Graph

15047 Commits

Author SHA1 Message Date
Thomas Haller
076ffda6f3 config: strip white space from configuration values
https://bugzilla.gnome.org/show_bug.cgi?id=750659
https://bugzilla.redhat.com/show_bug.cgi?id=1229861
2015-07-02 15:50:04 +02:00
Thomas Haller
7498b670a8 utils: strip whitespace for device spec in nm_match_spec_split()
Via escape sequences, the user still can specify trailing and leading
white spaces: such as "\s \s" will result in 3 spaces.
2015-07-02 15:50:04 +02:00
Thomas Haller
11c0e107b9 config: add config utility accessors 2015-07-02 15:50:04 +02:00
Thomas Haller
7e94785f28 config: ensure nm_config_get_plugins() to return stripped values 2015-07-02 15:50:04 +02:00
Thomas Haller
0abb502ff3 config: fix usage of g_key_file_get_value() vs. g_key_file_get_string()
g_key_file_get_value() returns the raw value as stored in the file.
When accessing a string value, in most cases it is correct to use
g_key_file_get_string() instead.

When working with internals, such as comparing two keyfiles for
equality, g_key_file_get_value() is correct.

When parsing booleans, we parse it based on the raw value.

Fix the usages. This is a change in behavior if the config file
contained unusual strings.
2015-07-02 15:50:04 +02:00
Thomas Haller
b506c29fe1 config: log configuration at startup and on reload 2015-07-02 15:50:04 +02:00
Thomas Haller
6d6ab20be0 config: add defines for keyfile groups to "nm-config.h"
Some plugins had their local defines for the name of the sections and
keys in NMConfig. Move those defines to "nm-config.h".

Usually plugins make use of code in core, but not the other
way round. Defining the names inside "nm-config.h" is no violation of
that because the config section names are anyway not local to the
plugin, but global in the shared name-space with other settings.
For example, another plugins shouldn't reuse the section "ifnet".
For that reason, it is correct and consistent to move these defines
to "nm-config.h".
We don't use those names in core, we merely signal their existance.
2015-07-02 15:50:04 +02:00
Thomas Haller
1b0ab2129c config: use nm_config_data_get_value_boolean()
This removes duplicate parsing, but also makes all places use the
same str-to-boolean convention.
2015-07-02 15:50:04 +02:00
Thomas Haller
a0e92799af config: add nm_config_data_get_value_boolean() 2015-07-02 15:50:04 +02:00
Thomas Haller
35d2981546 config: add nm_config_parse_boolean() function
Add function to parse as boolean according our NMConfig convention.
Split this out from nm_config_keyfile_get_boolean() so that we can use
it independently. Also, change the return type to gint, so that one might
pass -1 to indicate an invalid/missing boolean value.

Thereby also don't log a warning in nm_config_keyfile_get_boolean()
We don't want to log a warning every time we access a keyfile value.
If we want to warn about invalid values, we should do it once after
the configuration is loaded. And then we should not only do it
for booleans, but for other types as well.
2015-07-02 15:50:03 +02:00
Thomas Haller
2c46003e99 config: add macros NM_CONFIG_GET_DATA and NM_CONFIG_GET_DATA_ORIG 2015-07-02 15:50:03 +02:00
Thomas Haller
a5f7abb842 config: get rid of @error argument to nm_config_data_get_value()
We don't use this argument. A failure to retrieve a key is (for
every practical purpose) the same as no such key.
2015-07-02 15:50:03 +02:00
Thomas Haller
7fbfaf567d libnm: consider ordering for _nm_keyfile_equals()
GKeyFile considers the order of the files, so add a possibility
to check whether to keyfiles are equal -- also with respect to
the order of the elements.
2015-07-02 15:50:03 +02:00
Thomas Haller
e1b0195c67 libnm-keyfile/test: fix missing assertion in test 2015-07-02 15:50:03 +02:00
Thomas Haller
71323122c6 libnm: add keyfile utility functions 2015-07-02 15:50:03 +02:00
Thomas Haller
4a8a0b0918 config: reload also no-auto-default state
The content of the no-auto-default state file is part of NMConfig.
During a reload, also reload that.

This way, a user could edit the no-auto-default file and it would
be properly reloaded.
2015-07-02 15:50:03 +02:00
Thomas Haller
3e4458659b config: fix evaluation of no-auto-default setting
We used to merge the spec list for no-auto-default from keyfile with the
content of the state file. Since the addition of the "except:" spec this
is wrong.
For example, if the user configured:

  no-auto-default=except:mac:11:11:11:11:11

and statefile contained "11:11:11:11:11" and "22:22:22:22:22", we would
wrongly not match "11:11:11:11:11". The two lists must be kept separate,
so that devices that are blocked by internal decision always match.

This separation is also clearer. Now the spec list is devided into a
part that comes from user configuration, and a part that comes from
internal decision.
2015-07-02 15:50:03 +02:00
Thomas Haller
fab5c6a372 config: refactor processing of 'option+' and 'option-' config settings
We have a hack to extend GKeyFile to support specifying an 'option+'
key. Also add support for 'option-'.

Options that make use of these modifiers can only be string lists.
So do the concatenation not based on plain strings, but by treating
the values as string lists. Also, don't add duplicates.
2015-07-02 15:50:03 +02:00
Thomas Haller
bb4ae800a1 config: add nm_config_keyfile_set_string_list() utils function 2015-07-02 15:50:03 +02:00
Thomas Haller
a05e80913e config: add NM_CONFIG_KEYFILE_LIST_SEPARATOR define 2015-07-02 15:50:03 +02:00
Thomas Haller
3c8abc2d5b config/trivial: rename defines for default settings
Make them match to the variable names that we assign them to.
2015-07-02 15:50:03 +02:00
Thomas Haller
27bd7dc938 config: change examples for command line arguments to system default 2015-07-02 15:50:03 +02:00
Thomas Haller
f5177dbf7a test: add nmtst_assert_success() util 2015-07-02 15:50:03 +02:00
Thomas Haller
d6a331bd8c macros: add nm_strstrip() util 2015-07-02 15:50:03 +02:00
Thomas Haller
885d187d23 libnm: add _nm_utils_strv_cleanup() function 2015-07-02 15:50:03 +02:00
Thomas Haller
69f2d22bfe glib-compat: backport g_key_file_save_to_file() 2015-07-02 15:50:03 +02:00
Thomas Haller
f8c9863d55 config: fix order of processing [connection] sections in NMConfig
We support the "NetworkManager.conf" sections '[connection]' and
'[connection.\+]' (with arbitrary suffix).

Fix the order of how we evaluate these section.

Note that the literal '[connection]' section is always evaluated lastly
after any other '[connection.\+]' section.

Within one file, we want to evaluate the sections in top-to-bottom
order. But accross multiple files, we want to order them
later-files-first. That gives a reasonable behavior if the user
looks at one file, and also if he wants to overwrite configuration
via configuration snippets like "conf.d/99-last.conf".

Note that if a later file extends/overwrites a section defined in an
earlier file, the section is still considered with lower priority
This is intentional, because the user ~extends~ a lower priority
section. If he wants to add a higher priority section, he should
choose a new suffix.

Fixes: dc0193ac02
2015-07-02 15:50:03 +02:00
Thomas Haller
aa7a53bc67 libnm-keyfile: ensure g_key_file_get_groups() sets the length argument
Under certain cases, if g_key_file_get_groups() fails, it might not set the
out argument @length. Play it safe and initialize it.
2015-07-02 15:50:03 +02:00
Lubomir Rintel
e27aa5b4d7 ifcfg-rh: correct the error handling for NM_CONTROLLED=no connections
We ought to set an error if we're returning NULL from
connection_from_file_full(). Also, printing out a warning ourselves makes no
sense -- the caller communicates this if we signal an error by returning NULL.
2015-07-02 15:16:48 +02:00
Lubomir Rintel
3b853de2e9 ifcfg-rh: don't signal removal of the connection we didn't register
Removal of a NM_CONTROLLED=no connection and subsequent 'nmcli c reload' would
cause a crash.
2015-07-02 15:16:48 +02:00
Thomas Haller
49ade7a8da platform: minor refactor to logging and nm_platform_link_get_all()
Add trace logging to nm_platform_link_get_all().
2015-07-02 15:02:49 +02:00
Thomas Haller
5b208e718a platform: remove unreachable code in nm_platform_link_get_all()
Linux platform tracks links by ifindex. Hence an ifindex must be unique
and positive. Just assert against it.
2015-07-02 15:01:45 +02:00
Thomas Haller
6f5cb596ba platform/test: add test to call nm_platform_link_get_all() 2015-07-02 14:52:21 +02:00
Thomas Haller
987515ea73 platform: add trace-logging to nm_platform_link_get_all() 2015-07-02 14:42:08 +02:00
Thomas Haller
c9aeefb5a1 platform: replace debug() log macro with _LOGD() 2015-07-02 14:37:31 +02:00
Thomas Haller
e0630023e5 platform: add logging macros _LOGx() to nm-platform.c 2015-07-02 14:33:40 +02:00
Petr Vorel
ac497ccd6c autogen.sh: print errors to stderr, printf instead echo -n
Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
2015-07-02 09:55:32 +02:00
Lubomir Rintel
39ed60dc60 merge,cli: branch 'lr/cli-add-properties'
Make it possible to specify properties upon connection addition.

Addresses all these:

https://bugzilla.gnome.org/show_bug.cgi?id=750590
https://bugzilla.gnome.org/show_bug.cgi?id=698076
https://bugzilla.gnome.org/show_bug.cgi?id=740749
2015-07-02 09:34:09 +02:00
Lubomir Rintel
81f1e3da4f cli: add bash completion for 'nmcli c add -- <property list>'
Use the editor to obtain a list of possible properties for a type of
connection. Let 'nmcli c modify' completion reuse it as well, to avoid code
duplication.
2015-07-02 09:33:58 +02:00
Lubomir Rintel
b3e57cf3ca cli: allow specifying arbitrary properties on "nmcli c add"
Syntax: nmcli c add ... -- [+|-]<setting>.<property> <value> ...
2015-07-02 09:33:58 +02:00
Lubomir Rintel
15149d915f cli: refactor: split connection property reader from do_connection_modify()
No functional change.

We'll need it for specifying the properties on connection addition.
2015-07-02 09:33:58 +02:00
Lubomir Rintel
df69bd1625 cli: trivial: move is_property_valid()
This removes one extra forward definition and saves one in future.
2015-07-02 09:33:58 +02:00
Thomas Haller
8fdf198632 dispatcher: don't exit with failure in case D-Bus service stops
The initsystem should stop nm-dispatcher before stopping D-Bus
service. However, on some systems that is not implemented, so
nm-dispatcher should not exit with a failure message when the
system bus disappears.
Instead just assume that D-Bus service was stopped during shutdown
and exit gracefully.

Based-on-patch-by: Jacob <jacobgodserv@gmail.com>

https://bugzilla.gnome.org/show_bug.cgi?id=751017
2015-07-01 17:13:52 +02:00
Lubomir Rintel
295c9818b0 devices,platform: fix build with gcc
Warnings about missing initializers.
2015-07-01 16:35:52 +02:00
Lubomir Rintel
4ffd57f83d service: harden the NetworkManager service a bit
Tested with dnsmasq (ipv4.method=shared), openvpn & vpnc.

https://bugzilla.gnome.org/show_bug.cgi?id=750598
2015-07-01 16:26:15 +02:00
Thomas Haller
1749ad4068 core: merge branch 'th/device-route-bgo751264'
Several fixes to route and address handling in platform.
Especially refactor managing of IPv4 device routes and
let NMRouteManager handle them.

https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-07-01 16:06:36 +02:00
Thomas Haller
5f54a323d1 route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.

This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).

One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.

We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.

Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.

One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring  addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.

https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-07-01 16:02:10 +02:00
Thomas Haller
a96cba8845 route-manager: consider also 'proto kernel' routes during route_flush() 2015-07-01 16:02:10 +02:00
Thomas Haller
8336bd2a83 platform: properly consider address lifetimes in nm_platform_ip4_address_sync()
When checking whether an address from platform should be deleted, we
compare the address with our list of @known_addresses.
For that we must also check for expired lifetimes, because
@known_addresses might contain expired addresses.
2015-07-01 16:02:10 +02:00
Thomas Haller
347555795f route-manager: add argument @ignore_kernel_routes to route_sync()
Will be used later, no behavioral change yet.
2015-07-01 16:02:10 +02:00