Alan,
that's a patch that I made for rlm_radutmp to use session_id as index.
I would like that, if you can, revise it and maybe create a new module
for this type of rlm_radutmp.
It is working at my radius server (production).
I'm having trouble hacking radzap program. Every time I execute it
(radzap <nas> <session_id>) it cleans up every entry of that nas
and not just the related session_id.
Can you help me with that?
rgds,
Marcelo Costa
--- src/modules/rlm_radutmp/rlm_radutmp.c.ori Wed Jan 30 21:04:41 2002
+++ src/modules/rlm_radutmp/rlm_radutmp.c Thu Jan 31 12:12:55 2002
@@ -40,6 +40,7 @@
#include "modules.h"
#define LOCK_LEN sizeof(struct radutmp)
+#define SESSLEN 8
static const char porttypes[] = "ASITX";
@@ -80,6 +81,7 @@
typedef struct nas_port {
uint32_t nasaddr;
int port;
+ char *session_id;
off_t offset;
struct nas_port *next;
} NAS_PORT;
@@ -154,6 +156,7 @@
/*
* Find the entry for this NAS / portno combination.
+ * ( what port ??? )
*/
while (read(fd, &u, sizeof(u)) == sizeof(u)) {
if ((nasaddr != 0 && nasaddr != u.nas_address) ||
@@ -180,8 +183,23 @@
}
/*
+ * Lookup a SESSION_ID in the nas_port_list
+ */
+static NAS_PORT *nas_sessionid_find(NAS_PORT *nas_port_list, uint32_t
nasaddr, const char *session_id )
+{
+ NAS_PORT *cl;
+
+ for(cl = nas_port_list; cl; cl = cl->next)
+ if (nasaddr == cl->nasaddr &&
+ strncmp(session_id,cl->session_id,SESSLEN) == 0 )
+ break;
+ return cl;
+}
+
+/*
* Lookup a NAS_PORT in the nas_port_list
*/
+/*
static NAS_PORT *nas_port_find(NAS_PORT *nas_port_list, uint32_t nasaddr,
int port)
{
NAS_PORT *cl;
@@ -192,7 +210,7 @@
break;
return cl;
}
-
+*/
/*
* Store logins in the RADIUS utmp file.
@@ -406,8 +424,8 @@
/*
* Find the entry for this NAS / portno combination.
*/
- if ((cache = nas_port_find(inst->nas_port_list,
ut.nas_address,
- ut.nas_port)) != NULL)
+ if ((cache = nas_sessionid_find(inst->nas_port_list,
ut.nas_address,
+ ut.session_id)) != NULL)
lseek(fd, (off_t)cache->offset, SEEK_SET);
r = 0;
@@ -415,12 +433,11 @@
while (read(fd, &u, sizeof(u)) == sizeof(u)) {
off += sizeof(u);
if (u.nas_address != ut.nas_address ||
- u.nas_port != ut.nas_port)
+ strncmp(u.session_id,ut.session_id,SESSLEN) != 0 )
continue;
if (status == PW_STATUS_STOP &&
- strncmp(ut.session_id, u.session_id,
- sizeof(u.session_id)) != 0) {
+ strncmp(ut.session_id, u.session_id, SESSLEN) !=
0) {
/*
* Don't complain if this is not a
* login record (some clients can
@@ -435,8 +452,7 @@
}
if (status == PW_STATUS_START &&
- strncmp(ut.session_id, u.session_id,
- sizeof(u.session_id)) == 0 &&
+ strncmp(ut.session_id, u.session_id, SESSLEN) ==
0 &&
u.time >= ut.time) {
if (u.type == P_LOGIN) {
radlog(L_INFO,
@@ -458,8 +474,7 @@
* rather rewrite this mess -- miquels.
*/
if (status == PW_STATUS_ALIVE &&
- strncmp(ut.session_id, u.session_id,
- sizeof(u.session_id)) == 0 &&
+ strncmp(ut.session_id, u.session_id, SESSLEN) ==
0 &&
u.type == P_LOGIN) {
/*
* Keep the original login time.
@@ -485,6 +500,7 @@
cache = rad_malloc(sizeof(NAS_PORT));
cache->nasaddr = ut.nas_address;
cache->port = ut.nas_port;
+ cache->session_id = ut.session_id;
cache->offset = off;
cache->next = inst->nas_port_list;
inst->nas_port_list = cache;
@@ -500,8 +516,8 @@
write(fd, &u, sizeof(u));
} else if (r == 0) {
radlog(L_ERR,
- "Accounting: logout: login entry for NAS %s port %d not
found",
- nas_name(nas_address), ut.nas_port);
+ "Accounting: logout: login entry for NAS %s port %d
session_id %.8s not found",
+ nas_name(nas_address), ut.nas_port,
ut.session_id);
r = -1;
}
}
------------------------------------------------------------
Marcelo Ferreira
Canbras TVA Cabo Ltda
Canbras Acesso - STA
Phone: +5511-4993-8728
------------------------------------------------------------
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, January 30, 2002 7:03 PM
Subject: Re: Error: Accounting: logout: entry for NAS cnet-bsn port
1929379840 has wrong ID
> "Marcelo Ferreira" <[EMAIL PROTECTED]> wrote:
> > I think that the index of radutmp file is port number and when FR
> > receives a STOP accounting packet, the session ID at port position
> > is not the same because many others subscribers has logged in before
> > and, logically, the session ID at that port number position is not
> > the same of the STOP package.
>
> Ah, of course.
>
> Hmm... I guess that the only way around this is to hack the radutmp
> module to use the session ID as the key, not the port.
>
> I think that change will even be backwards compatible.
>
> Alan DeKok.
>
> -
> List info/subscribe/unsubscribe? See
http://www.freeradius.org/list/users.html
>
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html