Skip to content

Commit 79d9869

Browse files
Yafeng ShanValdikSS
Yafeng Shan
authored andcommitted
1. Don't send acct update package if not get traffic info
2. use traffic info from disconnect envp in acct stop package 3. wait for disconnect command to send acct stop package for rekey auth failed
1 parent 0170eb3 commit 79d9869

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

AccountingProcess.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void AccountingProcess::Accounting(PluginContext * context)
3939
AcctScheduler scheduler; //The scheduler for the accounting.
4040
fd_set set; //A set for the select function.
4141
struct timeval tv; //A timeinterval for the select function.
42+
uint64_t bytesin=0, bytesout=0;
4243

4344

4445

@@ -203,6 +204,8 @@ void AccountingProcess::Accounting(PluginContext * context)
203204
try
204205
{
205206
key=context->acctsocketforegr.recvStr();
207+
bytesout = strtoull(context->acctsocketforegr.recvStr().c_str(),NULL,10);
208+
bytesin = strtoull(context->acctsocketforegr.recvStr().c_str(),NULL,10);
206209
}
207210
catch (Exception &e)
208211
{
@@ -249,6 +252,11 @@ void AccountingProcess::Accounting(PluginContext * context)
249252
try
250253
{
251254
//delete the user from the accounting scheduler
255+
user->setBytesIn(bytesin & 0xFFFFFFFF);
256+
user->setBytesOut(bytesout & 0xFFFFFFFF);
257+
user->setGigaIn(bytesin >> 32);
258+
user->setGigaOut(bytesout >> 32);
259+
252260
scheduler.delUser(context, user);
253261

254262
if (DEBUG (context->getVerbosity()))

AcctScheduler.cpp

+12-17
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,6 @@ void AcctScheduler::addUser(UserAcct *user)
7373
*/
7474
void AcctScheduler::delUser(PluginContext * context, UserAcct *user)
7575
{
76-
uint64_t bytesin=0, bytesout=0;
77-
78-
//get the sent and received bytes
79-
this->parseStatusFile(context, &bytesin, &bytesout,user->getStatusFileKey().c_str());
80-
81-
user->setBytesIn(bytesin & 0xFFFFFFFF);
82-
user->setBytesOut(bytesout & 0xFFFFFFFF);
83-
user->setGigaIn(bytesin >> 32);
84-
user->setGigaOut(bytesout >> 32);
8576

8677
if (DEBUG (context->getVerbosity()))
8778
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Got accounting data from file, CN: " << user->getCommonname() << " in: " << user->getBytesIn() << " out: " << user->getBytesOut() << ".\n";
@@ -163,14 +154,18 @@ void AcctScheduler::doAccounting(PluginContext * context)
163154
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Update for User " << iter1->second.getUsername() << ".\n";
164155

165156
this->parseStatusFile(context, &bytesin, &bytesout,iter1->second.getStatusFileKey().c_str());
166-
iter1->second.setBytesIn(bytesin & 0xFFFFFFFF);
167-
iter1->second.setBytesOut(bytesout & 0xFFFFFFFF);
168-
iter1->second.setGigaIn(bytesin >> 32);
169-
iter1->second.setGigaOut(bytesout >> 32);
170-
iter1->second.sendUpdatePacket(context);
171-
172-
if (DEBUG (context->getVerbosity()))
173-
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Update packet for User " << iter1->second.getUsername() << " was send.\n";
157+
if (bytesin > 0 && bytesout > 0){
158+
iter1->second.setBytesIn(bytesin & 0xFFFFFFFF);
159+
iter1->second.setBytesOut(bytesout & 0xFFFFFFFF);
160+
iter1->second.setGigaIn(bytesin >> 32);
161+
iter1->second.setGigaOut(bytesout >> 32);
162+
iter1->second.sendUpdatePacket(context);
163+
164+
if (DEBUG (context->getVerbosity()))
165+
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Update packet for User " << iter1->second.getUsername() << " was send.\n";
166+
}else{
167+
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Don't update for "<< iter1->second.getUsername() << " because of lack of data.\n";
168+
}
174169

175170
//calculate the next update
176171
iter1->second.setNextUpdate(iter1->second.getNextUpdate()+iter1->second.getAcctInterimInterval());

radiusplugin.cpp

+19-5
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,17 @@ extern "C"
521521

522522
//send the information to the background process
523523
context->acctsocketbackgr.send ( DEL_USER );
524-
context->acctsocketbackgr.send ( newuser->getKey() );
524+
context->acctsocketbackgr.send ( newuser->getKey() );
525+
if ( get_env ( "bytes_sent", envp ) !=NULL ){
526+
context->acctsocketbackgr.send(get_env("bytes_sent", envp));
527+
}else{
528+
context->acctsocketbackgr.send("0");
529+
}
530+
if ( get_env ( "bytes_received", envp ) !=NULL ){
531+
context->acctsocketbackgr.send(get_env("bytes_received", envp));
532+
}else{
533+
context->acctsocketbackgr.send("0");
534+
}
525535

526536
//get the response
527537
const int status = context->acctsocketbackgr.recvInt();
@@ -983,6 +993,7 @@ void * auth_user_pass_verify(void * c)
983993
}
984994
else //AUTH failed
985995
{
996+
/* should wait for disconnect call
986997
if ( newuser->isAccounted() ) //user is already known, delete him from the accounting
987998
{
988999
cerr << getTime() << "RADIUS-PLUGIN: FOREGROUND THREAD: Error ar rekeying!" << endl;
@@ -1004,10 +1015,8 @@ void * auth_user_pass_verify(void * c)
10041015
cerr << getTime() << "RADIUS-PLUGIN: FOREGROUND THREAD: User is deleted from the user map!" << endl;
10051016
}
10061017
}
1018+
*/
10071019
cerr << getTime() << "RADIUS-PLUGIN: FOREGROUND THREAD: Error receiving auth confirmation from background process." << endl;
1008-
//clean up: nas port, context, memory
1009-
context->delNasPort(newuser->getPortnumber());
1010-
context->delUser(newuser->getKey());
10111020

10121021
if (newuser->getAuthControlFile().length()>0 && context->conf.getUseAuthControlFile())
10131022
{
@@ -1020,7 +1029,12 @@ void * auth_user_pass_verify(void * c)
10201029
pthread_cond_signal( context->getCondRecv( ));
10211030
pthread_mutex_unlock (context->getMutexRecv());
10221031
}
1023-
delete newuser;
1032+
//clean up: nas port, context, memory
1033+
if ( ! newuser->isAccounted() ){
1034+
context->delNasPort(newuser->getPortnumber());
1035+
context->delUser(newuser->getKey());
1036+
delete newuser;
1037+
}
10241038
}
10251039
}
10261040
else

0 commit comments

Comments
 (0)