Commit Graph

133 Commits

Author SHA1 Message Date
Thomas Haller
7dc65df020 core: add @max_wait_msec argument to nm_utils_kill_process_sync() 2015-06-30 14:19:30 +02:00
Thomas Haller
69c98a336e core: fix nm_utils_kill_process_sync() not to hang for a zombie process
kill(pid,sig) can return success for zombie processes. This
caused nm_utils_kill_process_sync() to hang indefinitely.

Fix it by also checking the process state.
2015-06-30 14:19:15 +02:00
Thomas Haller
39f2b51abb core: add option to suppress error logging if nm_utils_modprobe() fails
We don't want error logging for nm_platform_link_add() which
tries to load the bonding module. Later we will run tests as non-root,
where modprobe will fail. Logging an error would break the tests.
2015-06-05 16:52:49 +02:00
Thomas Haller
3fb60edf9f device: add device-spec "type:"
Support a device-spec to match by device-type.
This matches on the value as shown by

  nmcli -f GENERAL.TYPE device show
2015-06-05 12:38:29 +02:00
Thomas Haller
dce00f0d10 utils: move NM_FLAGS_*() macros to header file "include/nm-utils-internal.h" 2015-05-29 16:28:33 +02:00
Thomas Haller
d4dd9ba3cf keyfile: readd owner check of files (bgo #701112)
Commit 5dc4be54e6 dropped the
owner check for keyfiles to allow running `make check` as root.
Re-add it, but disable the check for tests.

https://bugzilla.gnome.org/show_bug.cgi?id=701112
2015-05-19 09:57:46 +02:00
Thomas Haller
b9d8dc050a core/tests: add nm_utils_get_testing() function
Code that is testable often needs special hooks to work
both for unit-tests and production.

Add a function nm_utils_get_testing() that returns whether
the code is run as part of a unit-test.

For non-testing mode, nm_utils_get_testing() will return
zero (NM_UTILS_TEST_NONE). For unit tests, the test should call
_nm_utils_set_testing() to configure tested functions.
By specifing the @flags attribute, the test can enable/disable
specific behaviors.

https://bugzilla.gnome.org/show_bug.cgi?id=701112
2015-05-19 09:57:46 +02:00
Beniamino Galvani
a1d76a019e core: capture DNS options from resolv.conf 2015-05-13 17:15:35 +02:00
Thomas Haller
63bb33b534 core: remove G_GNUC_WARN_UNUSED_RESULT from ASSERT_VALID_PATH_COMPONENT()
ASSERT_VALID_PATH_COMPONENT() always returns the input argument --
unless it fails an assertion and terminates the program. No need
to require the user to use the return value.
2015-05-01 14:25:58 -05:00
Thomas Haller
967376b840 core: add nm_utils_monotonic_timestamp_as_boottime() function 2015-04-29 07:32:42 +02:00
Thomas Haller
e65639bde9 util: add nm_utils_array_remove_at_indexes() function 2015-04-08 14:39:17 +02:00
Dan Winship
8da83a2ba3 core: port the daemon side of the dispatcher to gdbus 2015-04-03 16:58:40 -04:00
Dan Williams
06f25a3ec7 dns: ensure that update_dns() always returns a GError on failure
Callers may expect this, so make sure we do it.
2015-03-27 16:19:13 -05:00
Dan Williams
99a6201264 core: use dev_id when calculating the interface IPv6 IID (rh #1101809)
Some device types (s390 OSA and ipvlan) can use the same link-layer address
for multiple virtual interfaces, and the kernel used the dev_id property
to differentiate these devices when constructing the IID.  NM should do
this too to prevent IID clashes.

https://bugzilla.redhat.com/show_bug.cgi?id=1101809
2015-03-27 15:11:34 -05:00
Thomas Haller
e82293ebf6 libnm: move _nm_utils_uuid_generate_from_strings() from src/ to libnm-core/ 2015-03-12 18:12:26 +01:00
Thomas Haller
67510e323a trivial: rename nm_utils_uuid_generate_from_strings() to _nm_utils_uuid_generate_from_strings() 2015-03-12 18:12:26 +01:00
Thomas Haller
c5d23737fd libnm: move _nm_utils_ascii_str_to_int64() from src/ to libnm-core/ 2015-03-12 18:12:26 +01:00
Thomas Haller
093f6d477b trivial: rename nm_utils_ascii_str_to_int64() to _nm_utils_ascii_str_to_int64() 2015-03-12 18:12:26 +01:00
Dan Williams
231b0390a5 vpn: convert NMVpnConnection <-> VPN service communication to GDBus (bgo #745307)
Of special note is the new D-Bus rule to allow root to talk to
org.freedesktop.NetworkManager.VPN.Plugin, without which NetworkManager
would not hear signals from the VPN plugins.  Oddly, this worked
fine with dbus-glib...

https://bugzilla.gnome.org/show_bug.cgi?id=745307
2015-03-03 15:04:46 -06:00
Thomas Haller
3bcc5e4bd0 core: add nm_match_spec_split() function
There are currently three device spec properties: 'main.ignore-carrier',
'main.no-auto-default' and 'keyfile.unmanaged-devices'.

The first two, called g_key_file_parse_value_as_string() to split
the string into individual device specs. This uses ',' as separator
and supports escaping using '\\'.

'keyfile.unmanaged-devices' is split using ',' or ';' as separator
without supporting escaping.

Add a new function nm_match_spec_split(), to unify these two behaviors
and support both formats. That is, both previous formats are mostly
supported, but obviously there are some behavioral changes if the string
contains one of '\\', ',', or ';'.

nm_match_spec_split() is copied from glibs g_key_file_parse_value_as_string()
and adjusted.
2015-02-24 10:35:24 +01:00
Thomas Haller
5c2e1afd1b core: support "except:" spec to negate match
Extend nm_match_spec_*() to support an "except:" prefix to negate
the result of a match. "except:" only works when followed by
an exact match type, for example "except:interface-name:vboxnet0",
but not "except:vboxnet0".

A matching "except:" spec always wins, regardless of other positive
matchings.
2015-02-24 10:35:24 +01:00
Thomas Haller
2051944333 core: remove nm_match_spec_string()
It was only used to match against "*", in a case-insensitive
way.
2015-02-24 10:35:24 +01:00
Lubomir Rintel
0d59984ce8 core: Add NMUtilsIPv6IfaceId to nm-types.h
We'd like to use it in nm-platform.h, but it's included by
NetworkManagerUtils.h before the declaration occurs.
2015-01-26 13:05:06 +01:00
Thomas Haller
4ad6099b01 utils: add nm_utils_modprobe()
https://bugzilla.gnome.org/show_bug.cgi?id=740651
2015-01-19 12:07:27 -06:00
Dan Winship
fb792af7cb core: add nm_utils_setpgid(), and use it
Add nm_utils_setpgid() as a g_spawn*() child setup function for
calling setpgid(), and use it where appropriate rather than
reimplementing it every time.
2015-01-19 11:29:13 -05:00
Thomas Haller
422fbf48b9 all: move STRLEN() macro to global header nm-utils-internal.h
https://bugzilla.gnome.org/show_bug.cgi?id=741651
2014-12-18 17:36:57 +01:00
Thomas Haller
9a08d8602c core: add nm_utils_uuid_generate_from_strings()
Add function to create variant3 UUIDs based on a set
of concatenated strings.
2014-12-04 17:02:22 +01:00
Thomas Haller
ae2b8d6353 core: rename NM_PLATFORM_ROUTE_METRIC_DEFAULT to NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP6
For IPv4, iproute for example defaults to a metric of 0.
Hence, the name NM_PLATFORM_ROUTE_METRIC_DEFAULT was misleading.

Also add a NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP4 define for completeness.

https://bugzilla.gnome.org/show_bug.cgi?id=740780
2014-12-01 16:38:05 +01:00
Dan Williams
7df18cba5b core: add nm_utils_ip4_property_path() 2014-11-07 12:18:33 -06:00
Thomas Haller
c52e331014 core: move definition of NMLinkType to nm-types.h
As we use NMLinkType in NetworkManagerUtils.h, we cannot use
the utils header without nm-platform.h. That is clearly wrong.
Apparently NMLinkType has a wider use outside of platform (and
its name is not prefixed with 'platform' either).

Move the enum definition to nm-types.h.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:19:05 +01:00
Thomas Haller
f892ac4f45 core/trivial: remove semicolon from macro
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:19:05 +01:00
Thomas Haller
ff145486d1 core: add nm_ipX_config_get_direct_route_for_host() functions
add two functions nm_ip4_config_get_direct_route_for_host()
and nm_ip6_config_get_direct_route_for_host() to check if we have
a direct (non-gw) route to a certain host.

Signed-off-by: Thomas Haller <thaller@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=738590
2014-10-31 18:35:31 +01:00
Thomas Haller
22911696f4 core: add nm_utils_ip6_route_metric_normalize() function
Kernel treats IPv6 route metrics with value zero (0) special.
Add a utility function that helps accounting for that.

Signed-off-by: Thomas Haller <thaller@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=738590
2014-10-31 18:31:19 +01:00
Thomas Haller
41e0d5b9ce core: add nm_utils_log_connection_diff
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-12 21:17:17 +02:00
Thomas Haller
f87e876f79 core: prefer connections with higher priority for autoconnect
https://bugzilla.gnome.org/show_bug.cgi?id=580018

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-12 20:13:18 +02:00
Thomas Haller
efd8be04f1 core: add nm_utils_kill_process_sync() function
This utility function is for killing other processes.
Contrary to nm_utils_kill_child_*() which is for killing
and reaping child processes.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-10 12:28:59 +02:00
Thomas Haller
99c5edbacd core: add nm_utils_get_start_time_for_pid() function
Move the code from nm-auth-subject.c over to NetworkManagerUtils.c

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-10 11:51:40 +02:00
Thomas Haller
bda076bb3c core: add macros NM_FLAGS_HAS(), NM_FLAGS_ANY() and NM_FLAGS_ALL()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-24 16:12:45 +02:00
Dan Winship
6793a32a8c libnm: port to GDBus
Port libnm-core/libnm to GDBus.

The NetworkManager daemon continues to use dbus-glib; the
previously-added connection hash/variant conversion methods are now
moved to NetworkManagerUtils (along with a few other utilities that
are now only needed by the daemon code).
2014-09-18 11:51:09 -04:00
Dan Williams
544fc82aa7 core: consolidate helper progam searching (bgo #734131)
Instead of having basically the same code in a bunch of different
place to find helper programs, just have one place do it.  Yes, this
does mean that the same sequence of paths is searched for all helpers
(so for example, dnsmasq will no longer be found first in /usr/local)
but I think consistency is the better option here.

https://bugzilla.gnome.org/show_bug.cgi?id=734131
2014-09-11 12:11:56 -05:00
Jiří Klimeš
5d982b3810 utils: use gssize (signed) 'len' parameter in nm_ethernet_address_is_valid()
Fix copyright statement too.
2014-09-05 11:11:01 +02:00
Dan Winship
3a54d05098 libnm-core: change all mac-address properties to G_TYPE_STRING
Make all mac-address properties (including NMSettingBluetooth:bdaddr,
NMSettingOlpcMesh:dhcp-anycast-addr, and NMSettingWireless:bssid) be
strings, using _nm_setting_class_transform_property() to handle
translating to/from binary form when dealing with D-Bus.

Update everything accordingly for the change, and also add a test for
transformed setting properties to test-general.
2014-09-04 09:20:10 -04:00
Dan Winship
7d233cc956 core: abstract out the duplicated default-ifname-generating code
NMDeviceBond, NMDeviceBridge, and NMDeviceTeam all used basically the
same code to generate a default interface name. Move it into
nm_utils_complete_generic().
2014-09-04 09:18:44 -04:00
Thomas Haller
ed20177d27 core: refactor nm_utils_complete_generic() not to use a dynamic format string
For NMDeviceWifi and NMDeviceWimax, the printf format string for
nm_utils_complete_generic() was created based on ssid/nsp. Since
these input strings are untrusted, this is a serious bug.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-25 16:46:14 +02:00
Dan Winship
c81fb49aa5 all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).

Fix this by changing the include guards in the non-API-stable parts of
the tree:

  - libnm-glib/nm-ip4-config.h remains   NM_IP4_CONFIG_H
  - libnm/nm-ip4-config.h now uses     __NM_IP4_CONFIG_H__
  - src/nm-ip4-config.h now uses       __NETWORKMANAGER_IP4_CONFIG_H__

And likewise for all other headers.

The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-16 10:17:14 -04:00
Dan Winship
357efd26e4 libnm-core: include ETH_ALEN/INFINIBAND_ALEN defines in nm-utils.h
Include <linux/if_ether.h> and <linux/if_infiniband.h> from
nm-utils.h, to get ETH_ALEN and INFINIBAND_ALEN, and remove those
includes (as well as <net/ethernet.h> and <netinet/ether.h>, and
various headers that had been included to get the ARPHRD_* constants)
from other files where they're not needed now.
2014-08-07 14:04:14 -04:00
Dan Winship
ea456aaa81 all: remove use of struct ether_addr / ether_aton()
Lots of old code used struct ether_addr to store hardware addresses,
and ether_aton() to parse them, but more recent code generally uses
guint8 arrays, and the nm_utils_hwaddr_* methods, to be able to share
code between ETH_ALEN and INFINIBAND_ALEN cases. So update the old
code to match the new. (In many places, this ends up getting rid of
casts between struct ether_addr and guint8* anyway.)

(Also, in some places, variables were switched from struct ether_addr
to guint8[] a while back, but some code still used "&" when referring
to them even though that's unnecessary now. Clean that up.)
2014-08-07 12:11:49 -04:00
Dan Williams
e2270040c0 core: use Interface Identifiers for IPv6 SLAAC addresses
Ethernet-like interfaces aren't the only type of interfaces that can
run IPv6 but the rdisc code only returns an address if the interface's
hardware address is 6 bytes.

Interface types like PPP (rfc5072) and IPoIB (rfc4391) have their own
specifications for constructing IPv6 addresses and we should honor
those.

So instead of expecting a MAC address, let each device subclass
generate an Interface Identifier and use that for rdisc instead.
2014-07-23 12:53:55 -05:00
Dan Winship
b28f6526c2 core: fill in nm-types.h, clean out other headers
Clean up some of the cross-includes between headers (which made it so
that, eg, if you included NetworkManagerUtils.h in a test program, you
would need to build the test with -I$(top_srcdir)/src/platform, and if
you included nm-device.h you'd need $(POLKIT_CFLAGS)) by moving all
GObject struct definitions for src/ and src/settings/ into nm-types.h
(which already existed to solve the NMDevice/NMActRequest circular
references).

Update various .c files to explicitly include the headers they used to
get implicitly, and remove some now-unnecessary -I options from
Makefiles.
2014-07-23 10:56:26 -04:00
Jiří Klimeš
70e930bc0e utils: add nm_utils_is_specific_hostname()
The function detects whether the hostname is a specific hostname diferrent
from default hostnames like localhost, localhost[6].localdomain[6].
2014-07-14 17:36:07 +02:00