mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 13:20:08 +01:00
core: Merge branch 'th/get_monotonic_timestamp'
Add new functions nm_utils_get_monotonic_timestamp_*() to provide means to get timestamps for calculating durations. At several places, we used time() or clock_gettime() for that purpose. Update and unify those places to make use of the new functions. The new functions have the advantage, that the timestamps are guaranteed to be positive and the timestamp is independent of clock adjustments. Internally it uses CLOCK_BOOTTIME/clock_gettime. https://bugzilla.gnome.org/show_bug.cgi?id=720833 Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
commit
adbcd9a1f0
19 changed files with 173 additions and 106 deletions
|
|
@ -754,4 +754,90 @@ nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max
|
|||
}
|
||||
|
||||
|
||||
static gint64 monotonic_timestamp_offset_sec;
|
||||
|
||||
static void
|
||||
monotonic_timestamp_get (struct timespec *tp)
|
||||
{
|
||||
static gboolean initialized = FALSE;
|
||||
int err;
|
||||
|
||||
err = clock_gettime (CLOCK_BOOTTIME, tp);
|
||||
|
||||
g_assert (err == 0); (void)err;
|
||||
g_assert (tp->tv_nsec >= 0 && tp->tv_nsec < NM_UTILS_NS_PER_SECOND);
|
||||
|
||||
if (G_LIKELY (initialized))
|
||||
return;
|
||||
|
||||
/* Calculate an offset for the time stamp.
|
||||
*
|
||||
* We always want positive values, because then we can initialize
|
||||
* a timestamp with 0 and be sure, that it will be less then any
|
||||
* value nm_utils_get_monotonic_timestamp_*() might return.
|
||||
* For this to be true also for nm_utils_get_monotonic_timestamp_s() at
|
||||
* early boot, we have to shift the timestamp to start counting at
|
||||
* least from 1 second onward.
|
||||
*
|
||||
* Another advantage of shifting is, that this way we make use of the whole 31 bit
|
||||
* range of signed int, before the time stamp for nm_utils_get_monotonic_timestamp_s()
|
||||
* wraps (~68 years).
|
||||
**/
|
||||
monotonic_timestamp_offset_sec = (- ((gint64) tp->tv_sec)) + 1;
|
||||
initialized = TRUE;
|
||||
|
||||
if (nm_logging_enabled (LOGL_DEBUG, LOGD_CORE)) {
|
||||
time_t now = time (NULL);
|
||||
struct tm tm;
|
||||
char s[255];
|
||||
|
||||
strftime (s, sizeof (s), "%Y-%m-%d %H:%M:%S", localtime_r (&now, &tm));
|
||||
nm_log_dbg (LOGD_CORE, "monotonic timestamp starts counting with 1.%09ld seconds at "
|
||||
"CLOCK_BOOTTIME=%lld.%09ld (local time is %s)",
|
||||
tp->tv_nsec, (long long)tp->tv_sec, tp->tv_nsec, s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_get_monotonic_timestamp_ms:
|
||||
*
|
||||
* Returns: a monotonically increasing time stamp in milliseconds,
|
||||
* starting at an unspecified offset. See clock_gettime(), %CLOCK_BOOTTIME.
|
||||
*
|
||||
* The returned value will start counting at an undefined point
|
||||
* in the past and will always be positive.
|
||||
**/
|
||||
gint64
|
||||
nm_utils_get_monotonic_timestamp_ms (void)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
||||
monotonic_timestamp_get (&tp);
|
||||
|
||||
/* Although the result will always be positive, we return a signed
|
||||
* integer, which makes it easier to calculate time differences (when
|
||||
* you want to subtract signed values).
|
||||
**/
|
||||
return (((gint64) tp.tv_sec) + monotonic_timestamp_offset_sec) * ((gint64) 1000) +
|
||||
(tp.tv_nsec / (NM_UTILS_NS_PER_SECOND/1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_get_monotonic_timestamp_s:
|
||||
*
|
||||
* Returns: nm_utils_get_monotonic_timestamp_ms() in seconds (throwing
|
||||
* away sub second parts). The returned value will always be positive.
|
||||
*
|
||||
* This value wraps after roughly 68 years which should be fine for any
|
||||
* practical purpose.
|
||||
**/
|
||||
gint32
|
||||
nm_utils_get_monotonic_timestamp_s (void)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
||||
monotonic_timestamp_get (&tp);
|
||||
return (((gint64) tp.tv_sec) + monotonic_timestamp_offset_sec);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -96,4 +96,8 @@ NMConnection *nm_utils_match_connection (GSList *connections,
|
|||
|
||||
gint64 nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback);
|
||||
|
||||
#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000)
|
||||
gint64 nm_utils_get_monotonic_timestamp_ms (void);
|
||||
gint32 nm_utils_get_monotonic_timestamp_s (void);
|
||||
|
||||
#endif /* NETWORK_MANAGER_UTILS_H */
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ typedef struct {
|
|||
/* PPPoE */
|
||||
NMPPPManager *ppp_manager;
|
||||
NMIP4Config *pending_ip4_config;
|
||||
time_t last_pppoe_time;
|
||||
gint32 last_pppoe_time;
|
||||
guint pppoe_wait_id;
|
||||
} NMDeviceEthernetPrivate;
|
||||
|
||||
|
|
@ -949,11 +949,11 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
|
|||
* get confused and fail to negotiate the new connection. (rh #1023503)
|
||||
*/
|
||||
if (priv->last_pppoe_time) {
|
||||
time_t delay = time (NULL) - priv->last_pppoe_time;
|
||||
gint32 delay = nm_utils_get_monotonic_timestamp_s () - priv->last_pppoe_time;
|
||||
|
||||
if (delay < PPPOE_RECONNECT_DELAY && device_get_setting (dev, NM_TYPE_SETTING_PPPOE)) {
|
||||
nm_log_info (LOGD_DEVICE, "(%s) delaying PPPoE reconnect to ensure peer is ready...",
|
||||
nm_device_get_iface (dev));
|
||||
nm_log_info (LOGD_DEVICE, "(%s) delaying PPPoE reconnect for %d seconds to ensure peer is ready...",
|
||||
nm_device_get_iface (dev), delay);
|
||||
g_assert (!priv->pppoe_wait_id);
|
||||
priv->pppoe_wait_id = g_timeout_add_seconds (delay,
|
||||
pppoe_reconnect_delay,
|
||||
|
|
@ -1219,7 +1219,7 @@ deactivate (NMDevice *device)
|
|||
|
||||
/* Set last PPPoE connection time */
|
||||
if (device_get_setting (device, NM_TYPE_SETTING_PPPOE))
|
||||
NM_DEVICE_ETHERNET_GET_PRIVATE (device)->last_pppoe_time = time (NULL);
|
||||
NM_DEVICE_ETHERNET_GET_PRIVATE (device)->last_pppoe_time = nm_utils_get_monotonic_timestamp_s ();
|
||||
|
||||
/* Reset MAC address back to initial address */
|
||||
nm_device_set_hw_addr (device, priv->initial_hw_addr, "reset", LOGD_ETHER);
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ struct _NMDeviceWifiPrivate {
|
|||
guint32 rate;
|
||||
gboolean enabled; /* rfkilled or not */
|
||||
|
||||
time_t scheduled_scan_time;
|
||||
gint32 scheduled_scan_time;
|
||||
guint8 scan_interval; /* seconds */
|
||||
guint pending_scan_id;
|
||||
guint scanlist_cull_id;
|
||||
|
|
@ -1438,7 +1438,7 @@ impl_device_request_scan (NMDeviceWifi *self,
|
|||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
NMDevice *device = NM_DEVICE (self);
|
||||
time_t last_scan;
|
||||
gint32 last_scan;
|
||||
GError *error;
|
||||
|
||||
if ( !priv->enabled
|
||||
|
|
@ -1459,7 +1459,7 @@ impl_device_request_scan (NMDeviceWifi *self,
|
|||
}
|
||||
|
||||
last_scan = nm_supplicant_interface_get_last_scan_time (priv->supplicant.iface);
|
||||
if ((time (NULL) - last_scan) < 10) {
|
||||
if (last_scan && (nm_utils_get_monotonic_timestamp_s () - last_scan) < 10) {
|
||||
error = g_error_new_literal (NM_WIFI_ERROR,
|
||||
NM_WIFI_ERROR_SCAN_NOT_ALLOWED,
|
||||
"Scanning not allowed immediately following previous scan");
|
||||
|
|
@ -1709,7 +1709,7 @@ static void
|
|||
schedule_scan (NMDeviceWifi *self, gboolean backoff)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
time_t now = time (NULL);
|
||||
gint32 now = nm_utils_get_monotonic_timestamp_s ();
|
||||
|
||||
/* Cancel the pending scan if it would happen later than (now + the scan_interval) */
|
||||
if (priv->pending_scan_id) {
|
||||
|
|
@ -1897,7 +1897,7 @@ static gboolean
|
|||
cull_scan_list (NMDeviceWifi *self)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||
time_t now = time (NULL);
|
||||
gint32 now = nm_utils_get_monotonic_timestamp_s ();
|
||||
GSList *outdated_list = NULL;
|
||||
GSList *elt;
|
||||
guint32 removed = 0, total = 0;
|
||||
|
|
@ -1913,6 +1913,7 @@ cull_scan_list (NMDeviceWifi *self)
|
|||
for (elt = priv->ap_list; elt; elt = g_slist_next (elt), total++) {
|
||||
NMAccessPoint *ap = elt->data;
|
||||
const guint prune_interval_s = SCAN_INTERVAL_MAX * 3;
|
||||
gint32 last_seen;
|
||||
|
||||
/* Don't cull the associated AP or manually created APs */
|
||||
if (ap == priv->current_ap)
|
||||
|
|
@ -1930,7 +1931,8 @@ cull_scan_list (NMDeviceWifi *self)
|
|||
&& g_object_get_data (G_OBJECT (ap), WPAS_REMOVED_TAG) == NULL)
|
||||
continue;
|
||||
|
||||
if (nm_ap_get_last_seen (ap) + prune_interval_s < now)
|
||||
last_seen = nm_ap_get_last_seen (ap);
|
||||
if (!last_seen || last_seen + prune_interval_s < now)
|
||||
outdated_list = g_slist_prepend (outdated_list, ap);
|
||||
}
|
||||
|
||||
|
|
@ -2036,7 +2038,7 @@ supplicant_iface_bss_updated_cb (NMSupplicantInterface *iface,
|
|||
/* Update the AP's last-seen property */
|
||||
ap = get_ap_by_supplicant_path (self, object_path);
|
||||
if (ap)
|
||||
nm_ap_set_last_seen (ap, (guint32) time (NULL));
|
||||
nm_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ());
|
||||
|
||||
/* Remove outdated access points */
|
||||
schedule_scanlist_cull (self);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-logging.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
|
|
@ -802,16 +803,6 @@ nm_dhcp_client_foreach_option (NMDHCPClient *self,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static guint32
|
||||
get_time (void)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
||||
clock_gettime (CLOCK_MONOTONIC, &tp);
|
||||
|
||||
return tp.tv_sec;
|
||||
}
|
||||
|
||||
/********************************************/
|
||||
|
||||
static gboolean
|
||||
|
|
@ -1163,7 +1154,7 @@ ip4_options_to_config (NMDHCPClient *self)
|
|||
|
||||
ip4_config = nm_ip4_config_new ();
|
||||
memset (&address, 0, sizeof (address));
|
||||
address.timestamp = get_time ();
|
||||
address.timestamp = nm_utils_get_monotonic_timestamp_s ();
|
||||
|
||||
str = g_hash_table_lookup (priv->options, "new_ip_address");
|
||||
if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) {
|
||||
|
|
@ -1395,7 +1386,7 @@ ip6_options_to_config (NMDHCPClient *self)
|
|||
|
||||
memset (&address, 0, sizeof (address));
|
||||
address.plen = 128;
|
||||
address.timestamp = get_time ();
|
||||
address.timestamp = nm_utils_get_monotonic_timestamp_s ();
|
||||
|
||||
priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
|
||||
g_return_val_if_fail (priv->options != NULL, NULL);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-netlink-monitor.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
|
|
@ -107,18 +108,18 @@ detach_monitor (gpointer data)
|
|||
static void
|
||||
log_error_limited (NMNetlinkMonitor *monitor, guint32 code, const char *fmt, ...)
|
||||
{
|
||||
static time_t rl_time = 0;
|
||||
static gint64 rl_time = -10001;
|
||||
static guint32 rl_code = 0;
|
||||
static guint32 rl_count = 0;
|
||||
va_list args;
|
||||
char *msg;
|
||||
time_t now;
|
||||
gint64 now;
|
||||
|
||||
g_return_if_fail (monitor != NULL);
|
||||
|
||||
now = time (NULL);
|
||||
now = nm_utils_get_monotonic_timestamp_ms ();
|
||||
|
||||
if ((code != rl_code) || (now > rl_time + 10)) {
|
||||
if (code != rl_code || now > rl_time + 10000) {
|
||||
va_start (args, fmt);
|
||||
msg = g_strdup_vprintf (fmt, args);
|
||||
va_end (args);
|
||||
|
|
|
|||
|
|
@ -1252,13 +1252,13 @@ reset_connections_retries (gpointer user_data)
|
|||
NMPolicy *policy = (NMPolicy *) user_data;
|
||||
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
|
||||
GSList *connections, *iter;
|
||||
time_t con_stamp, min_stamp, now;
|
||||
gint32 con_stamp, min_stamp, now;
|
||||
gboolean changed = FALSE;
|
||||
|
||||
priv->reset_retries_id = 0;
|
||||
|
||||
min_stamp = 0;
|
||||
now = time (NULL);
|
||||
now = nm_utils_get_monotonic_timestamp_s ();
|
||||
connections = nm_settings_get_connections (priv->settings);
|
||||
for (iter = connections; iter; iter = g_slist_next (iter)) {
|
||||
NMSettingsConnection *connection = NM_SETTINGS_CONNECTION (iter->data);
|
||||
|
|
@ -1429,10 +1429,10 @@ device_state_changed (NMDevice *device,
|
|||
nm_connection_get_id (NM_CONNECTION (connection)));
|
||||
/* Schedule a handler to reset retries count */
|
||||
if (!priv->reset_retries_id) {
|
||||
time_t retry_time = nm_settings_connection_get_autoconnect_retry_time (connection);
|
||||
gint32 retry_time = nm_settings_connection_get_autoconnect_retry_time (connection);
|
||||
|
||||
g_warn_if_fail (retry_time != 0);
|
||||
priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - time (NULL)), reset_connections_retries, policy);
|
||||
priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - nm_utils_get_monotonic_timestamp_s ()), reset_connections_retries, policy);
|
||||
}
|
||||
}
|
||||
nm_connection_clear_secrets (NM_CONNECTION (connection));
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ typedef struct
|
|||
gboolean fake; /* Whether or not the AP is from a scan */
|
||||
gboolean hotspot; /* Whether the AP is a local device's hotspot network */
|
||||
gboolean broadcast; /* Whether or not the AP is broadcasting (hidden) */
|
||||
glong last_seen; /* Last time the AP was seen in a scan in seconds */
|
||||
gint32 last_seen; /* Timestamp when the AP was seen lastly (obtained via nm_utils_get_monotonic_timestamp_s()) */
|
||||
} NMAccessPointPrivate;
|
||||
|
||||
#define NM_AP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP, NMAccessPointPrivate))
|
||||
|
|
@ -504,7 +504,7 @@ nm_ap_new_from_properties (const char *supplicant_path, GHashTable *properties)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
nm_ap_set_last_seen (ap, (guint32) time (NULL));
|
||||
nm_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ());
|
||||
|
||||
if (!nm_ap_get_ssid (ap))
|
||||
nm_ap_set_broadcast (ap, FALSE);
|
||||
|
|
@ -745,7 +745,7 @@ nm_ap_dump (NMAccessPoint *ap, const char *prefix)
|
|||
nm_log_dbg (LOGD_WIFI_SCAN, " quality %d", priv->strength);
|
||||
nm_log_dbg (LOGD_WIFI_SCAN, " frequency %d", priv->freq);
|
||||
nm_log_dbg (LOGD_WIFI_SCAN, " max rate %d", priv->max_bitrate);
|
||||
nm_log_dbg (LOGD_WIFI_SCAN, " last-seen %ld", priv->last_seen);
|
||||
nm_log_dbg (LOGD_WIFI_SCAN, " last-seen %d", (int) priv->last_seen);
|
||||
}
|
||||
|
||||
const char *
|
||||
|
|
@ -1095,14 +1095,16 @@ void nm_ap_set_broadcast (NMAccessPoint *ap, gboolean broadcast)
|
|||
* APs older than a certain date are dropped from the list.
|
||||
*
|
||||
*/
|
||||
glong nm_ap_get_last_seen (const NMAccessPoint *ap)
|
||||
gint32
|
||||
nm_ap_get_last_seen (const NMAccessPoint *ap)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_AP (ap), FALSE);
|
||||
|
||||
return NM_AP_GET_PRIVATE (ap)->last_seen;
|
||||
}
|
||||
|
||||
void nm_ap_set_last_seen (NMAccessPoint *ap, const glong last_seen)
|
||||
void
|
||||
nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen)
|
||||
{
|
||||
g_return_if_fail (NM_IS_AP (ap));
|
||||
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ void nm_ap_set_fake (NMAccessPoint *ap, gboolean fake);
|
|||
gboolean nm_ap_get_broadcast (NMAccessPoint *ap);
|
||||
void nm_ap_set_broadcast (NMAccessPoint *ap, gboolean broadcast);
|
||||
|
||||
glong nm_ap_get_last_seen (const NMAccessPoint *ap);
|
||||
void nm_ap_set_last_seen (NMAccessPoint *ap, const glong last_seen);
|
||||
gint32 nm_ap_get_last_seen (const NMAccessPoint *ap);
|
||||
void nm_ap_set_last_seen (NMAccessPoint *ap, gint32 last_seen);
|
||||
|
||||
gboolean nm_ap_check_compatible (NMAccessPoint *self,
|
||||
NMConnection *connection);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <netinet/icmp6.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-fake-platform.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
|
|
@ -728,16 +729,6 @@ ip6_address_get_all (NMPlatform *platform, int ifindex)
|
|||
return addresses;
|
||||
}
|
||||
|
||||
static guint32
|
||||
get_time (void)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
||||
clock_gettime (CLOCK_MONOTONIC, &tp);
|
||||
|
||||
return tp.tv_sec;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ip4_address_add (NMPlatform *platform, int ifindex,
|
||||
in_addr_t addr, in_addr_t peer_addr,
|
||||
|
|
@ -752,7 +743,7 @@ ip4_address_add (NMPlatform *platform, int ifindex,
|
|||
address.address = addr;
|
||||
address.peer_address = peer_addr;
|
||||
address.plen = plen;
|
||||
address.timestamp = get_time ();
|
||||
address.timestamp = nm_utils_get_monotonic_timestamp_s ();
|
||||
address.lifetime = lifetime;
|
||||
address.preferred = preferred;
|
||||
|
||||
|
|
@ -791,7 +782,7 @@ ip6_address_add (NMPlatform *platform, int ifindex,
|
|||
address.address = addr;
|
||||
address.peer_address = peer_addr;
|
||||
address.plen = plen;
|
||||
address.timestamp = get_time ();
|
||||
address.timestamp = nm_utils_get_monotonic_timestamp_s ();
|
||||
address.lifetime = lifetime;
|
||||
address.preferred = preferred;
|
||||
address.flags = flags;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
#include <netlink/route/route.h>
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-linux-platform.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-utils.h"
|
||||
|
|
@ -814,16 +815,6 @@ hack_empty_master_iff_lower_up (NMPlatform *platform, struct nl_object *object)
|
|||
rtnl_link_unset_flags (rtnllink, IFF_LOWER_UP);
|
||||
}
|
||||
|
||||
static guint32
|
||||
get_time (void)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
||||
clock_gettime (CLOCK_MONOTONIC, &tp);
|
||||
|
||||
return tp.tv_sec;
|
||||
}
|
||||
|
||||
static void
|
||||
init_ip4_address (NMPlatformIP4Address *address, struct rtnl_addr *rtnladdr)
|
||||
{
|
||||
|
|
@ -836,7 +827,7 @@ init_ip4_address (NMPlatformIP4Address *address, struct rtnl_addr *rtnladdr)
|
|||
|
||||
address->ifindex = rtnl_addr_get_ifindex (rtnladdr);
|
||||
address->plen = rtnl_addr_get_prefixlen (rtnladdr);
|
||||
address->timestamp = get_time ();
|
||||
address->timestamp = nm_utils_get_monotonic_timestamp_s ();
|
||||
address->lifetime = rtnl_addr_get_valid_lifetime (rtnladdr);
|
||||
address->preferred = rtnl_addr_get_preferred_lifetime (rtnladdr);
|
||||
g_assert (nl_addr_get_len (nladdr) == sizeof (address->address));
|
||||
|
|
@ -857,7 +848,7 @@ init_ip6_address (NMPlatformIP6Address *address, struct rtnl_addr *rtnladdr)
|
|||
|
||||
address->ifindex = rtnl_addr_get_ifindex (rtnladdr);
|
||||
address->plen = rtnl_addr_get_prefixlen (rtnladdr);
|
||||
address->timestamp = get_time ();
|
||||
address->timestamp = nm_utils_get_monotonic_timestamp_s ();
|
||||
address->lifetime = rtnl_addr_get_valid_lifetime (rtnladdr);
|
||||
address->preferred = rtnl_addr_get_preferred_lifetime (rtnladdr);
|
||||
address->flags = rtnl_addr_get_flags (rtnladdr);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include <string.h>
|
||||
#include <netlink/route/addr.h>
|
||||
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-platform.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
|
|
@ -1339,16 +1340,6 @@ array_contains_ip6_address (const GArray *addresses, const NMPlatformIP6Address
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static guint32
|
||||
get_time (void)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
||||
clock_gettime (CLOCK_MONOTONIC, &tp);
|
||||
|
||||
return tp.tv_sec;
|
||||
}
|
||||
|
||||
/* Compute (a - b) in an overflow-safe manner. */
|
||||
static guint32
|
||||
subtract_guint32 (guint32 a, guint32 b)
|
||||
|
|
@ -1375,7 +1366,7 @@ nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses)
|
|||
{
|
||||
GArray *addresses;
|
||||
NMPlatformIP4Address *address;
|
||||
guint32 now = get_time ();
|
||||
guint32 now = nm_utils_get_monotonic_timestamp_s ();
|
||||
int i;
|
||||
|
||||
/* Delete unknown addresses */
|
||||
|
|
@ -1428,7 +1419,7 @@ nm_platform_ip6_address_sync (int ifindex, const GArray *known_addresses)
|
|||
{
|
||||
GArray *addresses;
|
||||
NMPlatformIP6Address *address;
|
||||
guint32 now = get_time ();
|
||||
guint32 now = nm_utils_get_monotonic_timestamp_s ();
|
||||
int i;
|
||||
|
||||
/* Delete unknown addresses */
|
||||
|
|
|
|||
|
|
@ -133,6 +133,10 @@ typedef enum {
|
|||
NM_PLATFORM_SOURCE_USER,
|
||||
} NMPlatformSource;
|
||||
|
||||
/**
|
||||
* NMPlatformIP4Address:
|
||||
* @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_s()
|
||||
**/
|
||||
typedef struct {
|
||||
int ifindex;
|
||||
NMPlatformSource source;
|
||||
|
|
@ -144,6 +148,10 @@ typedef struct {
|
|||
guint32 preferred; /* seconds */
|
||||
} NMPlatformIP4Address;
|
||||
|
||||
/**
|
||||
* NMPlatformIP6Address:
|
||||
* @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_s()
|
||||
**/
|
||||
typedef struct {
|
||||
int ifindex;
|
||||
NMPlatformSource source;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "nm-lndp-rdisc.h"
|
||||
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
#define debug(...) nm_log_dbg (LOGD_IP6, __VA_ARGS__)
|
||||
|
|
@ -384,20 +385,10 @@ check_timestamps (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap changed)
|
|||
}
|
||||
}
|
||||
|
||||
static guint32
|
||||
get_time (void)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
||||
clock_gettime (CLOCK_MONOTONIC, &tp);
|
||||
|
||||
return tp.tv_sec;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
timeout_cb (gpointer user_data)
|
||||
{
|
||||
check_timestamps (user_data, get_time (), 0);
|
||||
check_timestamps (user_data, nm_utils_get_monotonic_timestamp_s (), 0);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -470,7 +461,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
|
|||
const char *lladdr = NULL;
|
||||
struct ndp_msgra *msgra = ndp_msgra (msg);
|
||||
NMRDiscGateway gateway;
|
||||
guint32 now = get_time ();
|
||||
guint32 now = nm_utils_get_monotonic_timestamp_s ();
|
||||
int offset;
|
||||
|
||||
if (rdisc->lladdr)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,24 @@
|
|||
AM_CPPFLAGS = \
|
||||
-I${top_srcdir} \
|
||||
-I$(top_srcdir)/include \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/src/devices \
|
||||
-I${top_srcdir}/src/logging \
|
||||
-I${top_srcdir}/src/platform \
|
||||
-I${top_srcdir}/src/posix-signals \
|
||||
-I${top_srcdir}/libnm-util \
|
||||
-I${srcdir}/.. \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(DBUS_CFLAGS) \
|
||||
$(POLKIT_CFLAGS) \
|
||||
$(LIBNL_CFLAGS) \
|
||||
$(LIBNDP_CFLAGS)
|
||||
|
||||
AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
|
||||
AM_LDFLAGS = $(GLIB_LIBS) $(CODE_COVERAGE_LDFLAGS)
|
||||
AM_LDFLAGS = \
|
||||
$(GLIB_LIBS) \
|
||||
$(DBUS_LIBS) \
|
||||
$(CODE_COVERAGE_LDFLAGS)
|
||||
|
||||
@GNOME_CODE_COVERAGE_RULES@
|
||||
|
||||
|
|
@ -17,9 +26,8 @@ noinst_PROGRAMS = \
|
|||
rdisc
|
||||
|
||||
rdisc_SOURCES = \
|
||||
rdisc.c \
|
||||
../nm-rdisc.c \
|
||||
../nm-fake-rdisc.c \
|
||||
../nm-lndp-rdisc.c \
|
||||
../../logging/nm-logging.c
|
||||
rdisc_LDADD = $(LIBNDP_LIBS)
|
||||
rdisc.c
|
||||
rdisc_LDADD = \
|
||||
$(top_builddir)/src/libNetworkManager.la \
|
||||
$(LIBNDP_LIBS)
|
||||
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ typedef struct {
|
|||
GHashTable *seen_bssids; /* Up-to-date BSSIDs that's been seen for the connection */
|
||||
|
||||
int autoconnect_retries;
|
||||
time_t autoconnect_retry_time;
|
||||
gint32 autoconnect_retry_time;
|
||||
NMDeviceStateReason autoconnect_blocked_reason;
|
||||
|
||||
} NMSettingsConnectionPrivate;
|
||||
|
|
@ -1923,7 +1923,7 @@ nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *connection
|
|||
if (retries)
|
||||
priv->autoconnect_retry_time = 0;
|
||||
else
|
||||
priv->autoconnect_retry_time = time (NULL) + AUTOCONNECT_RESET_RETRIES_TIMER;
|
||||
priv->autoconnect_retry_time = nm_utils_get_monotonic_timestamp_s () + AUTOCONNECT_RESET_RETRIES_TIMER;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -1932,7 +1932,7 @@ nm_settings_connection_reset_autoconnect_retries (NMSettingsConnection *connecti
|
|||
nm_settings_connection_set_autoconnect_retries (connection, AUTOCONNECT_RETRIES_DEFAULT);
|
||||
}
|
||||
|
||||
time_t
|
||||
gint32
|
||||
nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *connection)
|
||||
{
|
||||
return NM_SETTINGS_CONNECTION_GET_PRIVATE (connection)->autoconnect_retry_time;
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ void nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *conne
|
|||
int retries);
|
||||
void nm_settings_connection_reset_autoconnect_retries (NMSettingsConnection *connection);
|
||||
|
||||
time_t nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *connection);
|
||||
gint32 nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *connection);
|
||||
|
||||
NMDeviceStateReason nm_settings_connection_get_autoconnect_blocked_reason (NMSettingsConnection *connection);
|
||||
void nm_settings_connection_set_autoconnect_blocked_reason (NMSettingsConnection *connection,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include <string.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-supplicant-interface.h"
|
||||
#include "nm-supplicant-manager.h"
|
||||
#include "nm-logging.h"
|
||||
|
|
@ -106,7 +107,7 @@ typedef struct {
|
|||
guint32 blobs_left;
|
||||
GHashTable * bss_proxies;
|
||||
|
||||
time_t last_scan;
|
||||
gint32 last_scan; /* timestamp as returned by nm_utils_get_monotonic_timestamp_s() */
|
||||
|
||||
NMSupplicantConfig * cfg;
|
||||
|
||||
|
|
@ -167,7 +168,7 @@ bss_properties_changed (DBusGProxy *proxy,
|
|||
NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
|
||||
|
||||
if (priv->scanning)
|
||||
priv->last_scan = time (NULL);
|
||||
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
|
||||
|
||||
if (g_strcmp0 (interface, WPAS_DBUS_IFACE_BSS) == 0)
|
||||
g_signal_emit (self, signals[BSS_UPDATED], 0, dbus_g_proxy_get_path (proxy), props);
|
||||
|
|
@ -230,7 +231,7 @@ wpas_iface_bss_added (DBusGProxy *proxy,
|
|||
NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
|
||||
|
||||
if (priv->scanning)
|
||||
priv->last_scan = time (NULL);
|
||||
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
|
||||
|
||||
handle_new_bss (self, object_path, props);
|
||||
}
|
||||
|
|
@ -334,7 +335,7 @@ set_state (NMSupplicantInterface *self, guint32 new_state)
|
|||
|
||||
if ( priv->state == NM_SUPPLICANT_INTERFACE_STATE_SCANNING
|
||||
|| old_state == NM_SUPPLICANT_INTERFACE_STATE_SCANNING)
|
||||
priv->last_scan = time (NULL);
|
||||
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
|
||||
|
||||
/* Disconnect reason is no longer relevant when not in the DISCONNECTED state */
|
||||
if (priv->state != NM_SUPPLICANT_INTERFACE_STATE_DISCONNECTED)
|
||||
|
|
@ -367,7 +368,7 @@ set_scanning (NMSupplicantInterface *self, gboolean new_scanning)
|
|||
|
||||
/* Cache time of last scan completion */
|
||||
if (priv->scanning == FALSE)
|
||||
priv->last_scan = time (NULL);
|
||||
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
|
||||
|
||||
g_object_notify (G_OBJECT (self), "scanning");
|
||||
}
|
||||
|
|
@ -388,7 +389,7 @@ nm_supplicant_interface_get_scanning (NMSupplicantInterface *self)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
time_t
|
||||
gint32
|
||||
nm_supplicant_interface_get_last_scan_time (NMSupplicantInterface *self)
|
||||
{
|
||||
return NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self)->last_scan;
|
||||
|
|
@ -403,7 +404,7 @@ wpas_iface_scan_done (DBusGProxy *proxy,
|
|||
NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
|
||||
|
||||
/* Cache last scan completed time */
|
||||
priv->last_scan = time (NULL);
|
||||
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
|
||||
g_signal_emit (self, signals[SCAN_DONE], 0, success);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ const char *nm_supplicant_interface_state_to_string (guint32 state);
|
|||
|
||||
gboolean nm_supplicant_interface_get_scanning (NMSupplicantInterface *self);
|
||||
|
||||
time_t nm_supplicant_interface_get_last_scan_time (NMSupplicantInterface *self);
|
||||
gint32 nm_supplicant_interface_get_last_scan_time (NMSupplicantInterface *self);
|
||||
|
||||
const char *nm_supplicant_interface_get_ifname (NMSupplicantInterface *self);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue