Commit Graph

13873 Commits

Author SHA1 Message Date
Thomas Haller
53f98e7f9e platform: implement NMPObject and NMPCache
NMPObject is a simple "object" implemenation around NMPlatformObject.
They are ref-counted and have a class-pointer. Several basic functions
like equality, hash, to-string are implemented.

NMPCache is can be used to store the NMPObject. Objects are indexed
via their primary id, but there is also multi-lookup via NMCacheId
and NMMultiIndex.

Part of the implementation is inside "nm-linux-platform.c",
because it depends on utility functions from there.
2015-06-17 11:23:51 +02:00
Thomas Haller
d1e7554a90 platform: move ObjectType to nmp-object.h 2015-06-17 11:23:51 +02:00
Thomas Haller
359fe9f8c1 platform: add nmp-object.h file 2015-06-17 11:23:51 +02:00
Thomas Haller
f99723eda5 core: add NMMultiIndex class
A class to do efficient lookup for multiple values based on a key.

The values are opaque pointers (void*). These values can be
associated with keys. The keys are an opaque type NMMultiIndexId
with arbitrary hash/equal functions.

Think of the keys being a set of buckets. A value can be associated with multiple
keys, just like with a regular GHashTable (i.e. it can be in multiple buckets).
But one key can also be associated with multiple values (i.e. one bucket can contain
multiple values). Hence the name "multi".
One bucket can only either contain a value or not. It cannot contain the same
value multiple times.

This is implemented as a hash of hashes with the outer keys being
NMMultiIndexId. The inner hashes are the "buckets".

This class will be used as an efficient lookup index to find all values
that belong to a certain key (bucket). Later we will ask for example
"Which IP4-Addresses are associated with a certain ifindex" and
efficiently retrieve the cached result list.
2015-06-17 11:23:51 +02:00
Thomas Haller
430658b17a core: add NMRefString
NMRefString is a simple, refcounted, immutable string. Increasing/decreasing
the refcount does not affect const-ness.

It can be used just like a regular 'const char *' pointer. The only
difference is that you need special alloc/free functions.
2015-06-17 11:23:42 +02:00
Thomas Haller
2bea70e750 glib-compat: add nm_g_hash_table_replace() compat function
The newer version of g_hash_table_replace() is useful, because it
saves an additional hash table lookup.
2015-06-17 10:54:56 +02:00
Thomas Haller
64d918293b platform: add _NM_IP_CONFIG_SOURCE_RTPROT_KERNEL source
Later we will need this flag to distinguish routes from kernel
that have source RTPROT_KERNEL.

This flag is still unused.
2015-06-17 10:54:56 +02:00
Thomas Haller
304abc909a platform: implement dispose() in NMLinuxPlatform 2015-06-17 10:54:56 +02:00
Thomas Haller
c34598fa23 platform: print more fields in nm_platform_link_to_string() 2015-06-17 10:54:56 +02:00
Thomas Haller
655a0e71d4 platform: expose internal buffer for to_string() functions
I'd like to reuse this buffer for other to-string functions that
are platform related.
2015-06-17 10:54:56 +02:00
Thomas Haller
806109c245 platform/trivial: rename to_string_buffer variable 2015-06-17 10:54:56 +02:00
Thomas Haller
32ab8c18f5 platform: add inet6_token parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
3ce4431695 platform: add arptype parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
5b2b62ff51 platform: add inet6_addr_get_mode_inv parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
36e77218a0 platform: add addr parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
3cdde18f52 platform: add vlan_id parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
b307abc010 platform: add flags parameter to NMPlatformLink 2015-06-17 10:54:55 +02:00
Thomas Haller
619f660a3e platform: add scope parameter to NMPlatformIP4Route
Cache the scope as part of the NMPlatformIP4Route and
no longer read it from libnl object when needed. Later
there will be no more libnl objects around, and we need
to scope when deleting an IPv4 route.
2015-06-17 10:53:55 +02:00
Thomas Haller
4c49d78f49 platform: return @now from _rtnl_addr_last_update_time_to_nm()
Will be used later.
2015-06-12 16:30:34 +02:00
Beniamino Galvani
135999c2ec merge: branch 'bg/hostname-bgo740409'
- move all hostname-related functions from plugins to the core
- allow to specify the method used to load and store the hostname at
  build time
- add hostnamed support
- remove unused setting plugins

