Commit graph

262 commits

Author SHA1 Message Date
Dan Winship
10a4df690c devices: propagate the hop limit from an IPv6 RA to the kernel config
If we set accept_ra_defrtr=0 then the kernel will ignore the "hop
limit" too. So parse it out of the RA and set it manually.
2014-02-27 15:28:11 -05:00
Dan Winship
c04db133fc devices: be more precise about kernel IPv6 RA handling
We don't want the kernel to do IPv6 addrconf, but we do want it to
notice the non-router-related fields in the RA (eg, Retrans Timer) and
update the interface state to reflect them. So instead of turning off
accept_ra, we leave it turned on, and turn off accept_ra_defrtr,
accept_ra_rtr_pref, and accept_ra_pinfo instead.
2014-02-27 15:28:11 -05:00
Dan Winship
6136630163 devices: abstract the handling of IPv6 sysfs properties
We're about to start using a bunch more IPv6 sysfs properties, so
let's start by making the code more extensible.
2014-02-27 15:28:11 -05:00
Dan Williams
4040198b47 core: queue re-activations to allow DEACTIVATING state
If a device is already activated, queue the new activation to allow
the transition through the DEACTIVATING state.

---

Also remove the "HACK" bits in nm_device_deactivate(). This hack was
added on 2007-09-25 in commit 9c2848d.  At the time, with user settings
services, if a client created a connection and requested that NM
activate it, NM may not have read the connection from the client over
D-Bus yet.  So NM created a "deferred" activation request which waited
until the connection was read from the client, and then began activation.

The Policy watched for device state changes and other events (like
it does now) and activated a new device if the old one was no longer
valid.  It specifically checked for deferred activations and then
did nothing.  However, when the client's connection was read, then
nm-device.c cleared the deferred activation bit, leading to a short
period of time where the device was in DISCONNECTED state but there
was no deferred activation, because the device only changes state to
PREPARE from the idle handler for stage1.  If other events happened
during this time, the policy would tear down the device that was
about to be activated. This early state transition to PREPARE
worked around that.

We need to remove it now though, because (a) the reason for its
existence is no longer valid, and (b) _device_activate() may now
be called from inside nm_device_state_changed() and thus it cannot
change to a new state inside the function.
2014-02-25 18:03:02 -06:00
Thomas Haller
d3a2219cee replace snprintf by g_snprintf
Use the glib wrapper for snprintf.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-24 21:35:33 +01:00
Thomas Haller
93e4e0f8a1 core: minor fix to ensure we call platform functions with positive ifindex
Actually, get_ip_ifindex() should always return 0 or > 0. Just in case,
be extra careful and modify the conditions.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-23 22:31:49 +01:00
Thomas Haller
dd2ce3dfbc core: fix waiting for bringing up/taking down device
This fixes a regression introduced in 5074898591.
The while loop did only refetch the cached value (because the glib main loop
was blocked and only the cached device flags were checked).

Also, instead on relying of g_usleep(), wait until a maximum time of waiting
is expired. The duration of g_usleep() might not be very accurate.

Also, do no longer check the cached device state before setting the
device flag. The cache might be out of date, so we just set the flag.

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-23 22:31:49 +01:00
Thomas Haller
2e1db48e71 core: ensure proper handling of sysctl paths in NMDevice (set NULL on dispose)
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-31 14:52:14 +01:00
Thomas Haller
1dea271469 core/rdisc: add support for IPv6 privacy
Add support for ipv6-private addresses. This feature
needs support from the kernel and libnl.

If there is no system support, temporary addresses are
not supported. Log a warning in this case.

Depending on whether ipv6-privacy (use_tempaddr) is enabled,
we add the address flag IFA_F_MANAGETEMPADDR and the kernel
will add temporary addresses for us.

https://bugzilla.gnome.org/show_bug.cgi?id=705170
https://bugzilla.redhat.com/show_bug.cgi?id=1003859
https://bugzilla.redhat.com/show_bug.cgi?id=1047139

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-30 17:04:36 +01:00
Thomas Haller
39cbe772a6 core/rdisc: add autoconf addresses as /64 (instead of /128)
This feature needs support from the kernel and libnl.

If there is no system support, NM acts as before, adding the
autoconf address as /128. It does so, to prevent the kernel
from adding a route for this prefix. With system support, we
add the address as /64 and set the flag IFA_F_NOPREFIXROUTE.

