summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-07-24 18:53:01 +0200
committerTom Gundersen <teg@jklm.no>2014-07-24 19:02:58 +0200
commitfa94c34b083b5b4019975624453e53d0cbad2a5d (patch)
tree8bd0d0486f7b9f3b0c36e9075bc3999ec7b28c09
parent77ff2de999b7ea6b1b4a3a218fbd9d62bb07cd54 (diff)
libsystemd-network: use CLOCK_BOOTTIME instead of CLOCK_MONOTONIC where possible
The timeouts in the networking library (DHCP lease timeouts and similar) should not be affected by suspend. In the cases where CLOCK_BOOTTIME is not implemented, it is still safe to fallback to CLOCK_MONOTONIC, as the consumers of the library (i.e., networkd) _should_ renew the leases when coming out of suspend.
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c20
-rw-r--r--src/libsystemd-network/sd-dhcp-server.c4
-rw-r--r--src/libsystemd-network/sd-dhcp6-client.c14
-rw-r--r--src/libsystemd-network/sd-icmp6-nd.c6
-rw-r--r--src/libsystemd-network/sd-ipv4ll.c12
-rw-r--r--src/libsystemd-network/test-dhcp-client.c4
-rw-r--r--src/libsystemd-network/test-dhcp6-client.c4
-rw-r--r--src/libsystemd-network/test-icmp6-rs.c4
8 files changed, 34 insertions, 34 deletions
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index f7a4018540..e6225642eb 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -412,7 +412,7 @@ static int client_send_discover(sd_dhcp_client *client) {
/* See RFC2131 section 4.4.1 */
- r = sd_event_now(client->event, CLOCK_MONOTONIC, &time_now);
+ r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
return r;
assert(time_now >= client->start_time);
@@ -612,7 +612,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
assert(client);
assert(client->event);
- r = sd_event_now(client->event, CLOCK_MONOTONIC, &time_now);
+ r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
goto error;
@@ -674,7 +674,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
r = sd_event_add_time(client->event,
&client->timeout_resend,
- CLOCK_MONOTONIC,
+ clock_boottime_or_monotonic(),
next_timeout, 10 * USEC_PER_MSEC,
client_timeout_resend, client);
if (r < 0)
@@ -762,7 +762,7 @@ static int client_initialize_events(sd_dhcp_client *client,
r = sd_event_add_time(client->event,
&client->timeout_resend,
- CLOCK_MONOTONIC,
+ clock_boottime_or_monotonic(),
0, 0,
client_timeout_resend, client);
if (r < 0)
@@ -800,7 +800,7 @@ static int client_start(sd_dhcp_client *client) {
client->fd = r;
if (client->state == DHCP_STATE_INIT) {
- client->start_time = now(CLOCK_MONOTONIC);
+ client->start_time = now(clock_boottime_or_monotonic());
client->secs = 0;
}
@@ -1006,7 +1006,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) {
if (client->lease->lifetime == 0xffffffff)
return 0;
- r = sd_event_now(client->event, CLOCK_MONOTONIC, &time_now);
+ r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
return r;
assert(client->request_sent <= time_now);
@@ -1057,7 +1057,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) {
/* arm lifetime timeout */
r = sd_event_add_time(client->event, &client->timeout_expire,
- CLOCK_MONOTONIC,
+ clock_boottime_or_monotonic(),
lifetime_timeout, 10 * USEC_PER_MSEC,
client_timeout_expire, client);
if (r < 0)
@@ -1079,7 +1079,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) {
/* arm T2 timeout */
r = sd_event_add_time(client->event,
&client->timeout_t2,
- CLOCK_MONOTONIC,
+ clock_boottime_or_monotonic(),
t2_timeout,
10 * USEC_PER_MSEC,
client_timeout_t2, client);
@@ -1102,7 +1102,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) {
/* arm T1 timeout */
r = sd_event_add_time(client->event,
&client->timeout_t1,
- CLOCK_MONOTONIC,
+ clock_boottime_or_monotonic(),
t1_timeout, 10 * USEC_PER_MSEC,
client_timeout_t1, client);
if (r < 0)
@@ -1172,7 +1172,7 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message,
r = sd_event_add_time(client->event,
&client->timeout_resend,
- CLOCK_MONOTONIC,
+ clock_boottime_or_monotonic(),
0, 0,
client_timeout_resend, client);
if (r < 0)
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index 53cf0d7e46..bcf7d1fa2c 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -712,9 +712,9 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
} else
lease = existing_lease;
- r = sd_event_now(server->event, CLOCK_MONOTONIC, &time_now);
+ r = sd_event_now(server->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
- time_now = now(CLOCK_MONOTONIC);
+ time_now = now(clock_boottime_or_monotonic());
lease->expiration = req->lifetime * USEC_PER_SEC + time_now;
r = server_send_ack(server, req, address);
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index 13bed67ad3..c6c82eb349 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -460,7 +460,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
client->retransmit_count++;
- r = sd_event_now(client->event, CLOCK_MONOTONIC, &time_now);
+ r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
goto error;
@@ -484,7 +484,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
client->retransmit_time, 0));
r = sd_event_add_time(client->event, &client->timeout_resend,
- CLOCK_MONOTONIC,
+ clock_boottime_or_monotonic(),
time_now + client->retransmit_time,
10 * USEC_PER_MSEC, client_timeout_resend,
client);
@@ -503,7 +503,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec,
r = sd_event_add_time(client->event,
&client->timeout_resend_expire,
- CLOCK_MONOTONIC,
+ clock_boottime_or_monotonic(),
time_now + max_retransmit_duration,
USEC_PER_SEC,
client_timeout_resend_expire, client);
@@ -908,7 +908,7 @@ static int client_start(sd_dhcp6_client *client, enum DHCP6State state)
case DHCP6_STATE_BOUND:
- r = sd_event_now(client->event, CLOCK_MONOTONIC, &time_now);
+ r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
return r;
@@ -931,7 +931,7 @@ static int client_start(sd_dhcp6_client *client, enum DHCP6State state)
r = sd_event_add_time(client->event,
&client->lease->ia.timeout_t1,
- CLOCK_MONOTONIC, time_now + timeout,
+ clock_boottime_or_monotonic(), time_now + timeout,
10 * USEC_PER_SEC, client_timeout_t1,
client);
if (r < 0)
@@ -951,7 +951,7 @@ static int client_start(sd_dhcp6_client *client, enum DHCP6State state)
r = sd_event_add_time(client->event,
&client->lease->ia.timeout_t2,
- CLOCK_MONOTONIC, time_now + timeout,
+ clock_boottime_or_monotonic(), time_now + timeout,
10 * USEC_PER_SEC, client_timeout_t2,
client);
if (r < 0)
@@ -970,7 +970,7 @@ static int client_start(sd_dhcp6_client *client, enum DHCP6State state)
client->transaction_id = random_u32() & htobe32(0x00ffffff);
r = sd_event_add_time(client->event, &client->timeout_resend,
- CLOCK_MONOTONIC, 0, 0, client_timeout_resend,
+ clock_boottime_or_monotonic(), 0, 0, client_timeout_resend,
client);
if (r < 0)
return r;
diff --git a/src/libsystemd-network/sd-icmp6-nd.c b/src/libsystemd-network/sd-icmp6-nd.c
index 80915c34d6..b264e793ee 100644
--- a/src/libsystemd-network/sd-icmp6-nd.c
+++ b/src/libsystemd-network/sd-icmp6-nd.c
@@ -255,7 +255,7 @@ static int icmp6_router_solicitation_timeout(sd_event_source *s, uint64_t usec,
nd->nd_sent++;
- r = sd_event_now(nd->event, CLOCK_MONOTONIC, &time_now);
+ r = sd_event_now(nd->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0) {
icmp6_nd_notify(nd, r);
return 0;
@@ -263,7 +263,7 @@ static int icmp6_router_solicitation_timeout(sd_event_source *s, uint64_t usec,
next_timeout = time_now + ICMP6_ROUTER_SOLICITATION_INTERVAL;
- r = sd_event_add_time(nd->event, &nd->timeout, CLOCK_MONOTONIC,
+ r = sd_event_add_time(nd->event, &nd->timeout, clock_boottime_or_monotonic(),
next_timeout, 0,
icmp6_router_solicitation_timeout, nd);
if (r < 0) {
@@ -322,7 +322,7 @@ int sd_icmp6_router_solicitation_start(sd_icmp6_nd *nd) {
if (r < 0)
goto error;
- r = sd_event_add_time(nd->event, &nd->timeout, CLOCK_MONOTONIC,
+ r = sd_event_add_time(nd->event, &nd->timeout, clock_boottime_or_monotonic(),
0, 0, icmp6_router_solicitation_timeout, nd);
if (r < 0)
goto error;
diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c
index fd39c12eb2..b17987904a 100644
--- a/src/libsystemd-network/sd-ipv4ll.c
+++ b/src/libsystemd-network/sd-ipv4ll.c
@@ -186,8 +186,8 @@ static void ipv4ll_set_next_wakeup(sd_ipv4ll *ll, int sec, int random_sec) {
if (random_sec)
next_timeout += random_u32() % (random_sec * USEC_PER_SEC);
- if (sd_event_now(ll->event, CLOCK_MONOTONIC, &time_now) < 0)
- time_now = now(CLOCK_MONOTONIC);
+ if (sd_event_now(ll->event, clock_boottime_or_monotonic(), &time_now) < 0)
+ time_now = now(clock_boottime_or_monotonic());
ll->next_wakeup = time_now + next_timeout;
ll->next_wakeup_valid = 1;
@@ -289,7 +289,7 @@ static void ipv4ll_run_state_machine(sd_ipv4ll *ll, IPv4LLTrigger trigger, void
if (ipv4ll_arp_conflict(ll, in_packet)) {
- r = sd_event_now(ll->event, CLOCK_MONOTONIC, &time_now);
+ r = sd_event_now(ll->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
goto out;
@@ -344,7 +344,7 @@ static void ipv4ll_run_state_machine(sd_ipv4ll *ll, IPv4LLTrigger trigger, void
if (ll->next_wakeup_valid) {
ll->timer = sd_event_source_unref(ll->timer);
- r = sd_event_add_time(ll->event, &ll->timer, CLOCK_MONOTONIC,
+ r = sd_event_add_time(ll->event, &ll->timer, clock_boottime_or_monotonic(),
ll->next_wakeup, 0, ipv4ll_timer, ll);
if (r < 0)
goto out;
@@ -562,8 +562,8 @@ int sd_ipv4ll_start (sd_ipv4ll *ll) {
r = sd_event_add_time(ll->event,
&ll->timer,
- CLOCK_MONOTONIC,
- now(CLOCK_MONOTONIC), 0,
+ clock_boottime_or_monotonic(),
+ now(clock_boottime_or_monotonic()), 0,
ipv4ll_timer, ll);
if (r < 0)
diff --git a/src/libsystemd-network/test-dhcp-client.c b/src/libsystemd-network/test-dhcp-client.c
index 7cbe10d5a7..c48aa04b8d 100644
--- a/src/libsystemd-network/test-dhcp-client.c
+++ b/src/libsystemd-network/test-dhcp-client.c
@@ -447,7 +447,7 @@ static int test_addr_acq_recv_discover(size_t size, DHCPMessage *discover) {
}
static void test_addr_acq(sd_event *e) {
- usec_t time_now = now(CLOCK_MONOTONIC);
+ usec_t time_now = now(clock_boottime_or_monotonic());
sd_dhcp_client *client;
int res, r;
@@ -470,7 +470,7 @@ static void test_addr_acq(sd_event *e) {
callback_recv = test_addr_acq_recv_discover;
assert_se(sd_event_add_time(e, &test_hangcheck,
- CLOCK_MONOTONIC,
+ clock_boottime_or_monotonic(),
time_now + 2 * USEC_PER_SEC, 0,
test_dhcp_hangcheck, NULL) >= 0);
diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c
index 5bb410dab3..96c68e1feb 100644
--- a/src/libsystemd-network/test-dhcp6-client.c
+++ b/src/libsystemd-network/test-dhcp6-client.c
@@ -537,7 +537,7 @@ static void test_client_solicit_cb(sd_dhcp6_client *client, int event,
static int test_client_solicit(sd_event *e) {
sd_dhcp6_client *client;
- usec_t time_now = now(CLOCK_MONOTONIC);
+ usec_t time_now = now(clock_boottime_or_monotonic());
if (verbose)
printf("* %s\n", __FUNCTION__);
@@ -553,7 +553,7 @@ static int test_client_solicit(sd_event *e) {
assert_se(sd_dhcp6_client_set_callback(client,
test_client_solicit_cb, e) >= 0);
- assert_se(sd_event_add_time(e, &hangcheck, CLOCK_MONOTONIC,
+ assert_se(sd_event_add_time(e, &hangcheck, clock_boottime_or_monotonic(),
time_now + 2 * USEC_PER_SEC, 0,
test_hangcheck, NULL) >= 0);
diff --git a/src/libsystemd-network/test-icmp6-rs.c b/src/libsystemd-network/test-icmp6-rs.c
index b81211f6bc..afa8562659 100644
--- a/src/libsystemd-network/test-icmp6-rs.c
+++ b/src/libsystemd-network/test-icmp6-rs.c
@@ -108,7 +108,7 @@ static void test_rs_done(sd_icmp6_nd *nd, int event, void *userdata) {
}
static void test_rs(sd_event *e) {
- usec_t time_now = now(CLOCK_MONOTONIC);
+ usec_t time_now = now(clock_boottime_or_monotonic());
sd_icmp6_nd *nd;
if (verbose)
@@ -123,7 +123,7 @@ static void test_rs(sd_event *e) {
assert(sd_icmp6_nd_set_mac(nd, &mac_addr) >= 0);
assert(sd_icmp6_nd_set_callback(nd, test_rs_done, e) >= 0);
- assert(sd_event_add_time(e, &test_hangcheck, CLOCK_MONOTONIC,
+ assert(sd_event_add_time(e, &test_hangcheck, clock_boottime_or_monotonic(),
time_now + 2 *USEC_PER_SEC, 0,
test_rs_hangcheck, NULL) >= 0);