core: use nm_utils_get_monotonic_timestamp_s for timestamp of NMPlatformIP[46]Address

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2013-12-10 19:04:22 +01:00
parent fca51f3717
commit 0535aa44db
7 changed files with 38 additions and 67 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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)

View File

@@ -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)