Navigation Menu

Skip to content

Commit

Permalink
new accounting event 'reject' for calls rejected with ARJ
Browse files Browse the repository at this point in the history
  • Loading branch information
willamowius committed Feb 7, 2018
1 parent a69f003 commit 577748b
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 11 deletions.
28 changes: 25 additions & 3 deletions RasSrv.cxx
Expand Up @@ -1375,7 +1375,7 @@ bool RasServer::ValidateAdditivePDU(RasPDU<H225_RegistrationRequest> & ras, RRQA
return (gkClient && gkClient->AdditiveRegister(rrq.m_terminalAlias, authData.m_rejectReason, tokens, cryptotokens));
}

bool RasServer::LogAcctEvent(int evt, callptr & call, time_t now)
bool RasServer::LogAcctEvent(int evt, const callptr & call, time_t now)
{
return acctList->LogAcctEvent((GkAcctLogger::AcctEvent)evt, call, now);
}
Expand Down Expand Up @@ -3139,12 +3139,16 @@ bool AdmissionRequestPDU::Process()

if (Toolkit::Instance()->IsMaintenanceMode()) {
PTRACE(1, "Rejecting new call in maintenance mode");
CallRec dummyCall(*this, 0, destinationString); // dummy call object so accounting variables can be filled
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctReject, callptr(&dummyCall)); // ignore success/failure
return BuildReply(H225_AdmissionRejectReason::e_resourceUnavailable);
}

// find the caller
RequestingEP = EndpointTbl->FindByEndpointId(request.m_endpointIdentifier);
if (!RequestingEP) {
CallRec dummyCall(*this, 0, destinationString); // dummy call object so accounting variables can be filled
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctReject, callptr(&dummyCall)); // ignore success/failure
return BuildReply(H225_AdmissionRejectReason::e_callerNotRegistered);
}

Expand All @@ -3154,6 +3158,8 @@ bool AdmissionRequestPDU::Process()
if (GetIPAndPortFromTransportAddr(RequestingEP->GetRasAddress(), storedAddr, storedPort)) {
if (storedAddr != m_msg->m_peerAddr) {
PTRACE(1, "RAS\tSender address of ARQ didn't match: " << AsString(storedAddr) << " != " << AsString(m_msg->m_peerAddr));
CallRec dummyCall(*this, 0, destinationString); // dummy call object so accounting variables can be filled
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctReject, callptr(&dummyCall)); // ignore success/failure
return BuildReply(H225_AdmissionRejectReason::e_callerNotRegistered);
}
} else {
Expand All @@ -3171,6 +3177,9 @@ bool AdmissionRequestPDU::Process()

if (RasSrv->IsRedirected(H225_RasMessage::e_admissionRequest) && !answer) {
PTRACE(1, "RAS\tWarning: Exceed call limit!!");
CallRec dummyCall(*this, 0, destinationString); // dummy call object so accounting variables can be filled
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctReject, callptr(&dummyCall)); // ignore success/failure

return BuildReply(H225_AdmissionRejectReason::e_resourceUnavailable);
}

Expand Down Expand Up @@ -3249,6 +3258,10 @@ bool AdmissionRequestPDU::Process()
if (authData.m_rejectReason < 0) {
authData.m_rejectReason = H225_AdmissionRejectReason::e_securityDenial;
}
PTRACE(0, "JW fire reject event");
CallRec dummyCall(*this, 0, destinationString, authData.m_proxyMode); // dummy call object so accounting variables can be filled
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctReject, callptr(&dummyCall)); // ignore success/failure

return BuildReply(authData.m_rejectReason);
}

Expand All @@ -3274,6 +3287,8 @@ bool AdmissionRequestPDU::Process()
}
}
if (bReject) {
CallRec dummyCall(*this, 0, destinationString, authData.m_proxyMode); // dummy call object so accounting variables can be filled
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctReject, callptr(&dummyCall)); // ignore success/failure
return BuildReply(H225_AdmissionRejectReason::e_routeCallToGatekeeper);
}
}
Expand Down Expand Up @@ -3358,6 +3373,8 @@ bool AdmissionRequestPDU::Process()
arq.Process();

if (arq.GetRoutes().empty()) {
CallRec dummyCall(*this, 0, destinationString, authData.m_proxyMode); // dummy call object so accounting variables can be filled
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctReject, callptr(&dummyCall)); // ignore success/failure
SetupResponseTokens(m_msg->m_replyRAS, RequestingEP);
return BuildReply(arq.GetRejectReason());
}
Expand All @@ -3375,6 +3392,8 @@ bool AdmissionRequestPDU::Process()

