Skip to content

Commit

Permalink
PortDetectionTimeout, new accounting event MediaFail
Browse files Browse the repository at this point in the history
  • Loading branch information
willamowius committed Aug 30, 2018
1 parent 74aee5c commit d7758d8
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 4 deletions.
63 changes: 62 additions & 1 deletion ProxyChannel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ class H245ProxyHandler : public H245Handler {
bool IsCaller() const { return m_isCaller; }
bool IsH245Master() const { return m_isH245Master; }
bool IsRTPInactive(short session) const;
void AbortLogicalChannel(short session);


protected:
Expand Down Expand Up @@ -9200,6 +9201,14 @@ bool CallSignalSocket::IsRTPInactive(short session) const
}
}

void CallSignalSocket::AbortLogicalChannel(short session)
{
H245ProxyHandler * proxyhandler = dynamic_cast<H245ProxyHandler *>(m_h245handler);
if (proxyhandler) {
proxyhandler->AbortLogicalChannel(session);
}
}


// class H245Handler
H245Handler::H245Handler(const PIPSocket::Address & local, const PIPSocket::Address & remote, const PIPSocket::Address & masq)
Expand Down Expand Up @@ -11088,6 +11097,9 @@ UDPProxySocket::UDPProxySocket(const char *t, PINDEX no)
m_lastPacketFromForwardSrc = time(NULL);
m_lastPacketFromReverseSrc = time(NULL);
m_inactivityTimeout = GkConfig()->GetInteger(ProxySection, "RTPInactivityTimeout", 300); // 300 sec = 5 min
m_portDetectionTimeout = GkConfig()->GetInteger(ProxySection, "PortDetectionTimeout", -1); // in seconds, -1 is off
m_firstMedia = 0;
m_mediaFailDetected = false;
}

UDPProxySocket::~UDPProxySocket()
Expand Down Expand Up @@ -11582,7 +11594,7 @@ ProxySocket::Result UDPProxySocket::ReceiveData()
}
}
if (!IsSet(m_multiplexDestination_A) && !IsSet(m_multiplexDestination_B)) {
// set if only one side sends multiplexex to GnuGk
// set if only one side sends multiplexed to GnuGk
H46019Session h46019chan = MultiplexedRTPHandler::Instance()->GetChannel(m_callNo, m_sessionID);
if ((h46019chan.m_multiplexID_fromA != INVALID_MULTIPLEX_ID) && (h46019chan.m_multiplexID_fromB == INVALID_MULTIPLEX_ID)) {
if (h46019chan.IsValid()) {
Expand Down Expand Up @@ -11821,6 +11833,22 @@ ProxySocket::Result UDPProxySocket::ReceiveData()
PTRACE(6, Type() << "\tForward from " << AsString(fromIP, fromPort)
<< " blocked, remote socket (" << AsString(fDestIP, fDestPort)
<< ") not yet known or ready");

PTRACE(0, "JW Check1: rtp=" << isRTP << " ignore=" << m_ignoreSignaledIPs << " timeout=" << m_portDetectionTimeout);
if (isRTP && m_ignoreSignaledIPs && m_portDetectionTimeout > 0) {
time_t now = time(NULL);
PTRACE(0, "JW checking firstmedia=" << m_firstMedia << " now=" << now << " diff=" << (now - m_firstMedia));
if (m_firstMedia == 0)
m_firstMedia = now;
// TODO: add check if we were able to send packets in the mean time ?
if (!m_mediaFailDetected && (now - m_firstMedia >= m_portDetectionTimeout)) {
PTRACE(0, "JW media fail");
m_mediaFailDetected = true;
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctMediaFail, *m_call); // plus string "H.239" ?
//(*m_call)->AbortLogicalChannel(m_sessionID);
}
}

if (m_dontQueueRTP)
return NoData;
}
Expand All @@ -11843,6 +11871,22 @@ ProxySocket::Result UDPProxySocket::ReceiveData()
PTRACE(6, Type() << "\tForward from " << AsString(fromIP, fromPort)
<< " blocked, remote socket (" << AsString(rDestIP, rDestPort)
<< ") not yet known or ready");

PTRACE(0, "JW Check2: rtp=" << isRTP << " ignore=" << m_ignoreSignaledIPs << " timeout=" << m_portDetectionTimeout);
if (isRTP && m_ignoreSignaledIPs && m_portDetectionTimeout > 0) {
time_t now = time(NULL);
PTRACE(0, "JW checking firstmedia=" << m_firstMedia << " now=" << now << " diff=" << (now - m_firstMedia));
if (m_firstMedia == 0)
m_firstMedia = now;
// TODO: add check if we were able to send packets in the mean time ?
if (!m_mediaFailDetected && (now - m_firstMedia >= m_portDetectionTimeout)) {
PTRACE(0, "JW media fail");
m_mediaFailDetected = true;
(void)RasServer::Instance()->LogAcctEvent(GkAcctLogger::AcctMediaFail, *m_call); // plus string "H.239" ?
//(*m_call)->AbortLogicalChannel(m_sessionID);
}
}

if (m_dontQueueRTP)
return NoData;
}
Expand Down Expand Up @@ -14490,6 +14534,23 @@ bool H245ProxyHandler::IsRTPInactive(short session) const
return inactive;
}

