From: yasuoka Date: Fri, 16 Aug 2024 09:54:21 +0000 (+0000) Subject: Make sure that the uptime field is always updated. Previously it was X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e1af567eac5023f9905a184388576539762d4cf2;p=openbsd Make sure that the uptime field is always updated. Previously it was used before initialized when the database has a session. --- diff --git a/usr.sbin/radiusd/radiusd_ipcp.c b/usr.sbin/radiusd/radiusd_ipcp.c index 308b0b314d3..27cd3c4bd13 100644 --- a/usr.sbin/radiusd/radiusd_ipcp.c +++ b/usr.sbin/radiusd/radiusd_ipcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radiusd_ipcp.c,v 1.11 2024/08/16 09:52:16 yasuoka Exp $ */ +/* $OpenBSD: radiusd_ipcp.c,v 1.12 2024/08/16 09:54:21 yasuoka Exp $ */ /* * Copyright (c) 2024 Internet Initiative Japan Inc. @@ -191,6 +191,7 @@ static void ipcp_put_db(struct module_ipcp *, struct assigned_ipv4 *); static void ipcp_del_db(struct module_ipcp *, struct assigned_ipv4 *); static void ipcp_db_dump_fill_record(struct radiusd_ipcp_db_dump *, int, struct assigned_ipv4 *); +static void ipcp_update_time(struct module_ipcp *); static void ipcp_on_timer(int, short, void *); static void ipcp_schedule_timer(struct module_ipcp *); static void ipcp_dae_send_disconnect_request(struct assigned_ipv4 *); @@ -268,6 +269,7 @@ ipcp_init(struct module_ipcp *self) TAILQ_INIT(&self->daes); self->seq = 1; self->no_session_timeout = true; + ipcp_update_time(self); } void @@ -278,6 +280,7 @@ ipcp_start(void *ctx) struct module_ipcp_dae *dae; int sock; + ipcp_update_time(self); if (self->start_wait == 0) self->start_wait = RADIUSD_IPCP_START_WAIT; @@ -323,6 +326,7 @@ ipcp_stop(void *ctx) struct module_ipcp *self = ctx; struct module_ipcp_dae *dae; + ipcp_update_time(self); /* stop the sockets for DAE */ TAILQ_FOREACH(dae, &self->daes, next) { if (dae->sock >= 0) { @@ -562,6 +566,7 @@ ipcp_dispatch_control(void *ctx, struct imsg *imsg) struct radiusctl_client *client; const char *cause; + ipcp_update_time(self); datalen = imsg->hdr.len - IMSG_HEADER_SIZE; switch (imsg->hdr.type) { case IMSG_RADIUSD_MODULE_CTRL_UNBIND: @@ -717,7 +722,7 @@ ipcp_resdeco(void *ctx, u_int q_id, const u_char *req, size_t reqlen, struct user *user = NULL; struct assigned_ipv4 *assigned = NULL, *assign; - clock_gettime(CLOCK_BOOTTIME, &self->uptime); + ipcp_update_time(self); if ((radres = radius_convert_packet(res, reslen)) == NULL) { log_warn("%s: radius_convert_packet() failed", __func__); @@ -1008,7 +1013,7 @@ ipcp_accounting_request(void *ctx, u_int q_id, const u_char *pkt, stat; struct module_ipcp_dae *dae; - clock_gettime(CLOCK_BOOTTIME, &self->uptime); + ipcp_update_time(self); if ((radpkt = radius_convert_packet(pkt, pktlen)) == NULL) { log_warn("%s: radius_convert_packet() failed", __func__); @@ -1472,12 +1477,18 @@ ipcp_db_dump_fill_record(struct radiusd_ipcp_db_dump *dump, int idx, /*********************************************************************** * Timer ***********************************************************************/ +void +ipcp_update_time(struct module_ipcp *self) +{ + clock_gettime(CLOCK_BOOTTIME, &self->uptime); +} + void ipcp_on_timer(int fd, short ev, void *ctx) { struct module_ipcp *self = ctx; - clock_gettime(CLOCK_BOOTTIME, &self->uptime); + ipcp_update_time(self); ipcp_schedule_timer(self); } @@ -1606,6 +1617,8 @@ ipcp_dae_on_event(int fd, short ev, void *ctx) const char *cause = ""; struct radiusctl_client *client; + ipcp_update_time(self); + if ((ev & EV_READ) == 0) return;