Commit Graph

7207 Commits

Author SHA1 Message Date
Dan Williams
9337a13a87 core: fix attaching managed slaves to master devices (rh #1141266)
Broken by 25387cd1ff

When an activation request comes in via D-Bus for a slave, the
slave device's priv->master is set in stage1 in master_ready_cb().
Then nm_device_bring_up() is called on the slave, which triggers
link_changed_cb() and device_link_changed().  That then executes
this code:

if (priv->master)
	nm_device_enslave_slave (priv->master, self, NULL);

which enslaves the slave, but due to the NULL will not configure
the slave.

This code was only meant to be run for externally triggered
master/slave changes.
2014-12-11 17:56:04 -06:00
Dan Williams
7d5c0db53a core: fix warning when releasing slaves on exit (rh #1169936)
NetworkManager[30304]: <info>  (virbr0): bridge port virbr0-nic was detached
NetworkManager[30304]: (devices/nm-device.c:962):nm_device_release_one_slave: runtime check failed: (reason == NM_DEVICE_STATE_REASON_NONE)
NetworkManager[30304]: <info>  (virbr0-nic): released from master virbr0

If the slave is removed, then the master is already cleaned up so NM
doesn't need to do anything.  5dd48f fixed that but forgot to update
the !configure case, causing the warning but no other problems.

Fixes: 5dd48f7527
2014-12-11 16:22:32 -06:00
Dan Williams
a1f4794c86 core: clean up half-done IP operations when re-entering NEED_AUTH state (bgo #741342)
When the device decides it needs re-auth during IP config and returns
to the NEED_AUTH state, make sure we clean up any half-done IP operations
since they will be re-started after auth is completed and the
IP_CONFIG state is re-entered.

https://bugzilla.gnome.org/show_bug.cgi?id=741342
2014-12-11 09:24:48 -06:00
Lubomir Rintel
53380159dd platform: Fix build with LIBNL_INET6_ADDR_GEN_MODE
platform/nm-linux-platform.c: In function 'setup':
  platform/nm-linux-platform.c:4364:2: error: 'object' undeclared (first use in this function)
    object = nl_cache_get_first (priv->link_cache);
    ^

Fixes 2b8060b9b3
2014-12-11 15:20:08 +01:00
Lubomir Rintel
62ad694421 device: assume connections for device with slaves
If a bridge/team/bond has slaves, assume it's connected. Recheck as devices
appear.

https://bugzilla.redhat.com/show_bug.cgi?id=1141266
2014-12-11 11:49:29 +01:00
Lubomir Rintel
25387cd1ff device: set the master on device addition
Otherwise we won't notice the device is a slave on NM startup until someone
changes the link or tries to activate the device.
2014-12-11 11:49:29 +01:00
Lubomir Rintel
81553b6978 device: release and enslave an interface if its master changed
In case of an atomic master change, we'd not notice that the master changed:

  ip link set dummy0 master bridge0
  ip link set dummy0 master bridge1
2014-12-11 11:49:29 +01:00
Lubomir Rintel
8b77b93169 Revert "platform: increase NL buffer for systems with lots of interfaces (rh #1141256)"
This reverts commit efd09845c4.

It turns out that the socket space might not be the only buffer that may get
too full. 128K ought to be enough for it and we should resynchronize with the
kernel now if needed.
2014-12-11 11:49:29 +01:00
Lubomir Rintel
2b8060b9b3 platform: resynchronize with kernel when we're out of buffer space
Kernel can return ENOBUFS in variety of reasons. If that happens, we know we've
lost events and should pick up kernel state.

Simple reproducer that triggers an ENOBUFS condition no matter how big our
netlink socket buffer is:

  ip link add bridge0 type bridge
  for i in seq $(0 1023); do ip link add dummy$i type dummy; \
    ip link set dummy$i master bridge0; done
  ip link del bridge0
2014-12-11 11:49:29 +01:00
Lubomir Rintel
85b811cc7c platform: refactor the object comparison logic into a separate function
One from libnl is not good enough (see comment).
2014-12-11 11:49:29 +01:00
Lubomir Rintel
ed78d3b3dc platform: ensure all objects in link cache are of AF_UNSPEC family
We assume that in nm_nl_cache_search() and correctly set that in
get_kernel_object(), but we rtnl_link_alloc_cache() can initialize the cache
with devices of other families.

The consequence is that we don't notify when the bridge changes to IFF_UP as we
fail to match and remove the old downed object from the cache:

  nm_device_bring_up(): [0xf506c0] (bridge0): bringing up device.
  nm_platform_link_set_up(): link: setting up 'bridge0' (12)
  link_change_flags(): link: change 12: flags set 'up' (1)
  get_kernel_object(): get_kernel_object for link: bridge0 (12, family 7)
  log_link(): signal: link   added: 12: bridge0 <UP> mtu 1500 bridge driver 'bridge' udi '/sys/devices/virtual/net/bridge0'
  get_kernel_object(): get_kernel_object for link: bridge0 (12, family 7)
  log_link(): signal: link changed: 12: bridge0 <UP> mtu 1500 bridge driver 'bridge' udi '/sys/devices/virtual/net/bridge0'
  log_link(): signal: link changed: 12: bridge0 <UP> mtu 1500 bridge driver 'bridge' udi '/sys/devices/virtual/net/bridge0'
  (bridge0): device not up after timeout!
  (bridge0): preparing device
2014-12-11 11:49:29 +01:00
Lubomir Rintel
4b3ad7709d device: don't fail activation when IP config is unavailable and unneeded
If we didn't start IPv4 and IPv6, but they're allowed to fail, progress
the activation without failing it. Also, progress assumed connections to
check-ip with whatever configuration that is available.

https://bugzilla.redhat.com/show_bug.cgi?id=1141264
2014-12-11 11:46:43 +01:00
Lubomir Rintel
55af4add90 device: don't disconnect assumed connections
Transition them to activated status when they fail.

https://bugzilla.redhat.com/show_bug.cgi?id=1141264
2014-12-11 11:46:43 +01:00
Lubomir Rintel
063ab8da5c device: turn nm_d_ip_config_should_fail to get_ip_config_may_fail
Has a cleaner semantics and will be useful later on. Also, make it static --
it's not used outside nm-device.c.
2014-12-11 11:46:42 +01:00
Jiří Klimeš
d19770102e tests: fix setting MAC address in tests
MAC address properties are strings now. The change has been done by commit
3a54d05098. But this place was not updated.

Reported by lrintel in copr.
2014-12-11 11:33:32 +01:00
Lubomir Rintel
dfdcbfe115 core: don't wipe out VPN secrets if we're changing the connection
The VPN secret properties are hashes and thus the default property value does
not work with them.
2014-12-11 11:15:53 +01:00
Lubomir Rintel
a3f9e51927 agent-manager: don't ever fail the secrets requests from GetSecrets()
VPN connections always return true for nm_connection_need_secrets(), but the
documented behavior of GetSecrets() is just to return any secrets we have
(otherwise nmcli c --show-secrets would not be useful for VPN connections).
2014-12-11 11:15:53 +01:00
Thomas Haller
5849c97c03 platform: avoid conflicts when reinstalling the device-route
Since f32075d2fc, we remove the kernel
added IPv4 device route, and re-add it with appropriate metric.

This could potentially replace existing, conflicting routes. Be more
careful and only take any action when we don't have a conflicting
route and when we add the address for the first time.

The motivation for this was libreswan which might install a VPN route
for a subnet that we also have configured on an interface. But the route
conflict could happen easily for other reasons, for example if you
configure a conflicting route manually.

Don't replace the device route if we have any indication that
a conflict could arise.

https://bugzilla.gnome.org/show_bug.cgi?id=723178
2014-12-11 10:07:00 +01:00
Thomas Haller
e439478ccd device: add logging macro _LOGT() 2014-12-09 16:17:46 +01:00
Thomas Haller
cb8af29f0b core: implement nm_utils_find_helper() based on nm_utils_file_search_in_paths()
This also changes behavior in that we now only find files that
are executable.

https://bugzilla.gnome.org/show_bug.cgi?id=740783
2014-12-05 11:07:42 +01:00
Jiří Klimeš
49bbafbb16 utils: fix converting milliseconds to microseconds
Coverity:
Defect type: CONSTANT_EXPRESSION_RESULT
/src/NetworkManagerUtils.c:726: result_independent_of_operands: "18446744073709551615UL /* 9223372036854775807L * 2UL + 1UL */ < (gulong)sleep_duration_msec * 1000UL" is always false regardless of the values of its operands. This occurs as the logical first operand of '?:'.
2014-12-05 09:38:40 +01:00
Jiří Klimeš
448b073bda bluetooth: the code cannot be reached
because either GSM or CDMA is present. It is checked just above.

Coverity:
Defect type: DEADCODE
src/devices/bluetooth/nm-device-bt.c:312: dead_error_line: Execution cannot reach this statement: "fallback_prefix = dcgettext...".
2014-12-05 09:38:40 +01:00
Jiří Klimeš
43b4c8f826 platform: ignore nm_platform_ip4_route_add/delete return value
Coverity:
Defect type: CHECKED_RETURN
2014-12-05 09:38:40 +01:00
Jiří Klimeš
7744bd0f85 utils: initialize timespec structure
Coverity:
Defect type: UNINIT
src/NetworkManagerUtils.c:1906: uninit_use_in_call: Using uninitialized value "tp.tv_nsec" when calling "monotonic_timestamp_get".
src/NetworkManagerUtils.c:1879: uninit_use_in_call: Using uninitialized value "tp.tv_nsec" when calling "monotonic_timestamp_get".
src/NetworkManagerUtils.c:1852: uninit_use_in_call: Using uninitialized value "tp.tv_nsec" when calling "monotonic_timestamp_get".
src/NetworkManagerUtils.c:1825: uninit_use_in_call: Using uninitialized value "tp.tv_nsec" when calling "monotonic_timestamp_get".
2014-12-05 09:38:40 +01:00
Jiří Klimeš
e52f352339 util: fix _log_connection_sort_names_fcn()
Coverity:
Defect type: CONSTANT_EXPRESSION_RESULT
src/NetworkManagerUtils.c:1978: same_on_both_sides: "(v1->diff_result & NM_SETTING_DIFF_RESULT_IN_B) != (v1->diff_result & NM_SETTING_DIFF_RESULT_IN_B)" is always false regardless of the values of its operands because those operands are identical. This occurs as the logical operand of if.
2014-12-05 09:38:40 +01:00
Thomas Haller
b159946798 settings: change algorithm for UUID generation based on strings
In several cases, connection uuids are generated based on
some strings. Change the algorithm, to prefix the hashed
identifier differently for each setting type. This makes
collisions very unlikely.

Also, change the algorithm, to create proper Variant3 UUIDs.

This is a behavioral change, but it only affects code places
that were added since nm-0-9-10 and were not yet part of
a stable release.
2014-12-04 17:02:22 +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
1e313e000d libnm: add a type argument to nm_utils_uuid_generate_from_string()
There are different types (variants) of UUIDs defined.
Especially variants 3 and 5 are name based variants (rfc4122).

The way we create our UUIDs in nm_utils_uuid_generate_from_string()
however does not create them according to RFC and does not set
the flags to indicate the variant.

Modify the signature of nm_utils_uuid_generate_from_string() to accept
a "uuid_type" argument, so that we later can add other algorithms without
breaking API.
2014-12-04 17:02:22 +01:00
Thomas Haller
21eb6b5d0d libnm: accept additional length argument in nm_utils_uuid_generate_from_string()
This makes the function also useful for non C-strings,
non UTF-8-strings, and generic blobs.
2014-12-04 17:02:22 +01:00
Jiří Klimeš
9a6e1e86cc core: don't bounce disable_ipv6 when assuming connections (rh #1170530)
Don't call set_nm_ipv6ll(self, TRUE) on any assumed connection since it
would bounce disable_ipv6, which would break IPv6 connectivity.
That is critical, for example, for installations via NFS.

Fixes: d37b7bed30

https://bugzilla.redhat.com/show_bug.cgi?id=1170530
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1052157
2014-12-04 15:50:36 +01:00
Dan Winship
3b86cc047e libnm: remove nm_utils_init() from the public API
Remove nm_utils_init() from the public API, and just do it as a
constructor instead.
2014-12-04 08:39:54 -05:00
Dan Williams
3cf2fbbf47 core: fix leak of generated connection if device is active
Don't generate (and add to settings) a connection if we aren't going
to use it anyway.
2014-12-03 14:25:45 -06:00
Dan Winship
5dd48f7527 devices: don't release slaves on exit (rh #1169936)
nm_device_removed() calls nm_device_release_one_slave() in order to
fix up NetworkManager's master/slave bookkeeping, but we don't want to
tell the kernel to actually unslave the device, since that would
happen automatically anyway if the device was really removed, and
shouldn't happen if the device is just being removed from NM's device
list.

(In particular, don't remove all libvirt-created virtual network
devices from virbr0 when NetworkManager exits.)
2014-12-03 13:19:48 -05:00
Thomas Haller
6d6c433bab ifcfg-rh: don't include nm-utils-private.h outside of libnm-core/ 2014-12-03 17:36:08 +01:00
Lubomir Rintel
e257744f9e device: Deal with links that vanish during initialization
nm_device_get_hw_address() may return NULL and nm_platform_link_get_type may
return NM_LINK_TYPE_NONE. While it might be a good idea to check for such cases
at the init time it seems easier to just ignore it and prevent blowing up in
subsequent deactivation.

A quick test case:

  # while :; do ip link add moo0 type veth peer moo1; ip link del moo0 ; done

Yields:

  NetworkManager:ERROR:devices/nm-device-ethernet.c:268:constructor:
    assertion failed: (link_type == NM_LINK_TYPE_ETHERNET ||
    link_type == NM_LINK_TYPE_VETH)

  nm_device_set_hw_addr: assertion 'addr != NULL' failed

https://bugzilla.gnome.org/show_bug.cgi?id=740992
2014-12-02 11:44:49 +01:00
Thomas Haller
711c0eab5b iface-helper: disambiguate route priority for IPv4 and IPv6
https://bugzilla.gnome.org/show_bug.cgi?id=740780
2014-12-01 16:58:31 +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
Thomas Haller
f6fba86984 keyfile: assert in writer to have valid connection id
Few lines above we already verify the connection. We must
have an @id.
2014-11-28 18:39:54 +01:00
Jiří Klimeš
313a4081b5 devices: NM_SETTING_WIRED_S390_SUBCHANNELS is now G_TYPE_STRV (rh #1168764)
Fixes crash on s390.
The type change of the property was done in 6a4127cfa0,
but we forgot to update this function.

https://bugzilla.redhat.com/show_bug.cgi?id=1168764
2014-11-28 12:20:04 +01:00
Thomas Haller
4bf04700bb core: adjust values for default route-metrics per device type
We recently changed default values for route metrics. Revise that
again and increase the space between the default values.

No strong reason to do this, but it seems better to have larger
gaps and make use of the available range.
2014-11-26 20:39:18 +01:00
Thomas Haller
3210bb93a1 vpn: don't choose route priority for VPN connections based on the parent device
The parent device is just the device that happens to be the best device.
It does not mean, that its route metric should be inherited to the VPN
connection.

This also makes the resulting route metric for VPN connections much
more predictable: now it is either ipv4.route-metric from the connection,
or it falls back to NM_VPN_ROUTE_METRIC_DEFAULT (10).
2014-11-26 19:25:12 +01:00
Thomas Haller
5dfad33823 iface-helper: make priority variable guint32
Also read the command line argument as G_OPTION_ARG_INT64 type. Otherwise, on
32-bit integers, you could not enter any number larger then G_MAXINT32.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-25 22:30:38 +01:00
Thomas Haller
34124296c0 core: fix route metrics for subnet routes
For IPv4 addresses, the kernel automatically adds a route when
configuring an IP address. Unfortunately, there is no way to control
this behavior or to set the route metric.

Fix this, by adding our own route and removing the kernel provided
one.

Note that this adds a major change in that we no longer call
nm_ip4_config_commit() for assumed devices.

https://bugzilla.gnome.org/show_bug.cgi?id=723178

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-25 22:30:38 +01:00
Thomas Haller
0b50940f43 platform: add paramter to ip4_route_add to set src (RTA_PREFSRC)
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-25 22:30:38 +01:00
Thomas Haller
a2e93f2de4 libnm: allow zero prefix length for NMIPRoute
NMIPRoute is used by NMSettingIPConfig, but also
NMIPConfig. In the former case, default routes are (still)
disallowed. But in the NMIPConfig use-case, it can make sense
to expose default routes as NMIPRoute instances.

Relax the restriction on the NMIPRoute API to allow this
future change.

No code actually supports having NMIPRoute instances with
prefix length zero (default routes). Up to now, all such uses
would be a bug.

https://bugzilla.gnome.org/show_bug.cgi?id=739969

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-24 18:02:46 +01:00
Thomas Haller
0b59752512 dhcp: fix printf format string for printing guint32 variable
Fixes: 9013fd42d6
2014-11-24 17:26:54 +01:00
Thomas Haller
13d9b28323 dhcp: pass device specific route metric to nm_dhcp_systemd_get_lease_ip_configs()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-24 10:52:56 -05:00
Dan Winship
9013fd42d6 dhcp: fix expiry time logging/exporting
The previous nm-dhcp-systemd code for logging the lease expiry time,
and exporting that value to D-Bus was clamping the value to
G_MAXUINT32-1, but that's unnecessary on x86_64, and incorrect on x86
(since time_t is signed).

Correctly adding a value to the current time and not overflowing seems
to be more-or-less impossible without having separate cases for 4- and
8-byte time_t. Since this was basically just for logging purposes
anyway, just log the number of seconds rather than the timestamp, and
then we don't have to worry about sizeof(time_t).
2014-11-24 10:52:56 -05:00
Jiří Klimeš
4e105c5012 core: add NM_UNMANAGED_PARENT flag for a dependency on parent device
VLAN device depends on its parent, for instance. If the parent is not managed,
then the VLAN can't be either.
2014-11-24 10:33:21 +01:00
Jiří Klimeš
fa325dca5a vlan: export parent device for VLANs as D-Bus property
and use the internal construct-time parent property for VLAN creation.
2014-11-24 10:33:13 +01:00