Commit Graph

15047 Commits

Author SHA1 Message Date
Dan Williams
d00e2147de core: implement PRE_DOWN dispatcher actions (bgo #387832)
https://bugzilla.gnome.org/show_bug.cgi?id=387832
2014-06-06 13:43:46 -05:00
Dan Williams
ce3d2cf0e6 vpn: implement PRE_UP dispatcher actions 2014-06-06 13:43:46 -05:00
Dan Williams
beb5529c42 vpn: make DOWN dispatcher action block on quit
Since the event loop isn't running on quit, but we want to ensure that
scripts can fully process the DOWN event, block on scripts completing
when disconnecting the VPN when quitting.
2014-06-06 13:43:46 -05:00
Dan Williams
e1ec6a5173 vpn: implement PRE_DOWN dispatcher actions (bgo #387832)
https://bugzilla.gnome.org/show_bug.cgi?id=387832
2014-06-06 13:43:46 -05:00
Dan Williams
27cb927d8f dispatcher: convert action_to_string to a table
Oddly, this increases the compiled+stripped size of the object file
by 24 bytes (8296 -> 8320), but I think it produces more readable code.
2014-06-06 13:43:46 -05:00
Dan Williams
19d7386b2f dispatcher: add PRE_UP states
This event runs before a connection/device is announced as
"activated" or "connected", to enable scripts to do things
before applications begin using connectivity.  For example,
this could be used to manage /etc/resolv.conf outside of
NetworkManager and ensure that resolv.conf had correct
information before DNS is used.

Note that this is different than the Debian or Gentoo "pre-up"
event used in /etc/network/interfaces, as that event runs before
any L2 configuration has started.  If we really need an event
like that, we'll add it later as "lower-up".
2014-06-06 13:43:46 -05:00
Dan Williams
286e926ee8 dispatcher: robustify canceling dispatcher calls
Thomas pointed out that using the address of the DispatcherInfo
structure as the dispatcher call ID could cause a mis-cancelation
if malloc re-used the same block in the future.  While the code
should be correctly clearing call IDs after the callback runs
or is canceled, just use numeric IDs to avoid potential crashses.
2014-06-06 13:43:46 -05:00
Dan Williams
90b747fa11 dispatcher: add synchronous dispatcher calls
On shutdown we can't defer the response to a callback, so we need to
use synchronous D-Bus calls.  Second, sometimes we want to block on
the dispatcher response, like for pre-down.
2014-06-06 13:43:46 -05:00
Dan Williams
5150cb88c2 dispatcher: only dispatch if scripts exist
If there are no dispatcher scripts, don't bother dispatching any
events.  This saves some time configuring networking if the event
would have no effect anyway.
2014-06-06 13:43:45 -05:00
Dan Williams
4cc13befd3 dispatcher: rename executable to 'nm-dispatcher' 2014-06-06 13:43:45 -05:00
Dan Williams
c93ae45b42 core: don't do anything interesting in NMDevice dispose()
The NMDevice dispose() function contained some badly-duplicated logic
about when to deactivate a device on its last ref.  This logic should
only run when the device is removed by the manager, since the  manager
controls the device's life-cycle, and the manager knows best when to
clean up the device.  But since it was tied to the device's refcount,
it could have run later than the manager wanted, or not at all.

It gets better.  Dispose duplicated logic that was already done in
nm_device_cleanup(), and then *called* nm_device_cleanup() if the
device was still activated and managed.  But the manager already
unmanages the device when removing it, which triggers a call to
nm_device_cleanup(), takes the device down, and resets the IPv6
sysctl properties, which dispose() duplicated too.  So by the time
dispose() runs, the device should already be unmanaged if the
manager wants to deconfigure it, and most of the dispose() code
should be a no-op.

Clean all that up and remove duplicated functions.  Now, the flow
should be like this:

1) manager decides to remove the device and calls remove_device()
2) if the device should be deconfigured, the manager unmanages
   the device
3) the NMDevice state change handler tears down the active connection
   via nm_device_cleanup() and resets IPv6 sysctl properties
4) when the device's last reference is finally released, only internal
   data members are freed in dispose() because the device should
   already have been cleaned up by the manager and be unmanaged
5) if the device should be left running because it has an assumable
   connection, then the device is not unmanaged, and no cleanup
   happens in the state change handler or in dispose()
2014-06-06 13:43:45 -05:00
Dan Williams
90242d74a9 core: consolidate generic device cleanup tasks
dispose() and nm_device_cleanup() both do common tasks; consolidate
these common tasks in one place and call when appropriate.
2014-06-06 13:43:45 -05:00
Dan Williams
47622420da core: (trivial) some NMDevice dispose/finalize cleanups
Ensure autoip4 is cleaned up when disposing, like we clean up DHCP.

