From c8d174ad00f02d27dbc4c211a45dbb99685cced6 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Tue, 11 Jul 2017 16:06:16 -0400 Subject: [PATCH] Ticket 48210 - Add IP addr and connid to monitor output Description: Add the IP address and connection id to the "connection" attribute under cn=monitor: Previous "connection" format: FD:DATE:OPS_INITIATED:OPS_COMPLETE:GET_BER:BIND_DN:MAX_THREAD_STATE:MAXTHREAD_COUNT:MAX_THREAD_BLOCKED connection: 64:20170711175127Z:1:1:-:cn=dm:0:0:0 New "connection" format: FD:DATE:OPS_INITIATED:OPS_COMPLETE:GET_BER:BIND_DN:MAX_THREAD_STATE:MAXTHREAD_COUNT:MAX_THREAD_BLOCKED:CONNID:ip=IP_ADDR connection: 64:20170711175127Z:1:1:-:cn=dm:0:0:0:1:ip=127.0.0.1 connection: 65:20170711200508Z:2:1:-:cn=dm:0:0:0:5:ip=::1 https://pagure.io/389-ds-base/issue/48210 Reviewed by: ? --- ldap/servers/slapd/connection.c | 2 ++ ldap/servers/slapd/conntable.c | 33 +++++++++++++++++++++++++-------- ldap/servers/slapd/slap.h | 1 + 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/ldap/servers/slapd/connection.c b/ldap/servers/slapd/connection.c index d3b0f7e..ccd70ad 100644 --- a/ldap/servers/slapd/connection.c +++ b/ldap/servers/slapd/connection.c @@ -207,6 +207,7 @@ connection_cleanup(Connection *conn) conn->c_isreplication_session = 0; slapi_ch_free((void**)&conn->cin_addr ); slapi_ch_free((void**)&conn->cin_destaddr ); + slapi_ch_free_string(&conn->c_ipaddr); if ( conn->c_domain != NULL ) { ber_bvecfree( conn->c_domain ); @@ -422,6 +423,7 @@ connection_reset(Connection* conn, int ns, PRNetAddr * from, int fromLen __attri * yet, which prevents us from getting the effective key length. */ conn->c_ssl_ssf = 0; conn->c_local_ssf = 0; + conn->c_ipaddr = slapi_ch_strdup(str_ip); } /* Create a pool of threads for handling the operations */ diff --git a/ldap/servers/slapd/conntable.c b/ldap/servers/slapd/conntable.c index 1c6757d..d84b76d 100644 --- a/ldap/servers/slapd/conntable.c +++ b/ldap/servers/slapd/conntable.c @@ -366,10 +366,19 @@ connection_table_as_entry(Connection_Table *ct, Slapi_Entry *e) { char buf2[20]; int lendn = ct->c[i].c_dn ? strlen(ct->c[i].c_dn) : 6; /* "NULLDN" */ + int lenip = ct->c[i].c_ipaddr ? strlen(ct->c[i].c_ipaddr) : 0; + int lenconn = 1; + uint64_t connid = ct->c[i].c_connid; char *bufptr = &buf[0]; char *newbuf = NULL; int maxthreadstate = 0; + /* Get the connid length */ + while (connid > 9) { + lenconn++; + connid /= 10; + } + if(ct->c[i].c_flags & CONN_FLAG_MAX_THREADS){ maxthreadstate = 1; } @@ -397,25 +406,33 @@ connection_table_as_entry(Connection_Table *ct, Slapi_Entry *e) maxthreadstate, ct->c[i].c_maxthreadscount, ct->c[i].c_maxthreadsblocked); - if ((lendn + strlen(maxthreadbuf)) > (BUFSIZ - 46)) { + if ((lenconn + lenip + lendn + strlen(maxthreadbuf)) > (BUFSIZ - 56)) { /* - * 46 = 4 for the "i" couter + 20 for buf2 + - * 10 for c_opsinitiated + 10 for c_opscompleted + - * 1 for c_gettingber + 1 + * 56 = 10 for the colon separators + + * 6 for the "i" counter + + * 15 for buf2 (date) + + * 10 for c_opsinitiated + + * 10 for c_opscompleted + + * 1 for c_gettingber + + * 3 for "ip=" + + * 1 for NULL terminator */ - newbuf = (char *) slapi_ch_malloc(lendn + strlen(maxthreadbuf) + 46); + newbuf = (char *) slapi_ch_malloc(lenconn + lendn + lenip + strlen(maxthreadbuf) + 56); bufptr = newbuf; } - sprintf( bufptr, "%d:%s:%d:%d:%s%s:%s:%s", i, + sprintf( bufptr, "%d:%s:%d:%d:%s%s:%s:%s:%lu:ip=%s", + i, buf2, ct->c[i].c_opsinitiated, ct->c[i].c_opscompleted, ct->c[i].c_gettingber ? "r" : "-", "", ct->c[i].c_dn ? ct->c[i].c_dn : "NULLDN", - maxthreadbuf - ); + maxthreadbuf, + ct->c[i].c_connid, + ct->c[i].c_ipaddr + ); val.bv_val = bufptr; val.bv_len = strlen( bufptr ); attrlist_merge( &e->e_attrs, "connection", vals ); diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h index 5edaf43..d26a792 100644 --- a/ldap/servers/slapd/slap.h +++ b/ldap/servers/slapd/slap.h @@ -1605,6 +1605,7 @@ typedef struct conn { struct connection_table *c_ct; /* connection table that this connection belongs to */ ns_thrpool_t *c_tp; /* thread pool for this connection */ int c_ns_close_jobs; /* number of current close jobs */ + char *c_ipaddr; /* ip address str - used by monitor */ } Connection; #define CONN_FLAG_SSL 1 /* Is this connection an SSL connection or not ? * Used to direct I/O code when SSL is handled differently -- 2.9.4