1/*	$NetBSD$	*/
2
3/* back-monitor.h - ldap monitor back-end header file */
4/* OpenLDAP: pkg/ldap/servers/slapd/back-monitor/back-monitor.h,v 1.52.2.9 2010/04/13 20:23:32 kurt Exp */
5/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 2001-2010 The OpenLDAP Foundation.
8 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted only as authorized by the OpenLDAP
13 * Public License.
14 *
15 * A copy of this license is available in file LICENSE in the
16 * top-level directory of the distribution or, alternatively, at
17 * <http://www.OpenLDAP.org/license.html>.
18 */
19/* ACKNOWLEDGEMENTS:
20 * This work was initially developed by Pierangelo Masarati for inclusion
21 * in OpenLDAP Software.
22 */
23
24#ifndef _BACK_MONITOR_H_
25#define _BACK_MONITOR_H_
26
27#include <ldap_pvt.h>
28#include <ldap_pvt_thread.h>
29#include <avl.h>
30#include <slap.h>
31
32LDAP_BEGIN_DECL
33
34/* define if si_ad_labeledURI is removed from slap_schema */
35#undef MONITOR_DEFINE_LABELEDURI
36
37typedef struct monitor_callback_t {
38	int				(*mc_update)( Operation *op, SlapReply *rs, Entry *e, void *priv );
39						/* update callback
40						   for user-defined entries */
41	int				(*mc_modify)( Operation *op, SlapReply *rs, Entry *e, void *priv );
42						/* modify callback
43						   for user-defined entries */
44	int				(*mc_free)( Entry *e, void **priv );
45						/* delete callback
46						   for user-defined entries */
47	void				(*mc_dispose)( void **priv );
48						/* dispose callback
49						   to dispose of the callback
50						   private data itself */
51	void				*mc_private;	/* opaque pointer to
52						   private data */
53	struct monitor_callback_t	*mc_next;
54} monitor_callback_t;
55
56
57typedef struct monitor_entry_t {
58	ldap_pvt_thread_mutex_t	mp_mutex;	/* entry mutex */
59	Entry			*mp_next;	/* pointer to next sibling */
60	Entry			*mp_children;	/* pointer to first child */
61	struct monitor_subsys_t	*mp_info;	/* subsystem info */
62#define mp_type		mp_info->mss_type
63	unsigned long		mp_flags;	/* flags */
64
65#define	MONITOR_F_NONE		0x0000U
66#define MONITOR_F_SUB		0x0001U		/* subentry of subsystem */
67#define MONITOR_F_PERSISTENT	0x0010U		/* persistent entry */
68#define MONITOR_F_PERSISTENT_CH	0x0020U		/* subsystem generates
69						   persistent entries */
70#define MONITOR_F_VOLATILE	0x0040U		/* volatile entry */
71#define MONITOR_F_VOLATILE_CH	0x0080U		/* subsystem generates
72						   volatile entries */
73#define MONITOR_F_EXTERNAL	0x0100U		/* externally added - don't free */
74/* NOTE: flags with 0xF0000000U mask are reserved for subsystem internals */
75
76	struct monitor_callback_t	*mp_cb;		/* callback sequence */
77} monitor_entry_t;
78
79struct entry_limbo_t;			/* in init.c */
80
81typedef struct monitor_info_t {
82
83	/*
84	 * Internal data
85	 */
86	Avlnode			*mi_cache;
87	ldap_pvt_thread_mutex_t	mi_cache_mutex;
88
89	/*
90	 * Config parameters
91	 */
92	struct berval		mi_startTime;		/* don't free it! */
93	struct berval		mi_creatorsName;	/* don't free it! */
94	struct berval		mi_ncreatorsName;	/* don't free it! */
95
96	/*
97	 * Specific schema entities
98	 */
99	ObjectClass		*mi_oc_monitor;
100	ObjectClass		*mi_oc_monitorServer;
101	ObjectClass		*mi_oc_monitorContainer;
102	ObjectClass		*mi_oc_monitorCounterObject;
103	ObjectClass		*mi_oc_monitorOperation;
104	ObjectClass		*mi_oc_monitorConnection;
105	ObjectClass		*mi_oc_managedObject;
106	ObjectClass		*mi_oc_monitoredObject;
107
108	AttributeDescription	*mi_ad_monitoredInfo;
109	AttributeDescription	*mi_ad_managedInfo;
110	AttributeDescription	*mi_ad_monitorCounter;
111	AttributeDescription	*mi_ad_monitorOpCompleted;
112	AttributeDescription	*mi_ad_monitorOpInitiated;
113	AttributeDescription	*mi_ad_monitorConnectionNumber;
114	AttributeDescription	*mi_ad_monitorConnectionAuthzDN;
115	AttributeDescription	*mi_ad_monitorConnectionLocalAddress;
116	AttributeDescription	*mi_ad_monitorConnectionPeerAddress;
117	AttributeDescription	*mi_ad_monitorTimestamp;
118	AttributeDescription	*mi_ad_monitorOverlay;
119	AttributeDescription	*mi_ad_monitorConnectionProtocol;
120	AttributeDescription	*mi_ad_monitorConnectionOpsReceived;
121	AttributeDescription	*mi_ad_monitorConnectionOpsExecuting;
122	AttributeDescription	*mi_ad_monitorConnectionOpsPending;
123	AttributeDescription	*mi_ad_monitorConnectionOpsCompleted;
124	AttributeDescription	*mi_ad_monitorConnectionGet;
125	AttributeDescription	*mi_ad_monitorConnectionRead;
126	AttributeDescription	*mi_ad_monitorConnectionWrite;
127	AttributeDescription	*mi_ad_monitorConnectionMask;
128	AttributeDescription	*mi_ad_monitorConnectionListener;
129	AttributeDescription	*mi_ad_monitorConnectionPeerDomain;
130	AttributeDescription	*mi_ad_monitorConnectionStartTime;
131	AttributeDescription	*mi_ad_monitorConnectionActivityTime;
132	AttributeDescription	*mi_ad_monitorIsShadow;
133	AttributeDescription	*mi_ad_monitorUpdateRef;
134	AttributeDescription	*mi_ad_monitorRuntimeConfig;
135	AttributeDescription	*mi_ad_monitorSuperiorDN;
136
137	/*
138	 * Generic description attribute
139	 */
140	AttributeDescription	*mi_ad_readOnly;
141	AttributeDescription	*mi_ad_restrictedOperation;
142
143	struct entry_limbo_t	*mi_entry_limbo;
144} monitor_info_t;
145
146/*
147 * DNs
148 */
149
150enum {
151	SLAPD_MONITOR_BACKEND = 0,
152	SLAPD_MONITOR_CONN,
153	SLAPD_MONITOR_DATABASE,
154	SLAPD_MONITOR_LISTENER,
155	SLAPD_MONITOR_LOG,
156	SLAPD_MONITOR_OPS,
157	SLAPD_MONITOR_OVERLAY,
158	SLAPD_MONITOR_SASL,
159	SLAPD_MONITOR_SENT,
160	SLAPD_MONITOR_THREAD,
161	SLAPD_MONITOR_TIME,
162	SLAPD_MONITOR_TLS,
163	SLAPD_MONITOR_RWW,
164
165	SLAPD_MONITOR_LAST
166};
167
168#define SLAPD_MONITOR_AT		"cn"
169
170#define SLAPD_MONITOR_BACKEND_NAME	"Backends"
171#define SLAPD_MONITOR_BACKEND_RDN	\
172	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_BACKEND_NAME
173#define SLAPD_MONITOR_BACKEND_DN	\
174	SLAPD_MONITOR_BACKEND_RDN "," SLAPD_MONITOR_DN
175
176#define SLAPD_MONITOR_CONN_NAME		"Connections"
177#define SLAPD_MONITOR_CONN_RDN	\
178	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_CONN_NAME
179#define SLAPD_MONITOR_CONN_DN	\
180	SLAPD_MONITOR_CONN_RDN "," SLAPD_MONITOR_DN
181
182#define SLAPD_MONITOR_DATABASE_NAME	"Databases"
183#define SLAPD_MONITOR_DATABASE_RDN	\
184	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_DATABASE_NAME
185#define SLAPD_MONITOR_DATABASE_DN	\
186	SLAPD_MONITOR_DATABASE_RDN "," SLAPD_MONITOR_DN
187
188#define SLAPD_MONITOR_LISTENER_NAME	"Listeners"
189#define SLAPD_MONITOR_LISTENER_RDN	\
190	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_LISTENER_NAME
191#define SLAPD_MONITOR_LISTENER_DN	\
192	SLAPD_MONITOR_LISTENER_RDN "," SLAPD_MONITOR_DN
193
194#define SLAPD_MONITOR_LOG_NAME		"Log"
195#define SLAPD_MONITOR_LOG_RDN	\
196	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_LOG_NAME
197#define SLAPD_MONITOR_LOG_DN	\
198	SLAPD_MONITOR_LOG_RDN "," SLAPD_MONITOR_DN
199
200#define SLAPD_MONITOR_OPS_NAME		"Operations"
201#define SLAPD_MONITOR_OPS_RDN	\
202	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_OPS_NAME
203#define SLAPD_MONITOR_OPS_DN	\
204	SLAPD_MONITOR_OPS_RDN "," SLAPD_MONITOR_DN
205
206#define SLAPD_MONITOR_OVERLAY_NAME	"Overlays"
207#define SLAPD_MONITOR_OVERLAY_RDN  \
208	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_OVERLAY_NAME
209#define SLAPD_MONITOR_OVERLAY_DN   \
210	SLAPD_MONITOR_OVERLAY_RDN "," SLAPD_MONITOR_DN
211
212#define SLAPD_MONITOR_SASL_NAME		"SASL"
213#define SLAPD_MONITOR_SASL_RDN	\
214	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_SASL_NAME
215#define SLAPD_MONITOR_SASL_DN	\
216	SLAPD_MONITOR_SASL_RDN "," SLAPD_MONITOR_DN
217
218#define SLAPD_MONITOR_SENT_NAME		"Statistics"
219#define SLAPD_MONITOR_SENT_RDN	\
220	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_SENT_NAME
221#define SLAPD_MONITOR_SENT_DN	\
222	SLAPD_MONITOR_SENT_RDN "," SLAPD_MONITOR_DN
223
224#define SLAPD_MONITOR_THREAD_NAME	"Threads"
225#define SLAPD_MONITOR_THREAD_RDN	\
226	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_THREAD_NAME
227#define SLAPD_MONITOR_THREAD_DN	\
228	SLAPD_MONITOR_THREAD_RDN "," SLAPD_MONITOR_DN
229
230#define SLAPD_MONITOR_TIME_NAME		"Time"
231#define SLAPD_MONITOR_TIME_RDN  \
232	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_TIME_NAME
233#define SLAPD_MONITOR_TIME_DN   \
234	SLAPD_MONITOR_TIME_RDN "," SLAPD_MONITOR_DN
235
236#define SLAPD_MONITOR_TLS_NAME		"TLS"
237#define SLAPD_MONITOR_TLS_RDN	\
238	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_TLS_NAME
239#define SLAPD_MONITOR_TLS_DN	\
240	SLAPD_MONITOR_TLS_RDN "," SLAPD_MONITOR_DN
241
242#define SLAPD_MONITOR_RWW_NAME		"Waiters"
243#define SLAPD_MONITOR_RWW_RDN	\
244	SLAPD_MONITOR_AT "=" SLAPD_MONITOR_RWW_NAME
245#define SLAPD_MONITOR_RWW_DN	\
246	SLAPD_MONITOR_RWW_RDN "," SLAPD_MONITOR_DN
247
248typedef struct monitor_subsys_t {
249	char		*mss_name;
250	struct berval	mss_rdn;
251	struct berval	mss_dn;
252	struct berval	mss_ndn;
253	struct berval	mss_desc[ 3 ];
254	int		mss_flags;
255#define MONITOR_F_OPENED	0x10000000U
256
257#define MONITOR_HAS_VOLATILE_CH( mp ) \
258	( ( mp )->mp_flags & MONITOR_F_VOLATILE_CH )
259#define MONITOR_HAS_CHILDREN( mp ) \
260	( ( mp )->mp_children || MONITOR_HAS_VOLATILE_CH( mp ) )
261
262	/* initialize entry and subentries */
263	int		( *mss_open )( BackendDB *, struct monitor_subsys_t *ms );
264	/* destroy structure */
265	int		( *mss_destroy )( BackendDB *, struct monitor_subsys_t *ms );
266	/* update existing dynamic entry and subentries */
267	int		( *mss_update )( Operation *, SlapReply *, Entry * );
268	/* create new dynamic subentries */
269	int		( *mss_create )( Operation *, SlapReply *,
270				struct berval *ndn, Entry *, Entry ** );
271	/* modify entry and subentries */
272	int		( *mss_modify )( Operation *, SlapReply *, Entry * );
273} monitor_subsys_t;
274
275extern BackendDB *be_monitor;
276
277/* increase this bufsize if entries in string form get too big */
278#define BACKMONITOR_BUFSIZE	8192
279
280typedef int (monitor_cbfunc)( struct berval *ndn, monitor_callback_t *cb,
281	struct berval *base, int scope, struct berval *filter );
282
283typedef int (monitor_cbafunc)( struct berval *ndn, Attribute *a,
284	monitor_callback_t *cb,
285	struct berval *base, int scope, struct berval *filter );
286
287typedef struct monitor_extra_t {
288	int (*is_configured)(void);
289	monitor_subsys_t * (*get_subsys)( const char *name );
290	monitor_subsys_t * (*get_subsys_by_dn)( struct berval *ndn, int sub );
291
292	int (*register_subsys)( monitor_subsys_t *ms );
293	int (*register_backend)( BackendInfo *bi );
294	int (*register_database)( BackendDB *be, struct berval *ndn_out );
295	int (*register_overlay_info)( slap_overinst *on );
296	int (*register_overlay)( BackendDB *be, slap_overinst *on, struct berval *ndn_out );
297	int (*register_entry)( Entry *e, monitor_callback_t *cb,
298		monitor_subsys_t *ms, unsigned long flags );
299	int (*register_entry_parent)( Entry *e, monitor_callback_t *cb,
300		monitor_subsys_t *ms, unsigned long flags,
301		struct berval *base, int scope, struct berval *filter );
302	monitor_cbafunc *register_entry_attrs;
303	monitor_cbfunc *register_entry_callback;
304
305	int (*unregister_entry)( struct berval *ndn );
306	monitor_cbfunc *unregister_entry_parent;
307	monitor_cbafunc *unregister_entry_attrs;
308	monitor_cbfunc *unregister_entry_callback;
309} monitor_extra_t;
310
311LDAP_END_DECL
312
313#include "proto-back-monitor.h"
314
315#endif /* _back_monitor_h_ */
316
317