Move things that only free stuff to finalize(), and move things that
unref stuff to dispose (eg, the Firewall Manager stuff).
2014-06-06 13:43:45 -05:00
Dan Williams
4b6f0d50a4 core: fix deactivation of assumed connections on device removal (bgo #729833)
The following procedure leaves an NMActiveConnection around for a deactivated
device, which causes errors in libnm-glib clients when they cannot create the
GObject for the non-existent device of the AC.

1) allow a device which can assume connections to be activated
2) stop NM, which should leave the device's IP configuration up
3) start NM and allow it to assume the device's existing connection
4) remove the device, either by unplugging it or 'rmmod'

The device is removed by nm-manager.c::remove_device(), but the device object
is not moved to UNMANAGED state, leaving the NMActiveConnection completely
unaware the device has gone away.

The nm-manager.c::remove_device() code did not correctly handle moving a
forcibly removed (eg, by unplugging or 'ip link del' or 'rmmod') device to
the UNMANAGED state when the device was active with an assumed connection.
To fix this, make the conditions when the device should be deactivated
on removal much more explicit.

A device should be deactivated on removal if:

1) it is forcibly removed, eg by the kernel network interface being
removed due to 'ip link del' or hotplugging, or internally by NM due
to a parent WWAN interface taking priority over a WWAN ethernet interface

2) if the device cannot assume connections, in which case NetworkManager
must have activated the device and since we cannot assume the connection
on restart, we should deactivate it

3) if the device is not activated, to ensure that its IPv6 parameters
and other things get reset to the pre-NetworkManager values

https://bugzilla.gnome.org/show_bug.cgi?id=729833
2014-06-06 13:43:45 -05:00
Dan Williams
76aa8ce40e core: simplify DHCP cleanup
dhcp6_cleanup() frees priv->dhcp6_ip6_config so dispose() doesn't need
to do that.  Also use g_clear_object() when appropriate.

Lastly, notify that the DHCP4/6 config objects have changed *after*
clearing them, so that the PropertiesChanged signal is emitted with a
blank path to indicate the object is gone.  Previously the PC signal
would have been emitted with the valid path of the DHCP4/6 config object,
but the object would already be dead.
2014-06-06 13:43:45 -05:00
Dan Williams
4809898e08 trivial: simplify nm_device_set_is_nm_owned()
Nothing used its return value or passed FALSE.
2014-06-06 13:43:45 -05:00
Dan Williams
f3fbbf4a77 core: rearrange and remove some NMDevice getters
For any function in nm-device.h which is not used outside of
nm-device.c, remove the public prototypes.  Functions that
are actually used get moved above their caller, and functions
that have no callers are removed.
2014-06-06 13:43:45 -05:00
Dan Williams
b4c368692d core: let NMDevice export itself
Saves some code and a memory allocation.
2014-06-06 13:43:45 -05:00
Dan Williams
c958540bcc core: clean up NMDevice simple getters/setters
Group most of the simple getters together near the top, and remove
getters that have no callers (mtu, firmware-version).
2014-06-06 13:43:44 -05:00
Dan Williams
ef2edfce4f trivial: re-organize IPv6 /proc property util functions 2014-06-06 13:43:44 -05:00
Dan Williams
1856a1c315 core: refactor state/reason string functions to use static tables 2014-06-06 13:43:44 -05:00
Dan Williams
1c737f230f core: re-order NMDevice functions to match current idoms
Move the GObject-related stuff to the bottom of the file and get
rid of no-longer-necessary forward prototypes since the stuff that
required those prototypes is now below the implementation.
2014-06-06 13:43:44 -05:00
Dan Williams
a2fc57beef trivial: remove redundant check
check_if_startup_complete() already checks priv->startup and returns
if it's FALSE.  This if() is redundant.
2014-06-06 13:43:44 -05:00
Dan Williams
d1095e00cb vpn: stop all connections of a service outside of dispose
Future patches will allow blocking dispatcher calls, which we
don't want to happen when deactivating a VPN connection during
normal operation.  So move code that stops VPN connections outside
of the VPNService object's dispose() function and require the object
that owns the VPNService (the VPNManager) to stop connections at the
right times.

