Skip to content

Commit

Permalink
1. Don't send acct update package if not get traffic info
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Yafeng Shan authored and ValdikSS committed Dec 23, 2015
1 parent 0170eb3 commit 79d9869
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
8 changes: 8 additions & 0 deletions AccountingProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void AccountingProcess::Accounting(PluginContext * context)
AcctScheduler scheduler; //The scheduler for the accounting.
fd_set set; //A set for the select function.
struct timeval tv; //A timeinterval for the select function.
uint64_t bytesin=0, bytesout=0;



Expand Down Expand Up @@ -203,6 +204,8 @@ void AccountingProcess::Accounting(PluginContext * context)
try
{
key=context->acctsocketforegr.recvStr();
bytesout = strtoull(context->acctsocketforegr.recvStr().c_str(),NULL,10);
bytesin = strtoull(context->acctsocketforegr.recvStr().c_str(),NULL,10);
}
catch (Exception &e)
{
Expand Down Expand Up @@ -249,6 +252,11 @@ void AccountingProcess::Accounting(PluginContext * context)
try
{
//delete the user from the accounting scheduler
user->setBytesIn(bytesin & 0xFFFFFFFF);
user->setBytesOut(bytesout & 0xFFFFFFFF);
user->setGigaIn(bytesin >> 32);
user->setGigaOut(bytesout >> 32);

scheduler.delUser(context, user);

if (DEBUG (context->getVerbosity()))
Expand Down
29 changes: 12 additions & 17 deletions AcctScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ void AcctScheduler::addUser(UserAcct *user)
*/
void AcctScheduler::delUser(PluginContext * context, UserAcct *user)
{
uint64_t bytesin=0, bytesout=0;

//get the sent and received bytes
this->parseStatusFile(context, &bytesin, &bytesout,user->getStatusFileKey().c_str());

user->setBytesIn(bytesin & 0xFFFFFFFF);
user->setBytesOut(bytesout & 0xFFFFFFFF);
user->setGigaIn(bytesin >> 32);
user->setGigaOut(bytesout >> 32);

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

this->parseStatusFile(context, &bytesin, &bytesout,iter1->second.getStatusFileKey().c_str());
iter1->second.setBytesIn(bytesin & 0xFFFFFFFF);
iter1->second.setBytesOut(bytesout & 0xFFFFFFFF);
iter1->second.setGigaIn(bytesin >> 32);
iter1->second.setGigaOut(bytesout >> 32);
iter1->second.sendUpdatePacket(context);

if (DEBUG (context->getVerbosity()))
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Update packet for User " << iter1->second.getUsername() << " was send.\n";
if (bytesin > 0 && bytesout > 0){
iter1->second.setBytesIn(bytesin & 0xFFFFFFFF);
iter1->second.setBytesOut(bytesout & 0xFFFFFFFF);
iter1->second.setGigaIn(bytesin >> 32);
iter1->second.setGigaOut(bytesout >> 32);
iter1->second.sendUpdatePacket(context);

if (DEBUG (context->getVerbosity()))
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Update packet for User " << iter1->second.getUsername() << " was send.\n";
}else{
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Don't update for "<< iter1->second.getUsername() << " because of lack of data.\n";
}

//calculate the next update
iter1->second.setNextUpdate(iter1->second.getNextUpdate()+iter1->second.getAcctInterimInterval());
Expand Down
24 changes: 19 additions & 5 deletions radiusplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,17 @@ extern "C"

//send the information to the background process
context->acctsocketbackgr.send ( DEL_USER );
context->acctsocketbackgr.send ( newuser->getKey() );
context->acctsocketbackgr.send ( newuser->getKey() );
if ( get_env ( "bytes_sent", envp ) !=NULL ){
context->acctsocketbackgr.send(get_env("bytes_sent", envp));
}else{
context->acctsocketbackgr.send("0");
}
if ( get_env ( "bytes_received", envp ) !=NULL ){
context->acctsocketbackgr.send(get_env("bytes_received", envp));
}else{
context->acctsocketbackgr.send("0");
}

//get the response
const int status = context->acctsocketbackgr.recvInt();
Expand Down Expand Up @@ -983,6 +993,7 @@ void * auth_user_pass_verify(void * c)
}
else //AUTH failed
{
/* should wait for disconnect call
if ( newuser->isAccounted() ) //user is already known, delete him from the accounting
{
cerr << getTime() << "RADIUS-PLUGIN: FOREGROUND THREAD: Error ar rekeying!" << endl;
Expand All @@ -1004,10 +1015,8 @@ void * auth_user_pass_verify(void * c)
cerr << getTime() << "RADIUS-PLUGIN: FOREGROUND THREAD: User is deleted from the user map!" << endl;
}
}
*/
cerr << getTime() << "RADIUS-PLUGIN: FOREGROUND THREAD: Error receiving auth confirmation from background process." << endl;
//clean up: nas port, context, memory
context->delNasPort(newuser->getPortnumber());
context->delUser(newuser->getKey());

if (newuser->getAuthControlFile().length()>0 && context->conf.getUseAuthControlFile())
{
Expand All @@ -1020,7 +1029,12 @@ void * auth_user_pass_verify(void * c)
pthread_cond_signal( context->getCondRecv( ));
pthread_mutex_unlock (context->getMutexRecv());
}
delete newuser;
//clean up: nas port, context, memory
if ( ! newuser->isAccounted() ){
context->delNasPort(newuser->getPortnumber());
context->delUser(newuser->getKey());
delete newuser;
}
}
}
else
Expand Down

0 comments on commit 79d9869

Please sign in to comment.