Commit graph

18528 commits

Author SHA1 Message Date
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
29e9b567f0 keyfile: cleanup error argument for read_field()
Rename @error to @out_err_str, because @error is usually used for GError
output arguments.

Also, make the string variables "const char *".

Use nm_assert() in read_field(), because it is a static function
with only four call sites. It's easily verified that the assertion
holds, so no need for a run-time check in production builds.
2017-10-04 11:34:51 +02:00
Thomas Haller
72c28cb6bc keyfile: minor cleanup in get_one_int() to use _nm_utils_ascii_str_to_int64() 2017-10-04 11:34:51 +02:00
Thomas Haller
102a58bb62 contrib/scripts: fix coloring for platform messages in NM-log for old logs
Older logfiles contain

  platform: route: adding or updating IPv4 route: 10.1.0

Hightlight that too.
2017-10-03 15:35:56 +02:00
Beniamino Galvani
b799de281b libnm: update property in the manager after connectivity check
Currently, after a client performs a connectivity check it cannot
access the up-to-date value of the manager.connectivity property right
away, but it must wait that the queued PropertiesChanged signal is
processed, which is cumbersome.

Arguably, clients already receive the new connectivity value as the
result of the connectivity check call, so they don't have to read it
from the object; however it would be better if the right value of the
object property was available immediately as well.

https://bugzilla.gnome.org/show_bug.cgi?id=784629
2017-10-03 11:55:18 +02:00
Thomas Haller
91be4c8c3d core: cleanup handling addr_family in NMDevice
- use nm_utils_addr_family_to_char(). It asserts that the input argument
  is either AF_INET or AF_INET6.
- rename variable @family to @addr_family for consistency.
- when logging addr_family for activation-stage, use v4 or v6 instead
  of numeric AF_INET/AF_INET6.
2017-10-02 13:56:00 +02:00
Thomas Haller
c17e0f7197 shared: add nm_utils_addr_family_to_char() 2017-10-02 13:50:56 +02:00
Thomas Haller
855cb39533 core: minor cleanup in dhcp_schedule_restart()
Move creating the logging output inside the logging macro, so it is
evaluated lazyly. Also, use a stack-allocated buffer.

Drop the redundant @inet4 variable.
2017-10-02 13:15:43 +02:00
Thomas Haller
6babaef755 core: merge branch 'th/manager-cleanup' 2017-09-29 17:36:42 +02:00
Thomas Haller
9ad8010fe0 device: fix delay startup complete for unrealized devices
Since commit 6845b9b80a ("device: delay
startup complete until device is initialized in platform", we also wait
for devices that are still initializing platform/UDEV.

Obviously, that only applies to realized devices.

Otherwise, an unrealized device is going to block startup complete.

Fixes: 6845b9b80a
2017-09-29 17:36:05 +02:00
Thomas Haller
ba8f81581e core: keep platform link object alive and don't copy it
Sometimes, when we have a platform object, we need to keep it
alive, because any subsequent platform operation might invalidate
the object.

Previously, we achieved that by copying the NMPlatformLink data.

For a while now, all platform object are immuable and recounted.
We should not copy the instance to a NMPlatformLink object, because
then the instance is no longer a full NMPObject. Instead, just take an
additional reference. Since the object must be immutable, that is
just as safe. But now callees down the stack get a proper NMPObject
instance, and might reference it too.
2017-09-29 17:04:20 +02:00
Thomas Haller
4db253b059 manager: refactor lifetime handling for idle callback _platform_link_cb_idle()
We call _platform_link_cb_idle() on idle, so we must take care of the lifetime
of NMManager.

We don't want to take a reference, so that the manager is not kept alive
by platform events.

Refactor the previous implementation with weak pointers to use a linked list
instead. Let's not have any pending idle actions after the manager instance
is destroyed. Instead, properly track and cancel the events.
2017-09-29 16:40:10 +02:00
Thomas Haller
3b3c5843cd manager: disconnect platform_link_cb() from NMManager in dispose() 2017-09-29 16:40:10 +02:00
Thomas Haller
cfe3d8bdd0 manager/trivial: rename self variable in NMManager:dispose() 2017-09-29 16:40:10 +02:00
Thomas Haller
81bb7c9138 manager: don't use platform singleton but keep a private pointer
We should reduce uses of singletons in general. Instead, the platform
instance should be passed around and kept for as long as it's needed.

Especially, as we subscribe platform_link_cb() signal. Currently, we
never unsubscribe it (wrongly). Subscribing signals is a strong
indication that the target object should keep the source object alive
until the signal is unsubscribed.
2017-09-29 16:40:10 +02:00
Beniamino Galvani
1ed9e68af0 core: merge branch 'bg/autoconnect-blocked-rh1310676'
https://bugzilla.redhat.com/show_bug.cgi?id=1310676
2017-09-29 15:37:35 +02:00
Beniamino Galvani
937ee1de82 core: rename NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_UNBLOCKED enum
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE sounds better.
2017-09-29 15:34:55 +02:00
Beniamino Galvani
32efb87d4d core: unblock failed connections when the master is available
In case the connection is blocked because it failed, the availability
of a master is a good reason to unblock it so that it can be tried
again.

Fixes: a1ea422aad
2017-09-29 15:32:19 +02:00
Beniamino Galvani
b80ee4a72c core: make auto-connect-blocked-reason more specific
Distinguish between connections blocked from autoconnecting by user
request and connections blocked because they failed (and would fail
again).

Later, the reason will be used to unblock failed connection when some
conditions change.
2017-09-29 15:32:16 +02:00
Thomas Haller
46dc919e68 man: clearify plain text secrets in keyfile 2017-09-28 17:56:49 +02:00
Thomas Haller
a47c48fd84 core: merge branch 'th/device-manage-conf'
https://github.com/NetworkManager/NetworkManager/pull/29
2017-09-28 14:45:17 +02:00
Thomas Haller
5778bc6a34 device: add configuration option to mark devices as unmanaged
We already have various ways to mark a device as unmanaged.

1) via udev-rule ENV{NM_UNMANAGED}. This can be overwritten via D-Bus
  at runtime.