When quitting, blocking calls are acceptable (because NetworkManager's
D-Bus interface is no longer useful, plus we can't easily schedule
callbacks because no mainloop is running), so it's ok to stop
connections from NMVPNManager:dispose.
2014-06-06 13:43:44 -05:00
Dan Williams
fbb38ebefe vpn: remove pointless child watch on VPN service daemons
D-Bus already watches the life-cycle, and we'll get a NameOwnerChanged
signal when the VPN service daemon quit.  So the GLib child watch is
just duplicated code that we don't need.  Remove it.
2014-06-06 13:43:44 -05:00
Dan Williams
e957a25db3 vpn: queue additional VPN connections
If a VPN connection is already active, tell it to deactivate and
queue the new VPN connection for activation when the first one is
disconnected.
2014-06-06 13:43:44 -05:00
Dan Williams
b6558ecf47 vpn: consolidate nm_vpn_connection_fail() and nm_vpn_connection_disconnect() 2014-06-06 13:43:44 -05:00
Dan Williams
f3c67726dc vpn: simplify VPN connection lookup 2014-06-06 13:43:44 -05:00
Dan Williams
0596939565 vpn: implement placeholder DEACTIVATING state 2014-06-06 13:43:43 -05:00
Dan Williams
cf62986857 vpn: add DEACTIVATING state
Since NM_VPN_CONNECTION_STATE_* are linear in number and defined API,
we can't add a DEACTIVATING state in the right place.  So create a
NMVPNConnection internal VPN state and convert that to the old
NM_VPN_CONNECTION_STATE_* numbers at exit points from the object.

(This will also allow us to get rid of priv->secrets_req in the future
and fold that into the VPN states)
2014-06-06 13:43:43 -05:00
Dan Williams
13a9f2781a vpn: remove useless 'disposed' member from NMVPNConnection 2014-06-06 13:43:43 -05:00
Dan Williams
c9d183f7fc vpn: simplify duplicate service checking 2014-06-06 13:43:43 -05:00
Dan Williams
063411df42 vpn: remove useless 'disposed' member from NMVPNManager
Just make dispose() able to be called again.
2014-06-06 13:43:43 -05:00
Dan Williams
ca7fd98bbe vpn: simplify creation of VPN service objects 2014-06-06 13:43:43 -05:00
Dan Williams
5d1610b347 vpn: optimize un-needed strlen (trivial) 2014-06-06 13:43:43 -05:00
Dan Williams
4b57f6920e vpn: let VPN services quit themselves
Instead of telling a VPN service to quit, leave that up to the service
itself.  Services based on libnm-glib-vpn already have a quit timeout
of 20 seconds.  We also eventually want to D-Bus activate the VPN
services, and at that point we won't have a PID we can send signals
to.
2014-06-06 13:43:43 -05:00
Dan Williams
8b7eaeb07e vpn: simplify service cleanup 2014-06-06 13:43:43 -05:00
Thomas Haller
26a65f4fe4 platform: fix compiler warning about uninitialized usage
CC       nm-linux-platform.lo
    platform/nm-linux-platform.c: In function '_nm_platform_link_get':
    platform/nm-linux-platform.c:161:17: error: 'rtnllink' may be used uninitialized in this function [-Werror=maybe-uninitialized]
       nl_object_put (*object);
                     ^
    platform/nm-linux-platform.c:1923:35: note: 'rtnllink' was declared here
      auto_nl_object struct rtnl_link *rtnllink;
                                       ^
    cc1: all warnings being treated as errors

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:11:36 +02:00
Thomas Haller
a04df905fd platform: fix format specifyer in _lifetime_to_string() for unsigned
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:05:08 +02:00
Thomas Haller
fcc34ef77b platform: merge branch 'th/bgo727382_platform_fix_addr_lifetime'
https://bugzilla.gnome.org/show_bug.cgi?id=727382

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:02:03 +02:00
Thomas Haller
58b318b53a platform: raise address changed signals for lifetime update
When only the lifetime of an address changes, we did not get a platform signal
as libnl does not consider the time fields in nl_object_diff().
Workaround by comparing the timestamps manually.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:38 +02:00
Thomas Haller
441f337412 platform: refactor setting the source of platform addresses to NM_PLATFORM_SOURCE_KERNEL
Moving setting the source of the address to the init_* functions.

This also has the advantage, that the platform internal to_string functions have the proper
source set.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:38 +02:00
Thomas Haller
2ff046e5aa platform: change address_to_string functions to show remaining lifetime/preferred times
Change the to_string functions to convert the lifetime/preferred values
to the time remaining when the function is evaluated. These functions
are used for printing/debugging, so it's more sensible to show the
remaining time.