if ((arq.GetRoutes().size() == 1 || !Toolkit::AsBool(GkConfig()->GetString(RoutedSec, "ActivateFailover", "0")))
&& route.m_destEndpoint && !route.m_destEndpoint->HasAvailableCapacity(request.m_destinationInfo)) {
CallRec dummyCall(*this, 0, destinationString, authData.m_proxyMode); // dummy call object so accounting variables can be filled
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctReject, callptr(&dummyCall)); // ignore success/failure
SetupResponseTokens(m_msg->m_replyRAS, RequestingEP);
return BuildReply(H225_AdmissionRejectReason::e_resourceUnavailable);
}
Expand Down Expand Up @@ -3439,7 +3458,8 @@ bool AdmissionRequestPDU::Process()
}
}
if (bReject) {
// TODO: fire new accounting event for rejected call
CallRec dummyCall(*this, BWRequest, destinationString, authData.m_proxyMode); // dummy call object so accounting variables can be filled
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctReject, callptr(&dummyCall)); // ignore success/failure
// set H.235.1 tokens
SetupResponseTokens(m_msg->m_replyRAS, RequestingEP);
return BuildReply(H225_AdmissionRejectReason::e_requestDenied);
Expand Down Expand Up @@ -3566,9 +3586,11 @@ bool AdmissionRequestPDU::Process()
if (Toolkit::Instance()->IsH46023Enabled() && !EPRequiresH46026) {
// Std24 proxy offload. See if the media can go direct.
if (natoffloadsupport == CallRec::e_natUnknown) {
if (!pCallRec->NATOffLoad(answer,natoffloadsupport)) {
if (!pCallRec->NATOffLoad(answer, natoffloadsupport)) {
if (natoffloadsupport == CallRec::e_natFailure) {
PTRACE(2, "RAS\tWarning: NAT Media Failure detected " << (unsigned)request.m_callReferenceValue);
CallRec dummyCall(*this, BWRequest, destinationString, authData.m_proxyMode); // dummy call object so accounting variables can be filled
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctReject, callptr(&dummyCall)); // ignore success/failure
SetupResponseTokens(m_msg->m_replyRAS, RequestingEP);
return BuildReply(H225_AdmissionRejectReason::e_noRouteToDestination, true);
}
Expand Down
2 changes: 1 addition & 1 deletion RasSrv.h
Expand Up @@ -163,7 +163,7 @@ class RasServer : public Singleton<RasServer>, public SocketsReader {
GkAcctLoggerList * GetAcctList() { return acctList; }
GkAuthenticatorList * GetAuthList() { return authList; }

bool LogAcctEvent(int evt, callptr & call, time_t now = 0);
bool LogAcctEvent(int evt, const callptr & call, time_t now = 0);

bool LogAcctEvent(int evt, const endptr & ep);

Expand Down
1 change: 1 addition & 0 deletions changes.txt
@@ -1,5 +1,6 @@
Changes from 4.8 to 4.9
=======================
- new accounting event 'reject' for calls rejected with ARJ
- new accounting module: HttpAcct
- many new accounting placeholder
- BUGFIX(RasTbl.cxx) fix disconnecting unregistered endpoints
Expand Down
15 changes: 13 additions & 2 deletions docs/manual/acct.sgml
Expand Up @@ -23,7 +23,7 @@ acctmod=actions
<acctmod> := FileAcct | RadAcct | SQLAcct | HttpAcct | StatusAcct | SyslogAcct | LuaAcct | RequireOneNet | CapacityControl | ...
<actions> := <control>[;<event>,<event>,...]
<control> := optional | required | sufficient | alternative
<event> := start | stop | alert | connect | update | register | unregister | on | off
<event> := start | stop | alert | connect | update | register | unregister | on | off | reject
</verb></tscreen>
</descrip>
The event list tells the gatekeeper which events should trigger logging
Expand All @@ -39,6 +39,7 @@ with the given accounting module (if an event type is supported by the module):
<item><tt/register/ - an endpoint has registered
<item><tt/unregister/ - an endpoint has unregistered
<item><tt/stop/ - a call has been disconnected (removed from the gatekeeper call table)
<item><tt/reject/ - a call has been rejected (ARJ) before becomming a true call by GnuGk's terms
<item><tt/on/ - the gatekeeper has been started
<item><tt/off/ - the gatekeeper has been shut down
</itemize>
Expand Down Expand Up @@ -96,7 +97,7 @@ See section <ref id="sqlacct" name="[SQLAcct]"> for configuration details.

<item><tt>HttpAcct</tt>
<p>
This module logs all accounting events over HTTP. It supports (start, connect, stop, update, alert, register, unregister, on, off)
This module logs all accounting events over HTTP. It supports (start, connect, stop, update, alert, reject, register, unregister, on, off)
See section <ref id="httpacct" name="[HttpAcct]"> for configuration details.

<item><tt>StatusAcct</tt>
Expand Down Expand Up @@ -1078,6 +1079,16 @@ Default: <tt>empty</tt>
<p>
The HTTP body for call connect events to use with POST requests.

<item><tt>RejectURL=http://example.com/call-rejected</tt><newline>
Default: <tt>N/A</tt>
<p>
The URL to fetch for call reject events.

<item><tt/RejectBody=gatekeeper=%g/<newline>
Default: <tt>empty</tt>
<p>
The HTTP body for call reject events to use with POST requests.

<item><tt>RegisterURL=http://example.com/ep-register</tt><newline>
Default: <tt>N/A</tt>
<p>
Expand Down
2 changes: 2 additions & 0 deletions gk.cxx
Expand Up @@ -358,6 +358,8 @@ const char * KnownConfigEntries[][2] = {
{ "HttpAcct", "OnURL" },
{ "HttpAcct", "RegisterBody" },
{ "HttpAcct", "RegisterURL" },
{ "HttpAcct", "RejectBody" },
{ "HttpAcct", "RejectURL" },
{ "HttpAcct", "StartBody" },
{ "HttpAcct", "StartURL" },
{ "HttpAcct", "StopBody" },
Expand Down
8 changes: 5 additions & 3 deletions gkacct.cxx
Expand Up @@ -5,7 +5,7 @@
* support for accounting to the gatekeeper.
*
* Copyright (c) 2003, Quarcom FHU, Michal Zygmuntowicz
* Copyright (c) 2005-2017, Jan Willamowius
* Copyright (c) 2005-2018, Jan Willamowius
*
* This work is published under the GNU Public License version 2 (GPLv2)
* see file COPYING for details.
Expand Down Expand Up @@ -79,7 +79,7 @@ GkAcctLogger::GkAcctLogger(

GkAcctLogger::~GkAcctLogger()
{
PTRACE(1, "GKACCT\tDestroyed module "<<GetName());
PTRACE(1, "GKACCT\tDestroyed module " << GetName());
}

int GkAcctLogger::GetEvents(
Expand All @@ -89,7 +89,7 @@ int GkAcctLogger::GetEvents(
int mask = 0;

for( PINDEX i = 1; i < tokens.GetSize(); i++ ) {
const PString& token = tokens[i];
const PString & token = tokens[i];
if( token *= "start" )
mask |= AcctStart;
else if( token *= "stop" )
Expand All @@ -108,6 +108,8 @@ int GkAcctLogger::GetEvents(
mask |= AcctOn;
else if( token *= "off" )
mask |= AcctOff;
else if( token *= "reject" )
mask |= AcctReject;
}

return mask;
Expand Down
1 change: 1 addition & 0 deletions gkacct.h
Expand Up @@ -72,6 +72,7 @@ class GkAcctLogger : public NamedObject
AcctAlert = 0x0040, /// call alerting
AcctRegister = 0x0100, /// endpoint registered
AcctUnregister = 0x0200, /// endpoint unregistered
AcctReject = 0x0400, /// rejected calls (ARJ)
AcctAll = -1,
AcctNone = 0
};
Expand Down
5 changes: 5 additions & 0 deletions httpacct.cxx
Expand Up @@ -55,6 +55,8 @@ HttpAcct::HttpAcct(const char* moduleName, const char* cfgSecName)
m_onBody = cfg->GetString(cfgSec, "OnBody", "");
m_offURL = cfg->GetString(cfgSec, "OffURL", "");
m_offBody = cfg->GetString(cfgSec, "OffBody", "");
m_rejectURL = cfg->GetString(cfgSec, "RejectURL", "");
m_rejectBody = cfg->GetString(cfgSec, "RejectBody", "");
}

HttpAcct::~HttpAcct()
Expand Down Expand Up @@ -96,6 +98,9 @@ GkAcctLogger::Status HttpAcct::Log(GkAcctLogger::AcctEvent evt, const callptr &
} else if (evt == AcctOff) {
eventURL = m_offURL;
eventBody = m_offBody;
} else if (evt == AcctReject) {
eventURL = m_rejectURL;
eventBody = m_rejectBody;
}

if (eventURL.IsEmpty()) {
Expand Down
7 changes: 5 additions & 2 deletions httpacct.h
Expand Up @@ -28,7 +28,7 @@ class HttpAcct : public GkAcctLogger
enum Constants
{
/// events recognized by this module
HttpAcctEvents = AcctStart | AcctStop | AcctUpdate | AcctConnect | AcctAlert | AcctRegister | AcctUnregister | AcctOn | AcctOff
HttpAcctEvents = AcctStart | AcctStop | AcctUpdate | AcctConnect | AcctAlert | AcctRegister | AcctUnregister | AcctOn | AcctOff | AcctReject
};

HttpAcct(
Expand Down Expand Up @@ -83,9 +83,12 @@ class HttpAcct : public GkAcctLogger
/// parametrized strings for the ON event
PString m_onURL;
PString m_onBody;
/// parametrized strings for the ON event
/// parametrized strings for the OFF event
PString m_offURL;
PString m_offBody;
/// parametrized strings for the reject event
PString m_rejectURL;
PString m_rejectBody;
/// HTTP method: GET or POST
PString m_method;
/// timestamp formatting string
Expand Down

0 comments on commit 577748b

Please sign in to comment.