https://bugzilla.gnome.org/show_bug.cgi?id=740409
2015-06-12 16:06:12 +02:00
Thomas Haller
e700211f00 settings/example: remove 'example' settings plugin
The 'example' settings plugin is (obviously) unused, but it is also
badly maintained and no longer best-practice in several ways:

  - it directly reads "NetworkManager.conf" instead of using NMConfig.
  - it parses device specs itself, instead of using
    nm_match_spec_split().
  - read_connections() doesn't ensure that loading a file
    does not replace a previously loaded one (due to conflicting
    UUID). In general the example doesn't show/handle the complexity
    of potential UUID conflicts.

Instead of fixing these issues it is better to ensure our main plugin
('keyfile') corresponds to current best practices. Should we ever add a
new pluginww, 'keyfile' should be the example.
2015-06-12 15:59:40 +02:00
Thomas Haller
b16f31af45 keyfile: refactor reading "keyfile.unmanaged-devices" setting
Instead of parsing "/etc/NM/NetworkManager.conf" in keyfile plugin itself,
use NMConfig. Parsing it outside of NMConfig API has the significant disadvantage
of not considering files under "conf.d/".

This also has a behavioral change: keyfile no longer monitors
"NetworkManager.conf" file for changes, but instead only reacts
on explict "config-changed" signals from NMConfig.

This previous behavior of picking up file changes without
user-interaction is anyway not what we want. NM should not react
on mere file changes, but only on explicit reload commands. And
even if we want to support it, file watching should be implemented
properly inside NMConfig, watching *all* relevant files.

This was the last out-of-api access to the configuration after
refactoring NMConfig. Now that keyfile plugin no longer writes
the hostname, we can get rid of this.
2015-06-12 15:59:40 +02:00
Thomas Haller
bffe507cda keyfile: refactor dispose() of SCPluginKeyfile 2015-06-12 15:59:39 +02:00
Beniamino Galvani
4739ff6e7c settings: remove ifcfg-suse plugin
After the hostname functionality has been moved from plugins to core,
the ifcfg-suse plugin contains only boilerplate code with no actual
functionality.

Remove the plugin, mark it as deprecated in manual page and print a
warning when it is selected in configuration file.
2015-06-12 15:59:39 +02:00
Beniamino Galvani
6dc35e66d4 settings: add hostnamed support
When the systemd-hostnamed daemon is available, use it to read and
change the hostname.

Based on 'danw/wip/hostnamed' branch by Dan Winship <danw@redhat.com>
2015-06-12 15:59:39 +02:00
Beniamino Galvani
92a426be17 settings: factor out monitor initialization from nm_settings_new() 2015-06-12 15:59:39 +02:00
Beniamino Galvani
d385a2a57a settings: remove hostname handling from plugins
Remove all hostname-related code from plugins since this functionality
has been moved to the core.
2015-06-12 15:59:39 +02:00
Beniamino Galvani
6c3d71c431 core: move handling of hostname from plugins to core
How to write and read the machine hostname is something that has been
handled until now by plugins; this is questionable since the method
using for storing the hostname should depend only on the distro used
and not on which plugins are enabled.

This commit moves all hostname-related functions from plugins to the
core and allows to specify the method used to load and store the
hostname at build time with the

  --with-hostname-persist=default|suse|gentoo

configure option.

'default' method stores the hostname to /etc/hostname and monitors it
to detect runtime changes.

When the selected method is 'suse', the hostname gets read from and
written to /etc/HOSTNAME; the file /etc/sysconfig/network/dhcp is also
read to detect if the hostname is dynamic and thus invalid. Both files
are monitored for changes.

