Commit graph

649 commits

Author SHA1 Message Date
Thomas Haller
1f5f576c33 policy: pick up externally configured default routes for managed interfaces
The previous commit made NM enforce the default route on interfaces for
which NM manages a default route.

For interfaces that are configured never-default, NM will now pick up
any externally configured default route, as if it was managed by NM.
This is important, because NMDefaultRouteManager needs a notion of which
is the best device. Without this change, it was agnostic to default routes
on managed, never-default interfaces.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-19 22:55:32 +01:00
Thomas Haller
57dd4a125b device: only add default route when having any addresses
This fixes the failure to add a default route because no
addresses are configured yet.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-19 22:55:32 +01:00
Thomas Haller
462456f255 policy: remove redundant remove_default_route() functions from NMDefaultRouteManager
When calling update_default_route(), NMDefaultRouteManager will look at the
source, and determine whether it has a default route or not. For example
for device sources, this means calling nm_device_get_ip4_default_route().

If the source indicates that it has no default route, the effect of
calling update_default_route() is the same as calling
remove_default_route() (hence, remove() can be replaced by update()).

If the source however still indicates a default route, the behavior
would be different. This case would be an undesired inconsistancy,
because source and NMDefaultRouteManager would disagree of whether
the source has a default route.
Source must always properly indicate whether it has a default route
or not, hence this situation does not arise.

Hence it is always better to call update().

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-19 22:55:32 +01:00
Thomas Haller
0555df65d3 core: minor fix to ensure safe boolean comparison in have_ip6_address()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-19 17:12:00 +01:00
Thomas Haller
06a45fdcaf firewall: don't set firewall zone for assumed devices
https://bugzilla.redhat.com/show_bug.cgi?id=1098281

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-19 12:59:42 +01:00
Thomas Haller
90a3332199 firewall: invoke FwAddToZoneFunc callback also when cancelling
Not invoking a callback when cancelling the operation is counter
intuitive.

Note that NMPolicy refs the device, cancelling the call would leave
the reference hanging. That was not an issue because the call was
never cancelled. But still the behavior of NMFirewallManager is
unexpected.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-19 12:58:36 +01:00
Thomas Haller
b0b7473af1 firewall: make call handle an opaque pointer type
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-19 12:58:36 +01:00
Dan Williams
70f227f552 core: bounce disable_ipv6 when setting userspace IPv6 link-local (bgo #740096)
The kernel does not terminate an ongoing IPv6LL address process when
the IPv6LL address generation mode is set to 'none' (indicating that
userspace wishes to handle IPv6LL).  Next, NetworkManager does not
expose IPv6 addresses internally until they have completed DAD.  This
means that the kernel may still be performing DAD for an IPv6LL
address when NetworkManager turns userspace IPv6LL on, and when
DAD is complete NetworkManager will finally pay attention to the
address.  If the device is in the DISCONNECTED state, NetworkManager
will then generate and assume an IPv6LL-only connection on the device.

Unfortunately, that behavior happens if the following is true:

1) IPv6LL addressing takes a while (eg, dad_transmits is high or
the kernel takes a while for some reason)

2) the activated connection fails quickly (dhclient fails or some
other fatal error terminates the activation attempt)

3) the activated connection has ipv6.method=ignore

In this case, when the device was brought up and ipv6.method=ignore,
NetworkManager re-enabled kernel IPv6LL and reset the IPv6 sysctl
properties.  The kernel then generated an IPv6LL address and began
DAD.  dhclient failed quickly, and NM deactivated the device.  NM
then turned off kernel IPv6LL when deactivating the device, but the
kernel does not terminate the ongoing DAD.  Some time after the device
entered the DISCONNECTED state, the kernel finished DAD and that
allowed NetworkManager to internally see the address, which caused
NetworkManager to emit the 'recheck-assume' signal.  This
generated a new IPv6LL-only connection which was then assumed.

Bouncing 'disable_ipv6' when re-enabling userspace IPv6LL during
device deactivation flushes the tentative kernel IPv6LL address,
thus preventing the address from being announced after userspace
IPv6LL is re-enabled.  The other alternative is to expose
tentative addresses (eg those still doing DAD) in NMPlatform so
they would be flushed when the device deactivates, but that is a
larger & riskier set of changes.