void H245ProxyHandler::AbortLogicalChannel(short session)
{
RTPLogicalChannel * lc = FindRTPLogicalChannelBySessionID(session);
if (lc) {
WORD flcn = lc->GetChannelNumber();
/*
if (h245sock) {
PTRACE(4, "H245\tTo send (CallID: " << h245sock->GetCallIdentifierAsString() << "): " << h245msg);
h245sock->Send(h245msg);
} else {
CallSignalSocket * css = call->GetCallSignalSocketCalling();
css->SendTunneledH245(h245msg);
}
*/
}
}

//void H245ProxyHandler::DumpChannels(const PString & msg, bool dumpPeer) const
//{
// if (PTrace::CanTrace(7)) {
Expand Down
4 changes: 4 additions & 0 deletions ProxyChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ class UDPProxySocket : public UDPSocket, public ProxySocket {
int m_inactivityTimeout;
time_t m_lastPacketFromForwardSrc;
time_t m_lastPacketFromReverseSrc;
int m_portDetectionTimeout;
time_t m_firstMedia;
bool m_mediaFailDetected;
};

#if H323_H450
Expand Down Expand Up @@ -433,6 +436,7 @@ class CallSignalSocket : public TCPProxySocket {
CallSignalSocket * GetRemote() const { return dynamic_cast<CallSignalSocket *>(remote); }

bool IsRTPInactive(short session) const;
void AbortLogicalChannel(short session);

protected:
void ForwardCall(FacilityMsg *msg);
Expand Down
10 changes: 10 additions & 0 deletions RasTbl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5140,6 +5140,16 @@ bool CallRec::IsRTPInactive(short session) const
}
}

void CallRec::AbortLogicalChannel(short session)
{
if (m_callingSocket) {
m_callingSocket->AbortLogicalChannel(session);
}
if (m_calledSocket) {
m_calledSocket->AbortLogicalChannel(session);
}
}

