Commit graph

649 commits

Author SHA1 Message Date
Thomas Haller
ad03cdbc73 device/trivial: rename private field in NMDevicePrivate
Rename "default_route.v4_configure_first_time" to "v4_commit_first_time".

For one, the name "commit" matches better to the @commit variable in ip4_config_merge_and_apply()
and ip6_config_merge_and_apply(). Then, we don't need this information
only for default-routes, so move the variable out of the @default_route
struct.
2015-07-22 13:33:01 +02:00
Tore Anderson
3efb6740fc device: prefer wifi over wwan by default
This makes wifi preferred to wwan (the modem and bluetooth device types
to be specific) by default, so that users that care about being
connected at all times can keep both enabled with auto-connect. As wifi
is usually unmetered and often faster than wwan, it makes sense to
prefer it. This is also how pretty much every smart-phone in the world
behaves, so it aligns better with user expectations too.

https://bugzilla.gnome.org/show_bug.cgi?id=744754
2015-07-22 10:50:23 +02:00
Thomas Haller
96a7f3a3ba logging: make use of journal configurable 2015-07-14 15:55:14 +02:00
Thomas Haller
8b015826e6 routes: fix race syncing routes by not doing full-sync
In most cases, when syncing routes, we should only remove routes
that were configured by us previously. Otherwise, there is a race
that we can remove routes added externally.

Now, when applying IP configuration for a device, only do a full-sync
at the first time when we activate the device. Later on, only remove
routes that were added by us.
2015-07-14 13:36:50 +02:00
Thomas Haller
6124f5b94a routes/trival: add argument @routes_full_sync to IP config commit
The argument is still unused, so no behavioral change yet.
2015-07-14 13:36:50 +02:00
Thomas Haller
d6831efc6b device: fix regression for ignored search domains in ip._config_merge_and_apply()
Reported-by: Fabrice Bellet <fabrice@bellet.info>
Fixes: 79630c11e5

https://bugzilla.gnome.org/show_bug.cgi?id=752193
2015-07-09 23:14:51 +02:00
Jiří Klimeš
46f29a4abc device: use NULL instead of 0 in g_return_val_if_fail() for pointer 2015-07-08 16:50:28 +02:00
Jiří Klimeš
dce050a45d device: trivial: fix a copy/paste error in comment 2015-07-08 16:50:18 +02:00
Jiří Klimeš
bb1692707f device: just get ip_iface in the place where it is needed
priv->iface could change in device_link_changed() which reacts on platform link
changes caused by nm_platform_link_set_user_ipv6ll_enabled(). (The variable could
change between obtaining and using its value, because emitting a glib signal runs
callbacks synchronously).

Actually, the problem is already fixed by commit 04caae735f.
But still this is better.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1224366
2015-07-07 18:50:38 +02:00
Thomas Haller
947fc9a278 config: add write support for NMConfig
Internal configuration is written as keyfile to
NMSTATEDIR"/NetworkManager-intern.conf"

Basically, the content of this file is merged with user
configuration from "NetworkManager.conf" files. After loading
the configuration, NMConfig exposes a merged view of user-provided
settings and internal overwrites.

All sections/groups named [.intern*] are reserved for internal
configuration values. They can be written by API, but are ignored
when the user sets them via "NetworkManager.conf". For these
internal sections, no conflicts can arise.

We can also overwrite individual properties from user configuration.
In this case, we store the value we want to set, but also remember
the value that the user configuration had, at the time of setting.
If on a later reload the user configuration changed, we ignore our
internal value -- as we assume that the user modified the value
afterwards.
We can also hide/delete value from user configuration.
This works on a per-setting basis.
2015-07-02 16:01:20 +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
Lubomir Rintel
295c9818b0 devices,platform: fix build with gcc
Warnings about missing initializers.
2015-07-01 16:35:52 +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
d9dba6b662 platform: change NMPlatformGetRouteMode enum to NMPlatformGetRouteFlags flags
By having flags instead of an enum/mode, we can encode more combinations
of filtering the result.
2015-07-01 16:00:21 +02:00
Beniamino Galvani
e86f8354a7 device: restart ping process when it exits with an error
When ping is launched to check the connectivity to the gateway it may
return earlier than the given timeout in case of error. When this
happens we need to respawn it until the timeout is reached.

While at it, increase maximum timeout value to 600 seconds.