2) via settings plugin. That is NM_CONTROLLED=no for ifcfg-rh and
  keyfile.unmanaged-devices in NetworkManager.conf.

3) at runtime, via D-Bus. This is persisted in the run state file
  and persists restarts (but not reboot).

This adds another way via NetworkManager.conf file. Note that the
existing keyfile.unmanaged-devices (above 2) is also a configuration
optin in NetworkManager.conf. However it has various downsides:

  - it cannot be overwritten at runtime (see commit
    c210134bd5).

  - you can only explicitly mark a device as unmanaged. That means,
    you cannot use it to manage a device which is unmanaged due to
    a udev rule.

  - the name "keyfile.*" sounds like it's only relevant for the keyfile settings
    plugin. Nowadays the keyfile plugin is always loaded, so the option applies
    to NetworkManager in general.

https://github.com/NetworkManager/NetworkManager/pull/29
2017-09-28 14:44:46 +02:00
Thomas Haller
286f21db1c man: fix example for device section in NetworkManager.conf's manual
We currently don't support marking a device a managed/unmanaged via
the [device] section. Eventually, I think we should, because the
existing "keyfile.unmanaged-devices" looks keyfile specific (which
it isn't). But more importantly, "keyfile.unmanaged-devices" sets the
unmanaged flag NM_UNMANAGED_USER_SETTINGS, which cannot be overruled
via D-Bus (see commit c210134bd5).
A device.managed flag would make sense for a more sensible way to
express configuration in NetworkManager.conf, which still can be
overwritten via D-Bus.

Anyway, it's not yet implemented. Fix the example.
2017-09-28 14:40:17 +02:00
Beniamino Galvani
c9edd222c5 core: merge branch 'bg/parent-uuid'
https://mail.gnome.org/archives/networkmanager-list/2017-September/msg00032.html
2017-09-28 13:27:28 +02:00
Beniamino Galvani
6a5363bc8b device: match all UUIDs when no connection is active
nm_device_match_parent() is called to check whether a device is
compatible with a given parent (UUID or interface). Accept any UUID If
there is no connection active on the device.

Without this, when there is a VLAN/MACVLAN connection with a parent
UUID the manager would create the device in
system_create_virtual_device(), realize it and then at the next call
of system_create_virtual_device() it would notice that the connection
is not compatible with the device because of the parent UUID;
therefore the manager would try to create again the same device,
failing.

https://mail.gnome.org/archives/networkmanager-list/2017-September/msg00034.html
2017-09-28 10:54:01 +02:00
Beniamino Galvani
d2e4a2f639 device: deduplicate match_hwaddr() 2017-09-28 10:54:01 +02:00
Beniamino Galvani
27c281ac5a device: deduplicate match_parent() 2017-09-28 10:54:01 +02:00
Beniamino Galvani
ed640f857a manager: ignore unmanaged devices when looking for parent by UUID
If the device is unmanaged, it is not compatible with any connection.

https://mail.gnome.org/archives/networkmanager-list/2017-September/msg00032.html
2017-09-28 10:54:01 +02:00
Thomas Haller
8a5ebd3cb7 libnl: merge branch 'th/libnm-ip-route-equals'
https://github.com/NetworkManager/NetworkManager/pull/30
2017-09-27 18:59:02 +02:00
Thomas Haller
f83e6b9743 libnm: add nm_ip_route_equal_full() function
Expose previously internal function nm_ip_route_equal_full(). It's
just useful API.

However, add a @cmp_flags argument, so that in the future we could
extend it.
2017-09-27 18:58:53 +02:00
Thomas Haller
f05ebc4261 libnm: don't skip routes in nm_setting_ip_config_add_route() that only differ by attributes
For kernel and NetworkManager's core, route identity is a complicated topic
(see NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID). For example, a route
without explity table is treated identical to "table 254" or "table 0".

It would be complicated to have nm_setting_ip_config_add_route()
implement that logic, especially since libnm offers not public API
to expose kernel's logic.

However, previously nm_setting_ip_config_add_route() would only consider
dest/prefix,next_hop,metric when comparing for equality. Hence, with

  nmcli connection modify "$CON" +ipv4.routes '192.168.5.0/24'
  nmcli connection modify "$CON" +ipv4.routes '192.168.5.0/24 table=42'

the second route was not actually added, although it is a very different
route. Fix that, and consider attributes too. Note that this allows the user
to add two routes that look different to libnm, but are actually idential:

  nmcli connection modify "$CON" +ipv4.routes '192.168.5.0/24'
  nmcli connection modify "$CON" +ipv4.routes '192.168.5.0/24 table=254'

In the above example, the route instances look different, but
sementically they are both the same route in the main table (254).

This also allows the user to add routes that are semantically different, but
are treated as the same route by kernel:

  nmcli connection modify "$CON" +ipv6.routes 'a🅱️c::/120'
  nmcli connection modify "$CON" +ipv6.routes 'a🅱️c::/120 mtu=600'

I think libnm should allow to add routes as long as they look different
to libnm. Regardless how kernel and NetworkManager-core thinks about
route identity.

This changes API of nm_setting_ip_config_add_route(). However, I think
the previous behavior was just broken.

Same for nm_setting_ip_config_remove_route_by_value().
2017-09-27 18:58:53 +02:00
Thomas Haller
d06c46b80f libnm: make index variable i unsigned for iterating array
GArray's and GPtrArray's plen argument is unsigned. The index variable
to iterate the list, should not have a smaller range (or different data type).

Also, assert against negative idx argument.
2017-09-27 18:58:53 +02:00
Thomas Haller
513d0c2286 contrib/rpm: enable "NetworkManager-wait-online.service" on package upgrade
Since commit d61eaf2545 ("service: don't
install dependency for "NetworkManager-wait-online.service" to
"network-online.target.wants") we no longer install NM-w-o.service
in "network-online.target.wants" directory.

Obviously, for previous RPM versions NM-w-o.service was always enabled.
For current versions, it depends now on the preset. Most importantly,
this allows the user to disable the service, without masking it.
Previously NM-w-o.service was always implicitly enabled.

But presets are not applied during package upgrade, so it means that
after upgrade the service will be disabled. Hack around that via an RPM
scriptlet.

https://bugzilla.redhat.com/show_bug.cgi?id=1455704
2017-09-27 18:02:51 +02:00
Beniamino Galvani
e25de114b2 nm-policy: use nm_g_hash_table_add() instead of g_hash_table_add()
The return value of g_hash_table_add() was added in GLib 2.40, use the
wrapper to avoid compile error on older versions:

 src/nm-policy.c: In function ‘auto_activate_device’:
 src/nm-policy.c:1279:7: error: void value not ignored as it ought to be

Fixes: a1ea422aad
2017-09-27 14:17:11 +02:00
Beniamino Galvani
a1ea422aad policy: watch active-connection state to detect autoconnect early failures
When a connection is autoactivated NMPolicy only detects a failure by
watching the device state, or when the activation fails immediately.

If the activation fails after the asynchronus authorization check
before the device enters the PREPARE state, no other connection is
tried.

Let NMPolicy watch the active-connection state to detect early
failures and disconnect the signal handler when we detect that the
device state is progressing.

https://bugzilla.redhat.com/show_bug.cgi?id=1310676
2017-09-27 13:45:07 +02:00
Thomas Haller
e6292bcb2a core: merge branch 'th/policy-routing-pt1-rh1436531'
Add initial support for policy-routing/source-routing.
It does not support rules (yet), only configuring routes
in a different routing table then 254 (main). And this
currently only works for manually configured routes,
not routes from DHCP or the default-route.

https://bugzilla.redhat.com/show_bug.cgi?id=1436531
2017-09-26 19:49:53 +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
Thomas Haller
a22b017830 cli: show additional route attributes in IP4_CONFIG output 2017-09-26 19:36:51 +02:00
Thomas Haller
ccb83e34a3 cli: refactor printing IP6 device info 2017-09-26 19:36:51 +02:00
Thomas Haller
6aed608011 libnm-core: sort attribute names for nm_ip_route_get_attribute_names()
The function shall return the attribute names in a consistent order.
Let's sort by name.
2017-09-26 19:36:51 +02:00
Thomas Haller
7cd04ce014 core: inject route list to delete for nm_platform_ip_route_sync()
Whenever we call a platform operation that reads or writes the netlink
socket, there is the possibility that the cache gets updated, as we
receive netlink events.

It is thus racy, if nm_platform_ip_route_sync() *first* adds routes, and
then obtains a list of routes to delete. The correct approach is to
determine which routes to delete first (and keep it in a list
@routes_prune), and pass that list down to nm_platform_ip_route_sync().

Arguably, this doesn't yet solve every race. For example, NMDevice
calls update_ext_ip_config() during ip4_config_merge_and_apply().
That is good, as it resyncs with platform. However, before calling
nm_ip4_config_commit() it calls other platform operations, like
_commit_mtu(). So, the race is still there.
2017-09-26 19:36:51 +02:00
Thomas Haller
0fce60c767 device: do full update_ext_ip_config() during merge-and-apply
Since commit a21b8882cc ("device: update
external configuration before commit"), we correctly re-sync the
external IP configuration before a merge, in case we notice that
there were some changes in platform.

Go a step further, and do the full update_ext_ip_config(). We should
have one way how to capture the external config, including intersect
and subtract. Otherwise, we end up with an @ext_ip4_config, which is
different from how it looks usually.
2017-09-26 19:36:51 +02:00
Thomas Haller
8207bfd5d6 device: refactor update-ip-config for device
Refactor the code. There should be no changes in behavior at all.

The point is, to be able to reuse update_ext_ip_config() in the
next commit.

And also, I think it's an antipattern to have mirroring functions like
ip4_xyz() and ip6_xyz(). Instead, there should be one function, with
extra addr_family argument. That way, it'much clearer where two
implementations differ and where they are identical.
Basically, it moves the differentiation per the address family down
the call stack, closer to the place where the behavior is actually
different.
2017-09-26 19:35:32 +02:00
Thomas Haller
f7616eee1e shared: move nm_dedup_multi_obj_ref() to header as inline
nm_dedup_multi_obj_ref() is a trivial function, that only uses the field
which is already declared in the same header file. Move it to the header
so that it can be inlined (without LTO).
2017-09-26 19:31:17 +02:00
Thomas Haller
9acf80a979 platform: handle route table RT_TABLE_UNSPEC specially
Kernel does not allow to add a route with table 0 (RT_TABLE_UNSPEC). It
effectively is an alias for the main table. We must consider that when
comparing routes sementically.
2017-09-26 19:31:17 +02:00
Thomas Haller
4ca2e1b10c cli: merge branch 'th/cli-interactive-mode-crash-bgo788104'
https://bugzilla.gnome.org/show_bug.cgi?id=788104
2017-09-26 15:14:57 +02:00
Thomas Haller
889ecc98a1 cli: use cleanup attribute in editor_menu_main() 2017-09-26 15:11:58 +02:00
Thomas Haller
54490be96d cli: fix crash in interactive mode for "describe ."
https://bugzilla.gnome.org/show_bug.cgi?id=788104
2017-09-26 15:11:58 +02:00
Beniamino Galvani
7070d17ced device: reset @con_ip6_config on failure before RA
If the commit of static connection parameters fails before starting
RA, we should reset @con_ip6_config; otherwise any external update
arriving before the commit of RA parameters will remove from
@con_ip6_config all parameters not present externally, because in
update_ip6_config() we do:

  /* This function was called upon external changes. Remove the configuration
   * (addresses,routes) that is no longer present externally from the internal
   * config. This way, we don't re-add addresses that were manually removed
   * by the user. */
  if (priv->con_ip6_config)
      nm_ip6_config_intersect (priv->con_ip6_config, priv->ext_ip6_config);

Instead if @con_ip6_config is cleared it will be rebuilt from the
connection setting at the next commit.

Fixes-test: @ipv6_preserve_cached_routes
2017-09-26 08:53:56 +02:00