'gentoo' method relies on /etc/conf.d/hostname for storing the
hostname.
2015-06-12 15:59:39 +02:00
Beniamino Galvani
fb304bc6b9 build: link core against SELinux
Some functions that rely on SELinux support are going to be moved from
plugins to core. Enable linking against the library.
2015-06-12 15:59:39 +02:00
Thomas Haller
ef4e017cfa libnm/utils: add _nm_utils_strv_find_first() function 2015-06-11 19:58:51 +02:00
Thomas Haller
176b13374a gitignore: ignore temporary files during build
If you type `git status` a certain times during build,
you see some temporary (untracked) files. Ignore them.
2015-06-11 13:45:37 +02:00
Jiří Klimeš
631f5b1e5c cli: use color names when TAB-completing "nmcli prompt-color" 2015-06-11 10:01:47 +02:00
Jiří Klimeš
3641ddb00a cli: take color name arguments for "nmcli prompt-color" in editor (bgo #744936)
Adjust nmcli prompt-color description and make it more friendly for
translators.

nmcli> nmcli prompt-color green

https://bugzilla.gnome.org/show_bug.cgi?id=744936
2015-06-11 10:00:54 +02:00
Thomas Haller
5eba53cd53 cli: fix metered to string property
nmc_property_connection_get_metered() must return non-localized strings
that can be parsed by nmc_property_connection_set_metered().

Fixes: f0aebfd746
2015-06-10 11:49:46 +02:00
Jiří Klimeš
94a393e9ed all: fix a compiler warning about function declarations
warning: function declaration isn’t a prototype [-Wstrict-prototypes]

In C function() and function(void) are two different prototypes (as opposed to
C++).
function()     accepts an arbitrary number of arguments
function(void) accepts zero arguments
2015-06-10 10:01:49 +02:00
Jiří Klimeš
036901b82e xml: (trivial) fix a typo 2015-06-10 09:34:58 +02:00
Beniamino Galvani
7d09debdf0 merge branch 'bg/metered-connections-bgo741725'
Expose information about whether a connection is metered and use some
heuristics to choose a reasonable default when the value is not
configured.

https://bugzilla.gnome.org/show_bug.cgi?id=741725
https://bugzilla.redhat.com/show_bug.cgi?id=1200452
2015-06-09 22:15:26 +02:00
Beniamino Galvani
04d5804dd5 nm-manager: add 'metered' property
This introduces a global metered property which makes easier for
clients to obtain the metered status of the current primary
connection.
2015-06-09 18:23:19 +02:00
Beniamino Galvani
bd4e1f37f8 cli: fix error message localization
Valid values must not be translated in error messages generated in
nmc_string_to_bool() and nmc_string_to_tristate().
2015-06-09 18:23:12 +02:00
Beniamino Galvani
7e5e624daf ifcfg-rh: add support for CONNECTION_METERED 2015-06-09 18:18:45 +02:00
Beniamino Galvani
862fd91df0 ifcfg-rh: change type of svTrueValue() return value and argument
Change type of return value and 'def' argument of svTrueValue() to
gint to make clear that it can be something different from TRUE and
FALSE.
2015-06-09 18:18:45 +02:00
Beniamino Galvani
a86255a043 core: update device 'metered' property on connection state change
The metered property of a NMDevice that reaches the activated state is
copied from the active connection and if its value is 'unknown' some
heuristics are used to guess the actual value.

When the connection is torn down the metered property is reset to
'unknown'.
2015-06-09 18:18:45 +02:00
Beniamino Galvani
1e39b2320d dhcp: detect NMIP4Config 'metered' flag based on ANDROID_METERED DHCP option
Some versions of Android's DHCP server send option 43 (Vendor specific
information) with value "ANDROID_METERED" in Wi-Fi hotspot mode.

Mark the NMIP4Config as metered when such option is received.
2015-06-09 18:18:45 +02:00
Beniamino Galvani
3c2f4a17f9 systemd/dhcp: add support for vendor specific DHCP option
This adds support for DHCP option 43 (Vendor Specific Information) to
the internal DHCP client. The option carries an opaque object of n
octets, interpreted by vendor-specific code on the clients and
servers.
2015-06-09 18:18:45 +02:00
Beniamino Galvani
68db65b727 core: add 'metered' flag to NMIP4Config
Some DHCP servers send specific options to give a hint that clients
should avoid unneeded data usage.

Add a metered flag to NMIP4Config to keep track of this information.
2015-06-09 18:18:45 +02:00
Beniamino Galvani
f0aebfd746 cli: add support for 'metered' connection property 2015-06-09 18:15:20 +02:00
Beniamino Galvani
609f4f37c0 cli: add nmc_string_to_tristate() 2015-06-09 18:11:25 +02:00
Beniamino Galvani
6f647fe689 libnm-core: add 'metered' property to NMSettingConnection
Add a 'metered' enum property to NMSettingConnection with possible
values: unknown,yes,no. The value indicates the presence of limitations
in the amount of traffic flowing through the connection.
2015-06-09 18:11:25 +02:00
Beniamino Galvani
f208e7030f cli: add 'metered' property to device 2015-06-09 18:11:25 +02:00
Beniamino Galvani
bbbf522941 core,libnm: add 'metered' property to NMDevice 2015-06-09 18:11:25 +02:00