On the other hand, for debugging, it's better to see the raw values (also).
In addition to the remaining time we keep to print the timestamps+now if the
address is not permanent. So when inspecting the logs it is possible to figure
out the real values.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:38 +02:00
Thomas Haller
e1410b5a88 platform: refactor calculating valid/preferred times when adding address
Replace the calls to subtract_guint32() by _rebase_relative_time_on_now()
and _address_get_lifetime().

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:37 +02:00
Thomas Haller
d90b9ff2c8 platform: fix setting preferred time for address
Before nm_platform_ip4_address_sync() set the preferred time to the same value
as the address lifetime. The result was that the preferred time was
always identical to valid lifetime.

This will lead to the kernel using the address longer then the desired
preferred time (until validity of the address expires).

https://bugzilla.redhat.com/show_bug.cgi?id=1082041
https://bugzilla.redhat.com/show_bug.cgi?id=1083283

Reported-by: Kai Engert <kengert@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:37 +02:00
Thomas Haller
84cfd06d6a core/platform: limit the preferred time to address lifetime
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1082041

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:37 +02:00
Thomas Haller
8310a039d8 platform: fix preferred and valid lifetimes for addresses from netlink/kernel
The kernel tells the address lifetimes in the 'struct ifa_cacheinfo'
attribute. This contains two timestamps (cstamp and tstamp) and two
relative lifetimes (ifa_prefered and ifa_valid).

The timestamps are equal to clock_gettime(CLOCK_MONOTONIC) scale in
1/100th of a second (wrapping every 497 days).

The preferred/valid times are re-adjusted everytime when sending the
message and count down as the time goes by. In other words, they are
anchored relatively to the moment of when kernel creates the netlink
message.

As platform is caching the rtnl_addr object, the information of *when* the
lifetimes started counting is not available.

This patch fixes reading these values by hacking the libnl object
when it gets received, so that valid and preferred are instead absolute
expiration timestamps in scale nm_utils_get_monotonic_timestamp_s() --
which NM internally is used for address timestamps.

There are two minor downsides to this hack:
- the valid and preferred properties of a cached rtnl_addr object have
  an unexpected meaning, i.e. they are absolute and in a different time
  scale.
- later when converting rtnl_addr to NMPlatformIPAddress, the base
  timestamp is set to "1", i.e. an NMPlatformIPAddress has no knowledge
  of when the address was created or last modified. The timestamp
  property of NMPlatformIPAddress is solely there to anchor the relative
  timestamps lifetime and preferred. Do not use it for anything
  else.
  Another reason the timestamp property is meaningless is that
  its scale nm_utils_get_monotonic_timestamp_s() starts counting at
  process start. So addresses that existed before would have a negative
  or zero timestamp, which we avoid. This in turn could be solved by either
  allowing negative timestamps or by shifting
  nm_utils_get_monotonic_timestamp_*(). Both is viable, but not
  necessary (ATM), because the age of an address has no other apparent
  use then to anchor the relative timestamps.
  Another implication is, that we potentially could get rid of the
  timestamp completely, and insteat make preferred and lifetime be
  absolute expiries.

This will be fixed properly later, by not caching libnl objects but  instead
native NMPlatform objects. For those we have full control over their properties.

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:37 +02:00
Thomas Haller
8f8b247e34 core: add nm_utils_get_monotonic_timestamp_ns() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 19:04:05 +02:00
Thomas Haller
bc34ee7779 core: add code comment to nm_utils_get_monotonic_timestamp_*s() functions
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 19:04:05 +02:00
Jiří Klimeš
3ef79ee249 device: don't call strtol() for NULL strings
#1  0x0000003c47239ea2 in __GI_strtol (nptr=nptr@entry=0x0, endptr=endptr@entry=0x0, base=base@entry=10) at ../stdlib/strtol.c:110
 #2  0x000000000043b896 in update_connection (device=<optimized out>, connection=<optimized out>) at devices/nm-device-bridge.c:308
 #3  0x000000000042ed2f in nm_device_generate_connection (device=device@entry=0xfbb260 [NMDeviceBridge]) at devices/nm-device.c:1644
 #4  0x0000000000481613 in get_existing_connection (device=0xfbb260 [NMDeviceBridge], manager=0xfb2000 [NMManager]) at nm-manager.c:1549
 #5  add_device (self=self@entry=0xfb2000 [NMManager], device=device@entry=0xfbb260 [NMDeviceBridge], generate_con=<optimized out>)
     at nm-manager.c:1688
 #6  0x0000000000481f50 in platform_link_added (plink=0x7fffffffdd50, ifindex=695, self=0xfb2000 [NMManager], reason=<optimized out>)
     at nm-manager.c:2023
 #7  platform_link_cb (platform=<optimized out>, ifindex=695, plink=0x7fffffffdd50, change_type=<optimized out>, reason=<optimized out>,
     user_data=<optimized out>) at nm-manager.c:2038
2014-06-06 18:30:45 +02:00