* Added tracing for binds and connects as well.

* Introduced the TCP_TRACING macro in tracing_config.h.
* Enlarged the default trace size to something a tiny bit useful (but still
  acceptable for systems with little RAM).
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25235 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-04-29 07:35:00 +00:00
parent ef13436f1f
commit 5abeea69a5
2 changed files with 121 additions and 61 deletions
+2 -1
View File
@@ -10,7 +10,7 @@
// tracing buffer size (in bytes) // tracing buffer size (in bytes)
#ifndef MAX_TRACE_SIZE #ifndef MAX_TRACE_SIZE
# define MAX_TRACE_SIZE (1024 * 1024) # define MAX_TRACE_SIZE (20 * 1024 * 1024)
#endif #endif
@@ -30,6 +30,7 @@
#define SIGNAL_TRACING 0 #define SIGNAL_TRACING 0
#define SYSCALL_TRACING 0 #define SYSCALL_TRACING 0
#define SYSCALL_TRACING_IGNORE_KTRACE_OUTPUT 1 #define SYSCALL_TRACING_IGNORE_KTRACE_OUTPUT 1
#define TCP_TRACING 0
#define TEAM_TRACING 0 #define TEAM_TRACING 0
#define USER_MALLOC_TRACING 0 #define USER_MALLOC_TRACING 0
@@ -29,45 +29,103 @@
# define TRACE(x) # define TRACE(x)
#endif #endif
//#define ENDPOINT_TRACING #if TCP_TRACING
# define ENDPOINT_TRACING
#endif
#ifdef ENDPOINT_TRACING #ifdef ENDPOINT_TRACING
namespace EndpointTracing { namespace EndpointTracing {
class Bind : public AbstractTraceEntry {
public:
Bind(TCPEndpoint* endpoint, ConstSocketAddress& address, bool ephemeral)
:
fEndpoint(endpoint),
fEphemeral(ephemeral)
{
address.AsString(fAddress, sizeof(fAddress), true);
Initialized();
}
Bind(TCPEndpoint* endpoint, SocketAddress& address, bool ephemeral)
:
fEndpoint(endpoint),
fEphemeral(ephemeral)
{
address.AsString(fAddress, sizeof(fAddress), true);
Initialized();
}
virtual void AddDump(TraceOutput& out)
{
out.Print("tcp:e:%p bind%s address %s", fEndpoint,
fEphemeral ? " ephemeral" : "", fAddress);
}
protected:
TCPEndpoint* fEndpoint;
char fAddress[32];
bool fEphemeral;
};
class Connect : public AbstractTraceEntry {
public:
Connect(TCPEndpoint* endpoint)
:
fEndpoint(endpoint)
{
endpoint->LocalAddress().AsString(fLocal, sizeof(fLocal), true);
endpoint->PeerAddress().AsString(fPeer, sizeof(fPeer), true);
Initialized();
}
virtual void AddDump(TraceOutput& out)
{
out.Print("tcp:e:%p connect local %s, peer %s", fEndpoint, fLocal,
fPeer);
}
protected:
TCPEndpoint* fEndpoint;
char fLocal[32];
char fPeer[32];
};
class Unbind : public AbstractTraceEntry { class Unbind : public AbstractTraceEntry {
public: public:
Unbind(TCPEndpoint* endpoint) Unbind(TCPEndpoint* endpoint)
: :
fEndpoint(endpoint) fEndpoint(endpoint)
{ {
fStackTrace = capture_tracing_stack_trace(10, 0, false); //fStackTrace = capture_tracing_stack_trace(10, 0, false);
endpoint->LocalAddress().AsString(fLocal, sizeof(fLocal), true); endpoint->LocalAddress().AsString(fLocal, sizeof(fLocal), true);
endpoint->PeerAddress().AsString(fPeer, sizeof(fPeer), true); endpoint->PeerAddress().AsString(fPeer, sizeof(fPeer), true);
Initialized(); Initialized();
} }
virtual void DumpStackTrace(TraceOutput& out) #if 0
{ virtual void DumpStackTrace(TraceOutput& out)
out.PrintStackTrace(fStackTrace); {
} out.PrintStackTrace(fStackTrace);
}
#endif
virtual void AddDump(TraceOutput& out) virtual void AddDump(TraceOutput& out)
{ {
out.Print("tcp:e:unbind: %p, local %s, peer %s" out.Print("tcp:e:%p unbind, local %s, peer %s", fEndpoint, fLocal,
"%lu", fEndpoint, fLocal, fPeer); fPeer);
} }
protected: protected:
TCPEndpoint* fEndpoint; TCPEndpoint* fEndpoint;
tracing_stack_trace* fStackTrace; //tracing_stack_trace* fStackTrace;
char fLocal[32]; char fLocal[32];
char fPeer[32]; char fPeer[32];
}; };
} // namespace EndpointTracing } // namespace EndpointTracing
# define T(x) new(std::nothrow) EndpointTracing::x # define T(x) new(std::nothrow) EndpointTracing::x
#else #else
# define T(x) # define T(x)
#endif // ENDPOINT_TRACING #endif // ENDPOINT_TRACING
@@ -77,7 +135,7 @@ static const uint16 kLastReservedPort = 1023;
static const uint16 kFirstEphemeralPort = 40000; static const uint16 kFirstEphemeralPort = 40000;
ConnectionHashDefinition::ConnectionHashDefinition(EndpointManager *manager) ConnectionHashDefinition::ConnectionHashDefinition(EndpointManager* manager)
: :
fManager(manager) fManager(manager)
{ {
@@ -85,7 +143,7 @@ ConnectionHashDefinition::ConnectionHashDefinition(EndpointManager *manager)
size_t size_t
ConnectionHashDefinition::HashKey(const KeyType &key) const ConnectionHashDefinition::HashKey(const KeyType& key) const
{ {
return ConstSocketAddress(fManager->AddressModule(), return ConstSocketAddress(fManager->AddressModule(),
key.first).HashPair(key.second); key.first).HashPair(key.second);
@@ -93,23 +151,23 @@ ConnectionHashDefinition::HashKey(const KeyType &key) const
size_t size_t
ConnectionHashDefinition::Hash(TCPEndpoint *endpoint) const ConnectionHashDefinition::Hash(TCPEndpoint* endpoint) const
{ {
return endpoint->LocalAddress().HashPair(*endpoint->PeerAddress()); return endpoint->LocalAddress().HashPair(*endpoint->PeerAddress());
} }
bool bool
ConnectionHashDefinition::Compare(const KeyType &key, ConnectionHashDefinition::Compare(const KeyType& key,
TCPEndpoint *endpoint) const TCPEndpoint* endpoint) const
{ {
return endpoint->LocalAddress().EqualTo(key.first, true) return endpoint->LocalAddress().EqualTo(key.first, true)
&& endpoint->PeerAddress().EqualTo(key.second, true); && endpoint->PeerAddress().EqualTo(key.second, true);
} }
HashTableLink<TCPEndpoint> * HashTableLink<TCPEndpoint>*
ConnectionHashDefinition::GetLink(TCPEndpoint *endpoint) const ConnectionHashDefinition::GetLink(TCPEndpoint* endpoint) const
{ {
return &endpoint->fConnectionHashLink; return &endpoint->fConnectionHashLink;
} }
@@ -126,29 +184,29 @@ EndpointHashDefinition::HashKey(uint16 port) const
size_t size_t
EndpointHashDefinition::Hash(TCPEndpoint *endpoint) const EndpointHashDefinition::Hash(TCPEndpoint* endpoint) const
{ {
return endpoint->LocalAddress().Port(); return endpoint->LocalAddress().Port();
} }
bool bool
EndpointHashDefinition::Compare(uint16 port, TCPEndpoint *endpoint) const EndpointHashDefinition::Compare(uint16 port, TCPEndpoint* endpoint) const
{ {
return endpoint->LocalAddress().Port() == port; return endpoint->LocalAddress().Port() == port;
} }
bool bool
EndpointHashDefinition::CompareValues(TCPEndpoint *first, EndpointHashDefinition::CompareValues(TCPEndpoint* first,
TCPEndpoint *second) const TCPEndpoint* second) const
{ {
return first->LocalAddress().Port() == second->LocalAddress().Port(); return first->LocalAddress().Port() == second->LocalAddress().Port();
} }
HashTableLink<TCPEndpoint> * HashTableLink<TCPEndpoint>*
EndpointHashDefinition::GetLink(TCPEndpoint *endpoint) const EndpointHashDefinition::GetLink(TCPEndpoint* endpoint) const
{ {
return &endpoint->fEndpointHashLink; return &endpoint->fEndpointHashLink;
} }
@@ -157,7 +215,7 @@ EndpointHashDefinition::GetLink(TCPEndpoint *endpoint) const
// #pragma mark - // #pragma mark -
EndpointManager::EndpointManager(net_domain *domain) EndpointManager::EndpointManager(net_domain* domain)
: :
fDomain(domain), fDomain(domain),
fConnectionHash(this), fConnectionHash(this),
@@ -195,16 +253,16 @@ EndpointManager::InitCheck() const
/*! Returns the endpoint matching the connection. /*! Returns the endpoint matching the connection.
You must hold the manager's lock when calling this method. You must hold the manager's lock when calling this method.
*/ */
TCPEndpoint * TCPEndpoint*
EndpointManager::_LookupConnection(const sockaddr *local, const sockaddr *peer) EndpointManager::_LookupConnection(const sockaddr* local, const sockaddr* peer)
{ {
return fConnectionHash.Lookup(std::make_pair(local, peer)); return fConnectionHash.Lookup(std::make_pair(local, peer));
} }
status_t status_t
EndpointManager::SetConnection(TCPEndpoint *endpoint, EndpointManager::SetConnection(TCPEndpoint* endpoint, const sockaddr* _local,
const sockaddr *_local, const sockaddr *peer, const sockaddr *interfaceLocal) const sockaddr* peer, const sockaddr* interfaceLocal)
{ {
TRACE(("EndpointManager::SetConnection(%p)\n", endpoint)); TRACE(("EndpointManager::SetConnection(%p)\n", endpoint));
@@ -224,6 +282,7 @@ EndpointManager::SetConnection(TCPEndpoint *endpoint,
endpoint->LocalAddress().SetTo(*local); endpoint->LocalAddress().SetTo(*local);
endpoint->PeerAddress().SetTo(peer); endpoint->PeerAddress().SetTo(peer);
T(Connect(endpoint));
fConnectionHash.Insert(endpoint); fConnectionHash.Insert(endpoint);
return B_OK; return B_OK;
@@ -231,7 +290,7 @@ EndpointManager::SetConnection(TCPEndpoint *endpoint,
status_t status_t
EndpointManager::SetPassive(TCPEndpoint *endpoint) EndpointManager::SetPassive(TCPEndpoint* endpoint)
{ {
BenaphoreLocker _(fLock); BenaphoreLocker _(fLock);
@@ -257,8 +316,8 @@ EndpointManager::SetPassive(TCPEndpoint *endpoint)
} }
TCPEndpoint * TCPEndpoint*
EndpointManager::FindConnection(sockaddr *local, sockaddr *peer) EndpointManager::FindConnection(sockaddr* local, sockaddr* peer)
{ {
BenaphoreLocker _(fLock); BenaphoreLocker _(fLock);
@@ -300,7 +359,7 @@ EndpointManager::FindConnection(sockaddr *local, sockaddr *peer)
status_t status_t
EndpointManager::Bind(TCPEndpoint *endpoint, const sockaddr *address) EndpointManager::Bind(TCPEndpoint* endpoint, const sockaddr* address)
{ {
// TODO check the family: // TODO check the family:
// //
@@ -317,7 +376,7 @@ EndpointManager::Bind(TCPEndpoint *endpoint, const sockaddr *address)
status_t status_t
EndpointManager::BindChild(TCPEndpoint *endpoint) EndpointManager::BindChild(TCPEndpoint* endpoint)
{ {
BenaphoreLocker _(fLock); BenaphoreLocker _(fLock);
return _Bind(endpoint, *endpoint->LocalAddress()); return _Bind(endpoint, *endpoint->LocalAddress());
@@ -325,14 +384,14 @@ EndpointManager::BindChild(TCPEndpoint *endpoint)
status_t status_t
EndpointManager::_BindToAddress(TCPEndpoint *endpoint, const sockaddr *_address) EndpointManager::_BindToAddress(TCPEndpoint* endpoint, const sockaddr* _address)
{ {
TRACE(("EndpointManager::BindToAddress(%p)\n", endpoint));
ConstSocketAddress address(AddressModule(), _address); ConstSocketAddress address(AddressModule(), _address);
uint16 port = address.Port(); uint16 port = address.Port();
TRACE(("EndpointManager::BindToAddress(%p)\n", endpoint));
T(Bind(endpoint, address, false));
// TODO this check follows very typical UNIX semantics // TODO this check follows very typical UNIX semantics
// and generally should be improved. // and generally should be improved.
if (ntohs(port) <= kLastReservedPort && geteuid() != 0) if (ntohs(port) <= kLastReservedPort && geteuid() != 0)
@@ -358,8 +417,8 @@ EndpointManager::_BindToAddress(TCPEndpoint *endpoint, const sockaddr *_address)
status_t status_t
EndpointManager::_BindToEphemeral(TCPEndpoint *endpoint, EndpointManager::_BindToEphemeral(TCPEndpoint* endpoint,
const sockaddr *address) const sockaddr* address)
{ {
TRACE(("EndpointManager::BindToEphemeral(%p)\n", endpoint)); TRACE(("EndpointManager::BindToEphemeral(%p)\n", endpoint));
@@ -387,6 +446,7 @@ EndpointManager::_BindToEphemeral(TCPEndpoint *endpoint,
TRACE((" EndpointManager::BindToEphemeral(%p) -> %s\n", TRACE((" EndpointManager::BindToEphemeral(%p) -> %s\n",
endpoint, AddressString(Domain(), *newAddress, endpoint, AddressString(Domain(), *newAddress,
true).Data())); true).Data()));
T(Bind(endpoint, newAddress, true));
return _Bind(endpoint, *newAddress); return _Bind(endpoint, *newAddress);
} }
@@ -401,7 +461,7 @@ EndpointManager::_BindToEphemeral(TCPEndpoint *endpoint,
status_t status_t
EndpointManager::_Bind(TCPEndpoint *endpoint, const sockaddr *address) EndpointManager::_Bind(TCPEndpoint* endpoint, const sockaddr* address)
{ {
// Thus far we have checked if the Bind() is allowed // Thus far we have checked if the Bind() is allowed
@@ -416,7 +476,7 @@ EndpointManager::_Bind(TCPEndpoint *endpoint, const sockaddr *address)
status_t status_t
EndpointManager::Unbind(TCPEndpoint *endpoint) EndpointManager::Unbind(TCPEndpoint* endpoint)
{ {
TRACE(("EndpointManager::Unbind(%p)\n", endpoint)); TRACE(("EndpointManager::Unbind(%p)\n", endpoint));
T(Unbind(endpoint)); T(Unbind(endpoint));
@@ -440,12 +500,11 @@ EndpointManager::Unbind(TCPEndpoint *endpoint)
status_t status_t
EndpointManager::ReplyWithReset(tcp_segment_header &segment, EndpointManager::ReplyWithReset(tcp_segment_header& segment, net_buffer* buffer)
net_buffer *buffer)
{ {
TRACE(("TCP: Sending RST...\n")); TRACE(("TCP: Sending RST...\n"));
net_buffer *reply = gBufferModule->create(512); net_buffer* reply = gBufferModule->create(512);
if (reply == NULL) if (reply == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;