1 /* conn.c - deal with connection subsystem */
3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
9 * This work has beed deveolped for the OpenLDAP Foundation
10 * in the hope that it may be useful to the Open Source community,
11 * but WITHOUT ANY WARRANTY.
13 * Permission is granted to anyone to use this software for any purpose
14 * on any computer system, and to alter it and redistribute it, subject
15 * to the following restrictions:
17 * 1. The author and SysNet s.n.c. are not responsible for the consequences
18 * of use of this software, no matter how awful, even if they arise from
21 * 2. The origin of this software must not be misrepresented, either by
22 * explicit claim or by omission. Since few users ever read sources,
23 * credits should appear in the documentation.
25 * 3. Altered versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software. Since few users
27 * ever read sources, credits should appear in the documentation.
28 * SysNet s.n.c. cannot be responsible for the consequences of the
31 * 4. This notice may not be removed or altered.
39 #include "back-monitor.h"
41 #define CONN_CN_PREFIX "Connection"
44 monitor_subsys_conn_init(
48 struct monitorinfo *mi;
50 Entry *e, *e_tmp, *e_conn;
51 struct monitorentrypriv *mp;
57 mi = ( struct monitorinfo * )be->be_private;
59 if ( monitor_cache_get( mi,
60 &monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e_conn ) ) {
62 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
63 "monitor_subsys_conn_init: "
64 "unable to get entry '%s'\n",
65 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
67 Debug( LDAP_DEBUG_ANY,
68 "monitor_subsys_conn_init: "
69 "unable to get entry '%s'\n%s%s",
70 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
81 snprintf( buf, sizeof( buf ),
83 SLAPD_MONITOR_OBJECTCLASSES
85 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val );
90 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
91 "monitor_subsys_conn_init: "
92 "unable to create entry 'cn=Total,%s'\n",
93 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
95 Debug( LDAP_DEBUG_ANY,
96 "monitor_subsys_conn_init: "
97 "unable to create entry 'cn=Total,%s'\n%s%s",
98 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
107 attr_merge( e, monitor_ad_desc, bv );
109 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
110 e->e_private = ( void * )mp;
112 mp->mp_children = NULL;
113 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN];
114 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \
115 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
116 mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
118 if ( monitor_cache_add( mi, e ) ) {
120 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
121 "monitor_subsys_conn_init: "
122 "unable to add entry 'cn=Total,%s'\n",
123 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
125 Debug( LDAP_DEBUG_ANY,
126 "monitor_subsys_conn_init: "
127 "unable to add entry 'cn=Total,%s'\n%s%s",
128 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
139 snprintf( buf, sizeof( buf ),
140 "dn: cn=Current,%s\n"
141 SLAPD_MONITOR_OBJECTCLASSES
143 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val );
145 e = str2entry( buf );
148 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
149 "monitor_subsys_conn_init: "
150 "unable to create entry 'cn=Current,%s'\n",
151 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
153 Debug( LDAP_DEBUG_ANY,
154 "monitor_subsys_conn_init: "
155 "unable to create entry 'cn=Current,%s'\n%s%s",
156 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
162 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
163 e->e_private = ( void * )mp;
165 mp->mp_children = NULL;
166 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN];
167 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \
168 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
169 mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
171 if ( monitor_cache_add( mi, e ) ) {
173 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
174 "monitor_subsys_conn_init: "
175 "unable to add entry 'cn=Current,%s'\n",
176 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
178 Debug( LDAP_DEBUG_ANY,
179 "monitor_subsys_conn_init: "
180 "unable to add entry 'cn=Current,%s'\n%s%s",
181 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
189 mp = ( struct monitorentrypriv * )e_conn->e_private;
190 mp->mp_children = e_tmp;
192 monitor_cache_release( mi, e_conn );
198 monitor_subsys_conn_update(
199 struct monitorinfo *mi,
208 if ( strncasecmp( e->e_ndn, "CN=TOTAL",
209 sizeof("CN=TOTAL")-1 ) == 0 ) {
210 n = connections_nextid();
212 } else if ( strncasecmp( e->e_ndn, "CN=CURRENT",
213 sizeof("CN=CURRENT")-1 ) == 0 ) {
217 for ( n = 0, c = connection_first( &connindex );
219 n++, c = connection_next( c, &connindex ) ) {
229 a = attr_find( e->e_attrs, monitor_ad_desc );
234 snprintf( buf, sizeof( buf ), "%ld", n );
235 free( a->a_vals[ 0 ].bv_val );
236 ber_str2bv( buf, 0, 1, a->a_vals );
248 struct monitorentrypriv *mp;
259 assert( ep != NULL );
261 snprintf( buf, sizeof( buf ),
262 "dn: cn=" CONN_CN_PREFIX " %ld,%s\n"
263 SLAPD_MONITOR_OBJECTCLASSES
264 "cn: " CONN_CN_PREFIX " %ld\n",
265 c->c_connid, monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val,
267 e = str2entry( buf );
271 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
272 "monitor_subsys_conn_create: "
273 "unable to create entry "
274 "'cn=" CONN_CN_PREFIX " %ld,%s' entry\n",
276 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val ));
278 Debug( LDAP_DEBUG_ANY,
279 "monitor_subsys_conn_create: "
280 "unable to create entry "
281 "'cn=" CONN_CN_PREFIX " %ld,%s' entry\n",
283 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val, 0 );
288 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
290 ltm = gmtime( &c->c_starttime );
291 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
293 ltm = gmtime( &c->c_activitytime );
294 strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
296 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
304 ": %s : %s : %s : %s",
306 (long) c->c_protocol,
307 c->c_n_ops_received, c->c_n_ops_executing,
308 c->c_n_ops_pending, c->c_n_ops_completed,
310 /* add low-level counters here */
311 c->c_n_get, c->c_n_read, c->c_n_write,
313 c->c_currentber ? "r" : "",
314 c->c_writewaiter ? "w" : "",
315 LDAP_STAILQ_EMPTY( &c->c_ops ) ? "" : "x",
316 LDAP_STAILQ_EMPTY( &c->c_pending_ops ) ? "" : "p",
317 connection_state2str( c->c_conn_state ),
318 c->c_sasl_bind_in_progress ? "S" : "",
320 c->c_cdn.bv_len ? c->c_cdn.bv_val : SLAPD_ANONYMOUS,
322 c->c_listener_url.bv_val,
323 c->c_peer_domain.bv_val,
324 c->c_peer_name.bv_val,
325 c->c_sock_name.bv_val,
333 bv[0].bv_len = strlen( buf );
334 attr_merge( e, monitor_ad_desc, bv );
336 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
337 e->e_private = ( void * )mp;
338 mp->mp_info = &monitor_subsys[ SLAPD_MONITOR_CONN ];
339 mp->mp_children = NULL;
340 mp->mp_flags = MONITOR_F_SUB | MONITOR_F_VOLATILE;
348 monitor_subsys_conn_create(
349 struct monitorinfo *mi,
357 struct monitorentrypriv *mp;
359 assert( mi != NULL );
360 assert( e_parent != NULL );
361 assert( ep != NULL );
366 Entry *e, *e_tmp = NULL;
368 /* create all the children of e_parent */
369 for ( c = connection_first( &connindex );
371 c = connection_next( c, &connindex )) {
372 if ( conn_create( c, &e ) || e == NULL ) {
374 for ( ; e_tmp != NULL; ) {
375 mp = ( struct monitorentrypriv * )e_tmp->e_private;
379 e_tmp->e_private = NULL;
386 mp = ( struct monitorentrypriv * )e->e_private;
395 LDAPRDN *values = NULL;
396 const char *text = NULL;
397 unsigned long connid;
399 /* create exactly the required entry */
401 if ( ldap_bv2rdn( ndn, &values, (char **)&text,
402 LDAP_DN_FORMAT_LDAP ) )
408 assert( values[ 0 ][ 0 ] );
410 connid = atol( values[ 0 ][ 0 ]->la_value.bv_val
411 + sizeof( CONN_CN_PREFIX ) );
413 ldap_rdnfree( values );
415 for ( c = connection_first( &connindex );
417 c = connection_next( c, &connindex )) {
418 if ( c->c_connid == connid ) {
419 if ( conn_create( c, ep ) || *ep == NULL ) {