Skip to content

Commit cf3669d

Browse files
committed
Don't count a session that didn't start within start-wait seconds for
user-max-session. Delete it instead.
1 parent 5a385b2 commit cf3669d

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

usr.sbin/radiusd/radiusd_ipcp.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: radiusd_ipcp.c,v 1.23 2025/01/29 10:16:05 yasuoka Exp $ */
1+
/* $OpenBSD: radiusd_ipcp.c,v 1.24 2025/06/19 09:24:49 yasuoka Exp $ */
22

33
/*
44
* Copyright (c) 2024 Internet Initiative Japan Inc.
@@ -180,6 +180,9 @@ struct assigned_ipv4
180180
struct in_addr);
181181
static struct assigned_ipv4
182182
*ipcp_ipv4_find(struct module_ipcp *, struct in_addr);
183+
static struct assigned_ipv4
184+
*ipcp_ipv4_check_valid(struct module_ipcp *,
185+
struct assigned_ipv4 *);
183186
static void ipcp_ipv4_delete(struct module_ipcp *,
184187
struct assigned_ipv4 *, const char *);
185188
static void ipcp_ipv4_release(struct module_ipcp *,
@@ -740,7 +743,7 @@ ipcp_resdeco(void *ctx, u_int q_id, const u_char *req, size_t reqlen,
740743
bool found = false;
741744
char username[256], buf[128];
742745
struct user *user = NULL;
743-
struct assigned_ipv4 *assigned = NULL, *assign;
746+
struct assigned_ipv4 *assigned = NULL, *assign, *assignt;
744747

745748
ipcp_update_time(self);
746749

@@ -788,8 +791,12 @@ ipcp_resdeco(void *ctx, u_int q_id, const u_char *req, size_t reqlen,
788791
}
789792
if (self->user_max_sessions != 0) {
790793
n = 0;
791-
TAILQ_FOREACH(assign, &user->ipv4s, next)
792-
n++;
794+
TAILQ_FOREACH_SAFE(assign, &user->ipv4s, next, assignt){
795+
assign = ipcp_ipv4_check_valid(self, assign);
796+
if (assign != NULL)
797+
n++;
798+
}
799+
793800
if (n >= self->user_max_sessions) {
794801
log_info("q=%u user=%s rejected: number of "
795802
"sessions per a user reached the limit(%d)",
@@ -1280,23 +1287,32 @@ struct assigned_ipv4 *
12801287
ipcp_ipv4_find(struct module_ipcp *self, struct in_addr ina)
12811288
{
12821289
struct assigned_ipv4 key, *ret;
1283-
struct timespec dif;
12841290

12851291
key.ipv4 = ina;
12861292
ret = RB_FIND(assigned_ipv4_tree, &self->ipv4s, &key);
1287-
if (ret != NULL && ret->start.tv_sec == 0) {
1293+
ret = ipcp_ipv4_check_valid(self, ret);
1294+
return (ret);
1295+
}
1296+
1297+
struct assigned_ipv4 *
1298+
ipcp_ipv4_check_valid(struct module_ipcp *self, struct assigned_ipv4 *ip)
1299+
{
1300+
struct timespec dif;
1301+
1302+
if (ip != NULL && ip->start.tv_sec == 0) {
12881303
/* not yet assigned */
1289-
timespecsub(&self->uptime, &ret->authtime, &dif);
1304+
timespecsub(&self->uptime, &ip->authtime, &dif);
12901305
if (dif.tv_sec >= self->start_wait) {
12911306
/* assumed NAS finally didn't use the address */
1292-
TAILQ_REMOVE(&ret->user->ipv4s, ret, next);
1293-
RB_REMOVE(assigned_ipv4_tree, &self->ipv4s, ret);
1294-
free(ret);
1295-
ret = NULL;
1307+
TAILQ_REMOVE(&ip->user->ipv4s, ip, next);
1308+
RB_REMOVE(assigned_ipv4_tree, &self->ipv4s, ip);
1309+
free(ip);
12961310
self->nsessions--;
1311+
return (NULL);
12971312
}
12981313
}
1299-
return (ret);
1314+
1315+
return (ip);
13001316
}
13011317

13021318
void

0 commit comments

Comments
 (0)