https://bugzilla.redhat.com/show_bug.cgi?id=1128581
2015-07-01 13:42:41 +02:00
Thomas Haller
3b21738d9c device: fix cleanup DHCP instance when unmanaging device on removed platform link
When the platform link gets removed outside of NetworkManager, we would
unmanage the device first. By checking the device state reason
NM_DEVICE_STATE_REASON_REMOVED, we would then not deconfigure the
interface, as it is already gone.

This was not correct because we must at least stop the dhcp client.
Otherwise the dhclient process keeps running. That meant, if the device
reappeared later, we would start dhclient again. Then we would find the
PID of the still running instance in the pidfile and kill it only than.

Fix it by replacing the 'deconfigure' boolean by a tri-state
'cleanup_type'.
2015-07-01 11:16:35 +02:00
Lubomir Rintel
4843e625a8 device: only reset ipx fields when there L3 configuration is present
Fixes: 79630c11e5
2015-06-28 20:10:58 +02:00
Jiří Klimeš
348452f1e0 device: renew DHCP lease for active "ignore-carrier" devices on carrier-on (bgo #743368)
When carrier appears (e.g. the plug was re-inserted) we re-new addresses,
because the network could change.

https://bugzilla.gnome.org/show_bug.cgi?id=743368
2015-06-26 14:32:50 +02:00
Beniamino Galvani
79630c11e5 device: fix handling of ignore-auto-dns and ignore-auto-routes
Since commit ab6548c621 ("device: better accept external IP
changes"), ipX_config_merge_and_apply() applies the configuration
static settings to an intermediate, initially empty configuration
(priv->con_ipX_config) instead of the composite configuration, and
thus the handling of ignore-auto-routes and ignore-auto-dns options
done in nm_ipX_config_merge_setting() has no effect.

Fix this by clearing the routes and the DNS information when needed
before merging static settings to the composite configuration.

Fixes: ab6548c621
2015-06-25 16:53:42 +02:00
Thomas Haller
7f8f0d04b0 device: merge device_ipx_changed() signal handler 2015-06-24 16:09:57 +02:00
Thomas Haller
b88c309167 platform: pass object type with platform changed signal 2015-06-24 16:09:57 +02:00
Jiří Klimeš
84b5fa21ed device: split IP config changes signal handling to IPv4 and IPv6
So that we don't process IPv4 changes for IPv6 and vice versa.
2015-06-24 15:08:05 +02:00
Jiří Klimeš
0a00eb67dd device: split ensure_ipx_config() into IPv4 and IPv6 (bgo #751430)
Without that we can remove addresses from con-ip6-config due to external
changes *before* it is applied and thus manual IPv6 addresses are not applied
together with ipv6.method=auto.

Testcase:
$ nmcli con add type ether con-name AAA ifname eth0 autoconnect no
$ nmcli con mod AAA ipv4.addresses 1.1.1.1/24 ipv6.addresses 99::99/64
$ nmcli con up AAA

Fixes:Beaker:NetworkManager_Test37_run_once_new_connection
Fixes:Beaker:NetworkManager_Test84_ipv6_addresses_no_when_static_switch_asked

https://bugzilla.gnome.org/show_bug.cgi?id=751430
2015-06-24 15:07:18 +02:00
Thomas Haller
e8e455817b platform: refactor virtual methods for link objects in NMPlatform
Change nm_platform_link_get() to return the cached NMPlatformLink
instance. Now what all our implementations (fake and linux) have such a
cache internal object, let's just expose it directly.
Note that the lifetime of the exposed link object is possibly quite
short. A caller must copy the returned value if he intends to preserve
it for later.
Also add nm_platform_link_get_by_ifname() and modify nm_platform_link_get_by_address()
to return the instance.

Certain functions, such as nm_platform_link_get_name(),
nm_platform_link_get_ifindex(), etc. are solely implemented based
on looking at the returned NMPlatformLink object. No longer implement
them as virtual functions but instead implement them in the base class
(nm-platform.c).
This removes code and eliminates the redundancy of the exposed
NMPlatformLink instance and the nm_platform_link_get_*() accessors.
Thereby also fix a bug in NMFakePlatform that tracked the link address
in a separate "address" field, instead of using "link.addr". That was
a case where the redundancy actually led to a bug in fake platform.

Also remove some stub implementations in NMFakePlatform that just
bail out. Instead allow for a missing virtual functions and perform
the "default" action in the accessor.
An example for that is nm_platform_link_get_permanent_address().
2015-06-21 12:53:48 +02:00
Dan Williams
86abc34e26 trivial: move some code around in nm-device.c 2015-06-19 14:17:20 +02:00
Lubomir Rintel
2bfbf33720 manager: use proper reason when stealing a connection
The user-requested reason is not really appropriate and blocks autoreconnect.
We added a new reason precisely for that.

Fixes: 4cb97cf66f
2015-06-18 15:45:15 -04:00
Thomas Haller
04caae735f device: delay handling of link-changed platform event
When inside a state-change, we set for example the device up.
This triggers a link-changed event, which then causes further
state-changes of the devices.
A state-change in process of a device is not reentrant, so we must
delay the handling of the link-changed event.
2015-06-18 10:33:30 +02:00
Thomas Haller
baec894139 device: drop logging platform error on failure to set permanent MAC address
The platform error is in many cases not meaningful anyway.
2015-06-17 11:44:16 +02:00
Thomas Haller
c1a945b95d platform: signal missing firmware in nm_platform_set_up()
Don't use nm_platform_get_error() anymore.
2015-06-17 11:44:16 +02:00
Thomas Haller
8334171a4e device: don't check for NM_PLATFORM_ERROR_NOT_FOUND in set_nm_ipv6ll()
Unconditionally log a warning if the function fails.
We are about to drop nm_platform_get_error(), it's anyway unclear
why we don't want to log a warning about non-existing interface.
2015-06-17 11:44:16 +02:00
Thomas Haller
1b2b988ea9 platform: no longer expose udi field in NMPlatformLink
The @udi field is not a static string, so any user of a NMPlatformLink
instance must make sure not to use the field beyond the lifetime of the
NMPlatformLink instance.
As we pass on the platform link instance during platform changed events,
this is hard to ensure for the subscriber of the signal -- because a
call back into platform could invalidate/modify the object.

Just not expose this field as part of the link instance. The few callers
who actually needed it should instead call nm_platform_get_uid(). With
that, the lifetime of the returned 'const char *' pointer is clearly
defined.
2015-06-17 11:41:43 +02:00
Thomas Haller
076fe578e3 platform: remove redundant NMPlatformLink fields "arp" and "up" 2015-06-17 11:41:43 +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
bbbf522941 core,libnm: add 'metered' property to NMDevice 2015-06-09 18:11:25 +02:00
Thomas Haller
d6ce01f115 platform: merge setup_devices() function into constructed()
We already populate the netlink cache in constructed(). No need
to wait with udev devices until nm_platform_query_devices(). Just
do it right away.

Add a hack to keep 'lo' default-unmanaged. Now that we load
udev devices earlier, we end up clearing the default-unmanged
flag on 'lo', which has bad consequences.
2015-06-05 16:52:49 +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
f3c61f8141 device: remove reading ipv6 privacy setting from sysctl
Since introduction for support of ip6-privacy (use_tempaddr,
RFC4941) with commit d376270bfe,
the sysctl value from /etc was always read first.

This is problematic, because an explicit setting in the
connection should not be ignored over a global configuration.

Drop that old behavior. It was also problematic, because we did
not read any files under /etc/sysctl.d (except for sysctl.conf).
Also, we did not honor per-interface configurations.

Now we also use as last fallback the value from
/proc/sys/net/ipv6/conf/default/use_tempaddr
That has the advantage of falling back to the system default value
so that NM doesn't need to have it's own default policy
(Related: https://bugzilla.redhat.com/show_bug.cgi?id=1187525).

This is a change in behavior.
2015-06-05 12:38:30 +02:00
Thomas Haller
e729dd70ae device: add global configuration default for ip6-privacy (use_tempaddr, RFC4941)
Support default value for setting 'ipv6.ip6-privacy' in
NetworkManager.conf.

If the global value is unset, preserve old behavior of looking into
/etc/sycctl.conf first. That behavior was introduced with commit
d376270bfe, since we support ip6-privacy
setting.

If the global value is set to "unknown", add a new fallback
that instead reads the runtime value from
  "/proc/sys/net/ipv6/conf/default/use_tempaddr"
This seems more sensible behavior because we fallback to sysctl,
but instead of looking at static files in /etc, read /proc.
But to preserve the old behavior, we only do that when a global
value is configured at all.

https://bugzilla.gnome.org/show_bug.cgi?id=721200
2015-06-05 12:38:30 +02:00
Thomas Haller
59a991725a device: make route-metric configurable per-device
The route-metric can be configured per connection via the
ipv4.route-metric and ipv6.route-metric fields. When the
value is left at -1 (the default), we would determine the
route-metric based on the device type (nm_device_get_priority()).

Extend that scheme by making the default value overwritable in
NetworkManager.conf.
2015-06-05 12:38:30 +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
e9e9d44468 device: add nm_device_get_type_description() function
Add a function to get a concise representation of the
device type.

libnm already has nm_device_get_type_description() for that
and it is shown by

  nmcli -f GENERAL.TYPE device show

Reimplement that function for nm-core. Just take care that the
two implementations don't diverge.
2015-06-05 12:38:29 +02:00
Beniamino Galvani
3bc097b084 device: don't assume by default IPv6LL-only connections
Add the new configuration option 'assume-ipv6ll-only' which specifies
the devices for which NM will try to assume an existing IPv6LL-only
configuration.

The new default behavior is to ignore such configurations since IPv6LL
addresses are automatically assigned by the kernel when the device is
brought up and thus the presence of an IPv6LL address doesn't mean
that the device was configured by the administrator.

The previous behavior was to always assume IPv6LL-only configurations
but this often had the unwanted effect of preventing other on-disk
configurations to be activated. To preserve the old behavior the
option must be set to '*'.

https://bugzilla.redhat.com/show_bug.cgi?id=1138426
2015-06-02 14:04:54 +02:00
Thomas Haller
d51975ed92 default-route: also configure default-routes for assumed connections
Previously for assumed connections we would never configure a default route.
That has serious problems for example in the following two scenarios:

  - the default-route might have a limited lifetime from a previous
    SLAAC/accept_ra setting. In this case, once we assume the connection
    we must also ensure that we extend the lifetime of the default
    route.
  - the gateway could be received via DHCP/RA and it might change.
    If we ignore default-routes for assumed connection we miss that
    change.

The problem is that the notion of "assumed connection" wrongly combines
two conflicting goals (related bug bgo#746440):
  a) have an external device that is entirely unmanged by NM.
  b) do a seamless takeover of a previously managed connection at start,
     but still fully manage.

This patch changes the handling of default-routes towards meaning b).

https://bugzilla.redhat.com/show_bug.cgi?id=1224291
2015-05-29 11:48:57 +02:00
Thomas Haller
98e50e358b default-route: for devices with 'never-default' enforce the default-route only once
Since da708059da, we would pickup the
default-route as configured externally, except at those moments when
NM re-applys the IP configuration of the interface, such as during a
DHCP lease.

That allows the user to add/remove the default-route externally (iproute).
But still, at random times (DHCP lease), we will revert those external
changes.

Extend this, that if the connection is explicitly configured as
'never-default=yes', that it tells NM not to interfere with externally
added default-routes on this device. That means, NM will only remove
any preexisting default-routes when configuring the device a first
time.
On any later attempts, NM will assume whatever is configured there.
That makes sense because the user indicated not wanting NM to
manage a default-route on that device, so if something externally
added a default-route, assume that is what the user wants.

This only affects non-assumed connections, with 'never-default=yes'.

https://bugzilla.redhat.com/show_bug.cgi?id=1205405
2015-05-29 11:45:48 +02:00
Thomas Haller
49227a07f3 default-route: add @out_is_never_default argument to has_default_route()
Also accept a NULL connection in
nm_default_route_manager_ip4_connection_has_default_route() and
nm_default_route_manager_ip6_connection_has_default_route().
2015-05-29 11:43:58 +02:00
Jiří Klimeš
bfd502a9b1 core/cli: add missing device state-reason to string conversions
for NM_DEVICE_STATE_REASON_PARENT_CHANGED
and NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED

Fixes: cd3df12c8f
2015-05-27 11:11:47 +02:00
Dan Williams
d4e0a1e8cc core: earlier software capability detection
We need to know whether we can create interfaces of any given
NMDevice subclass or not.  So don't rely on just the NMPlatformLink
for that information, because we won't have a platform link for
software devices before we create them.
2015-05-19 09:25:16 -05:00
Beniamino Galvani
0a04be41d4 device: set MTU on IP interface
Fixes: 7ba2a058f2
2015-05-13 13:29:38 +02:00
Thomas Haller
067202b34e core: use explict NMLogDomain enum instead of int
A while ago (f4f3f4d69b) we added an
enum to represent the logging domain. Use it.
2015-05-12 16:46:48 +02:00
Thomas Haller
843205521f device: fix configuring static ip addresses
When a connection had static IP addresses, an early event
from plaform would clear them from priv->con_ip4_config.

Fix that, by don't initializing priv->con_ip4_config
before we commit the first time.

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

Fixes: 557667df12
2015-05-11 21:44:26 +02:00