Skip to content

Commit 838ab80

Browse files
SeppoTakalocarlescufi
authored andcommitted
net: coap: Use 64bit timestamps
Use 64bit timestamps from k_uptime_get() so they don't roll over during the expected device lifetime. Fixes #60826 Signed-off-by: Seppo Takalo <[email protected]>
1 parent 5037e3a commit 838ab80

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

include/zephyr/net/coap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ typedef int (*coap_reply_t)(const struct coap_packet *response,
269269
*/
270270
struct coap_pending {
271271
struct sockaddr addr;
272-
uint32_t t0;
272+
int64_t t0;
273273
uint32_t timeout;
274274
uint16_t id;
275275
uint8_t *data;

samples/net/sockets/coap_server/src/coap-server.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,8 @@ static int large_create_post(struct coap_resource *resource,
954954
static void schedule_next_retransmission(void)
955955
{
956956
struct coap_pending *pending;
957-
int32_t remaining;
958-
uint32_t now = k_uptime_get_32();
957+
int64_t remaining;
958+
int64_t now = k_uptime_get();
959959

960960
/* Get the first pending retransmission to expire after cycling. */
961961
pending = coap_pending_next_to_expire(pendings, NUM_PENDINGS);

subsys/net/lib/coap/coap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ int coap_pending_init(struct coap_pending *pending,
12871287

12881288
pending->data = request->data;
12891289
pending->len = request->offset;
1290-
pending->t0 = k_uptime_get_32();
1290+
pending->t0 = k_uptime_get();
12911291
pending->retries = retries;
12921292

12931293
return 0;
@@ -1382,7 +1382,7 @@ struct coap_pending *coap_pending_next_to_expire(
13821382
{
13831383
struct coap_pending *p, *found = NULL;
13841384
size_t i;
1385-
uint32_t expiry, min_expiry;
1385+
int64_t expiry, min_expiry = INT64_MAX;
13861386

13871387
for (i = 0, p = pendings; i < len; i++, p++) {
13881388
if (!p->timeout) {
@@ -1391,7 +1391,7 @@ struct coap_pending *coap_pending_next_to_expire(
13911391

13921392
expiry = p->t0 + p->timeout;
13931393

1394-
if (!found || (int32_t)(expiry - min_expiry) < 0) {
1394+
if (expiry < min_expiry) {
13951395
min_expiry = expiry;
13961396
found = p;
13971397
}

subsys/net/lib/lwm2m/lwm2m_engine.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ static int64_t retransmit_request(struct lwm2m_ctx *client_ctx, const int64_t ti
368368
continue;
369369
}
370370

371-
/* TODO: will roll over in 47 days */
372371
remaining = p->t0 + p->timeout;
373372
if (remaining < timestamp) {
374373
msg = find_msg(p, NULL);

0 commit comments

Comments
 (0)