https://bugzilla.redhat.com/show_bug.cgi?id=1044590
https://bugzilla.redhat.com/show_bug.cgi?id=1045118

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-30 17:04:36 +01:00
Thomas Haller
84dc64c8af core/rdisc: limit the number of autoconf addresses to 'max_addresses'
NetworkManager uses the sysctl value 'max_addresses' as the kernel does.
There is however a difference in what addresses are taken into account.
The kernel counts all addresses on the interface (including temporary,
private addresses and user configured ones).
NM instead only limits the number of public autoconf addresses to
'max_addresses'. This is because it is difficult for NM to count all
addresses (which can come from different sources) and it is not
necessarily a more logical behavior. Only be aware, that NM uses
the same config value as the kernel, but counts differently.

Especially, the kernel might reach the limit earlier then NM in the
presence of temporary addresses or addresses not from SLAAC.

Note, that the kernel uses 'max_addresses' only to limit public, autoconf
addresses. So this limit does not affect NM adding as many addresses as
it wants.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-30 17:04:36 +01:00
Dan Williams
067db6f8d7 core/platform: add address/route sources (rh#1005416, bgo#722843)
Tag addresses and routes with their source.  We'll use this later to do
(or not do) operations based on where the item came from.

One thing to note is that when synchronizing items with the kernel, all
items are read as source=KERNEL even when they originally came from
NetworkManager, since the kernel has no way of providing this source
information.  This requires the source 'priority', which
nm_ip*_config_add_address() and nm_ip*_config_add_route() must respect
to ensure that NM-owned routes don't have their source overwritten
when merging various IP configs in ip*_config_merge_and_apply().

Also of note is that memcmp() can no longer be used to compare
addresses/routes in nm-platform.c, but this had problems before
anyway with ifindex, so that workaround from nm_platform_ip4_route_sync()
can be removed.

https://bugzilla.gnome.org/show_bug.cgi?id=722843
https://bugzilla.redhat.com/show_bug.cgi?id=1005416
2014-01-24 09:42:52 -06:00
Dan Williams
32a001f526 core: allow custom IP address ranges for Shared connections (bgo #675973)
Given an IPv4 address and prefix for a shared config, figure out
the DHCP address range automatically.  To keep things simple we
allow a max of 252 addresses (not including network address,
broadcast address, and the hotspot) no matter what prefix you use,
so if the address is 10.0.10.1, you still only get a range of
10.0.10.2 -> 10.0.10.254.

But we also leave some addresses available above the host address
for static stuff, like we did before.  This is done on a sliding
scale from 0 to 8 addresses, where about 1/10th the number of
available addresses are reserved.

https://bugzilla.gnome.org/show_bug.cgi?id=675973
2014-01-23 16:21:01 -06:00
Dan Williams
13f4a00d4d core: only log about IPv6 Commit the first time
Since IPv6 configuration gets updated every time a router advertisement
comes in, it can lead NM to continuously logging:

NetworkManager: <info> Activation (eth0) Stage 5 of 5 (IPv6 Commit) scheduled...
NetworkManager: <info> Activation (eth0) Stage 5 of 5 (IPv6 Commit) started...
NetworkManager: <info> Activation (eth0) Stage 5 of 5 (IPv6 Commit) complete.

that's annoying.  So after the initial configuration is done, make
subsequent IPv6 Commit log messages debug instead of info.
2014-01-23 16:06:01 -06:00
Dan Williams
6e8345d89b core: don't disable IPv6 when assuming connections (rh #1052157)
Don't disable IPv6 when we're about to assume a connection that may well
have IPv6 already configured on the interface, which removes all addresses
and routes from the interface and generally Breaks Stuff.
2014-01-23 16:05:44 -06:00
Dan Winship
e2ab0eaf75 devices: when disconnecting master, propagate reason to the slaves
When disconnecting a master device, propagate its NMDeviceStateReason
to the slaves. That way, if the reason is USER_REQUESTED, then the
slaves will be blocked from re-autoconnecting as well.
2014-01-23 15:16:09 -05:00
Dan Winship
5cac8dad79 devices: add :master property
Add a property to NMDevice that can be used to tell whether the device
is enslaved, and if so what its master is.

This is currently internal-only, but it could be exported later
perhaps.
2014-01-23 15:16:09 -05:00
Dan Winship
979b8920b4 core: move virtual device autoconnect tracking bits out of NMManager
Virtual devices may be created and destroyed, but we need to keep
their autoconnect state across that. Previously this was handled by
NMManager, but it really belongs with the other autoconnect tracking
in NMPolicy and NMSettingsConnection.

This also fixes a bug where NMPolicy would sometimes decide to
autoactivate a virtual device connection which NMManager would then
have to cancel.
2014-01-23 15:16:09 -05:00
Dan Winship
c4fc72c795 devices: start using the DEACTIVATING state
When a device is disconnected by the user (as opposed to due to
network or hardware error, etc), set it first to DEACTIVATING, which
does nothing but queue a transition to disconnected. This lets other
parts of NM observe the device when it is about-to-disconnect, but
still has an associated connection.
2014-01-23 15:15:00 -05:00
Dan Winship
3d30ff01ef core: remove useless NMSettings::connections-loaded signal
NMSettings (and NMConnectionProvider) had a signal to indicate when it
had loaded the connections, but in reality this always happened before
nm_settings_new() returned (as a side effect of calling
unmanaged_specs_changed()) and so no one else would ever actually see
the signal. So just kill it.
2014-01-23 15:14:49 -05:00
Thomas Haller
2b87dbb2a9 core: cleanup data types for nm_platform_sysctl_get_int32()
The sysctl values in the kernel (for those values for which
nm_platform_sysctl_get_uint() is currently used) are defined as s32.
Change nm_platform_sysctl_get_uint() to nm_platform_sysctl_get_int32()
and ensure, that a matching integer type is used thoroughly.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-22 12:23:58 +01:00
Dan Williams
eb8bc5396e core: respect connection user permissions for activation/deactivation
This appears to be a bug since the original 0.9.0 release when
connection permissions were implemented.

If all the following are true:
- the user is local (as determined by systemd or ConsoleKit)
- the user has been given the NETWORK_CONTROL PolicyKit permission
- the user is not listed in the connection's permissions
- the user knows the D-Bus object path of a connection which they
have no permissions for

then that user may activate/deactivate connections that are not
visible to that user as determined by the connection permissions.
Fix that by ensuring that these operations check whether the user
has permission.

These operations are *not* affected, and have always checked user
permissions before allowing the operation:
- modifying any connection details
- requesting any secrets or passwords for the connection
- deleting the connection
2014-01-21 12:18:49 -06:00
Dan Williams
91eafe95a3 core: fix stale DHCPv6 information for dispatcher lease-change events (bgo #721002)
dhcp6_lease_change() needs to be called *after* updating the DHCP config
object to ensure that the dispatcher gets the new values.
2014-01-06 16:08:06 -06:00
Scott Shambarger
a30030b82b core: fix stale DHCPv4 information for dispatcher lease-change events (bgo #721002)
dhcp4_lease_change() needs to be called *after* updating the DHCP config
object to ensure that the dispatcher gets the new values.
2014-01-06 16:07:57 -06:00
Dan Winship
0e3432fbea logging: tweak logging-enabled functions
Rather than having separate nm_logging_level_enabled() and
nm_logging_domain_enabled(), have just nm_logging_enabled() that
checks both.
2013-12-20 09:57:13 -05:00
Dan Winship
f2413ae498 devices: don't try to capture resolv.conf if not managing it (rh #1035861)
If NM is not explicitly managing resolv.conf (either due to the "dns"
NetworkManager.conf setting, or because resolv.conf is immutable),
then don't try to parse nameservers out of it when capturing a
connection, since there's no reason to believe that the name servers
there are related to any particular connection.
2013-12-20 09:28:01 -05:00
Jiří Klimeš
44bd2275e7 device: add 'mtu' property 2013-12-20 11:37:54 +01:00
Dan Williams
5ef3d9027d trivial: show interface name in IPv6 rdisc log message 2013-12-19 12:06:54 -06:00
Dan Williams
5f1a62877c rdisc: clear domain list when updating from RA
Appears to be a simple oversight.  If the IPv6 router changes the
domain list, old domains could stick around.
2013-12-19 12:06:54 -06:00
Jiří Klimeš
1e3edc176b device: add missing state-change reasons to reason_to_string() 2013-12-19 10:00:00 +01:00
Jiří Klimeš
7e95d03f44 device: fix compilation in nm_device_add_pending_action()
The function doesn't return any value.
2013-12-19 10:00:00 +01:00
Thomas Haller
813ea5995b core: allow dynamic strings for pending action names
Use a GSList of the string values, instead of an array of GQuarks.
Using GQuarks does not allow to add arbitrary strings, because they
would leak the internalized strings.  The next patch will begin
using unique, non-const action strings.

Given the rather small number of expected pending states, a singly
linked list seems appropriate.

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

(some fixes and simplifications by dcbw based on patch reviews)
2013-12-18 12:35:44 -06:00
Thomas Haller
bb9deec9ef core: fix NMDevice.ip6_use_tempaddr to avoid buffer overrun for zero char in config file
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-13 20:49:27 +01:00
Dan Williams
2556aa32ed core: ensure 'activation' pending action encompasses full activation process
The NMActiveConnection class tracks the full activation request, and internal
activation requests go through the same process as external ones, including
some authentication.  Sometimes that means activation is scheduled, control
returns to the mainloop, and then the activation proceeds from an idle
handler.

Unfortunately, that means that adding a pending "activation" action from
nm-device.c doesn't always work, since there is a short window between when
the activation is started in nm-manager.c (in nm_manager_activate_connection())
and when the device actually changes state.  Inside that window, the pending
actions may drop to zero, and startup will be declared complete before the
device actually starts activating.

Instead, ensure that the pending action is added when the internal activation
is actually started (eg, when NMActiveConnection receives the NMDevice object).
2013-12-12 11:16:51 -06:00
Dan Williams
61463ed2ab core: delay startup complete until carrier is found or timeout (rh #1034921) (rh #1030583)
Carrier state is only valid if the network interface is IFF_UP, because drivers
are not required to do carrier detection if the device is not up.  Thus, if NM
is the first process to set the interface IFF_UP, there may be a short delay
while the driver performs carrier detection.  NetworkManager must suppress
"startup complete" during this delay to ensure that the carrier state is known
before making startup property decisions.

Previously, when NetworkManager set the interface IFF_UP, the interface would
not have a carrier for a few seconds until the driver's carrier detection was
done.  Since the interface had no carrier, NetworkManager could not begin
connection activation on the interface, and the interface would not suppress
the "startup complete" transition.  Thus, NetworkManager would declare that
startup was complete prematurely and anything depending on startup network
connectivity would fail as no interfaces were active.

https://bugzilla.redhat.com/show_bug.cgi?id=1034921
https://bugzilla.redhat.com/show_bug.cgi?id=1030583
2013-12-12 11:16:51 -06:00
Dan Williams
b2cec90b79 core: convert pending actions from a counter to a GArray
This lets us do two things:

1) ensure that pending actions are unique and not doubly added/removed
2) we can (eventually) print out the pending action list for debugging

However, since we cannot have two pending actions with the same name at
the same time, we need to change the queued device state actions to
include the state name.  But that makes debugging even more descriptive
so it's a bonus.
2013-12-12 11:16:51 -06:00
Jiří Klimeš
d0c2a24b71 device: do not remove software devices on initial disconnected (rh #1035814)
When a device is initialized to be managed, it will transition through states
unmanaged -> unavailable -> disconnected. We don't want to remove software
devices during this initial transition to disconnected, because it prevents
auto-activation.

Test case:
$ nmcli con add type vlan ifname myvlan dev eth0 id 123
NM should immediately create myvlan interface and automatically activate it.

https://bugzilla.redhat.com/show_bug.cgi?id=1035814
2013-12-04 14:08:30 +01:00
Dan Williams
ea5c30b1d9 core: generated slave connections should not have IP settings
Slaves have no IP configuration and should not have any IP settings.
This fixes connection comparison between generated slave connections
and persistent slave connections, as persistent slave connections won't
have any IP configuration.
2013-12-02 15:32:31 -06:00
Dan Williams
038e45d29a Revert "device: bind the generated loopback connection to 'lo' interface"
This reverts commit 9a019f1fb5.

Generic connections should be bound to their interface names in a more generic
way instead of in nm-device.c.  The Generic device itself should set the
attributes it needs when generating the connection, like other device types do.
This will be done in a following commit.
2013-12-02 15:32:23 -06:00
Dan Winship
ff93ed672b devices: if IP4 and IP6 config both fail right away, fail the device
Previously, the device activation would stall in this case, because
the code wasn't expecting it to happen. In particular, this happens
when trying to assume a device that is up but has no IP config.

https://bugzilla.gnome.org/show_bug.cgi?id=715181
2013-11-27 08:54:18 -05:00
Dan Williams
12d96c30f2 core: capture DNS configuration from resolv.conf when generating connections
If the interface who's IP configuration is being captured has the default
route, then read DNS servers from resolv.conf into the NMIP[4|6]Config.

This allows NetworkManager to repopulate resolv.conf if anything changes.
For example, if the system does not define a persistent hostname, then
when a device which has generated a connection activates, a hostname
lookup will be performed.  The results of that lookup may change resolv.conf,
and thus NetworkManager must rewrite resolv.conf.  Without capturing
DNS information at startup when generating connections, an empty
resolv.conf would be written.
2013-11-22 15:01:10 -06:00
Dan Williams
7994778723 core: ignore RA-provided default routes (rh #1029213)
The router has no idea what the local configuration or user preferences are,
so sending routes with a prefix length of 0 is at best misinformed and at
worst breaks things.  The kernel also ignores plen=0 routes in its in-kernel
RA processing code in net/ipv6/ndisc.c.

https://bugzilla.redhat.com/show_bug.cgi?id=1029213
2013-11-20 14:24:38 -06:00
Jiří Klimeš
f93c154161 device: remove invalid assertion in slave_state_changed()
When activating a team slave and 'teamd' binary is not installed, the
priv->state of master device will be NM_DEVICE_STATE_FAILED, which is greater
than NM_DEVICE_STATE_ACTIVATED.

<info> Activation (nm-team) Stage 1 of 5 (Device Prepare) started...
<warn> Activation (nm-team) to start teamd: not found
<info> (nm-team): device state change: prepare -> failed (reason 'none') [40 120 0]
...
<debug> master_state_cb(): (0x81d6968): master ActiveConnection [0x91d69d0] 'team0' failed
<info> (eth1): device state change: config -> failed (reason 'dependency-failed') [50 120 50]
...
<debug> slave_state_changed(): (nm-team): slave eth1 state change 50 (config) -> 120 (failed)
--- ASSERTION ---
2013-11-18 14:24:10 -06:00
Dan Williams
63d486b4de trivial: fix some prototypes 2013-11-18 12:06:10 -06:00
Dan Winship
65737d9e48 devices: use disable_ipv6 as appropriate
Set and clear disable_ipv6 on devices as needed to ensure that:

  1) devices never get IPv6 link local addresses until they are
     actually activated

  2) devices always lose their IPv6 link local addresses when they are
     deactivated

  3) slaves never get IPv6 link local addresses at all

https://bugzilla.gnome.org/show_bug.cgi?id=700414
https://bugzilla.redhat.com/show_bug.cgi?id=1004255
2013-11-15 10:50:45 -05:00
Dan Winship
7496cc3db2 devices: enable/disable kernel IPv6 autoconf at the appropriate times
Set accept_ra and use_tempaddr to "0" when managing a device (and
restore them to their original values after unmanaging it) to ensure
that calling nm_device_bring_up() on a managed device won't ever cause
kernel IPv6 autoconf to happen. Remove some other redundant accept_ra
setting.

Fix up the deconfigure case of dispose() to clear the device's IP6
config as well as its IP4 config.

https://bugzilla.gnome.org/show_bug.cgi?id=700414
2013-11-15 10:49:43 -05:00
Dan Winship
29dc6d1ebe devices: clean up accept_ra/use_tempaddr handling
update_accept_ra_path() and update_ip6_privacy_save() were freeing
their path variables if they failed to read the existing values, but
if this ever actually happened it would cause problems later since
other code assumed that the variables were always set. Use
"priv->ip6_accept_ra_save = -1", etc, instead to indicate that the
value couldn't be read (and so shouldn't be restored later).

Merge the accept_ra and use_tempaddr code save/restore code together,
since they're always called together.

Fix the accept_ra-restoring code to correctly handle an original value
of "2".

Call update_ip6_properties_paths() from nm_device_set_ip_iface()
rather than act_stage3_ip6_config_start(), since set_ip_iface() is
when the paths actually change. Also, split the default-value-saving
code out into a separate function, since we only care about doing that
at construct time; if the IP6 property paths change later (because
iface != ip_iface), then we don't need to save and restore the values
on the ip_iface, since the interface will go away when we're done with
it.

https://bugzilla.gnome.org/show_bug.cgi?id=700414
2013-11-15 10:49:43 -05:00
Dan Winship
ee2b50fce8 devices: rename ip6_privacy_tempaddr_* vars to match sysctl
Rename ip6_privacy_tempaddr_path and ip6_privacy_tempaddr_save to
ip6_use_tempaddr_*, to match the sysctls, for consistency with the
accept_ra variables.
2013-11-15 10:49:43 -05:00
Dan Winship
46295e8fa1 devices: "deactivate" devices when going from UNMANAGED->UNAVAILABLE
We used to call nm_device_deactivate() when moving a device from
UNMANAGED to UNAVAILABLE (unless we were assuming the existing
connection), but this got lost when default-unmanaged was added. Fix
it to do this again, so the device will be in a known-clean state when
it is activated.
2013-11-15 10:49:43 -05:00
Dan Winship
7bc7da83ec core: remove redundant sysctl utilities
NMDevice was still using the old sysctl functions from
NetworkManagerUtils rather than the new NMPlatform ones. Fix it, and
remove the old functions.
2013-11-15 10:49:43 -05:00