Reproducer:
- ifconfig eth0 down
- prepare a DHCPv4 connection with ipv6.method=ignore
- set /proc/sys/net/ipv6/conf/all/dad_transmits to "15"
- ensure that DHCPv4 will fail (replace dhclient with a script
    that exits after 2 seconds or something)
- run NetworkManager
- activate the DHCP connection and watch it immediately fail
- wait for the kernel to announce the IPv6LL address after DAD finishes
- watch NM "assume" the new IPv6LL connection

https://bugzilla.gnome.org/show_bug.cgi?id=740096
2014-11-17 10:20:37 -06:00
Dan Williams
d1295b12e9 dhcp: wait for an IPv6LL address before starting DHCPv6 (bgo #740147)
For ipv6.method=dhcp NM was not waiting for an IPv6LL address, which
caused the DHCP client to exit early because it had no local address
to bind to.

https://bugzilla.gnome.org/show_bug.cgi?id=740147
2014-11-17 09:52:12 -06:00
Dan Williams
264c0f162c core: fix return type of addrconf6_start()
It returned a boolean and the caller expected a boolean, but the
return type was NMActStageReturn.
2014-11-14 16:15:35 -06:00
Dan Winship
d1faee9228 core: fix a spurious warning with non-kernel network devices
NMDevice was warning about not being able to set ifindex even on
devices that we know don't have an ifindex.

https://bugzilla.gnome.org/show_bug.cgi?id=739889
2014-11-14 15:36:31 -05:00
Dan Winship
3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Thomas Haller
5f017e96b3 device: fix fetching the IPv6 default route for assumed devices
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-11 12:21:14 +01:00
Dan Williams
5149fd120d iface-helper: add nm-iface-helper for dynamic configure-then-quit support
When quitting, the Manager asks each device to spawn the interface helper,
which persists and manages dynamic address on the interface after NetworkManager
is gone.  If the dynamic address cannot be maintaned, the helper quits and
the interface's address may be removed when their lifetime runs out.

To keep the helper as simple as possible, NetworkManager passes most of the
configuration on the command-line, including some properties of the device's
current state, which are necessary for the helper to maintain DHCP leases
or IPv6 SLAAC addresses.
2014-11-07 12:18:33 -06:00
Dan Williams
49cac9f32f dhcp: track last IPv4 address on start for renewal
Really only used by systemd because it doesn't have as good lease
handling, but it's also necessary if we switch DHCP clients mid-stream
(which we'll be doing later) since the new DHCP client won't
have a lease file for the current IP address, and thus has nowhere
to pull the current IP address from to request the same address
from the DHCP server.
2014-11-07 12:18:33 -06:00
Thomas Haller
5dcd853bff core: even vor MODEM devices don't add IPv6 default routes without gateway
We'll ever have WWAN devices with a NULL gateway because the IPv6 over
WWAN still uses router advertisements to get a prefix. Thus you'll
always have a gateway if the device has real IPv6 connectivity.

For the IPv4 case, we still allow default routes without gateway on
WWAN.

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:23:12 +01:00
Thomas Haller
e8824f6a52 policy: add manager for default routes and support multiple default routes
Up to now, NMPolicy would iterate over all devices to find the "best"
device and assign the default route to that device.

A better approach is to add a default route to *all* devices that
are never-default=no. The relative priority is choosen according to
the route metrics.

If two devices receive the same metric, we want to prefer the device
that activates first. That way, the default route sticks to the same
device until a better device activates or the device deactivates.
Hence, the order of activation is imporant in this case (as it is
already now).

Also, if several devices have identical metrics, increment their
metrics so that every metric is unique.
This makes the routing deterministic according to what we choose as best
device.

A special case is assumed devices. In this case we cannot adjust the metric
in face of equal metrics.

Add a new singleton class NMDefaultRouteManager that has a list of all
devices and their default routes. The manager will order the devices by
their priority and configure the routes using platform.

Also update the metric for VPN connections. Later we will track VPN
routes also via NMDefaultRouteManager. For now, fix the VPN metric because
otherwise VPNs would always get metric 1024 (which is usually much larger then the
device metrics).

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:23:12 +01:00
Thomas Haller
f5c0646e1c device: add function nm_device_uses_assumed_connection()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:23:11 +01:00
Thomas Haller
df923622b1 core: overwrite the default route priority via connection setting
Make use of the new setting nm_setting_ip_config_get_route_metric()
If set, this override the route metric determined based on the device
type.

Similarly for VPN also prefer the setting from the connection. Thereby change
the default priority (for VPN that have their own device) to NM_VPN_ROUTE_METRIC_DEFAULT
instead of NM_PLATFORM_ROUTE_METRIC_DEFAULT. The latter would be a very
low priority compared to the default metrics for devices.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:19:06 +01:00
Thomas Haller
172c1eb652 core: add explicit functions for the route priority/metric
Before, we would always call unanimously nm_device_get_priority()
to get the default route metric for a device. Add new functions
nm_device_get_ip4_route_priority() and nm_device_get_ip6_route_priority()
and use them at the proper places.

Also add new function nm_vpn_connection_get_ip4_route_metric() and
nm_vpn_connection_get_ip6_route_metric().

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:19:06 +01:00
Thomas Haller
a2662633a5 core: modify the values/route metric returned by nm_device_get_priority()
nm_device_get_priority() is used to select the "best" device
for the default route. The absolute values don't matter
at that point and the relative ordering is not changed by
this patch.

It is also directly used for route priority/metric. As we soon
allow the user to overwrite the setting, we want to get more
space between the individual device-types.

That way, a user could overwrite the default metric for a wifi
device to be 109 (making it lower then the default value 110), but
still less preferred then other non-wifi types.

Obviously, this patch is a visible change of behavior as now
routes get different metrics assigned.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:19:06 +01:00
Lubomir Rintel
892602c912 device: Don't delete the link if a re-activation is scheduled 2014-11-07 14:26:41 +01:00
Dan Winship
35f6264745 core, clients: implement dhcp-send-hostname for IPv6
Now that NMSettingIP6Config inherits the dhcp-send-hostname property
from NMSettingIPConfig, fix things up so that it actually gets used.

(Note that this changes behavior: previously if ip6.dhcp-hostname was
unset, no hostname would be sent. Now, the system hostname will be
set. Also, ifcfg-rh does not currently support this property, so there
is no way to disable this...)
2014-11-07 07:49:40 -05:00
Dan Winship
3f30c6f1c2 libnm-core: extract NMSettingIPConfig superclass out of IP4, IP6 classes
Split a base NMSettingIPConfig class out of NMSettingIP4Config and
NMSettingIP6Config, and update things accordingly.

Further simplifications of now-redundant IPv4-vs-IPv6 code are
possible, and should happen in the future.
2014-11-07 07:49:40 -05:00
Dan Winship
21c8a6b20e libnm-core, all: merge IPv4 and IPv6 address/route types
Merge NMIP4Address and NMIP6Address into NMIPAddress, and NMIP4Route
and NMIP6Route into NMIPRoute. The new types represent IP addresses as
strings, rather than in binary, and so are address-family agnostic.
2014-11-07 07:49:40 -05:00
Dan Winship
b108790833 libnm-core: add nm-core-types.h, remove cross-includes
Add nm-core-types.h, typedefing all of the GObject types in
libnm-core; this is needed so that nm-setting.h can reference
NMConnection in addition to nm-connection.h referencing NMSetting.

Removing the cross-includes from the various headers causes lots of
fallout elsewhere. (In particular, nm-utils.h used to include
nm-connection.h, which included every setting header, so any file that
included nm-utils.h automatically got most of the rest of libnm-core
without needing to pay attention to specifics.) Fix this up by
including nm-core-internal.h from those files that are now missing
includes.
2014-10-28 17:17:17 -04:00
Thomas Haller
4ae958757b core: don't use libnm-core private header outside of libnm-core/
Code outside of libnm-core/ should not include the private headers.
nm-core-internal.h should be used instead.

Fixes: 98fe073fb9

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-27 21:12:07 +01:00
Dan Williams
d147c26517 core: autoconnect fixes for default-unmanaged devices and property notification
Previously the only thing preventing default-unmanaged devices from
being auto-activated was luck and the fact that they didn't have any
available connections when in the UNMANAGED state.  That's no longer
true, so we must be more explicit about their behavior.

Furthermore it makes no sense to allow default-unmanaged devices
to set priv->autoconnect=TRUE since that is never supposed to
happen, so enforce that both in NM itself and if the change
request comes in over the D-Bus interface.

Lastly, internal priv->autoconnect=TRUE changes never emitted a
property change notification, meaning the NMPolicy would never
schedule an autoconnect check if the device's priv->autoconnect
was set to TRUE as a result of re-activating or waking from sleep.
2014-10-27 13:46:06 -05:00
Dan Williams
2bf7d6b5db core: loosen master device carrier check before IP configuration
Previously a master device would wait for a carrier before starting
IP configuration only for 'manual' connections, but that's not quite
broad enough.  We also want to allow SHARED methods to proceed
immediately since they are also effectively static/manual configuration.

Use the newly split out methods for checking whether a connection
requires a carrier or not to allow the SHARED method to proceed
for master devices without a carrier.

For example, this allows bridge configurations with tun/tap ports
to set up SHARED addressing before the tun/tap gets a carrier which
only happens when something opens the other side of the tun/tap
(like the VM or container).
2014-10-27 13:46:06 -05:00
Dan Williams
9e1d31763b trivial: move connection_requires_carrer() up
No code change, only move above a future user.
2014-10-27 13:46:06 -05:00
Dan Williams
37da01b517 core: refactor connection_requires_carrier() to split out method checking
The split out functions will be used next for master/slave decisions.
2014-10-27 13:46:06 -05:00
Dan Williams
98fe073fb9 core: use _nm_utils_string_in_list() instead of private function 2014-10-27 13:46:06 -05:00
Dan Williams
07e086dd0d core: shared connections don't require a carrier
They are effectively static connections since the address is manually
assigned, so they do not require a carrier.
2014-10-27 13:46:06 -05:00
Dan Williams
82d62c2c4e core: allow default unmanaged devices to have available connections when unmanaged
Default unmanaged devices become managed when the user explicitly activated
a connection on the device, but the user can't do that unless the device
has some available connections.  Fix things up so that default unmanaged
devices can have available connections.
2014-10-27 13:46:06 -05:00
Dan Winship
4f75ff92b4 libnm-core, libnm, devices: merge client and daemon NMDeviceError
Merge libnm's NMDeviceError and the daemon's NMDeviceError into a
single enum (in nm-errors.h). Register the domain with D-Bus, and add
a test that the client side decodes it correctly.

The daemon's NM_DEVICE_ERROR_CONNECTION_INVALID gets absorbed into
libnm's NM_DEVICE_ERROR_INVALID_CONNECTION, and
NM_DEVICE_ERROR_UNSUPPORTED_DEVICE_TYPE gets dropped, since it was
only returned from one place, which is now using
NM_DEVICE_ERROR_FAILED, since (a) it ought to be a "can't happen", and
(b) the only caller of that function just logs error->message and then
frees the error without ever looking at the code.
2014-10-22 08:29:08 -04:00
Dan Williams
d37b7bed30 core: let kernel add IPv6LL address when method=ignore (rh #1132938)
The IPv6LL address handling in userspace patches failed to handle the
case where the IPv6 method was 'ignore'.  Previously the kernel would
usually add the IPv6LL address itself, but if NM has turned off kernel
IPv6LL then obviously this wouldn't happen.  So when the method is
'ignore', turn off userspace IPv6LL handling and bounce disable_ipv6
to make the kernel add the IPv6LL address if it wants to.
2014-10-21 13:46:43 -05:00
Lubomir Rintel
7d57793004 rdisc,device: set MTU if an appropriate option is present in a RA
https://bugzilla.gnome.org/show_bug.cgi?id=738104

Reported-by: Charles R. Anderson <cra@wpi.edu>
2014-10-20 14:32:38 +02:00
Lubomir Rintel
33866e4030 core: Move NMPlatformSource to nm-types.h
...and rename it while at it. It's going to be useful outside nm-platform,
to weight MTU options from various sources.
2014-10-20 12:41:50 +02:00
Dan Williams
44900a1584 core: ensure interface is up before applying IP configuration (bgo #738479)
Routing configuration fails to apply if the device is not IFF_UP, so if
we're going to apply IP configuration to the device, make sure it's IFF_UP
first.

https://bugzilla.gnome.org/show_bug.cgi?id=738479
2014-10-17 15:21:34 -05:00
Dan Williams
8283672451 core: don't override external route metrics (bgo #738268)
A generated connection contains a copy of the device's existing
configuration, so it's entirely redundant to merge the connection
back into the device's IP config.  But even though that should
result in no changes to the IP config, NMSettingIPxConfig treats a
route metric of '0' as the device priority, while NMIPxConfig
allows 0 as a valid route metric.  Since the setting values
are preferred (they are supposed to be user-supplied and thus
override anythign else, but in this case they are generated and
thus not user-supplied) external routes with a metric of 0 are
overwritten with the device priority metric.

https://bugzilla.gnome.org/show_bug.cgi?id=738268
2014-10-17 15:00:31 -05:00
Thomas Haller
91ec7dac90 core: remove nm_device_get_best_auto_connection()
nm_device_get_best_auto_connection() was only used at one place.
It was a very simple function, just iterated over a list finding
the first can_auto_connect() connection. At the very least, the name
was misleading, because it did not return the 'best', but the 'first'
connection.

Get rid of the function altogether.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-12 20:13:18 +02:00
Thomas Haller
f68faccd7f core: add nm_device_can_auto_connect() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-12 20:13:18 +02:00
Lubomir Rintel
5a040b4058 device: drop leftover bad assert
NetworkManager:ERROR:devices/nm-device.c:7089:nm_device_update_hw_address: assertion failed: (hwaddrlen <= sizeof (priv->hw_addr))
Aborted (core dumped)

Breaks 32-bit, works on 64-bit by dumb luck.

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

Fixes: b019348fdd
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-05 11:29:33 +02:00
Dan Williams
acee2eb9e4 dhcp: fail the device if DHCP fails after having succeeded earlier (rh #1139326)
If DHCP fails to renew or rebind a lease, fail the device since the
IP config is no longer valid.  Commit e2b7c482 was actually wrong for
dhcp[4|6]_fail(), since (ip_state == IP_FAIL) will never be true if
DHCP has ever been started, as IP_FAIL is only set from
nm_device_activate_ip[4|6]_config_timeout(), which obviously will not
be called in DHCP code paths if DHCP has previously succeeded.
2014-10-02 15:02:43 -05:00
Thomas Haller
05494423de auth: rename file nm-manager-auth.* to nm-auth-utils.*
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-29 13:00:11 +02:00
Jiří Klimeš
c9b9229c2e core: do not assert when a device is enslaved externally
Test case:
 # ip link add name BR type bridge
 # brctl addif BR eth0

Monitoring external master/slave changes was intruduced by
08e0cfb484.
2014-09-26 11:17:57 +02:00
Dan Williams
6ae3c1bb82 trivial: quiet error setting userspace IPv6LL if link no longer exists 2014-09-25 16:05:31 -05:00
Thomas Haller
6546e9d1ae core: use "nm-generated-assumed" flag instead of "nm-generated" for assumed connections
At a few places, we checked for nm_device_uses_generated_connection()
whether to touch the device or not. nm_device_uses_generated_connection() used
to look at the "nm-generated" property of the NMSettingsConnection.

We are about to change the meaning of "nm-generated", which will mean
"any connection generated by NM, for whatever reason".

Instead now use the new "nm-generated-assumed" connection flag that has
the meaning "nm-generated" used to have.
So rename nm_device_uses_generated_connection() to nm_device_uses_generated_assumed_connection()
which looks at the "nm-generated-assumed" flag instead.

Also, be more strict in nm_device_uses_generated_assumed_connection() to require
both an "nm-generated-assumed" connection *and* an active connection that is
nm_active_connection_get_assumed().

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-24 16:32:11 +02:00
Thomas Haller
3744544920 core: log when emitting RECHECK_ASSUME signal
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-24 16:12:45 +02:00
Christian Hesse
c668297257 core: only set IPv6 hop_limit for values greater than zero
A "Cur Hop Limit" field value of 0 in a router advertisement means
"unspecified by this router" and should not be set in the kernel.
2014-09-15 12:10:24 -05:00