/*
bool CallRec::IsTimeout(
const time_t now,
Expand Down
1 change: 1 addition & 0 deletions RasTbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ class CallRec {
#endif

bool IsRTPInactive(short session) const;
void AbortLogicalChannel(short session);

private:
void SendDRQ();
Expand Down
2 changes: 2 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Changes from 5.0 to 5.1
=======================
- new accounting event MediaFail
- new switch: [Proxy] PortDetectionTimeout=
- public IP detection for Google Cloud


Expand Down
3 changes: 3 additions & 0 deletions gk.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ const char * KnownConfigEntries[][2] = {
{ "HttpAcct", "AlertURL" },
{ "HttpAcct", "ConnectBody" },
{ "HttpAcct", "ConnectURL" },
{ "HttpAcct", "MediaFailBody" },
{ "HttpAcct", "MediaFailURL" },
{ "HttpAcct", "Method" },
{ "HttpAcct", "OffBody" },
{ "HttpAcct", "OffURL" },
Expand Down Expand Up @@ -453,6 +455,7 @@ const char * KnownConfigEntries[][2] = {
{ "Proxy", "InternalNetwork" },
#ifdef HAS_H46018
{ "Proxy", "LegacyPortDetection" },
{ "Proxy", "PortDetectionTimeout" },
#endif
{ "Proxy", "ProxyAlways" },
{ "Proxy", "ProxyForNAT" },
Expand Down
2 changes: 2 additions & 0 deletions gkacct.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ int GkAcctLogger::GetEvents(const PStringArray & tokens) const
mask |= AcctOff;
else if (token *= "reject")
mask |= AcctReject;
else if (token *= "mediafail")
mask |= AcctMediaFail;
}

return mask;
Expand Down
1 change: 1 addition & 0 deletions gkacct.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class GkAcctLogger : public NamedObject
AcctRegister = 0x0100, /// endpoint registered
AcctUnregister = 0x0200, /// endpoint unregistered
AcctReject = 0x0400, /// rejected calls (ARJ)
AcctMediaFail = 0x0800, /// media failure
AcctAll = -1,
AcctNone = 0
};
Expand Down
5 changes: 5 additions & 0 deletions httpacct.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ HttpAcct::HttpAcct(const char* moduleName, const char* cfgSecName)
m_offBody = cfg->GetString(cfgSec, "OffBody", "");
m_rejectURL = cfg->GetString(cfgSec, "RejectURL", "");
m_rejectBody = cfg->GetString(cfgSec, "RejectBody", "");
m_mediaFailURL = cfg->GetString(cfgSec, "MediaFailURL", "");
m_mediaFailBody = cfg->GetString(cfgSec, "MediaFailBody", "");
}

HttpAcct::~HttpAcct()
Expand Down Expand Up @@ -101,6 +103,9 @@ GkAcctLogger::Status HttpAcct::Log(GkAcctLogger::AcctEvent evt, const callptr &
} else if (evt == AcctReject) {
eventURL = m_rejectURL;
eventBody = m_rejectBody;
} else if (evt == AcctMediaFail) {
eventURL = m_mediaFailURL;
eventBody = m_mediaFailBody;
}

if (eventURL.IsEmpty()) {
Expand Down
5 changes: 4 additions & 1 deletion httpacct.h
Original file line number Diff line number Diff line change
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 | AcctReject
HttpAcctEvents = AcctStart | AcctStop | AcctUpdate | AcctConnect | AcctAlert | AcctRegister | AcctUnregister | AcctOn | AcctOff | AcctReject | AcctMediaFail
};

HttpAcct(
Expand Down Expand Up @@ -89,6 +89,9 @@ class HttpAcct : public GkAcctLogger
/// parametrized strings for the reject event
PString m_rejectURL;
PString m_rejectBody;
/// parametrized strings for the mediafail event
PString m_mediaFailURL;
PString m_mediaFailBody;
/// HTTP method: GET or POST
PString m_method;
/// timestamp formatting string
Expand Down
8 changes: 7 additions & 1 deletion statusacct.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* accounting module for GNU Gatekeeper for the status port.
*
* Copyright (c) 2005-2016, 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 @@ -34,6 +34,8 @@ StatusAcct::StatusAcct(const char* moduleName, const char* cfgSecName)
m_alertEvent = cfg->GetString(cfgSec, "AlertEvent", "CALL|Alert|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}");
m_registerEvent = cfg->GetString(cfgSec, "RegisterEvent", "EP|Register|%{endpoint-ip}:%{endpoint-port}|%{aliases}");
m_unregisterEvent = cfg->GetString(cfgSec, "UnregisterEvent", "EP|Unregister|%{endpoint-ip}:%{endpoint-port}|%{aliases}");
m_rejectEvent = cfg->GetString(cfgSec, "RejectEvent", "CALL|Reject|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}");
m_mediaFailEvent = cfg->GetString(cfgSec, "MediaFailEvent", "CALL|MediaFail|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}");
}

StatusAcct::~StatusAcct()
Expand Down Expand Up @@ -63,6 +65,10 @@ GkAcctLogger::Status StatusAcct::Log(GkAcctLogger::AcctEvent evt, const callptr
eventTmpl = m_stopEvent;
} else if (evt == AcctAlert) {
eventTmpl = m_alertEvent;
} else if (evt == AcctReject) {
eventTmpl = m_rejectEvent;
} else if (evt == AcctMediaFail) {
eventTmpl = m_mediaFailEvent;
}

if (!eventTmpl.IsEmpty()) { // don't send event if the template string is empty
Expand Down
6 changes: 5 additions & 1 deletion statusacct.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StatusAcct : public GkAcctLogger
enum Constants
{
/// events recognized by this module
StatusAcctEvents = AcctStart | AcctStop | AcctUpdate | AcctConnect | AcctAlert | AcctRegister | AcctUnregister
StatusAcctEvents = AcctStart | AcctStop | AcctUpdate | AcctConnect | AcctAlert | AcctRegister | AcctUnregister | AcctReject | AcctMediaFail
};

StatusAcct(
Expand Down Expand Up @@ -78,6 +78,10 @@ class StatusAcct : public GkAcctLogger
PString m_registerEvent;
/// parametrized string for the endpoint un-register event
PString m_unregisterEvent;
/// parametrized string for the call reject event
PString m_rejectEvent;
/// parametrized string for the call mediafail event
PString m_mediaFailEvent;
/// timestamp formatting string
PString m_timestampFormat;
};
Expand Down

0 comments on commit d7758d8

Please sign in to comment.