mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
2134. [func] Additional statistics support. [RT #16666]
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: socket.c,v 1.268 2007/01/10 18:56:20 explorer Exp $ */
|
||||
/* $Id: socket.c,v 1.269 2007/02/13 02:49:08 marka Exp $ */
|
||||
|
||||
/*! \file */
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include <isc/task.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/xml.h>
|
||||
|
||||
#include "errno2result.h"
|
||||
|
||||
@@ -63,6 +64,11 @@
|
||||
#include "socket_p.h"
|
||||
#endif /* ISC_PLATFORM_USETHREADS */
|
||||
|
||||
/*
|
||||
* Support names for sockets.
|
||||
*/
|
||||
#define ISC_SOCKET_NAMES 1
|
||||
|
||||
/*%
|
||||
* Some systems define the socket length argument as an int, some as size_t,
|
||||
* some as socklen_t. This is here so it can be easily changed if needed.
|
||||
@@ -155,6 +161,11 @@ struct isc_socket {
|
||||
int fd;
|
||||
int pf;
|
||||
|
||||
#ifdef ISC_SOCKET_NAMES
|
||||
char name[16];
|
||||
void * tag;
|
||||
#endif
|
||||
|
||||
ISC_LIST(isc_socketevent_t) send_list;
|
||||
ISC_LIST(isc_socketevent_t) recv_list;
|
||||
ISC_LIST(isc_socket_newconnev_t) accept_list;
|
||||
@@ -1621,6 +1632,11 @@ isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type,
|
||||
}
|
||||
#endif /* defined(USE_CMSG) || defined(SO_RCVBUF) */
|
||||
|
||||
#ifdef ISC_SOCKET_NAMES
|
||||
memset(sock->name, 0, sizeof(sock->name));
|
||||
sock->tag = NULL;
|
||||
#endif
|
||||
|
||||
sock->references = 1;
|
||||
*socketp = sock;
|
||||
|
||||
@@ -3958,3 +3974,144 @@ isc__socketmgr_dispatch(fd_set *readset, fd_set *writeset, int maxfd) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
#endif /* ISC_PLATFORM_USETHREADS */
|
||||
|
||||
void
|
||||
isc_socket_setname(isc_socket_t *socket, const char *name, void *tag) {
|
||||
|
||||
/*
|
||||
* Name 'socket'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_SOCKET(socket));
|
||||
|
||||
#ifdef ISC_SOCKET_NAMES
|
||||
LOCK(&socket->lock);
|
||||
memset(socket->name, 0, sizeof(socket->name));
|
||||
strncpy(socket->name, name, sizeof(socket->name) - 1);
|
||||
socket->tag = tag;
|
||||
UNLOCK(&socket->lock);
|
||||
#else
|
||||
UNUSED(name);
|
||||
UNUSED(tag);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
const char *
|
||||
isc_socket_getname(isc_socket_t *socket) {
|
||||
return (socket->name);
|
||||
}
|
||||
|
||||
void *
|
||||
isc_socket_gettag(isc_socket_t *socket) {
|
||||
return (socket->tag);
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBXML2
|
||||
|
||||
static const char *
|
||||
_socktype(int type)
|
||||
{
|
||||
if (type == 1)
|
||||
return ("udp");
|
||||
else if (type == 2)
|
||||
return ("tcp");
|
||||
else if (type == 3)
|
||||
return ("unix");
|
||||
else if (type == 4)
|
||||
return ("fdwatch");
|
||||
else
|
||||
return ("not-initialized");
|
||||
}
|
||||
|
||||
void
|
||||
isc_socketmgr_renderxml(isc_socketmgr_t *mgr, xmlTextWriterPtr writer)
|
||||
{
|
||||
isc_socket_t *sock;
|
||||
char peerbuf[ISC_SOCKADDR_FORMATSIZE];
|
||||
isc_sockaddr_t addr;
|
||||
ISC_SOCKADDR_LEN_T len;
|
||||
|
||||
LOCK(&mgr->lock);
|
||||
|
||||
#ifndef ISC_PLATFORM_USETHREADS
|
||||
xmlTextWriterStartElement(writer, ISC_XMLCHAR "references");
|
||||
xmlTextWriterWriteFormatString(writer, "%d", mgr->refs);
|
||||
xmlTextWriterEndElement(writer);
|
||||
#endif
|
||||
|
||||
xmlTextWriterStartElement(writer, ISC_XMLCHAR "sockets");
|
||||
sock = ISC_LIST_HEAD(mgr->socklist);
|
||||
while (sock != NULL) {
|
||||
LOCK(&sock->lock);
|
||||
xmlTextWriterStartElement(writer, ISC_XMLCHAR "socket");
|
||||
|
||||
xmlTextWriterStartElement(writer, ISC_XMLCHAR "id");
|
||||
xmlTextWriterWriteFormatString(writer, "%p", sock);
|
||||
xmlTextWriterEndElement(writer);
|
||||
|
||||
if (sock->name[0] != 0) {
|
||||
xmlTextWriterStartElement(writer, ISC_XMLCHAR "name");
|
||||
xmlTextWriterWriteFormatString(writer, "%s",
|
||||
sock->name);
|
||||
xmlTextWriterEndElement(writer); /* name */
|
||||
}
|
||||
|
||||
xmlTextWriterStartElement(writer, ISC_XMLCHAR "references");
|
||||
xmlTextWriterWriteFormatString(writer, "%d", sock->references);
|
||||
xmlTextWriterEndElement(writer);
|
||||
|
||||
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "type",
|
||||
ISC_XMLCHAR _socktype(sock->type));
|
||||
|
||||
if (sock->connected) {
|
||||
isc_sockaddr_format(&sock->peer_address, peerbuf,
|
||||
sizeof(peerbuf));
|
||||
xmlTextWriterWriteElement(writer,
|
||||
ISC_XMLCHAR "peer-address",
|
||||
ISC_XMLCHAR peerbuf);
|
||||
}
|
||||
|
||||
len = sizeof(addr);
|
||||
if (getsockname(sock->fd, &addr.type.sa, (void *)&len) == 0) {
|
||||
isc_sockaddr_format(&addr, peerbuf, sizeof(peerbuf));
|
||||
xmlTextWriterWriteElement(writer,
|
||||
ISC_XMLCHAR "local-address",
|
||||
ISC_XMLCHAR peerbuf);
|
||||
}
|
||||
|
||||
xmlTextWriterStartElement(writer, ISC_XMLCHAR "states");
|
||||
if (sock->pending_recv)
|
||||
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
|
||||
ISC_XMLCHAR "pending-receive");
|
||||
if (sock->pending_send)
|
||||
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
|
||||
ISC_XMLCHAR "pending-send");
|
||||
if (sock->pending_accept)
|
||||
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
|
||||
ISC_XMLCHAR "pending_accept");
|
||||
if (sock->listener)
|
||||
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
|
||||
ISC_XMLCHAR "listener");
|
||||
if (sock->connected)
|
||||
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
|
||||
ISC_XMLCHAR "connected");
|
||||
if (sock->connecting)
|
||||
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
|
||||
ISC_XMLCHAR "connecting");
|
||||
if (sock->bound)
|
||||
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
|
||||
ISC_XMLCHAR "bound");
|
||||
|
||||
xmlTextWriterEndElement(writer); /* states */
|
||||
|
||||
xmlTextWriterEndElement(writer); /* socket */
|
||||
|
||||
UNLOCK(&sock->lock);
|
||||
sock = ISC_LIST_NEXT(sock, link);
|
||||
}
|
||||
xmlTextWriterEndElement(writer); /* sockets */
|
||||
|
||||
UNLOCK(&mgr->lock);
|
||||
}
|
||||
#endif /* HAVE_LIBXML2 */
|
||||
|
Reference in New Issue
Block a user